Skip to content

Commit

Permalink
wip memory64
Browse files Browse the repository at this point in the history
* updated testsuite to use memory64 tests
* updated limits to parse u32/u64 sizes
  • Loading branch information
rdunnington committed Apr 7, 2024
1 parent 51b402b commit b3125fe
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 25 deletions.
10 changes: 5 additions & 5 deletions src/definition.zig
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,21 @@ pub const TaggedVal = struct {
};

pub const Limits = struct {
min: u32,
max: ?u32,
min: u64,
max: ?u64,

fn decode(reader: anytype) !Limits {
const has_max = try reader.readByte();
if (has_max > 1) {
return error.MalformedLimits;
}
const min = try common.decodeLEB128(u32, reader);
var max: ?u32 = null;
const min = try common.decodeLEB128(u64, reader);
var max: ?u64 = null;

switch (has_max) {
0 => {},
1 => {
max = try common.decodeLEB128(u32, reader);
max = try common.decodeLEB128(u64, reader);
if (max.? < min) {
return error.ValidationLimitsMinMustNotBeLargerThanMax;
}
Expand Down
4 changes: 2 additions & 2 deletions src/instance.zig
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ pub const ModuleInstance = struct {
return false;
}

var def_max: u32 = if (def_limits.max) |max| max else std.math.maxInt(u32);
var instance_max: u32 = if (instance_limits.max) |max| max else 0;
var def_max: u64 = if (def_limits.max) |max| max else std.math.maxInt(u64);
var instance_max: u64 = if (instance_limits.max) |max| max else 0;

return def_limits.min <= instance_limits.min and def_max >= instance_max;
}
Expand Down
75 changes: 58 additions & 17 deletions test/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ fn run(allocator: std.mem.Allocator, suite_path: []const u8, opts: *const TestOp
return !did_fail_any_test;
}

pub fn parse_vm_type(backend_str: []const u8) VmType {
pub fn parseVmType(backend_str: []const u8) VmType {
if (strcmp("stack", backend_str)) {
return .Stack;
} else if (strcmp("register", backend_str)) {
Expand All @@ -1233,6 +1233,31 @@ pub fn parse_vm_type(backend_str: []const u8) VmType {
}
}

fn pathExists(path: []const u8) bool {
std.fs.cwd().access(path, .{ .mode = .read_only }) catch |e| {
return switch (e) {
error.PermissionDenied,
error.FileBusy,
error.ReadOnlyFileSystem,
=> true,

error.FileNotFound => false,

// unknown status, but we'll count it as a fail
error.NameTooLong,
error.InputOutput,
error.SystemResources,
error.BadPathName,
error.SymLinkLoop,
error.InvalidUtf8,
=> false,
else => false,
};
};

return true;
}

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var allocator: std.mem.Allocator = gpa.allocator();
Expand Down Expand Up @@ -1284,7 +1309,7 @@ pub fn main() !void {
return;
} else if (strcmp("--backend", arg)) {
args_index += 1;
opts.vm_type = parse_vm_type(args[args_index]);
opts.vm_type = parseVmType(args[args_index]);
} else if (strcmp("--suite", arg)) {
args_index += 1;
opts.suite_filter_or_null = args[args_index];
Expand Down Expand Up @@ -1324,7 +1349,7 @@ pub fn main() !void {
"bulk",
"call",
"call_indirect",
"comments",
// "comments", // wabt seems to error on this
"const",
"conversions",
"custom",
Expand Down Expand Up @@ -1469,32 +1494,48 @@ pub fn main() !void {
}
}

var suite_path_no_extension: []const u8 = try std.fs.path.join(allocator, &[_][]const u8{ "test", "wasm", suite, suite });
// determine if there is a memory64 version of the test - if so, run that one
const suite_wast_base_path_no_extension: []const u8 = try std.fs.path.join(allocator, &[_][]const u8{ "test", "testsuite", suite });
defer allocator.free(suite_wast_base_path_no_extension);
const suite_wast_base_path: []u8 = try std.mem.join(allocator, "", &[_][]const u8{ suite_wast_base_path_no_extension, ".wast" });
defer allocator.free(suite_wast_base_path);

const suite_wast_mem64_path_no_extension: []const u8 = try std.fs.path.join(allocator, &[_][]const u8{ "test", "testsuite", "proposals", "memory64", suite });
defer allocator.free(suite_wast_mem64_path_no_extension);
const suite_wast_mem64_path: []u8 = try std.mem.join(allocator, "", &[_][]const u8{ suite_wast_mem64_path_no_extension, ".wast" });
defer allocator.free(suite_wast_mem64_path);

const suite_wast_path = blk: {
if (pathExists(suite_wast_mem64_path)) {
if (opts.log_suite) {
print("Using memory64 for suite {s}\n", .{suite});
}
break :blk suite_wast_mem64_path;
} else {
break :blk suite_wast_base_path;
}
};

// wasm path
const suite_path_no_extension: []const u8 = try std.fs.path.join(allocator, &[_][]const u8{ "test", "wasm", suite, suite });
defer allocator.free(suite_path_no_extension);

var suite_path = try std.mem.join(allocator, "", &[_][]const u8{ suite_path_no_extension, ".json" });
const suite_path = try std.mem.join(allocator, "", &[_][]const u8{ suite_path_no_extension, ".json" });
defer allocator.free(suite_path);

var needs_regen: bool = false;
if (opts.force_wasm_regen_only) {
needs_regen = true;
} else {
std.fs.cwd().access(suite_path, .{ .mode = .read_only }) catch |e| {
if (e == std.os.AccessError.FileNotFound) {
needs_regen = true;
}
};
needs_regen = pathExists(suite_path) == false;
}

if (needs_regen) {
logVerbose("Regenerating wasm and json driver for suite {s}\n", .{suite});

// var suite_wast_path_no_extension = try std.fs.path.join(allocator, &[_][]const u8{ "test", "testsuite", suite });
var suite_wast_path_no_extension = try std.fs.path.join(allocator, &[_][]const u8{ "../../testsuite", suite });
defer allocator.free(suite_wast_path_no_extension);

var suite_wast_path = try std.mem.join(allocator, "", &[_][]const u8{ suite_wast_path_no_extension, ".wast" });
defer allocator.free(suite_wast_path);
// need to navigate back to repo root because the wast2json process will be running in a subdir
var suite_wast_path_relative = try std.fs.path.join(allocator, &[_][]const u8{ "../../../", suite_wast_path });
defer allocator.free(suite_wast_path_relative);

var suite_wasm_folder: []const u8 = try std.fs.path.join(allocator, &[_][]const u8{ "test", "wasm", suite });
defer allocator.free(suite_wasm_folder);
Expand All @@ -1511,7 +1552,7 @@ pub fn main() !void {
}
};

var process = std.ChildProcess.init(&[_][]const u8{ "wast2json", suite_wast_path }, allocator);
var process = std.ChildProcess.init(&[_][]const u8{ "wast2json", "--enable-memory64", suite_wast_path_relative }, allocator);

process.cwd = suite_wasm_folder;

Expand Down
2 changes: 1 addition & 1 deletion test/testsuite
Submodule testsuite updated 129 files

0 comments on commit b3125fe

Please sign in to comment.