Skip to content

Commit

Permalink
tests: update to new std.Target abis, and remove 32-bit CPU support f…
Browse files Browse the repository at this point in the history
…or Apple platforms
  • Loading branch information
ehaas committed Dec 30, 2024
1 parent 24578d8 commit 10fa5bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/aro/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,9 @@ pub fn isPICDefaultForced(target: std.Target) DefaultPIStatus {
test "alignment functions - smoke test" {
var target: std.Target = undefined;
const x86 = std.Target.Cpu.Arch.x86_64;
target.cpu = std.Target.Cpu.baseline(x86, .{ .tag = .linux, .version_range = std.Target.Os.VersionRange.default(.linux, x86) });
target.os = std.Target.Os.Tag.defaultVersionRange(.linux, x86);
target.abi = std.Target.Abi.default(x86, target.os);
target.abi = .gnu;
target.cpu = std.Target.Cpu.baseline(x86, .{ .tag = .linux, .version_range = std.Target.Os.VersionRange.default(x86, .linux, target.abi) });
target.os = std.Target.Os.Tag.defaultVersionRange(.linux, x86, target.abi);

try std.testing.expect(isTlsSupported(target));
try std.testing.expect(!ignoreNonZeroSizedBitfieldTypeAlignment(target));
Expand All @@ -973,9 +973,9 @@ test "alignment functions - smoke test" {
try std.testing.expect(systemCompiler(target) == .gcc);

const arm = std.Target.Cpu.Arch.arm;
target.cpu = std.Target.Cpu.baseline(arm, .{ .tag = .linux, .version_range = std.Target.Os.VersionRange.default(.linux, arm) });
target.os = std.Target.Os.Tag.defaultVersionRange(.ios, arm);
target.abi = std.Target.Abi.default(arm, target.os);
target.cpu = std.Target.Cpu.baseline(arm, .{ .tag = .linux, .version_range = std.Target.Os.VersionRange.default(arm, .linux, target.abi) });
target.os = std.Target.Os.Tag.defaultVersionRange(.ios, arm, target.abi);

try std.testing.expect(!isTlsSupported(target));
try std.testing.expect(ignoreNonZeroSizedBitfieldTypeAlignment(target));
Expand All @@ -992,8 +992,8 @@ test "target size/align tests" {
const x86 = std.Target.Cpu.Arch.x86;
comp.target.cpu.arch = x86;
comp.target.cpu.model = &std.Target.x86.cpu.i586;
comp.target.os = std.Target.Os.Tag.defaultVersionRange(.linux, x86);
comp.target.abi = std.Target.Abi.gnu;
comp.target.os = std.Target.Os.Tag.defaultVersionRange(.linux, x86, comp.target.abi);

const tt: Type = .{
.specifier = .long_long,
Expand All @@ -1004,8 +1004,8 @@ test "target size/align tests" {

const arm = std.Target.Cpu.Arch.arm;
comp.target.cpu = std.Target.Cpu.Model.toCpu(&std.Target.arm.cpu.cortex_r4, arm);
comp.target.os = std.Target.Os.Tag.defaultVersionRange(.ios, arm);
comp.target.abi = std.Target.Abi.none;
comp.target.os = std.Target.Os.Tag.defaultVersionRange(.ios, arm, comp.target.abi);

const ct: Type = .{
.specifier = .char,
Expand Down
58 changes: 26 additions & 32 deletions test/record_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,21 @@ fn singleRun(alloc: std.mem.Allocator, test_dir: []const u8, test_case: TestCase
try comp.addDefaultPragmaHandlers();
try comp.addBuiltinIncludeDir(test_dir);

const target = setTarget(&comp, test_case.target) catch |err| switch (err) {
error.UnknownCpuModel => unreachable,
};
switch (target.os.tag) {
try setTarget(&comp, test_case.target);
switch (comp.target.os.tag) {
.hermit => {
stats.recordResult(.invalid_target);
return; // Skip targets Aro doesn't support.
},
.ios, .macos => {
switch (comp.target.cpu.arch) {
.x86, .arm => {
stats.recordResult(.invalid_target);
return; // Skip targets Aro doesn't support.
},
else => {},
}
},
else => {},
}

Expand Down Expand Up @@ -339,44 +346,31 @@ fn singleRun(alloc: std.mem.Allocator, test_dir: []const u8, test_case: TestCase

/// Get Zig std.Target from string in the arch-cpu-os-abi format.
fn getTarget(zig_target_string: []const u8) !std.Target {
var ret: std.Target = undefined;
var buf: [128]u8 = undefined;
var iter = std.mem.tokenizeScalar(u8, zig_target_string, '-');

ret.cpu.arch = std.meta.stringToEnum(std.Target.Cpu.Arch, iter.next().?).?;
ret.cpu.model = try std.Target.Cpu.Arch.parseCpuModel(ret.cpu.arch, iter.next().?);

const tag = std.meta.stringToEnum(std.Target.Os.Tag, iter.next().?).?;
// `defaultVersionRange` will panic for invalid targets, check that
// here and set it to a reasonable default instead
var os: ?std.Target.Os = null;
if (tag == .macos) {
switch (ret.cpu.arch) {
.x86_64, .aarch64 => {},
else => os = .{ .version_range = .{ .none = {} }, .tag = .macos },
}
}

ret.os = os orelse std.Target.Os.Tag.defaultVersionRange(tag, ret.cpu.arch);
ret.abi = std.meta.stringToEnum(std.Target.Abi, iter.next().?).?;
return ret;
const arch = iter.next().?;
const model = iter.next().?;
const os = iter.next().?;
const abi = iter.next().?;
var fb = std.io.fixedBufferStream(&buf);
try std.fmt.format(fb.writer(), "{s}-{s}-{s}", .{ arch, os, abi });

const query = try std.Target.Query.parse(.{
.arch_os_abi = fb.getWritten(),
.cpu_features = model,
});
return std.zig.system.resolveTargetQuery(query);
}

fn setTarget(comp: *aro.Compilation, target: []const u8) !std.Target {
fn setTarget(comp: *aro.Compilation, target: []const u8) !void {
const compiler_split_index = std.mem.indexOf(u8, target, ":").?;

const zig_target = try getTarget(target[0..compiler_split_index]);
comp.target.cpu = std.Target.Cpu.Model.toCpu(zig_target.cpu.model, zig_target.cpu.arch);
comp.target.os.tag = zig_target.os.tag;
comp.target.os.version_range = zig_target.os.version_range;
comp.target.abi = zig_target.abi;

comp.target = try getTarget(target[0..compiler_split_index]);
comp.langopts.emulate = aro.target_util.systemCompiler(comp.target);

const expected_compiler_name = target[compiler_split_index + 1 ..];
const set_name = @tagName(comp.langopts.emulate);
std.debug.assert(std.ascii.eqlIgnoreCase(set_name, expected_compiler_name));

return zig_target;
}

fn parseTargetsFromCode(cases: *TestCase.List, path: []const u8, source: []const u8) !void {
Expand Down

0 comments on commit 10fa5bb

Please sign in to comment.