Skip to documentation
SLOP

tiny.profiling.experiment.oracle

Reference tiny.profiling experiment oracle

Defined in experiment.

API (3)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callsexperimentoracle
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallstest; no linksrc.profiling.experiment.oracletest: profiling experiment oracle ver...private; no linksrc.profiling.experiment.oraclematchesprivate; no linksrc.profiling.experiment.oracleverifyFilesfingerprintinspectexperiment.oracleverify
Static calls · unresolved targets: 0 · external targets: 2.

Source: src/profiling/experiment/oracle.zig

zig
const std = @import("std");const profiling = @import("../root.zig");const fingerprint = profiling.fingerprint;const scenario = profiling.scenario;pub const FileResult = struct {    path: []const u8,    expected_sha256: []const u8,    actual_sha256: ?fingerprint.Hex,    passed: bool,};pub const Result = struct {    passed: bool,    exit_code_matches: bool,    stdout_sha256: fingerprint.Hex,    stderr_sha256: fingerprint.Hex,    stdout_matches: bool,    stderr_matches: bool,    files: []const FileResult,};pub fn verify(    allocator: std.mem.Allocator,    expected: scenario.Oracle,    values: scenario.Substitutions,    cwd: ?[]const u8,    exit_code: i64,    stdout_path: []const u8,    stderr_path: []const u8,) !Result {    const stdout = try fingerprint.inspect(stdout_path);    const stderr = try fingerprint.inspect(stderr_path);    const stdout_hex = stdout.hex();    const stderr_hex = stderr.hex();    const stdout_matches = matches(expected.stdout_sha256, &stdout_hex);    const stderr_matches = matches(expected.stderr_sha256, &stderr_hex);    const files = try verifyFiles(        allocator,        expected.files,        values,        cwd,    );    var files_pass = true;    for (files) |file| files_pass = files_pass and file.passed;    const exit_matches = exit_code == expected.exit_code;    return .{        .passed = exit_matches and stdout_matches and            stderr_matches and files_pass,        .exit_code_matches = exit_matches,        .stdout_sha256 = stdout_hex,        .stderr_sha256 = stderr_hex,        .stdout_matches = stdout_matches,        .stderr_matches = stderr_matches,        .files = files,    };}fn verifyFiles(    allocator: std.mem.Allocator,    expected: []const scenario.FileOracle,    values: scenario.Substitutions,    cwd: ?[]const u8,) ![]const FileResult {    const result = try allocator.alloc(FileResult, expected.len);    for (expected, 0..) |file, index| {        const substituted = try scenario.substitute(            allocator,            file.path,            values,        );        const path = try resolvePath(allocator, cwd, substituted);        const actual = fingerprint.inspect(path) catch null;        const actual_hex = if (actual) |value| value.hex() else null;        result[index] = .{            .path = path,            .expected_sha256 = file.sha256,            .actual_sha256 = actual_hex,            .passed = if (actual_hex) |hex|                std.mem.eql(u8, file.sha256, &hex)            else                false,        };    }    return result;}fn resolvePath(    allocator: std.mem.Allocator,    cwd: ?[]const u8,    path: []const u8,) ![]const u8 {    if (std.fs.path.isAbsolute(path)) return path;    return try std.fs.path.join(allocator, &.{ cwd orelse ".", path });}fn matches(expected: ?[]const u8, actual: []const u8) bool {    const value = expected orelse return true;    return std.mem.eql(u8, value, actual);}test "profiling experiment oracle verifies exit and output digests" {    var temporary = std.testing.tmpDir(.{});    defer temporary.cleanup();    try temporary.dir.writeFile(std.Options.debug_io, .{        .sub_path = "stdout",        .data = "",    });    try temporary.dir.writeFile(std.Options.debug_io, .{        .sub_path = "stderr",        .data = "",    });    var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);    defer arena_state.deinit();    const allocator = arena_state.allocator();    const root = try temporary.parent_dir.realPathFileAlloc(        std.Options.debug_io,        temporary.sub_path[0..],        allocator,    );    const stdout_path = try std.fs.path.join(        allocator,        &.{ root, "stdout" },    );    const stderr_path = try std.fs.path.join(        allocator,        &.{ root, "stderr" },    );    const empty_digest = "e3b0c44298fc1c149afbf4c8996fb924" ++        "27ae41e4649b934ca495991b7852b855";    const result = try verify(        allocator,        .{ .stdout_sha256 = empty_digest },        .{ .binary = "bin", .root = root, .side = "baseline" },        root,        0,        stdout_path,        stderr_path,    );    try std.testing.expect(result.passed);    try std.testing.expect(result.stdout_matches);    const mismatch = try verify(        allocator,        .{ .exit_code = 1 },        .{ .binary = "bin", .root = root, .side = "baseline" },        root,        0,        stdout_path,        stderr_path,    );    try std.testing.expect(!mismatch.passed);    try std.testing.expect(!mismatch.exit_code_matches);}

Source: src/profiling/experiment/root.zig:4

zig
pub const oracle = @import("oracle.zig");

Audit

Definitions4
Public names4
Members11
Version26.7.0
Revisiondaab053ee433