Rev 2020 | Rev 2050 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2020 | Rev 2027 | ||
|---|---|---|---|
| Line 29... | Line 29... | ||
| 29 | #include <test.h> |
29 | #include <test.h> |
| 30 | #include <print.h> |
30 | #include <print.h> |
| 31 | #include <atomic.h> |
31 | #include <atomic.h> |
| 32 | #include <debug.h> |
32 | #include <debug.h> |
| 33 | 33 | ||
| 34 | #ifdef CONFIG_BENCH |
- | |
| 35 | #include <arch/cycle.h> |
- | |
| 36 | #endif |
- | |
| 37 | - | ||
| 38 | void test_atomic1(void) |
34 | char * test_atomic1(void) |
| 39 | { |
35 | { |
| 40 | #ifdef CONFIG_BENCH |
- | |
| 41 | uint64_t t0 = get_cycle(); |
- | |
| 42 | #endif |
- | |
| 43 | atomic_t a; |
36 | atomic_t a; |
| 44 | 37 | ||
| 45 | atomic_set(&a, 10); |
38 | atomic_set(&a, 10); |
| - | 39 | if (atomic_get(&a) != 10) |
|
| 46 | printf("Testing atomic_set() and atomic_get().\n"); |
40 | return "Failed atomic_set()/atomic_get()"; |
| - | 41 | ||
| 47 | ASSERT(atomic_get(&a) == 10); |
42 | if (atomic_postinc(&a) != 10) |
| 48 | printf("Testing atomic_postinc()\n"); |
43 | return "Failed atomic_postinc()"; |
| 49 | ASSERT(atomic_postinc(&a) == 10); |
44 | if (atomic_get(&a) != 11) |
| 50 | ASSERT(atomic_get(&a) == 11); |
45 | return "Failed atomic_get() after atomic_postinc()"; |
| - | 46 | ||
| 51 | printf("Testing atomic_postdec()\n"); |
47 | if (atomic_postdec(&a) != 11) |
| 52 | ASSERT(atomic_postdec(&a) == 11); |
48 | return "Failed atomic_postdec()"; |
| 53 | ASSERT(atomic_get(&a) == 10); |
49 | if (atomic_get(&a) != 10) |
| 54 | printf("Testing atomic_preinc()\n"); |
50 | return "Failed atomic_get() after atomic_postdec()"; |
| - | 51 | ||
| 55 | ASSERT(atomic_preinc(&a) == 11); |
52 | if (atomic_preinc(&a) != 11) |
| 56 | ASSERT(atomic_get(&a) == 11); |
- | |
| 57 | printf("Testing atomic_predec()\n"); |
53 | return "Failed atomic_preinc()"; |
| 58 | ASSERT(atomic_postdec(&a) == 11); |
54 | if (atomic_get(&a) != 11) |
| 59 | ASSERT(atomic_get(&a) == 10); |
55 | return "Failed atomic_get() after atomic_preinc()"; |
| 60 | 56 | ||
| 61 | printf("Test passed.\n"); |
57 | if (atomic_predec(&a) != 10) |
| 62 | #ifdef CONFIG_BENCH |
58 | return "Failed atomic_predec()"; |
| 63 | uint64_t dt = get_cycle() - t0; |
59 | if (atomic_get(&a) != 10) |
| 64 | printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); |
60 | return "Failed atomic_get() after atomic_predec()"; |
| - | 61 | ||
| 65 | #endif |
62 | return NULL; |
| 66 | } |
63 | } |