aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2015-07-13 06:55:58 -0400
committerThomas Gleixner <tglx@linutronix.de>2015-07-27 08:06:24 -0400
commit41b9e9fcc1c44b84a785115058ce9c703e3fca6e (patch)
tree11ed300cc313d1d4bb19bcc7bc2b5b21090916f0 /lib
parent805de8f43c20ba8b479bb598b543fa86b20067f6 (diff)
atomic: Add simple atomic_t tests
Add a few atomic_t tests, gets some compile coverage for the new operations. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/atomic64_test.c68
1 files changed, 47 insertions, 21 deletions
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c
index 0211d30d8c39..83c33a5bcffb 100644
--- a/lib/atomic64_test.c
+++ b/lib/atomic64_test.c
@@ -16,8 +16,39 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/atomic.h> 17#include <linux/atomic.h>
18 18
19#define TEST(bit, op, c_op, val) \
20do { \
21 atomic##bit##_set(&v, v0); \
22 r = v0; \
23 atomic##bit##_##op(val, &v); \
24 r c_op val; \
25 WARN(atomic##bit##_read(&v) != r, "%Lx != %Lx\n", \
26 (unsigned long long)atomic##bit##_read(&v), \
27 (unsigned long long)r); \
28} while (0)
29
30static __init void test_atomic(void)
31{
32 int v0 = 0xaaa31337;
33 int v1 = 0xdeadbeef;
34 int onestwos = 0x11112222;
35 int one = 1;
36
37 atomic_t v;
38 int r;
39
40 TEST(, add, +=, onestwos);
41 TEST(, add, +=, -one);
42 TEST(, sub, -=, onestwos);
43 TEST(, sub, -=, -one);
44 TEST(, or, |=, v1);
45 TEST(, and, &=, v1);
46 TEST(, xor, ^=, v1);
47 TEST(, andnot, &= ~, v1);
48}
49
19#define INIT(c) do { atomic64_set(&v, c); r = c; } while (0) 50#define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
20static __init int test_atomic64(void) 51static __init void test_atomic64(void)
21{ 52{
22 long long v0 = 0xaaa31337c001d00dLL; 53 long long v0 = 0xaaa31337c001d00dLL;
23 long long v1 = 0xdeadbeefdeafcafeLL; 54 long long v1 = 0xdeadbeefdeafcafeLL;
@@ -34,15 +65,14 @@ static __init int test_atomic64(void)
34 BUG_ON(v.counter != r); 65 BUG_ON(v.counter != r);
35 BUG_ON(atomic64_read(&v) != r); 66 BUG_ON(atomic64_read(&v) != r);
36 67
37 INIT(v0); 68 TEST(64, add, +=, onestwos);
38 atomic64_add(onestwos, &v); 69 TEST(64, add, +=, -one);
39 r += onestwos; 70 TEST(64, sub, -=, onestwos);
40 BUG_ON(v.counter != r); 71 TEST(64, sub, -=, -one);
41 72 TEST(64, or, |=, v1);
42 INIT(v0); 73 TEST(64, and, &=, v1);
43 atomic64_add(-one, &v); 74 TEST(64, xor, ^=, v1);
44 r += -one; 75 TEST(64, andnot, &= ~, v1);
45 BUG_ON(v.counter != r);
46 76
47 INIT(v0); 77 INIT(v0);
48 r += onestwos; 78 r += onestwos;
@@ -55,16 +85,6 @@ static __init int test_atomic64(void)
55 BUG_ON(v.counter != r); 85 BUG_ON(v.counter != r);
56 86
57 INIT(v0); 87 INIT(v0);
58 atomic64_sub(onestwos, &v);
59 r -= onestwos;
60 BUG_ON(v.counter != r);
61
62 INIT(v0);
63 atomic64_sub(-one, &v);
64 r -= -one;
65 BUG_ON(v.counter != r);
66
67 INIT(v0);
68 r -= onestwos; 88 r -= onestwos;
69 BUG_ON(atomic64_sub_return(onestwos, &v) != r); 89 BUG_ON(atomic64_sub_return(onestwos, &v) != r);
70 BUG_ON(v.counter != r); 90 BUG_ON(v.counter != r);
@@ -147,6 +167,12 @@ static __init int test_atomic64(void)
147 BUG_ON(!atomic64_inc_not_zero(&v)); 167 BUG_ON(!atomic64_inc_not_zero(&v));
148 r += one; 168 r += one;
149 BUG_ON(v.counter != r); 169 BUG_ON(v.counter != r);
170}
171
172static __init int test_atomics(void)
173{
174 test_atomic();
175 test_atomic64();
150 176
151#ifdef CONFIG_X86 177#ifdef CONFIG_X86
152 pr_info("passed for %s platform %s CX8 and %s SSE\n", 178 pr_info("passed for %s platform %s CX8 and %s SSE\n",
@@ -166,4 +192,4 @@ static __init int test_atomic64(void)
166 return 0; 192 return 0;
167} 193}
168 194
169core_initcall(test_atomic64); 195core_initcall(test_atomics);