Skip to content

Commit 7cbc40e

Browse files
committed
[#1202] Use two threads in spin lock tests
1 parent 0c35788 commit 7cbc40e

File tree

5 files changed

+64
-15
lines changed

5 files changed

+64
-15
lines changed

Cargo.Bazel.lock

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "563d0e8362e7a0fdf5edbbb67cc938f507385238ff9d2d72cd0517e12b0615f3",
2+
"checksum": "acdc53091fa5ea808b172a271bcfe34767af644bf1b1e7ca06e6ca6e12f6cb5e",
33
"crates": {
44
"addr2line 0.24.2": {
55
"name": "addr2line",
@@ -7723,6 +7723,56 @@
77237723
],
77247724
"license_file": null
77257725
},
7726+
"iceoryx2-bb-concurrency 0.7.0": {
7727+
"name": "iceoryx2-bb-concurrency",
7728+
"version": "0.7.0",
7729+
"package_url": "https://github.com/eclipse-iceoryx/iceoryx2",
7730+
"repository": null,
7731+
"targets": [
7732+
{
7733+
"Library": {
7734+
"crate_name": "iceoryx2_bb_concurrency",
7735+
"crate_root": "src/lib.rs",
7736+
"srcs": {
7737+
"allow_empty": true,
7738+
"include": [
7739+
"**/*.rs"
7740+
]
7741+
}
7742+
}
7743+
}
7744+
],
7745+
"library_target_name": "iceoryx2_bb_concurrency",
7746+
"common_attrs": {
7747+
"compile_data_glob": [
7748+
"**"
7749+
],
7750+
"crate_features": {
7751+
"common": [
7752+
"default",
7753+
"std"
7754+
],
7755+
"selects": {}
7756+
},
7757+
"edition": "2021",
7758+
"proc_macro_deps": {
7759+
"common": [
7760+
{
7761+
"id": "paste 1.0.15",
7762+
"target": "paste"
7763+
}
7764+
],
7765+
"selects": {}
7766+
},
7767+
"version": "0.7.0"
7768+
},
7769+
"license": "MIT OR Apache-2.0",
7770+
"license_ids": [
7771+
"Apache-2.0",
7772+
"MIT"
7773+
],
7774+
"license_file": null
7775+
},
77267776
"iceoryx2-bb-conformance-test-macros 0.7.0": {
77277777
"name": "iceoryx2-bb-conformance-test-macros",
77287778
"version": "0.7.0",
@@ -8830,8 +8880,7 @@
88308880
],
88318881
"crate_features": {
88328882
"common": [
8833-
"default",
8834-
"std"
8883+
"default"
88358884
],
88368885
"selects": {}
88378886
},
@@ -30960,6 +31009,7 @@
3096031009
"component-tests_rust 0.7.0": "component-tests/rust",
3096131010
"example 0.7.0": "examples",
3096231011
"iceoryx2 0.7.0": "iceoryx2",
31012+
"iceoryx2-bb-concurrency 0.7.0": "iceoryx2-bb/concurrency",
3096331013
"iceoryx2-bb-conformance-test-macros 0.7.0": "iceoryx2-bb/conformance-test-macros",
3096431014
"iceoryx2-bb-container 0.7.0": "iceoryx2-bb/container",
3096531015
"iceoryx2-bb-derive-macros 0.7.0": "iceoryx2-bb/derive-macros",
@@ -31247,6 +31297,7 @@
3124731297
"human-panic 2.0.2",
3124831298
"lazy_static 1.5.0",
3124931299
"libc 0.2.172",
31300+
"paste 1.0.15",
3125031301
"postcard 1.1.3",
3125131302
"proc-macro2 1.0.86",
3125231303
"pyo3 0.25.0",

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iceoryx2-bb/concurrency/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ rust_test_suite(
3737
deps = [
3838
":iceoryx2-bb-concurrency",
3939
"//iceoryx2-bb/elementary-traits:iceoryx2-bb-elementary-traits",
40-
"//iceoryx2-bb/posix:iceoryx2-bb-posix",
4140
"//iceoryx2-bb/testing:iceoryx2-bb-testing",
4241
"//iceoryx2-pal/concurrency-sync:iceoryx2-pal-concurrency-sync",
4342
"//iceoryx2-pal/testing:iceoryx2-pal-testing",

iceoryx2-bb/concurrency/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ iceoryx2-pal-concurrency-sync = { workspace = true }
2121
paste = { workspace = true }
2222

2323
[dev-dependencies]
24-
iceoryx2-bb-posix = { workspace = true }
2524
iceoryx2-bb-testing = { workspace = true }
2625
iceoryx2-pal-testing = { workspace = true }

iceoryx2-bb/concurrency/tests/spin_tests.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use core::alloc::Layout;
1414
use iceoryx2_bb_concurrency::spin::SpinLock;
1515
use iceoryx2_bb_elementary_traits::placement_default::PlacementDefault;
16-
use iceoryx2_bb_posix::system_configuration::SystemInfo;
1716
use iceoryx2_bb_testing::lifetime_tracker::LifetimeTracker;
1817
use iceoryx2_bb_testing::{assert_that, watchdog::Watchdog};
1918
use std::alloc::{alloc, dealloc};
@@ -48,12 +47,13 @@ fn lock_guard_behaves_like_reference() {
4847

4948
#[test]
5049
fn blocking_lock_locks_exclusively() {
50+
const NUMBER_OF_THREADS: usize = 2;
51+
5152
let _watchdog = Watchdog::new();
52-
let number_of_threads = SystemInfo::NumberOfCpuCores.value() * 2;
53-
let barrier = Barrier::new(number_of_threads);
53+
let barrier = Barrier::new(NUMBER_OF_THREADS);
5454
let lk = SpinLock::new(0);
5555
thread::scope(|s| {
56-
for _ in 0..number_of_threads {
56+
for _ in 0..NUMBER_OF_THREADS {
5757
s.spawn(|| {
5858
barrier.wait();
5959
let mut guard = lk.blocking_lock();
@@ -62,17 +62,18 @@ fn blocking_lock_locks_exclusively() {
6262
}
6363
});
6464
let guard = lk.blocking_lock();
65-
assert_that!(*guard, eq number_of_threads);
65+
assert_that!(*guard, eq NUMBER_OF_THREADS);
6666
}
6767

6868
#[test]
6969
fn try_lock_locks_exclusively() {
70+
const NUMBER_OF_THREADS: usize = 2;
71+
7072
let _watchdog = Watchdog::new();
71-
let number_of_threads = SystemInfo::NumberOfCpuCores.value() * 2;
72-
let barrier = Barrier::new(number_of_threads);
73+
let barrier = Barrier::new(NUMBER_OF_THREADS);
7374
let lk = SpinLock::new(0);
7475
thread::scope(|s| {
75-
for _n in 0..number_of_threads {
76+
for _n in 0..NUMBER_OF_THREADS {
7677
s.spawn(|| {
7778
barrier.wait();
7879
let guard = lk.try_lock();
@@ -84,7 +85,7 @@ fn try_lock_locks_exclusively() {
8485
});
8586
let guard = lk.blocking_lock();
8687
assert_that!(*guard, gt 0);
87-
assert_that!(*guard, le number_of_threads);
88+
assert_that!(*guard, le NUMBER_OF_THREADS);
8889
}
8990

9091
#[test]

0 commit comments

Comments
 (0)