Commit 41b9e9fc authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Thomas Gleixner

atomic: Add simple atomic_t tests

Add a few atomic_t tests, gets some compile coverage for the new
operations.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 805de8f4
...@@ -16,8 +16,39 @@ ...@@ -16,8 +16,39 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/atomic.h> #include <linux/atomic.h>
#define TEST(bit, op, c_op, val) \
do { \
atomic##bit##_set(&v, v0); \
r = v0; \
atomic##bit##_##op(val, &v); \
r c_op val; \
WARN(atomic##bit##_read(&v) != r, "%Lx != %Lx\n", \
(unsigned long long)atomic##bit##_read(&v), \
(unsigned long long)r); \
} while (0)
static __init void test_atomic(void)
{
int v0 = 0xaaa31337;
int v1 = 0xdeadbeef;
int onestwos = 0x11112222;
int one = 1;
atomic_t v;
int r;
TEST(, add, +=, onestwos);
TEST(, add, +=, -one);
TEST(, sub, -=, onestwos);
TEST(, sub, -=, -one);
TEST(, or, |=, v1);
TEST(, and, &=, v1);
TEST(, xor, ^=, v1);
TEST(, andnot, &= ~, v1);
}
#define INIT(c) do { atomic64_set(&v, c); r = c; } while (0) #define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
static __init int test_atomic64(void) static __init void test_atomic64(void)
{ {
long long v0 = 0xaaa31337c001d00dLL; long long v0 = 0xaaa31337c001d00dLL;
long long v1 = 0xdeadbeefdeafcafeLL; long long v1 = 0xdeadbeefdeafcafeLL;
...@@ -34,15 +65,14 @@ static __init int test_atomic64(void) ...@@ -34,15 +65,14 @@ static __init int test_atomic64(void)
BUG_ON(v.counter != r); BUG_ON(v.counter != r);
BUG_ON(atomic64_read(&v) != r); BUG_ON(atomic64_read(&v) != r);
INIT(v0); TEST(64, add, +=, onestwos);
atomic64_add(onestwos, &v); TEST(64, add, +=, -one);
r += onestwos; TEST(64, sub, -=, onestwos);
BUG_ON(v.counter != r); TEST(64, sub, -=, -one);
TEST(64, or, |=, v1);
INIT(v0); TEST(64, and, &=, v1);
atomic64_add(-one, &v); TEST(64, xor, ^=, v1);
r += -one; TEST(64, andnot, &= ~, v1);
BUG_ON(v.counter != r);
INIT(v0); INIT(v0);
r += onestwos; r += onestwos;
...@@ -54,16 +84,6 @@ static __init int test_atomic64(void) ...@@ -54,16 +84,6 @@ static __init int test_atomic64(void)
BUG_ON(atomic64_add_return(-one, &v) != r); BUG_ON(atomic64_add_return(-one, &v) != r);
BUG_ON(v.counter != r); BUG_ON(v.counter != r);
INIT(v0);
atomic64_sub(onestwos, &v);
r -= onestwos;
BUG_ON(v.counter != r);
INIT(v0);
atomic64_sub(-one, &v);
r -= -one;
BUG_ON(v.counter != r);
INIT(v0); INIT(v0);
r -= onestwos; r -= onestwos;
BUG_ON(atomic64_sub_return(onestwos, &v) != r); BUG_ON(atomic64_sub_return(onestwos, &v) != r);
...@@ -147,6 +167,12 @@ static __init int test_atomic64(void) ...@@ -147,6 +167,12 @@ static __init int test_atomic64(void)
BUG_ON(!atomic64_inc_not_zero(&v)); BUG_ON(!atomic64_inc_not_zero(&v));
r += one; r += one;
BUG_ON(v.counter != r); BUG_ON(v.counter != r);
}
static __init int test_atomics(void)
{
test_atomic();
test_atomic64();
#ifdef CONFIG_X86 #ifdef CONFIG_X86
pr_info("passed for %s platform %s CX8 and %s SSE\n", pr_info("passed for %s platform %s CX8 and %s SSE\n",
...@@ -166,4 +192,4 @@ static __init int test_atomic64(void) ...@@ -166,4 +192,4 @@ static __init int test_atomic64(void)
return 0; return 0;
} }
core_initcall(test_atomic64); core_initcall(test_atomics);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment