Add load-locked and store-conditional helpers and check that a store-conditional with no preceding load-locked fails, and that returning from a syscall drops the reservation.
Signed-off-by: Brian Cain <[email protected]> --- tests/tcg/hexagon/atomics.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/tcg/hexagon/atomics.c b/tests/tcg/hexagon/atomics.c index 1c2169b28bd..5017ca003f1 100644 --- a/tests/tcg/hexagon/atomics.c +++ b/tests/tcg/hexagon/atomics.c @@ -27,6 +27,30 @@ int err; #include "hex_test.h" +static inline int32_t load_locked32(int32_t *x) +{ + int32_t value; + + __asm__ __volatile__("%[value] = memw_locked(%[addr])" + : [value] "=r"(value) + : [addr] "r"(x) + : "memory"); + return value; +} + +static inline int store_conditional32(int32_t *x, int32_t value) +{ + int result; + + __asm__ __volatile__( + "memw_locked(%[addr], p0) = %[value]\n\t" + "%[result] = p0" + : [result] "=r"(result) + : [addr] "r"(x), [value] "r"(value) + : "p0", "memory"); + return result != 0; +} + static inline int32_t atomic_inc32(int32_t *x) { int32_t old, dummy; @@ -89,6 +113,21 @@ static inline int64_t atomic_dec64(int64_t *x) volatile int32_t tick32 = 1; /* Using volatile because we are testing atomics */ volatile int64_t tick64 = 1; /* Using volatile because we are testing atomics */ +static void test_reservations(void) +{ + int32_t value = 1; + + /* A store-conditional with no preceding load-locked must fail. */ + check32(store_conditional32(&value, 2), 0); + check32(value, 1); + + /* Returning from a syscall drops the reservation. */ + check32(load_locked32(&value), 1); + getpid(); + check32(store_conditional32(&value, 3), 0); + check32(value, 1); +} + void *thread1_func(void *arg) { for (int i = 0; i < LOOP_CNT; i++) { @@ -122,6 +161,7 @@ void test_pthread(void) int main(int argc, char **argv) { + test_reservations(); test_pthread(); puts(err ? "FAIL" : "PASS"); return err; -- 2.34.1
