Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use ScopedValues for TestSets #53462

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

use ScopedValues for TestSets #53462

wants to merge 20 commits into from

Conversation

simonbyrne
Copy link
Contributor

Another attempt at #51012

@simonbyrne simonbyrne force-pushed the sb/test-scope branch 6 times, most recently from 1c67443 to b1fec32 Compare February 27, 2024 05:38
@simonbyrne
Copy link
Contributor Author

@vchuravy @Keno I'm getting some weird failures on this branch originating from this line:

@assert current_mapping == val

The simplest reproducer I have is:

using Test
@testset begin
    @testset for r in Int[1]
    end
end

@simonbyrne
Copy link
Contributor Author

Blocked by #53521

@simonbyrne simonbyrne force-pushed the sb/test-scope branch 2 times, most recently from 73b39d1 to 0cd361c Compare March 9, 2024 01:00
@nickrobinson251
Copy link
Contributor

Would love to see this merged!

@simonbyrne do you have any time to work on this? I'd be happy to rebase and help get it over the line. I think rebasing, and then deciding what to do with the commented-out scope tests might be all that's needed here?

@giordano giordano added testsystem The unit testing framework and Test stdlib stdlib Julia's standard library labels Sep 23, 2024
@giordano
Copy link
Contributor

I initially thought I managed to badly botch the rebase, but I believe this is now failing to build because after the rebase #55452 was merged in and that PR removed using .ScopedValues inside Base, so imports need to change a little bit. I'll leave this exercise to someone else 😁

@simonbyrne
Copy link
Contributor Author

Sorry, it still needs some work. The handling of errors is wasn't quite correct, and the resetting of rng state is kind of confusing (arguably should be handled differently)

@simonbyrne simonbyrne marked this pull request as ready for review October 5, 2024 03:51
@simonbyrne
Copy link
Contributor Author

Currently blocked by #56062

@d-netto
Copy link
Member

d-netto commented Jan 30, 2025

FYI, #56062 was recently fixed.

@simonbyrne
Copy link
Contributor Author

Okay, I think this is now passing. Any thoughts?

@simonbyrne
Copy link
Contributor Author

@nanosoldier runtests()

Copy link
Contributor

@giordano giordano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I recently touched the Test stdlib I'm not particularly familiar with its code, I don't understand some of the design choices. That said, this looks overall good to me (as much as that mean, not knowing the code), looks like a decent simplification. I'm going to trust hope existing tests already cover corner cases of nested testsets that we should make sure keep working.

@test sprint(show, Core.current_scope()) == "nothing"
@test sprint(show, ScopedValue{Int}()) == "$ScopedValue{$Int}(undefined)"
@test sprint(show, sval) == "$ScopedValue{$Int}(1)"
# @test sprint(show, Core.current_scope()) == "nothing"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this test commented out? Can we move it at the top-level, outside of any testset, to keep the test, or that's still within an implicit scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on how the runtests is called, it might be inside a scope. The only way to guarantee it is to run it in a separate process.

objid = sprint(show, Base.objectid(sval))
@test sprint(show, Core.current_scope()) == "Base.ScopedValues.Scope(Base.ScopedValues.ScopedValue{$Int}@$objid => 2)"
# @test sprint(show, Core.current_scope()) == "Base.ScopedValues.Scope(Base.ScopedValues.ScopedValue{$Int}@$objid => 2)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this: why was it removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, I can't see a way to make this work.

Comment on lines -1952 to -1961
"""
push_testset(ts::AbstractTestSet)

Adds the test set to the `task_local_storage`.
"""
function push_testset(ts::AbstractTestSet)
testsets = get(task_local_storage(), :__BASETESTNEXT__, AbstractTestSet[])
push!(testsets, ts)
setindex!(task_local_storage(), testsets, :__BASETESTNEXT__)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently some (testing) packages were using this: https://juliahub.com/ui/Search?type=symbols&q=push_testset&u=use. Presumably it's ok to ask them to adapt their use of internal functions? These aren't documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, unfortunately I don't see how we could keep that working

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would one update a codebase that is using push_testset? is it as simple as changing from

push_testset(ts)
try
   ...
finally
  pop_testset()
end

to

@with_testset ts begin
  ...
end

?

