mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-09-20 15:21:42 +01:00
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>
45 lines
1.2 KiB
C
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);
|