lib/memtrace/src/test.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const std = @import("std");
 2 const census_test = @import("census/test.zig");
 3 const stack_test = @import("stack/test.zig");
 4 const namespace_owner = @import("root.zig");
 5 
 6 const Census = namespace_owner.Census;
 7 const CensusCapacity = namespace_owner.CensusCapacity;
 8 const CensusLimits = namespace_owner.CensusLimits;
 9 const CensusStorage = namespace_owner.CensusStorage;
10 
11 test "memtrace: package namespace" {
12     std.testing.refAllDecls(namespace_owner);
13     _ = census_test;
14     _ = stack_test;
15 }
16 
17 test "Memtrace root composes caller-selected Census limits and storage" {
18     comptime {
19         @stardustClaim(
20             @import("alloc_phase").capacity.witness(@import("./census/root.zig").Storage, "memtrace_census_root"),
21             null,
22             null,
23             null,
24             null,
25             null,
26             null,
27         );
28     }
29 
30     const limits = CensusLimits{
31         .categories = 2,
32         .label_bytes = 16,
33         .joined_label_bytes = 8,
34     };
35     const capacity = try CensusCapacity.derive(limits);
36     var storage = try CensusStorage.init(std.testing.allocator, limits);
37     defer storage.deinit(std.testing.allocator);
38     try std.testing.expectEqual(capacity.storage_bytes, storage.status().storage_bytes);
39     storage.activate();
40     var actual = try Census.init(&storage);
41     defer actual.deinit();
42     try actual.record("root", 4);
43     try std.testing.expectEqual(@as(usize, 1), actual.status().categories);
44 }