2 * Testsuite for atomic64_t functions
4 * Copyright © 2010 Luca Barbieri
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/init.h>
15 #include <linux/bug.h>
16 #include <linux/kernel.h>
17 #include <linux/atomic.h>
19 #define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
20 static __init
int test_atomic64(void)
22 long long v0
= 0xaaa31337c001d00dLL
;
23 long long v1
= 0xdeadbeefdeafcafeLL
;
24 long long v2
= 0xfaceabadf00df001LL
;
25 long long onestwos
= 0x1111111122222222LL
;
28 atomic64_t v
= ATOMIC64_INIT(v0
);
30 BUG_ON(v
.counter
!= r
);
34 BUG_ON(v
.counter
!= r
);
35 BUG_ON(atomic64_read(&v
) != r
);
38 atomic64_add(onestwos
, &v
);
40 BUG_ON(v
.counter
!= r
);
43 atomic64_add(-one
, &v
);
45 BUG_ON(v
.counter
!= r
);
49 BUG_ON(atomic64_add_return(onestwos
, &v
) != r
);
50 BUG_ON(v
.counter
!= r
);
54 BUG_ON(atomic64_add_return(-one
, &v
) != r
);
55 BUG_ON(v
.counter
!= r
);
58 atomic64_sub(onestwos
, &v
);
60 BUG_ON(v
.counter
!= r
);
63 atomic64_sub(-one
, &v
);
65 BUG_ON(v
.counter
!= r
);
69 BUG_ON(atomic64_sub_return(onestwos
, &v
) != r
);
70 BUG_ON(v
.counter
!= r
);
74 BUG_ON(atomic64_sub_return(-one
, &v
) != r
);
75 BUG_ON(v
.counter
!= r
);
80 BUG_ON(v
.counter
!= r
);
84 BUG_ON(atomic64_inc_return(&v
) != r
);
85 BUG_ON(v
.counter
!= r
);
90 BUG_ON(v
.counter
!= r
);
94 BUG_ON(atomic64_dec_return(&v
) != r
);
95 BUG_ON(v
.counter
!= r
);
98 BUG_ON(atomic64_xchg(&v
, v1
) != v0
);
100 BUG_ON(v
.counter
!= r
);
103 BUG_ON(atomic64_cmpxchg(&v
, v0
, v1
) != v0
);
105 BUG_ON(v
.counter
!= r
);
108 BUG_ON(atomic64_cmpxchg(&v
, v2
, v1
) != v0
);
109 BUG_ON(v
.counter
!= r
);
112 BUG_ON(atomic64_add_unless(&v
, one
, v0
));
113 BUG_ON(v
.counter
!= r
);
116 BUG_ON(!atomic64_add_unless(&v
, one
, v1
));
118 BUG_ON(v
.counter
!= r
);
120 #ifdef CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
122 BUG_ON(atomic64_dec_if_positive(&v
) != (onestwos
- 1));
124 BUG_ON(v
.counter
!= r
);
127 BUG_ON(atomic64_dec_if_positive(&v
) != -one
);
128 BUG_ON(v
.counter
!= r
);
131 BUG_ON(atomic64_dec_if_positive(&v
) != (-one
- one
));
132 BUG_ON(v
.counter
!= r
);
134 #warning Please implement atomic64_dec_if_positive for your architecture and select the above Kconfig symbol
138 BUG_ON(!atomic64_inc_not_zero(&v
));
140 BUG_ON(v
.counter
!= r
);
143 BUG_ON(atomic64_inc_not_zero(&v
));
144 BUG_ON(v
.counter
!= r
);
147 BUG_ON(!atomic64_inc_not_zero(&v
));
149 BUG_ON(v
.counter
!= r
);
152 pr_info("passed for %s platform %s CX8 and %s SSE\n",
155 #elif defined(CONFIG_X86_CMPXCHG64)
160 boot_cpu_has(X86_FEATURE_CX8
) ? "with" : "without",
161 boot_cpu_has(X86_FEATURE_XMM
) ? "with" : "without");
169 core_initcall(test_atomic64
);