xen-blkfront: don't add indirect pages to list when !feature_persistent
[linux-2.6-block.git] / lib / atomic64_test.c
CommitLineData
86a89380
LB
1/*
2 * Testsuite for atomic64_t functions
3 *
4 * Copyright © 2010 Luca Barbieri
5 *
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.
10 */
b3b16d28
FF
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
86a89380 14#include <linux/init.h>
50af5ead 15#include <linux/bug.h>
0dbdd1bf 16#include <linux/kernel.h>
60063497 17#include <linux/atomic.h>
86a89380
LB
18
19#define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
20static __init int test_atomic64(void)
21{
22 long long v0 = 0xaaa31337c001d00dLL;
23 long long v1 = 0xdeadbeefdeafcafeLL;
24 long long v2 = 0xfaceabadf00df001LL;
25 long long onestwos = 0x1111111122222222LL;
26 long long one = 1LL;
27
28 atomic64_t v = ATOMIC64_INIT(v0);
29 long long r = v0;
30 BUG_ON(v.counter != r);
31
32 atomic64_set(&v, v1);
33 r = v1;
34 BUG_ON(v.counter != r);
35 BUG_ON(atomic64_read(&v) != r);
36
37 INIT(v0);
38 atomic64_add(onestwos, &v);
39 r += onestwos;
40 BUG_ON(v.counter != r);
41
42 INIT(v0);
43 atomic64_add(-one, &v);
44 r += -one;
45 BUG_ON(v.counter != r);
46
47 INIT(v0);
48 r += onestwos;
49 BUG_ON(atomic64_add_return(onestwos, &v) != r);
50 BUG_ON(v.counter != r);
51
52 INIT(v0);
53 r += -one;
54 BUG_ON(atomic64_add_return(-one, &v) != r);
55 BUG_ON(v.counter != r);
56
57 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;
69 BUG_ON(atomic64_sub_return(onestwos, &v) != r);
70 BUG_ON(v.counter != r);
71
72 INIT(v0);
73 r -= -one;
74 BUG_ON(atomic64_sub_return(-one, &v) != r);
75 BUG_ON(v.counter != r);
76
77 INIT(v0);
78 atomic64_inc(&v);
79 r += one;
80 BUG_ON(v.counter != r);
81
82 INIT(v0);
83 r += one;
84 BUG_ON(atomic64_inc_return(&v) != r);
85 BUG_ON(v.counter != r);
86
87 INIT(v0);
88 atomic64_dec(&v);
89 r -= one;
90 BUG_ON(v.counter != r);
91
92 INIT(v0);
93 r -= one;
94 BUG_ON(atomic64_dec_return(&v) != r);
95 BUG_ON(v.counter != r);
96
97 INIT(v0);
98 BUG_ON(atomic64_xchg(&v, v1) != v0);
99 r = v1;
100 BUG_ON(v.counter != r);
101
102 INIT(v0);
103 BUG_ON(atomic64_cmpxchg(&v, v0, v1) != v0);
104 r = v1;
105 BUG_ON(v.counter != r);
106
107 INIT(v0);
108 BUG_ON(atomic64_cmpxchg(&v, v2, v1) != v0);
109 BUG_ON(v.counter != r);
110
111 INIT(v0);
9efbcd59 112 BUG_ON(atomic64_add_unless(&v, one, v0));
86a89380
LB
113 BUG_ON(v.counter != r);
114
115 INIT(v0);
9efbcd59 116 BUG_ON(!atomic64_add_unless(&v, one, v1));
86a89380
LB
117 r += one;
118 BUG_ON(v.counter != r);
119
7463449b 120#ifdef CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
86a89380
LB
121 INIT(onestwos);
122 BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1));
123 r -= one;
124 BUG_ON(v.counter != r);
125
126 INIT(0);
127 BUG_ON(atomic64_dec_if_positive(&v) != -one);
128 BUG_ON(v.counter != r);
129
130 INIT(-one);
131 BUG_ON(atomic64_dec_if_positive(&v) != (-one - one));
132 BUG_ON(v.counter != r);
8f4f202b 133#else
7463449b 134#warning Please implement atomic64_dec_if_positive for your architecture and select the above Kconfig symbol
8f4f202b 135#endif
86a89380
LB
136
137 INIT(onestwos);
25a304f2 138 BUG_ON(!atomic64_inc_not_zero(&v));
86a89380
LB
139 r += one;
140 BUG_ON(v.counter != r);
141
142 INIT(0);
25a304f2 143 BUG_ON(atomic64_inc_not_zero(&v));
86a89380
LB
144 BUG_ON(v.counter != r);
145
146 INIT(-one);
25a304f2 147 BUG_ON(!atomic64_inc_not_zero(&v));
86a89380
LB
148 r += one;
149 BUG_ON(v.counter != r);
150
151#ifdef CONFIG_X86
b3b16d28 152 pr_info("passed for %s platform %s CX8 and %s SSE\n",
a5c9161f 153#ifdef CONFIG_X86_64
b3b16d28 154 "x86-64",
a5c9161f 155#elif defined(CONFIG_X86_CMPXCHG64)
b3b16d28 156 "i586+",
86a89380 157#else
b3b16d28 158 "i386+",
86a89380 159#endif
a5c9161f
PA
160 boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without",
161 boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without");
86a89380 162#else
b3b16d28 163 pr_info("passed\n");
86a89380
LB
164#endif
165
166 return 0;
167}
168
169core_initcall(test_atomic64);