(p.s. Very pleased to see this improvement!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should work I think.

Comment on lines -1779 to +1774
get_testset_depth() > 1 ? rethrow() : failfast_print()
get_testset_depth() > 0 ? rethrow() : failfast_print()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't immediately tell the motivation for this change, could you please elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the check used to be inside the scope, now it is outside

simonbyrne and others added 2 commits March 2, 2025 17:50
Co-authored-by: Mosè Giordano <[email protected]>
@nanosoldier
Copy link
Collaborator

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Report summary

❗ Packages that crashed

3 packages crashed only on the current version.

  • An internal error was encountered: 1 packages
  • A segmentation fault happened: 2 packages

14 packages crashed on the previous version too.

✖ Packages that failed

181 packages failed only on the current version.

  • Package fails to precompile: 19 packages
  • Package has test failures: 3 packages
  • Package tests unexpectedly errored: 133 packages
  • Test duration exceeded the time limit: 26 packages

1132 packages failed on the previous version too.

✔ Packages that passed tests

22 packages passed tests only on the current version.

  • Other: 22 packages

5158 packages passed tests on the previous version too.

~ Packages that at least loaded

18 packages successfully loaded only on the current version.

  • Other: 18 packages

2933 packages successfully loaded on the previous version too.

➖ Packages that were skipped altogether

897 packages were skipped on the previous version too.

@simonbyrne
Copy link
Contributor Author

I think this is ready to go. @vchuravy any last thoughts?

@vchuravy
Copy link
Member

vchuravy commented Mar 9, 2025

ScopedValue use seems fine!

@giordano
Copy link
Contributor

giordano commented Mar 9, 2025

Why is llvmpasses failing on this PR? That sounds surprising https://buildkite.com/julialang/julia-master/builds/45612#01957cc9-70e1-4ef5-a7e5-f3aceedce57d/1209-1246

FAIL: Julia :: image-codegen.jl (30 of 44)
******************** TEST 'Julia :: image-codegen.jl' FAILED ********************
Exit Code: 1
Command Output (stderr):
--
RUN: at line 2: export JULIA_LLVM_ARGS="--print-before=loop-vectorize --print-module-scope"
+ export 'JULIA_LLVM_ARGS=--print-before=loop-vectorize --print-module-scope'
+ JULIA_LLVM_ARGS='--print-before=loop-vectorize --print-module-scope'
RUN: at line 3: rm -rf /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/Output/image-codegen.jl.tmp
+ rm -rf /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/Output/image-codegen.jl.tmp
RUN: at line 4: mkdir /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/Output/image-codegen.jl.tmp
+ mkdir /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/Output/image-codegen.jl.tmp
RUN: at line 5: julia --image-codegen --startup-file=no /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/image-codegen.jl 2> /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/Output/image-codegen.jl.tmp/output.txt
+ julia --image-codegen --startup-file=no /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/image-codegen.jl
RUN: at line 6: FileCheck /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/image-codegen.jl < /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/Output/image-codegen.jl.tmp/output.txt
+ FileCheck /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/image-codegen.jl
/cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/image-codegen.jl:17:15: error: CHECK-SAME: is not on the same line as the previous match
# CHECK-SAME: = {{(external )?}}
              ^
<stdin>:89:5: note: 'next' match was here
 %7 = addrspacecast ptr %6 to ptr addrspace(10), !dbg !16
    ^
<stdin>:88:32: note: previous match ended here
 %6 = load ptr, ptr @"jl_global#5", align 8, !dbg !16, !tbaa !13, !invariant.load !0, !alias.scope !17, !noalias !20, !nonnull !0
                               ^
Input file: <stdin>
Check file: /cache/build/builder-amdci5-1/julialang/julia-master/test/llvmpasses/image-codegen.jl
-dump-input=help explains the following input dump.
Input was:
<<<<<<
         .
         .
         .
        84: %4, align 8, !tbaa !13, !invariant.load !0
        85:  fence syncscope("singlethread") seq_cst
        86:  call void @julia.safepoint(ptr %5), !dbg !15
        87:  fence syncscope("singlethread") seq_cst
        88:  %6 = load ptr, ptr @"jl_global#5", align 8, !dbg !16, !tbaa !13, !invariant.load !0, !alias.scope !17, !noalias !20, !nonnull !0
        89:  %7 = addrspacecast ptr %6 to ptr addrspace(10), !dbg !16
same:17         !~                                                     error: match on wrong line
        90:  ret ptr addrspace(10) %7, !dbg !16
        91: }
        92:
        93: ; Function Attrs: noinline optnone
        94: define nonnull ptr addrspace(10) @jfptr_f_4(ptr addrspace(10) %0, ptr noalias nocapture noundef readonly %1, i32 %2) local_unnamed_addr #1 {
         .
         .
         .
>>>>>>
--
********************

@vchuravy vchuravy added the needs news A NEWS entry is required for this change label Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs news A NEWS entry is required for this change stdlib Julia's standard library testsystem The unit testing framework and Test stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants