History

Enable atomic test for all targets

herman ten brugge committed 1 year ago

Commit 717a5101 parent 7657d873 files · +7 −47Browse files

Unified · Split

3 files
  1. tests/tests2/124_atomic_counter.c +0 −20
  2. tests/tests2/125_atomic_misc.c +0 −20
  3. tests/tests2/125_atomic_misc.expect +7 −7
tests/tests2/124_atomic_counter.c+0−20
@@ -14,18 +14,12 @@ · 13 unmodified lines
14 abort(); \14 abort(); \
15 } while (0)15 } while (0)
16 16
17#if defined __x86_64__ || defined __aarch64__ || defined __riscv
18#define HAS_64BITS
19#endif
20
21typedef struct {17typedef struct {
22 atomic_flag flag;18 atomic_flag flag;
23 atomic_uchar uc;19 atomic_uchar uc;
24 atomic_ushort us;20 atomic_ushort us;
25 atomic_uint ui;21 atomic_uint ui;
26#ifdef HAS_64BITS
27 atomic_size_t ul;22 atomic_size_t ul;
28#endif
29} counter_type;23} counter_type;
30 24
31static25static
@@ -38,9 +32,7 @@ void *adder_simple(void *arg) · 6 unmodified lines
38 atomic_fetch_add_explicit(&counter->uc, 1, memory_order_relaxed);32 atomic_fetch_add_explicit(&counter->uc, 1, memory_order_relaxed);
39 atomic_fetch_add_explicit(&counter->us, 1, memory_order_relaxed);33 atomic_fetch_add_explicit(&counter->us, 1, memory_order_relaxed);
40 atomic_fetch_add_explicit(&counter->ui, 1, memory_order_relaxed);34 atomic_fetch_add_explicit(&counter->ui, 1, memory_order_relaxed);
41#ifdef HAS_64BITS
42 atomic_fetch_add_explicit(&counter->ul, 1, memory_order_relaxed);35 atomic_fetch_add_explicit(&counter->ul, 1, memory_order_relaxed);
43#endif
44 }36 }
45 37
46 return NULL;38 return NULL;
@@ -56,15 +48,11 @@ void *adder_cmpxchg(void *arg) · 9 unmodified lines
56 unsigned char xchgc;48 unsigned char xchgc;
57 unsigned short xchgs;49 unsigned short xchgs;
58 unsigned int xchgi;50 unsigned int xchgi;
59#ifdef HAS_64BITS
60 size_t xchgl;51 size_t xchgl;
61#endif
62 unsigned char cmpc = atomic_load_explicit(&counter->uc, memory_order_relaxed);52 unsigned char cmpc = atomic_load_explicit(&counter->uc, memory_order_relaxed);
63 unsigned short cmps = atomic_load_explicit(&counter->us, memory_order_relaxed);53 unsigned short cmps = atomic_load_explicit(&counter->us, memory_order_relaxed);
64 unsigned int cmpi = atomic_load_explicit(&counter->ui, memory_order_relaxed);54 unsigned int cmpi = atomic_load_explicit(&counter->ui, memory_order_relaxed);
65#ifdef HAS_64BITS
66 size_t cmpl = atomic_load_explicit(&counter->ul, memory_order_relaxed);55 size_t cmpl = atomic_load_explicit(&counter->ul, memory_order_relaxed);
67#endif
68 56
69 do {57 do {
70 xchgc = (cmpc + 1);58 xchgc = (cmpc + 1);
@@ -78,12 +66,10 @@ void *adder_cmpxchg(void *arg) · 7 unmodified lines
78 xchgi = (cmpi + 1);66 xchgi = (cmpi + 1);
79 } while (!atomic_compare_exchange_strong_explicit(&counter->ui,67 } while (!atomic_compare_exchange_strong_explicit(&counter->ui,
80 &cmpi, xchgi, memory_order_relaxed, memory_order_relaxed));68 &cmpi, xchgi, memory_order_relaxed, memory_order_relaxed));
81#ifdef HAS_64BITS
82 do {69 do {
83 xchgl = (cmpl + 1);70 xchgl = (cmpl + 1);
84 } while (!atomic_compare_exchange_strong_explicit(&counter->ul,71 } while (!atomic_compare_exchange_strong_explicit(&counter->ul,
85 &cmpl, xchgl, memory_order_relaxed, memory_order_relaxed));72 &cmpl, xchgl, memory_order_relaxed, memory_order_relaxed));
86#endif
87 }73 }
88 74
89 return NULL;75 return NULL;
@@ -100,9 +86,7 @@ void *adder_test_and_set(void *arg) · 10 unmodified lines
100 ++counter->uc;86 ++counter->uc;
101 ++counter->us;87 ++counter->us;
102 ++counter->ui;88 ++counter->ui;
103#ifdef HAS_64BITS
104 ++counter->ul;89 ++counter->ul;
105#endif
106 atomic_flag_clear(&counter->flag);90 atomic_flag_clear(&counter->flag);
107 }91 }
108 92
@@ -120,9 +104,7 @@ void atomic_counter_test(void *(*adder)(void *arg)) · 11 unmodified lines
120 atomic_init(&counter.uc, 0);104 atomic_init(&counter.uc, 0);
121 atomic_init(&counter.us, 0);105 atomic_init(&counter.us, 0);
122 atomic_init(&counter.ui, 0);106 atomic_init(&counter.ui, 0);
123#ifdef HAS_64BITS
124 atomic_init(&counter.ul, 0);107 atomic_init(&counter.ul, 0);
125#endif
126 108
127 for (index = 0; index < NR_THREADS; ++index)109 for (index = 0; index < NR_THREADS; ++index)
128 BUG_ON(pthread_create(&thread[index], NULL, adder, (void *)&counter));110 BUG_ON(pthread_create(&thread[index], NULL, adder, (void *)&counter));
@@ -133,9 +115,7 @@ void atomic_counter_test(void *(*adder)(void *arg)) · 4 unmodified lines
133 if (atomic_load(&counter.uc) == ((NR_THREADS * NR_STEPS) & 0xffu)115 if (atomic_load(&counter.uc) == ((NR_THREADS * NR_STEPS) & 0xffu)
134 && atomic_load(&counter.us) == ((NR_THREADS * NR_STEPS) & 0xffffu)116 && atomic_load(&counter.us) == ((NR_THREADS * NR_STEPS) & 0xffffu)
135 && atomic_load(&counter.ui) == (NR_THREADS * NR_STEPS)117 && atomic_load(&counter.ui) == (NR_THREADS * NR_STEPS)
136#ifdef HAS_64BITS
137 && atomic_load(&counter.ul) == (NR_THREADS * NR_STEPS)118 && atomic_load(&counter.ul) == (NR_THREADS * NR_STEPS)
138#endif
139 )119 )
140 printf("SUCCESS\n");120 printf("SUCCESS\n");
141 else121 else
tests/tests2/125_atomic_misc.c+0−20
@@ -63,12 +63,7 @@ int main() · 62 unmodified lines
63#define OP1(func, v, e1, e2) atomic_##func(&c, v) == e1 && c == e263#define OP1(func, v, e1, e2) atomic_##func(&c, v) == e1 && c == e2
64#define OP2(func, v, e1, e2) atomic_##func(&s, v) == e1 && s == e264#define OP2(func, v, e1, e2) atomic_##func(&s, v) == e1 && s == e2
65#define OP4(func, v, e1, e2) atomic_##func(&i, v) == e1 && i == e265#define OP4(func, v, e1, e2) atomic_##func(&i, v) == e1 && i == e2
66#if defined __x86_64__ || defined __aarch64__ || defined __riscv
67#define OP8(func, v, e1, e2) atomic_##func(&l, v) == e1 && l == e266#define OP8(func, v, e1, e2) atomic_##func(&l, v) == e1 && l == e2
68#define HAS_64BITS
69#else
70#define OP8(func, v, e1, e2) 1
71#endif
72 67
73#define OP(func, v, e1, e2) printf ("%s: %s\n", #func, \68#define OP(func, v, e1, e2) printf ("%s: %s\n", #func, \
74 OP1(func,v,e1,e2) && OP2(func,v,e1,e2) && \69 OP1(func,v,e1,e2) && OP2(func,v,e1,e2) && \
@@ -80,16 +75,12 @@ int main() · 5 unmodified lines
80 atomic_char c;75 atomic_char c;
81 atomic_short s;76 atomic_short s;
82 atomic_int i;77 atomic_int i;
83#ifdef HAS_64BITS
84 atomic_size_t l;78 atomic_size_t l;
85#endif
86 79
87 atomic_init(&c, 0);80 atomic_init(&c, 0);
88 atomic_init(&s, 0);81 atomic_init(&s, 0);
89 atomic_init(&i, 0);82 atomic_init(&i, 0);
90#ifdef HAS_64BITS
91 atomic_init(&l, 0);83 atomic_init(&l, 0);
92#endif
93 84
94 OP(fetch_add, 10, 0, 10);85 OP(fetch_add, 10, 0, 10);
95 OP(fetch_sub, 5, 10, 5);86 OP(fetch_sub, 5, 10, 5);
@@ -108,13 +99,8 @@ typedef __SIZE_TYPE__ size64_t; · 12 unmodified lines
108 __atomic_##func(&s, v, __ATOMIC_SEQ_CST) == e1 && s == e299 __atomic_##func(&s, v, __ATOMIC_SEQ_CST) == e1 && s == e2
109#define OP4(func, v, e1, e2)\100#define OP4(func, v, e1, e2)\
110 __atomic_##func(&i, v, __ATOMIC_SEQ_CST) == e1 && i == e2101 __atomic_##func(&i, v, __ATOMIC_SEQ_CST) == e1 && i == e2
111#if defined __x86_64__ || defined __aarch64__ || defined __riscv
112#define OP8(func, v, e1, e2)\102#define OP8(func, v, e1, e2)\
113 __atomic_##func(&l, v, __ATOMIC_SEQ_CST) == e1 && l == e2103 __atomic_##func(&l, v, __ATOMIC_SEQ_CST) == e1 && l == e2
114#define HAS_64BITS
115#else
116#define OP8(func, v, e1, e2) 1
117#endif
118 104
119#define OP(func, v, e1, e2) printf ("%s: %s\n", #func, \105#define OP(func, v, e1, e2) printf ("%s: %s\n", #func, \
120 OP1(func,v,e1,e2) && OP2(func,v,e1,e2) && \106 OP1(func,v,e1,e2) && OP2(func,v,e1,e2) && \
@@ -126,16 +112,12 @@ int main() · 5 unmodified lines
126 signed char c;112 signed char c;
127 short s;113 short s;
128 int i;114 int i;
129#ifdef HAS_64BITS
130 size64_t l;115 size64_t l;
131#endif
132 116
133 atomic_init(&c, 0);117 atomic_init(&c, 0);
134 atomic_init(&s, 0);118 atomic_init(&s, 0);
135 atomic_init(&i, 0);119 atomic_init(&i, 0);
136#ifdef HAS_64BITS
137 atomic_init(&l, 0);120 atomic_init(&l, 0);
138#endif
139 121
140 OP(fetch_add, 10, 0, 10);122 OP(fetch_add, 10, 0, 10);
141 OP(fetch_sub, 5, 10, 5);123 OP(fetch_sub, 5, 10, 5);
@@ -147,9 +129,7 @@ int main() · 5 unmodified lines
147 atomic_init(&c, 0);129 atomic_init(&c, 0);
148 atomic_init(&s, 0);130 atomic_init(&s, 0);
149 atomic_init(&i, 0);131 atomic_init(&i, 0);
150#ifdef HAS_64BITS
151 atomic_init(&l, 0);132 atomic_init(&l, 0);
152#endif
153 133
154 OP(add_fetch, 10, 10, 10);134 OP(add_fetch, 10, 10, 10);
155 OP(sub_fetch, 5, 5, 5);135 OP(sub_fetch, 5, 5, 5);
tests/tests2/125_atomic_misc.expect+7−7
@@ -38,22 +38,22 @@ nand_fetch: SUCCESS · 37 unmodified lines
381381
39 39
40[test_atomic_error_1]40[test_atomic_error_1]
41125_atomic_misc.c:176: error: pointer expected41125_atomic_misc.c:156: error: pointer expected
42 42
43[test_atomic_error_2]43[test_atomic_error_2]
44125_atomic_misc.c:183: error: integral or integer-sized pointer target type expected44125_atomic_misc.c:163: error: integral or integer-sized pointer target type expected
45 45
46[test_atomic_error_3]46[test_atomic_error_3]
47125_atomic_misc.c:190: error: integral or integer-sized pointer target type expected47125_atomic_misc.c:170: error: integral or integer-sized pointer target type expected
48 48
49[test_atomic_error_4]49[test_atomic_error_4]
50125_atomic_misc.c:198: error: pointer target type mismatch in argument 250125_atomic_misc.c:178: error: pointer target type mismatch in argument 2
51 51
52[test_atomic_warn_1]52[test_atomic_warn_1]
53125_atomic_misc.c:206: warning: assignment makes integer from pointer without a cast53125_atomic_misc.c:186: warning: assignment makes integer from pointer without a cast
54 54
55[test_atomic_warn_2]55[test_atomic_warn_2]
56125_atomic_misc.c:216: warning: assignment from incompatible pointer type56125_atomic_misc.c:196: warning: assignment from incompatible pointer type
57 57
58[test_atomic_warn_3]58[test_atomic_warn_3]
59125_atomic_misc.c:224: warning: assignment of read-only location59125_atomic_misc.c:204: warning: assignment of read-only location

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t