-
Notifications
You must be signed in to change notification settings - Fork 2
test: add more tests #1
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
base: main
Are you sure you want to change the base?
Conversation
|
Let me fix the CI issue first. |
| _percpu_start = .; | ||
| _percpu_end = _percpu_start + SIZEOF(.percpu); | ||
| .percpu 0x0 (NOLOAD) : AT(_percpu_start) { | ||
| .percpu (NOLOAD) : AT(_percpu_start) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it also fix issues like arceos-org/percpu#5 and arceos-org/percpu#12? If so, you may also contribute it to percpu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change would make the load address no longer 0x0, which causes the assertions in the tests to fail. The corresponding tests would also need to be adjusted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. You may adjust the test codes accordingly.
AsakuraMizu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the threading and panic::catch_unwind part. Though there are still issues:
- There is some overlap with existing tests; let's merge them.
- What is the purpose of serial_test? If it's due to data conflicts, please isolate the data used by the test cases.
tests/tests.rs
Outdated
|
|
||
| #[allow(dead_code)] | ||
| struct Counter { | ||
| id: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of id?
tests/tests.rs
Outdated
| } | ||
|
|
||
| scope_local! { | ||
| static COUNTER: Arc<Counter> = Arc::new(Counter{id: 0}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of Arc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you may want to use an Arc<AtomicUsize>?
14e03dc to
043a26c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances test coverage for scope-local functionality by adding three new test scenarios and fixes a linker script issue to ensure tests run properly. The changes add comprehensive testing for multi-threading, panic handling, thread isolation, and nested scope behavior.
Key Changes:
- Added multi-threading and panic recovery tests to the existing
sharedtest - Introduced new
isolationtest to verify thread-local scope independence - Added new
nestedtest to verify scope stacking behavior - Fixed linker script by removing explicit
0x0VMA address from.percpusection
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/scope_local.rs | Adds panic and thread imports, extends shared test with multi-threading and panic scenarios, adds isolation and nested test functions to verify thread safety and scope nesting |
| percpu.x | Removes explicit 0x0 VMA address from .percpu section definition to allow relative positioning and ensure tests run correctly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/scope_local.rs
Outdated
|
|
||
| assert_eq!(Arc::strong_count(&SHARED), 1); | ||
|
|
||
| let handles: Vec<_> = (0..9) |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The range 0..9 creates 9 threads, which appears inconsistent with the isolation test that uses 0..10 for 10 threads. Consider using 0..10 here as well for consistency, or document why 9 threads is the intended count.
|
|
||
| ActiveScope::set_global(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line? I remember percpu delegates to thread local if target_os = "linux"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this line will cause a SIGSEGV
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this line will cause a SIGSEGV
That's strange, and may indicate a bug in our design.
| } | ||
|
|
||
| #[test] | ||
| fn isolation() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test that multiple threads share one scope?
|
I tested it several times locally and found the results to be unstable. This is likely related to an issue with |
tests/scope_local.rs
Outdated
|
|
||
| let handles: Vec<_> = (0..10) | ||
| .map(|_| { | ||
| thread::spawn(move || { | ||
| let mut scope = Scope::new(); | ||
| *SHARED.scope_mut(&mut scope) = SHARED.clone(); | ||
| assert!(Arc::strong_count(&SHARED) >= 2); | ||
| }) | ||
| }) | ||
| .collect(); | ||
|
|
||
| for h in handles { | ||
| h.join().unwrap(); | ||
| } | ||
|
|
||
| assert_eq!(Arc::strong_count(&SHARED), 1); | ||
|
|
||
| { | ||
| let mut scope = Scope::new(); | ||
| *SHARED.scope_mut(&mut scope) = SHARED.clone(); | ||
| let scope = Arc::new(scope); | ||
|
|
||
| let handles: Vec<_> = (0..10) | ||
| .map(|_| { | ||
| let scope = scope.clone(); | ||
| thread::spawn(move || { | ||
| unsafe { ActiveScope::set(&scope) }; | ||
| assert_eq!(Arc::strong_count(&SHARED), 2); | ||
| assert_eq!(*SHARED, Arc::new("qwq".to_string())); | ||
| ActiveScope::set_global(); | ||
| }) | ||
| }) | ||
| .collect(); | ||
|
|
||
| for h in handles { | ||
| h.join().unwrap(); | ||
| } | ||
| } | ||
|
|
||
| assert_eq!(Arc::strong_count(&SHARED), 1); | ||
|
|
||
| let panic = panic::catch_unwind(|| { | ||
| let mut scope = Scope::new(); | ||
| *SHARED.scope_mut(&mut scope) = SHARED.clone(); | ||
| panic!("panic"); | ||
| }); | ||
| assert!(panic.is_err()); | ||
|
|
||
| assert_eq!(Arc::strong_count(&SHARED), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test function is too large now. Let's break it down.
|
Waiting for |
adjust linker script to ensure tests run