Move passing behavior tests

Singular tests (such as in the bug ones) are moved to top level with exclusions for non-passing backends.
The big behavior tests such as array_llvm and slice are moved to the inner scope with the C backend disabled.
They all pass for the wasm backend now
This commit is contained in:
Luuk de Gram 2022-02-03 22:25:46 +01:00
parent e35414bf5c
commit 588b88b987
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664
7 changed files with 52 additions and 7 deletions

View File

@ -1198,7 +1198,7 @@ pub const DeclGen = struct {
const elem_ptr = val.castTag(.elem_ptr).?.data;
const elem_size = ty.childType().abiSize(self.target());
const offset = elem_ptr.index * elem_size;
return self.lowerParentPtr(elem_ptr.array_ptr, offset);
return self.lowerParentPtr(elem_ptr.array_ptr, @intCast(usize, offset));
},
.int_u64 => return self.genTypedValue(Type.usize, val),
else => return self.fail("TODO: Implement zig decl gen for pointer type value: '{s}'", .{@tagName(val.tag())}),

View File

@ -10,6 +10,7 @@ test {
_ = @import("behavior/bugs/655.zig");
_ = @import("behavior/bugs/656.zig");
_ = @import("behavior/bugs/679.zig");
_ = @import("behavior/bugs/1025.zig");
_ = @import("behavior/bugs/1111.zig");
_ = @import("behavior/bugs/1277.zig");
_ = @import("behavior/bugs/1310.zig");
@ -17,6 +18,8 @@ test {
_ = @import("behavior/bugs/1486.zig");
_ = @import("behavior/bugs/1500.zig");
_ = @import("behavior/bugs/1735.zig");
_ = @import("behavior/bugs/1741.zig");
_ = @import("behavior/bugs/1914.zig");
_ = @import("behavior/bugs/2006.zig");
_ = @import("behavior/bugs/2346.zig");
_ = @import("behavior/bugs/3112.zig");
@ -38,7 +41,8 @@ test {
_ = @import("behavior/struct.zig");
if (builtin.zig_backend != .stage2_arm and builtin.zig_backend != .stage2_x86_64) {
// Tests that pass for stage1, llvm backend, C backend, wasm backend.
// Tests that pass (partly) for stage1, llvm backend, C backend, wasm backend.
_ = @import("behavior/array_llvm.zig");
_ = @import("behavior/basic.zig");
_ = @import("behavior/bitcast.zig");
_ = @import("behavior/bugs/624.zig");
@ -69,6 +73,7 @@ test {
_ = @import("behavior/pointers.zig");
_ = @import("behavior/ptrcast.zig");
_ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
_ = @import("behavior/slice.zig");
_ = @import("behavior/src.zig");
_ = @import("behavior/this.zig");
_ = @import("behavior/try.zig");
@ -88,11 +93,7 @@ test {
if (builtin.zig_backend != .stage2_c) {
// Tests that pass for stage1 and the llvm backend.
_ = @import("behavior/array_llvm.zig");
_ = @import("behavior/atomics.zig");
_ = @import("behavior/bugs/1025.zig");
_ = @import("behavior/bugs/1741.zig");
_ = @import("behavior/bugs/1914.zig");
_ = @import("behavior/bugs/2578.zig");
_ = @import("behavior/bugs/3007.zig");
_ = @import("behavior/bugs/9584.zig");
@ -108,7 +109,6 @@ test {
_ = @import("behavior/popcount.zig");
_ = @import("behavior/saturating_arithmetic.zig");
_ = @import("behavior/sizeof_and_typeof.zig");
_ = @import("behavior/slice.zig");
_ = @import("behavior/struct_llvm.zig");
_ = @import("behavior/switch.zig");
_ = @import("behavior/widening.zig");

View File

@ -7,6 +7,7 @@ var s_array: [8]Sub = undefined;
const Sub = struct { b: u8 };
const Str = struct { a: []Sub };
test "set global var array via slice embedded in struct" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
var s = Str{ .a = s_array[0..] };
s.a[0].b = 1;
@ -19,6 +20,7 @@ test "set global var array via slice embedded in struct" {
}
test "read/write through global variable array of struct fields initialized via array mult" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
try expect(storage[0].term == 1);
@ -36,6 +38,7 @@ test "read/write through global variable array of struct fields initialized via
}
test "implicit cast single-item pointer" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
try testImplicitCastSingleItemPtr();
comptime try testImplicitCastSingleItemPtr();
}
@ -52,6 +55,7 @@ fn testArrayByValAtComptime(b: [2]u8) u8 {
}
test "comptime evaluating function that takes array by value" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const arr = [_]u8{ 1, 2 };
const x = comptime testArrayByValAtComptime(arr);
const y = comptime testArrayByValAtComptime(arr);
@ -60,12 +64,14 @@ test "comptime evaluating function that takes array by value" {
}
test "runtime initialize array elem and then implicit cast to slice" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
var two: i32 = 2;
const x: []const i32 = &[_]i32{two};
try expect(x[0] == 2);
}
test "array literal as argument to function" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn entry(two: i32) !void {
try foo(&[_]i32{ 1, 2, 3 });
@ -90,6 +96,7 @@ test "array literal as argument to function" {
}
test "double nested array to const slice cast in array literal" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn entry(two: i32) !void {
const cases = [_][]const []const i32{
@ -147,6 +154,7 @@ test "double nested array to const slice cast in array literal" {
}
test "anonymous literal in array" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
const Foo = struct {
a: usize = 2,
@ -168,6 +176,7 @@ test "anonymous literal in array" {
}
test "access the null element of a null terminated array" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
@ -181,6 +190,7 @@ test "access the null element of a null terminated array" {
}
test "type deduction for array subscript expression" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
var array = [_]u8{ 0x55, 0xAA };
@ -196,6 +206,8 @@ test "type deduction for array subscript expression" {
test "sentinel element count towards the ABI size calculation" {
if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
@ -218,6 +230,8 @@ test "sentinel element count towards the ABI size calculation" {
test "zero-sized array with recursive type definition" {
if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const U = struct {
fn foo(comptime T: type, comptime n: usize) type {
@ -237,6 +251,7 @@ test "zero-sized array with recursive type definition" {
}
test "type coercion of anon struct literal to array" {
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
const U = union {
a: u32,
@ -253,6 +268,7 @@ test "type coercion of anon struct literal to array" {
try expect(arr1[2] == 54);
if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
var x2: U = .{ .a = 42 };
const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
@ -268,6 +284,8 @@ test "type coercion of anon struct literal to array" {
test "type coercion of pointer to anon struct literal to pointer to array" {
if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
const U = union {

View File

@ -1,3 +1,5 @@
const builtin = @import("builtin");
const A = struct {
B: type,
};
@ -7,6 +9,8 @@ fn getA() A {
}
test "bug 1025" {
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const a = getA();
try @import("std").testing.expect(a.B == u8);
}

View File

@ -1,6 +1,9 @@
const std = @import("std");
const builtin = @import("builtin");
test "fixed" {
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const x: f32 align(128) = 12.34;
try std.testing.expect(@ptrToInt(&x) % 128 == 0);
}

View File

@ -1,4 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const A = struct {
b_list_pointer: *const []B,
@ -11,6 +12,9 @@ const b_list: []B = &[_]B{};
const a = A{ .b_list_pointer = &b_list };
test "segfault bug" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const assert = std.debug.assert;
const obj = B{ .a_pointer = &a };
assert(obj.a_pointer == &a); // this makes zig crash
@ -27,5 +31,8 @@ pub const B2 = struct {
var b_value = B2{ .pointer_array = &[_]*A2{} };
test "basic stuff" {
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
std.debug.assert(&b_value == &b_value);
}

View File

@ -27,6 +27,7 @@ comptime {
}
test "slicing" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
var array: [20]i32 = undefined;
array[5] = 1234;
@ -43,6 +44,7 @@ test "slicing" {
}
test "const slice" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
comptime {
const a = "1234567890";
try expect(a.len == 10);
@ -53,6 +55,7 @@ test "const slice" {
}
test "comptime slice of undefined pointer of length 0" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const slice1 = @as([*]i32, undefined)[0..0];
try expect(slice1.len == 0);
const slice2 = @as([*]i32, undefined)[100..100];
@ -60,6 +63,7 @@ test "comptime slice of undefined pointer of length 0" {
}
test "implicitly cast array of size 0 to slice" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
var msg = [_]u8{};
try assertLenIsZero(&msg);
}
@ -69,6 +73,7 @@ fn assertLenIsZero(msg: []const u8) !void {
}
test "access len index of sentinel-terminated slice" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
var slice: [:0]const u8 = "hello";
@ -82,6 +87,7 @@ test "access len index of sentinel-terminated slice" {
}
test "comptime slice of slice preserves comptime var" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
comptime {
var buff: [10]u8 = undefined;
buff[0..][0..][0] = 1;
@ -90,6 +96,7 @@ test "comptime slice of slice preserves comptime var" {
}
test "slice of type" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
comptime {
var types_array = [_]type{ i32, f64, type };
for (types_array) |T, i| {
@ -112,6 +119,7 @@ test "slice of type" {
}
test "generic malloc free" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const a = memAlloc(u8, 10) catch unreachable;
memFree(u8, a);
}
@ -124,6 +132,7 @@ fn memFree(comptime T: type, memory: []T) void {
}
test "slice of hardcoded address to pointer" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
const pointer = @intToPtr([*]u8, 0x04)[0..2];
@ -138,6 +147,7 @@ test "slice of hardcoded address to pointer" {
}
test "comptime slice of pointer preserves comptime var" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
comptime {
var buff: [10]u8 = undefined;
var a = @ptrCast([*]u8, &buff);
@ -147,6 +157,7 @@ test "comptime slice of pointer preserves comptime var" {
}
test "comptime pointer cast array and then slice" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
const ptrA: [*]const u8 = @ptrCast([*]const u8, &array);
@ -160,6 +171,7 @@ test "comptime pointer cast array and then slice" {
}
test "slicing zero length array" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
const s1 = ""[0..];
const s2 = ([_]u32{})[0..];
try expect(s1.len == 0);
@ -171,6 +183,7 @@ test "slicing zero length array" {
const x = @intToPtr([*]i32, 0x1000)[0..0x500];
const y = x[0x100..];
test "compile time slice of pointer to hard coded address" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
try expect(@ptrToInt(x) == 0x1000);