Skip to content

Commit

Permalink
tests: fix TSAN warnings in atomlist test
Browse files Browse the repository at this point in the history
The atomlist test consists of a sequence of (MT) sub-tests, from which
counters are collected and verified.  TSAN doesn't know that these
counters are synchronized by way of the sub-test starting and finishing,
so it complains.  Just use atomics to get rid of the warning.

(This is solely an issue with the test, not the atomlist code.  There
are no warnings from that.)

Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Jun 20, 2024
1 parent b9541fe commit 1db7ebf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tests/lib/test_atomlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static struct asort_head shead;
static struct testthread {
pthread_t pt;
struct seqlock sqlo;
size_t counter, nullops;
_Atomic size_t counter, nullops;
} thr[NTHREADS];

struct testrun {
Expand Down Expand Up @@ -98,8 +98,8 @@ static void trfunc_##name(unsigned int offset) \
size_t i = 0, n = 0;

#define endtestrun \
thr[offset].counter = i; \
thr[offset].nullops = n; \
atomic_store(&thr[offset].counter, i); \
atomic_store(&thr[offset].nullops, n); \
}

deftestrun(add, "add vs. add", 0, false)
Expand Down Expand Up @@ -288,10 +288,10 @@ static void run_tr(struct testrun *tr)
sv = seqlock_bump(&sqlo) - SEQLOCK_INCR;
for (size_t i = 0; i < NTHREADS; i++) {
seqlock_wait(&thr[i].sqlo, seqlock_cur(&sqlo));
s += thr[i].counter;
n += thr[i].nullops;
thr[i].counter = 0;
thr[i].nullops = 0;
s += atomic_load(&thr[i].counter);
n += atomic_load(&thr[i].nullops);
atomic_store(&thr[i].counter, 0);
atomic_store(&thr[i].nullops, 0);
}

delta = monotime_since(&tv, NULL);
Expand Down

0 comments on commit 1db7ebf

Please sign in to comment.