aboutsummaryrefslogtreecommitdiff
path: root/lib/std/build/CheckObjectStep.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-07-18 00:43:11 +0200
committerJakub Konka <kubkon@jakubkonka.com>2022-07-22 16:58:21 +0200
commit2c184f9a5fc78be4f38cc74106c203b7bc80deb4 (patch)
treeec4df1baf19942ca759bd5b28bc1274b3f54ae19 /lib/std/build/CheckObjectStep.zig
parent2dfc78dc0369052033c8469e00bf599e12e73f52 (diff)
downloadzig-2c184f9a5fc78be4f38cc74106c203b7bc80deb4.tar.gz
zig-2c184f9a5fc78be4f38cc74106c203b7bc80deb4.zip
link-tests: add checkNotPresent and add -dead_strip smoke test
`checkNotPresent` is the inverse of `checkNext` - if the phrase is found in the output, then it fails the test.
Diffstat (limited to 'lib/std/build/CheckObjectStep.zig')
-rw-r--r--lib/std/build/CheckObjectStep.zig35
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/std/build/CheckObjectStep.zig b/lib/std/build/CheckObjectStep.zig
index cb91f883c9..b807e1de45 100644
--- a/lib/std/build/CheckObjectStep.zig
+++ b/lib/std/build/CheckObjectStep.zig
@@ -50,7 +50,7 @@ pub fn create(builder: *Builder, source: build.FileSource, obj_format: std.Targe
/// For example, if the two extracted values were saved as `vmaddr` and `entryoff` respectively
/// they could then be added with this simple program `vmaddr entryoff +`.
const Action = struct {
- tag: enum { match, compute_cmp },
+ tag: enum { match, not_present, compute_cmp },
phrase: []const u8,
expected: ?ComputeCompareExpected = null,
@@ -63,7 +63,7 @@ const Action = struct {
/// name {*}libobjc{*}.dylib => will match `name` followed by a token which contains `libobjc` and `.dylib`
/// in that order with other letters in between
fn match(act: Action, haystack: []const u8, global_vars: anytype) !bool {
- assert(act.tag == .match);
+ assert(act.tag == .match or act.tag == .not_present);
var candidate_var: ?struct { name: []const u8, value: u64 } = null;
var hay_it = mem.tokenize(u8, mem.trim(u8, haystack, " "), " ");
@@ -202,6 +202,13 @@ const Check = struct {
}) catch unreachable;
}
+ fn notPresent(self: *Check, phrase: []const u8) void {
+ self.actions.append(.{
+ .tag = .not_present,
+ .phrase = self.builder.dupe(phrase),
+ }) catch unreachable;
+ }
+
fn computeCmp(self: *Check, phrase: []const u8, expected: ComputeCompareExpected) void {
self.actions.append(.{
.tag = .compute_cmp,
@@ -226,6 +233,15 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
last.match(phrase);
}
+/// Adds another searched phrase to the latest created Check with `CheckObjectStep.checkStart(...)`
+/// however ensures there is no matching phrase in the output.
+/// Asserts at least one check already exists.
+pub fn checkNotPresent(self: *CheckObjectStep, phrase: []const u8) void {
+ assert(self.checks.items.len > 0);
+ const last = &self.checks.items[self.checks.items.len - 1];
+ last.notPresent(phrase);
+}
+
/// Creates a new check checking specifically symbol table parsed and dumped from the object
/// file.
/// Issuing this check will force parsing and dumping of the symbol table.
@@ -293,6 +309,21 @@ fn make(step: *Step) !void {
return error.TestFailed;
}
},
+ .not_present => {
+ while (it.next()) |line| {
+ if (try act.match(line, &vars)) {
+ std.debug.print(
+ \\
+ \\========= Expected not to find: ===================
+ \\{s}
+ \\========= But parsed file does contain it: ========
+ \\{s}
+ \\
+ , .{ act.phrase, output });
+ return error.TestFailed;
+ }
+ }
+ },
.compute_cmp => {
const res = act.computeCmp(gpa, vars) catch |err| switch (err) {
error.UnknownVariable => {