diff options
author | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | 2024-03-05 10:31:19 -0500 |
---|---|---|
committer | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | 2024-03-05 10:33:16 -0500 |
commit | 25e59085d045d1a13b1b140d012541b30897b531 (patch) | |
tree | 23337e1e947c3daf9cc4d7c8b1ca65da61455233 | |
parent | 6b30db4e78a3ebe2c925c2336996aef894bf241a (diff) | |
download | librseq-25e59085d045d1a13b1b140d012541b30897b531.tar.gz |
param test: membarrier: validate total number of increments
While reviewing the riscv implementation for this test, I noticed that
the final store is only incrementing the content of its register,
without ever storing it to memory.
This passes testing because the increment is effectively a no-op, and
the test never validates that any increment happen in the first place.
Introduce a validation of the increment total to eliminate those
false-positives.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ie9ee1c7902509da75dd85babd07bc180ad0b9ae9
-rw-r--r-- | tests/param_test.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/param_test.c b/tests/param_test.c index a8fb1b9..c8ac956 100644 --- a/tests/param_test.c +++ b/tests/param_test.c @@ -1369,8 +1369,8 @@ void *test_membarrier_worker_thread(void *arg) { struct test_membarrier_thread_args *args = (struct test_membarrier_thread_args *)arg; - const int iters = opt_reps; - int i; + const long long iters = opt_reps; + long long i; if (rseq_register_current_thread()) { fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n", @@ -1437,6 +1437,17 @@ void test_membarrier_free_percpu_list(struct percpu_list __rseq_percpu *list) rseq_percpu_free(list); } +static +long long test_membarrier_count_percpu_list(struct percpu_list __rseq_percpu *list) +{ + long long total_count = 0; + int i; + + for (i = 0; i < CPU_SETSIZE; i++) + total_count += rseq_percpu_ptr(list, i)->head->data; + return total_count; +} + /* * The manager thread swaps per-cpu lists that worker threads see, * and validates that there are no unexpected modifications. @@ -1451,6 +1462,7 @@ void *test_membarrier_manager_thread(void *arg) int cpu_a = 0, cpu_b = 0; struct rseq_percpu_pool *mempool; int ret; + long long total_count = 0; mempool = rseq_percpu_pool_create(sizeof(struct percpu_list), PERCPU_POOL_LEN, CPU_SETSIZE, NULL, 0); @@ -1523,6 +1535,15 @@ void *test_membarrier_manager_thread(void *arg) expect_b = RSEQ_READ_ONCE(rseq_percpu_ptr(list_b, cpu_b)->head->data); } + total_count += test_membarrier_count_percpu_list(list_a); + total_count += test_membarrier_count_percpu_list(list_b); + + /* Validate that we observe the right number of increments. */ + if (total_count != opt_threads * opt_reps) { + fprintf(stderr, "Error: Observed %lld increments, expected %lld\n", + total_count, opt_threads * opt_reps); + abort(); + } test_membarrier_free_percpu_list(list_a); test_membarrier_free_percpu_list(list_b); |