add test
This commit is contained in:
parent
882f02bfd0
commit
7d3604957e
4 changed files with 33 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
zig-cache
|
||||
zig-out
|
||||
*.elf
|
||||
*.dol
|
||||
*.dol
|
||||
!testdata/*.elf
|
12
build.zig
12
build.zig
|
@ -23,4 +23,16 @@ pub fn build(b: *std.Build) void {
|
|||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
// Testing
|
||||
const elf_unit_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/elf.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const run_elf_unit_tests = b.addRunArtifact(elf_unit_tests);
|
||||
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_elf_unit_tests.step);
|
||||
}
|
||||
|
|
19
src/elf.zig
19
src/elf.zig
|
@ -255,3 +255,22 @@ fn checkELFHeader(header: ELFHeader) !void {
|
|||
return ELFError.NoEntrypoint;
|
||||
}
|
||||
}
|
||||
|
||||
test "readELF: parses known .elf" {
|
||||
const input = try std.fs.cwd().openFile("testdata/example.elf", .{});
|
||||
defer input.close();
|
||||
|
||||
const map = try readELF(input);
|
||||
try std.testing.expectEqual(0x80003100, map.entryPoint);
|
||||
try std.testing.expectEqual(1, map.textCount);
|
||||
try std.testing.expectEqual(1, map.dataCount);
|
||||
try std.testing.expectEqual(0x80003100, map.text[0].address);
|
||||
try std.testing.expectEqual(0x2DD0, map.text[0].size);
|
||||
try std.testing.expectEqual(0x3100, map.text[0].offset);
|
||||
try std.testing.expectEqual(0x80005ed0, map.data[0].address);
|
||||
try std.testing.expectEqual(0xD0, map.data[0].size);
|
||||
try std.testing.expectEqual(0x5ed0, map.data[0].offset);
|
||||
try std.testing.expectEqual(true, map.hasBSS);
|
||||
try std.testing.expectEqual(0x80005fa0, map.bssAddress);
|
||||
try std.testing.expectEqual(0x160, map.bssSize);
|
||||
}
|
||||
|
|
BIN
testdata/example.elf
vendored
Normal file
BIN
testdata/example.elf
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue