authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2022-12-17 14:15:03-05:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-01-01 16:44:29-05:00
log5b8245d35a88d3d1a0d8bd4670c735824ad40837
treea75819b39c92bcf108c4654637ced7831ab530e2
parent047fe58a53f8381503d8cffd29dab37216cb5557

tests: update "atomicrmw with ints" to test u8 through u64


1 files changed, 52 insertions(+), 22 deletions(-)

test/behavior/atomics.zig+52-22
...@@ -251,31 +251,61 @@ test "atomicrmw with ints" {...@@ -251,31 +251,61 @@ test "atomicrmw with ints" {
251 return error.SkipZigTest;251 return error.SkipZigTest;
252 }252 }
253253
254 try testAtomicRmwInt();254 // TODO: https://github.com/ziglang/zig/issues/13989
255 comptime try testAtomicRmwInt();255 const bit_values = [_]usize{ 8, 16, 32, 64 };// ++ if (builtin.zig_backend != .stage2_c) [_]usize{ } else [_]usize{ 128 };
256 inline for (bit_values) |bits| {
257 try testAtomicRmwInt(.unsigned, bits);
258 comptime try testAtomicRmwInt(.unsigned, bits);
259 }
256}260}
257261
258fn testAtomicRmwInt() !void {262fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usize) !void {
259 var x: u8 = 1;263 const int = std.meta.Int(signedness, N);
260 var res = @atomicRmw(u8, &x, .Xchg, 3, .SeqCst);264
265 var x: int = 1;
266 var res = @atomicRmw(int, &x, .Xchg, 3, .SeqCst);
261 try expect(x == 3 and res == 1);267 try expect(x == 3 and res == 1);
262 _ = @atomicRmw(u8, &x, .Add, 3, .SeqCst);268
263 try expect(x == 6);269 res = @atomicRmw(int, &x, .Add, 3, .SeqCst);
264 _ = @atomicRmw(u8, &x, .Sub, 1, .SeqCst);270 var y: int = 3;
265 try expect(x == 5);271 try expect(res == y);
266 _ = @atomicRmw(u8, &x, .And, 4, .SeqCst);272 y = y + 3;
267 try expect(x == 4);273 try expect(x == y);
268 _ = @atomicRmw(u8, &x, .Nand, 4, .SeqCst);274
269 try expect(x == 0xfb);275 res = @atomicRmw(int, &x, .Sub, 1, .SeqCst);
270 _ = @atomicRmw(u8, &x, .Or, 6, .SeqCst);276 try expect(res == y);
271 try expect(x == 0xff);277 y = y - 1;
272 _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst);278 try expect(x == y);
273 try expect(x == 0xfd);279
274280 res = @atomicRmw(int, &x, .And, 4, .SeqCst);
275 _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst);281 try expect(res == y);
276 try expect(x == 0xfd);282 y = y & 4;
277 _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst);283 try expect(x == y);
278 try expect(x == 1);284
285 res = @atomicRmw(int, &x, .Nand, 4, .SeqCst);
286 try expect(res == y);
287 y = ~(y & 4);
288 try expect(x == y);
289
290 res = @atomicRmw(int, &x, .Or, 6, .SeqCst);
291 try expect(res == y);
292 y = y | 6;
293 try expect(x == y);
294
295 res = @atomicRmw(int, &x, .Xor, 2, .SeqCst);
296 try expect(res == y);
297 y = y ^ 2;
298 try expect(x == y);
299
300 res = @atomicRmw(int, &x, .Max, 1, .SeqCst);
301 try expect(res == y);
302 y = @max(y, 1);
303 try expect(x == y);
304
305 res = @atomicRmw(int, &x, .Min, 1, .SeqCst);
306 try expect(res == y);
307 y = @min(y, 1);
308 try expect(x == y);
279}309}
280310
281test "atomics with different types" {311test "atomics with different types" {