std: add a couple of tests to valgrind module

This commit is contained in:
daurnimator 2019-11-17 14:16:09 +11:00
parent 7d582d0a00
commit d870a68e68
No known key found for this signature in database
GPG Key ID: 45B429A8F9D9D22A
2 changed files with 34 additions and 0 deletions

View File

@ -99,6 +99,10 @@ pub fn runningOnValgrind() usize {
return doClientRequestExpr(0, .RunningOnValgrind, 0, 0, 0, 0, 0);
}
test "works whether running on valgrind or not" {
_ = runningOnValgrind();
}
/// Discard translation of code in the slice qzz. Useful if you are debugging
/// a JITter or some such, since it provides a way to make sure valgrind will
/// retranslate the invalidated area. Returns no value.
@ -266,3 +270,8 @@ pub fn monitorCommand(command: [*]u8) bool {
pub const memcheck = @import("valgrind/memcheck.zig");
pub const callgrind = @import("valgrind/callgrind.zig");
test "" {
_ = @import("valgrind/memcheck.zig");
_ = @import("valgrind/callgrind.zig");
}

View File

@ -1,4 +1,5 @@
const std = @import("../std.zig");
const testing = std.testing;
const valgrind = std.valgrind;
pub const MemCheckClientRequest = extern enum {
@ -142,6 +143,18 @@ pub fn countLeaks() CountResult {
return res;
}
test "countLeaks" {
testing.expectEqual(
@as(CountResult, .{
.leaked = 0,
.dubious = 0,
.reachable = 0,
.suppressed = 0,
}),
countLeaks(),
);
}
pub fn countLeakBlocks() CountResult {
var res: CountResult = .{
.leaked = 0,
@ -160,6 +173,18 @@ pub fn countLeakBlocks() CountResult {
return res;
}
test "countLeakBlocks" {
testing.expectEqual(
@as(CountResult, .{
.leaked = 0,
.dubious = 0,
.reachable = 0,
.suppressed = 0,
}),
countLeakBlocks(),
);
}
/// Get the validity data for addresses zza and copy it
/// into the provided zzvbits array. Return values:
/// 0 if not running on valgrind