stage2: return error.SkipZigTest in unsupported behavior tests

This commit is contained in:
Jakub Konka 2022-01-17 20:30:44 +01:00
parent 9b715cb462
commit ab204f81b0
5 changed files with 350 additions and 305 deletions

View File

@ -16,16 +16,11 @@ test {
_ = @import("behavior/type.zig");
_ = @import("behavior/bugs/655.zig");
_ = @import("behavior/bool.zig");
if (builtin.zig_backend != .stage2_arm) {
// Tests that pass for stage1, llvm backend, C backend, wasm backend and x86_64 backend.
_ = @import("behavior/align_simple.zig");
_ = @import("behavior/array_simple.zig");
_ = @import("behavior/align.zig");
_ = @import("behavior/array.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.
_ = @import("behavior/align.zig");
_ = @import("behavior/array.zig");
_ = @import("behavior/basic.zig");
_ = @import("behavior/bitcast.zig");
_ = @import("behavior/bugs/624.zig");
@ -215,5 +210,4 @@ test {
}
}
}
}
}

View File

@ -3,7 +3,124 @@ const expect = std.testing.expect;
const builtin = @import("builtin");
const native_arch = builtin.target.cpu.arch;
var foo: u8 align(4) = 100;
test "global variable alignment" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
comptime try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
comptime try expect(@TypeOf(&foo) == *align(4) u8);
{
const slice = @as(*[1]u8, &foo)[0..];
comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
}
{
var runtime_zero: usize = 0;
const slice = @as(*[1]u8, &foo)[runtime_zero..];
comptime try expect(@TypeOf(slice) == []align(4) u8);
}
}
test "default alignment allows unspecified in type syntax" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(*u32 == *align(@alignOf(u32)) u32);
}
test "implicitly decreasing pointer alignment" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
try expect(addUnaligned(&a, &b) == 7);
}
fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
return a.* + b.*;
}
test "@alignCast pointers" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var x: u32 align(4) = 1;
expectsOnly1(&x);
try expect(x == 2);
}
fn expectsOnly1(x: *align(1) u32) void {
expects4(@alignCast(4, x));
}
fn expects4(x: *align(4) u32) void {
x.* += 1;
}
test "alignment of structs" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(@alignOf(struct {
a: i32,
b: *i32,
}) == @alignOf(usize));
}
test "alignment of >= 128-bit integer type" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(@alignOf(u128) == 16);
try expect(@alignOf(u129) == 16);
}
test "alignment of struct with 128-bit field" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(@alignOf(struct {
x: u128,
}) == 16);
comptime {
try expect(@alignOf(struct {
x: u128,
}) == 16);
}
}
test "size of extern struct with 128-bit field" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(@sizeOf(extern struct {
x: u128,
y: u8,
}) == 32);
comptime {
try expect(@sizeOf(extern struct {
x: u128,
y: u8,
}) == 32);
}
}
test "@ptrCast preserves alignment of bigger source" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var x: u32 align(16) = 1234;
const ptr = @ptrCast(*u8, &x);
try expect(@TypeOf(ptr) == *align(16) u8);
}
test "alignstack" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(fnWithAlignedStack() == 1234);
}
fn fnWithAlignedStack() i32 {
@setAlignStack(256);
return 1234;
}
test "implicitly decreasing slice alignment" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
try expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7);
@ -13,6 +130,8 @@ fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 {
}
test "specifying alignment allows pointer cast" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try testBytesAlign(0x33);
}
fn testBytesAlign(b: u8) !void {
@ -22,6 +141,8 @@ fn testBytesAlign(b: u8) !void {
}
test "@alignCast slices" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var array align(4) = [_]u32{ 1, 1 };
const slice = array[0..];
sliceExpectsOnly1(slice);
@ -35,6 +156,8 @@ fn sliceExpects4(slice: []align(4) u32) void {
}
test "return error union with 128-bit integer" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(3 == try give());
}
fn give() anyerror!u128 {

View File

@ -1,99 +0,0 @@
const std = @import("std");
const expect = std.testing.expect;
const builtin = @import("builtin");
const native_arch = builtin.target.cpu.arch;
var foo: u8 align(4) = 100;
test "global variable alignment" {
comptime try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
comptime try expect(@TypeOf(&foo) == *align(4) u8);
{
const slice = @as(*[1]u8, &foo)[0..];
comptime try expect(@TypeOf(slice) == *align(4) [1]u8);
}
{
var runtime_zero: usize = 0;
const slice = @as(*[1]u8, &foo)[runtime_zero..];
comptime try expect(@TypeOf(slice) == []align(4) u8);
}
}
test "default alignment allows unspecified in type syntax" {
try expect(*u32 == *align(@alignOf(u32)) u32);
}
test "implicitly decreasing pointer alignment" {
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
try expect(addUnaligned(&a, &b) == 7);
}
fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 {
return a.* + b.*;
}
test "@alignCast pointers" {
var x: u32 align(4) = 1;
expectsOnly1(&x);
try expect(x == 2);
}
fn expectsOnly1(x: *align(1) u32) void {
expects4(@alignCast(4, x));
}
fn expects4(x: *align(4) u32) void {
x.* += 1;
}
test "alignment of structs" {
try expect(@alignOf(struct {
a: i32,
b: *i32,
}) == @alignOf(usize));
}
test "alignment of >= 128-bit integer type" {
try expect(@alignOf(u128) == 16);
try expect(@alignOf(u129) == 16);
}
test "alignment of struct with 128-bit field" {
try expect(@alignOf(struct {
x: u128,
}) == 16);
comptime {
try expect(@alignOf(struct {
x: u128,
}) == 16);
}
}
test "size of extern struct with 128-bit field" {
try expect(@sizeOf(extern struct {
x: u128,
y: u8,
}) == 32);
comptime {
try expect(@sizeOf(extern struct {
x: u128,
y: u8,
}) == 32);
}
}
test "@ptrCast preserves alignment of bigger source" {
var x: u32 align(16) = 1234;
const ptr = @ptrCast(*u8, &x);
try expect(@TypeOf(ptr) == *align(16) u8);
}
test "alignstack" {
try expect(fnWithAlignedStack() == 1234);
}
fn fnWithAlignedStack() i32 {
@setAlignStack(256);
return 1234;
}

View File

@ -5,7 +5,23 @@ const mem = std.mem;
const expect = testing.expect;
const expectEqual = testing.expectEqual;
test "array to slice" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
const a_slice: []align(1) const u32 = @as(*const [1]u32, &a)[0..];
const b_slice: []align(1) const u32 = @as(*const [1]u32, &b)[0..];
try expect(a_slice[0] + b_slice[0] == 7);
const d: []const u32 = &[2]u32{ 1, 2 };
const e: []const u32 = &[3]u32{ 3, 4, 5 };
try expect(d[0] + e[0] + d[1] + e[1] == 10);
}
test "arrays" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var array: [5]u32 = undefined;
var i: u32 = 0;
@ -30,6 +46,8 @@ fn getArrayLen(a: []const u32) usize {
}
test "array init with mult" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const a = 'a';
var i: [8]u8 = [2]u8{ a, 'b' } ** 4;
try expect(std.mem.eql(u8, &i, "abababab"));
@ -39,6 +57,8 @@ test "array init with mult" {
}
test "array literal with explicit type" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const hex_mult: [4]u16 = .{ 4096, 256, 16, 1 };
try expect(hex_mult.len == 4);
@ -46,6 +66,8 @@ test "array literal with explicit type" {
}
test "array literal with inferred length" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const hex_mult = [_]u16{ 4096, 256, 16, 1 };
try expect(hex_mult.len == 4);
@ -53,6 +75,8 @@ test "array literal with inferred length" {
}
test "array dot len const expr" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try expect(comptime x: {
break :x some_array.len == 4;
});
@ -64,12 +88,16 @@ const ArrayDotLenConstExpr = struct {
const some_array = [_]u8{ 0, 1, 2, 3 };
test "array literal with specified size" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var array = [2]u8{ 1, 2 };
try expect(array[0] == 1);
try expect(array[1] == 2);
}
test "array len field" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var arr = [4]u8{ 0, 0, 0, 0 };
var ptr = &arr;
try expect(arr.len == 4);
@ -79,6 +107,8 @@ test "array len field" {
}
test "array with sentinels" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const S = struct {
fn doTheTest(is_ct: bool) !void {
if (is_ct or builtin.zig_is_stage2) {
@ -106,6 +136,8 @@ test "array with sentinels" {
}
test "void arrays" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var array: [4]void = undefined;
array[0] = void{};
array[1] = array[2];
@ -114,6 +146,8 @@ test "void arrays" {
}
test "nested arrays" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_wasm) {
// TODO this is a recent stage2 test case regression due to an enhancement;
// now arrays are properly detected as comptime. This exercised a new code
@ -132,6 +166,8 @@ test "nested arrays" {
}
test "implicit comptime in array type size" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
var arr: [plusOne(10)]bool = undefined;
try expect(arr.len == 11);
}
@ -141,6 +177,8 @@ fn plusOne(x: u32) u32 {
}
test "single-item pointer to array indexing and slicing" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
try testSingleItemPtrArrayIndexSlice();
comptime try testSingleItemPtrArrayIndexSlice();
}
@ -164,6 +202,8 @@ fn doSomeMangling(array: *[4]u8) void {
}
test "implicit cast zero sized array ptr to slice" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
{
var b = "".*;
const c: []const u8 = &b;
@ -177,6 +217,8 @@ test "implicit cast zero sized array ptr to slice" {
}
test "anonymous list literal syntax" {
if (builtin.zig_backend == .stage2_x86_64 or builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
const S = struct {
fn doTheTest() !void {
var array: [4]u8 = .{ 1, 2, 3, 4 };

View File

@ -1,15 +0,0 @@
const std = @import("std");
const testing = std.testing;
const expect = testing.expect;
test "array to slice" {
const a: u32 align(4) = 3;
const b: u32 align(8) = 4;
const a_slice: []align(1) const u32 = @as(*const [1]u32, &a)[0..];
const b_slice: []align(1) const u32 = @as(*const [1]u32, &b)[0..];
try expect(a_slice[0] + b_slice[0] == 7);
const d: []const u32 = &[2]u32{ 1, 2 };
const e: []const u32 = &[3]u32{ 3, 4, 5 };
try expect(d[0] + e[0] + d[1] + e[1] == 10);
}