blob: 7894c4e9873c3c12223a8137dfb55b9b656187a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#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)
{
/* 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)
{
/* 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)
{
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);
|