Files
opensbi/lib/sbi/tests/riscv_locks_test.c
T
Carlos López 92b24d6acb lib: test: disable TSA for spinlock tests
The spinlock tests deliberately use unconventional locking patterns to
test edge cases. Disable thread safety analysis for them so that they
don't generate false positives when the feature is enabled.

Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260909162322.29778-15-carlos.lopezr4096@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
2026-09-16 09:48:30 +05:30

45 lines
1.2 KiB
C

#include <sbi/sbi_unit_test.h>
#include <sbi/riscv_locks.h>
static spinlock_t test_lock = SPIN_LOCK_INITIALIZER;
static void spin_lock_test(struct sbiunit_test_case *test)
NO_THREAD_SAFETY_ANALYSIS
{
/* We don't want to accidentally get locked */
SBIUNIT_ASSERT(test, !spin_lock_check(&test_lock));
spin_lock(&test_lock);
SBIUNIT_EXPECT(test, spin_lock_check(&test_lock));
spin_unlock(&test_lock);
SBIUNIT_ASSERT(test, !spin_lock_check(&test_lock));
}
static void spin_trylock_fail(struct sbiunit_test_case *test)
NO_THREAD_SAFETY_ANALYSIS
{
/* We don't want to accidentally get locked */
SBIUNIT_ASSERT(test, !spin_lock_check(&test_lock));
spin_lock(&test_lock);
SBIUNIT_EXPECT(test, !spin_trylock(&test_lock));
spin_unlock(&test_lock);
}
static void spin_trylock_success(struct sbiunit_test_case *test)
NO_THREAD_SAFETY_ANALYSIS
{
SBIUNIT_EXPECT(test, spin_trylock(&test_lock));
spin_unlock(&test_lock);
}
static struct sbiunit_test_case locks_test_cases[] = {
SBIUNIT_TEST_CASE(spin_lock_test),
SBIUNIT_TEST_CASE(spin_trylock_fail),
SBIUNIT_TEST_CASE(spin_trylock_success),
SBIUNIT_END_CASE,
};
SBIUNIT_TEST_SUITE(locks_test_suite, locks_test_cases);