]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - lib/atomic64_test.c
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.
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <asm/atomic.h>
15 #define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
16 static __init
int test_atomic64(void)
18 long long v0
= 0xaaa31337c001d00dLL
;
19 long long v1
= 0xdeadbeefdeafcafeLL
;
20 long long v2
= 0xfaceabadf00df001LL
;
21 long long onestwos
= 0x1111111122222222LL
;
24 atomic64_t v
= ATOMIC64_INIT(v0
);
26 BUG_ON(v
.counter
!= r
);
30 BUG_ON(v
.counter
!= r
);
31 BUG_ON(atomic64_read(&v
) != r
);
34 atomic64_add(onestwos
, &v
);
36 BUG_ON(v
.counter
!= r
);
39 atomic64_add(-one
, &v
);
41 BUG_ON(v
.counter
!= r
);
45 BUG_ON(atomic64_add_return(onestwos
, &v
) != r
);
46 BUG_ON(v
.counter
!= r
);
50 BUG_ON(atomic64_add_return(-one
, &v
) != r
);
51 BUG_ON(v
.counter
!= r
);
54 atomic64_sub(onestwos
, &v
);
56 BUG_ON(v
.counter
!= r
);
59 atomic64_sub(-one
, &v
);
61 BUG_ON(v
.counter
!= r
);
65 BUG_ON(atomic64_sub_return(onestwos
, &v
) != r
);
66 BUG_ON(v
.counter
!= r
);
70 BUG_ON(atomic64_sub_return(-one
, &v
) != r
);
71 BUG_ON(v
.counter
!= r
);
76 BUG_ON(v
.counter
!= r
);
80 BUG_ON(atomic64_inc_return(&v
) != r
);
81 BUG_ON(v
.counter
!= r
);
86 BUG_ON(v
.counter
!= r
);
90 BUG_ON(atomic64_dec_return(&v
) != r
);
91 BUG_ON(v
.counter
!= r
);
94 BUG_ON(atomic64_xchg(&v
, v1
) != v0
);
96 BUG_ON(v
.counter
!= r
);
99 BUG_ON(atomic64_cmpxchg(&v
, v0
, v1
) != v0
);
101 BUG_ON(v
.counter
!= r
);
104 BUG_ON(atomic64_cmpxchg(&v
, v2
, v1
) != v0
);
105 BUG_ON(v
.counter
!= r
);
108 BUG_ON(atomic64_add_unless(&v
, one
, v0
));
109 BUG_ON(v
.counter
!= r
);
112 BUG_ON(!atomic64_add_unless(&v
, one
, v1
));
114 BUG_ON(v
.counter
!= r
);
116 #if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
117 defined(CONFIG_S390) || defined(_ASM_GENERIC_ATOMIC64_H) || defined(CONFIG_ARM)
119 BUG_ON(atomic64_dec_if_positive(&v
) != (onestwos
- 1));
121 BUG_ON(v
.counter
!= r
);
124 BUG_ON(atomic64_dec_if_positive(&v
) != -one
);
125 BUG_ON(v
.counter
!= r
);
128 BUG_ON(atomic64_dec_if_positive(&v
) != (-one
- one
));
129 BUG_ON(v
.counter
!= r
);
131 #warning Please implement atomic64_dec_if_positive for your architecture, and add it to the IF above
135 BUG_ON(!atomic64_inc_not_zero(&v
));
137 BUG_ON(v
.counter
!= r
);
140 BUG_ON(atomic64_inc_not_zero(&v
));
141 BUG_ON(v
.counter
!= r
);
144 BUG_ON(!atomic64_inc_not_zero(&v
));
146 BUG_ON(v
.counter
!= r
);
149 printk(KERN_INFO
"atomic64 test passed for %s platform %s CX8 and %s SSE\n",
152 #elif defined(CONFIG_X86_CMPXCHG64)
157 boot_cpu_has(X86_FEATURE_CX8
) ? "with" : "without",
158 boot_cpu_has(X86_FEATURE_XMM
) ? "with" : "without");
160 printk(KERN_INFO
"atomic64 test passed\n");
166 core_initcall(test_atomic64
);