aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGuillaume Wenzek <gwenzek@users.noreply.github.com>2022-03-01 23:26:43 +0100
committerAndrew Kelley <andrew@ziglang.org>2022-03-12 14:25:59 -0500
commitf000f8a59a8bf1121ecbe9b60ae50cc0218d3ba3 (patch)
treef4578be5065b377c3c158562206311ed4d28f99d /test
parent5ff7b04a6ad72eb86b6d467dfdc25bea1a9ecf63 (diff)
downloadzig-f000f8a59a8bf1121ecbe9b60ae50cc0218d3ba3.tar.gz
zig-f000f8a59a8bf1121ecbe9b60ae50cc0218d3ba3.zip
fix nvptx test failure #10968
allow test cases to chose wether to link libc or not. default behavior is to not link libc, except for `exeUsingLLVMBackend`
Diffstat (limited to 'test')
-rw-r--r--test/cases.zig3
-rw-r--r--test/stage2/nvptx.zig42
2 files changed, 30 insertions, 15 deletions
diff --git a/test/cases.zig b/test/cases.zig
index 994781132e..a65baeeef6 100644
--- a/test/cases.zig
+++ b/test/cases.zig
@@ -16,6 +16,5 @@ pub fn addCases(ctx: *TestContext) !void {
try @import("stage2/riscv64.zig").addCases(ctx);
try @import("stage2/plan9.zig").addCases(ctx);
try @import("stage2/x86_64.zig").addCases(ctx);
- // TODO https://github.com/ziglang/zig/issues/10968
- //try @import("stage2/nvptx.zig").addCases(ctx);
+ try @import("stage2/nvptx.zig").addCases(ctx);
}
diff --git a/test/stage2/nvptx.zig b/test/stage2/nvptx.zig
index 95ca79d448..7182092be7 100644
--- a/test/stage2/nvptx.zig
+++ b/test/stage2/nvptx.zig
@@ -1,21 +1,16 @@
const std = @import("std");
const TestContext = @import("../../src/test.zig").TestContext;
-const nvptx = std.zig.CrossTarget{
- .cpu_arch = .nvptx64,
- .os_tag = .cuda,
-};
-
pub fn addCases(ctx: *TestContext) !void {
{
- var case = ctx.exeUsingLlvmBackend("simple addition and subtraction", nvptx);
+ var case = addPtx(ctx, "nvptx: simple addition and subtraction");
case.compiles(
\\fn add(a: i32, b: i32) i32 {
\\ return a + b;
\\}
\\
- \\pub export fn main(a: i32, out: *i32) callconv(.PtxKernel) void {
+ \\pub export fn add_and_substract(a: i32, out: *i32) callconv(.PtxKernel) void {
\\ const x = add(a, 7);
\\ var y = add(2, 0);
\\ y -= x;
@@ -25,28 +20,28 @@ pub fn addCases(ctx: *TestContext) !void {
}
{
- var case = ctx.exeUsingLlvmBackend("read special registers", nvptx);
+ var case = addPtx(ctx, "nvptx: read special registers");
case.compiles(
- \\fn tid() usize {
+ \\fn threadIdX() usize {
\\ var tid = asm volatile ("mov.u32 \t$0, %tid.x;"
\\ : [ret] "=r" (-> u32),
\\ );
\\ return @as(usize, tid);
\\}
\\
- \\pub export fn main(a: []const i32, out: []i32) callconv(.PtxKernel) void {
- \\ const i = tid();
+ \\pub export fn special_reg(a: []const i32, out: []i32) callconv(.PtxKernel) void {
+ \\ const i = threadIdX();
\\ out[i] = a[i] + 7;
\\}
);
}
{
- var case = ctx.exeUsingLlvmBackend("address spaces", nvptx);
+ var case = addPtx(ctx, "nvptx: address spaces");
case.compiles(
- \\var x: u32 addrspace(.global) = 0;
+ \\var x: i32 addrspace(.global) = 0;
\\
\\pub export fn increment(out: *i32) callconv(.PtxKernel) void {
\\ x += 1;
@@ -55,3 +50,24 @@ pub fn addCases(ctx: *TestContext) !void {
);
}
}
+
+const nvptx_target = std.zig.CrossTarget{
+ .cpu_arch = .nvptx64,
+ .os_tag = .cuda,
+};
+
+pub fn addPtx(
+ ctx: *TestContext,
+ name: []const u8,
+) *TestContext.Case {
+ ctx.cases.append(TestContext.Case{
+ .name = name,
+ .target = nvptx_target,
+ .updates = std.ArrayList(TestContext.Update).init(ctx.cases.allocator),
+ .output_mode = .Obj,
+ .files = std.ArrayList(TestContext.File).init(ctx.cases.allocator),
+ .link_libc = false,
+ .backend = .llvm,
+ }) catch @panic("out of memory");
+ return &ctx.cases.items[ctx.cases.items.len - 1];
+}