authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-11-17 14:16:09+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-11-17 14:16:09+11:00
logd870a68e680242d130dcecef1f1ccc0969f326c0
treed88b974a5f7e5f1f8519938aa31ca3bb092bd575
parent7d582d0a00f2111f68409666c74705910bb82fdd
signaturelock-open Commit is signed but in an unrecognized format.

std: add a couple of tests to valgrind module


2 files changed, 34 insertions(+), 0 deletions(-)

lib/std/valgrind.zig+9
...@@ -99,6 +99,10 @@ pub fn runningOnValgrind() usize {...@@ -99,6 +99,10 @@ pub fn runningOnValgrind() usize {
99 return doClientRequestExpr(0, .RunningOnValgrind, 0, 0, 0, 0, 0);99 return doClientRequestExpr(0, .RunningOnValgrind, 0, 0, 0, 0, 0);
100}100}
101101
102test "works whether running on valgrind or not" {
103 _ = runningOnValgrind();
104}
105
102/// Discard translation of code in the slice qzz. Useful if you are debugging106/// Discard translation of code in the slice qzz. Useful if you are debugging
103/// a JITter or some such, since it provides a way to make sure valgrind will107/// a JITter or some such, since it provides a way to make sure valgrind will
104/// retranslate the invalidated area. Returns no value.108/// retranslate the invalidated area. Returns no value.
...@@ -266,3 +270,8 @@ pub fn monitorCommand(command: [*]u8) bool {...@@ -266,3 +270,8 @@ pub fn monitorCommand(command: [*]u8) bool {
266270
267pub const memcheck = @import("valgrind/memcheck.zig");271pub const memcheck = @import("valgrind/memcheck.zig");
268pub const callgrind = @import("valgrind/callgrind.zig");272pub const callgrind = @import("valgrind/callgrind.zig");
273
274test "" {
275 _ = @import("valgrind/memcheck.zig");
276 _ = @import("valgrind/callgrind.zig");
277}
lib/std/valgrind/memcheck.zig+25
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const testing = std.testing;
2const valgrind = std.valgrind;3const valgrind = std.valgrind;
34
4pub const MemCheckClientRequest = extern enum {5pub const MemCheckClientRequest = extern enum {
...@@ -142,6 +143,18 @@ pub fn countLeaks() CountResult {...@@ -142,6 +143,18 @@ pub fn countLeaks() CountResult {
142 return res;143 return res;
143}144}
144145
146test "countLeaks" {
147 testing.expectEqual(
148 @as(CountResult, .{
149 .leaked = 0,
150 .dubious = 0,
151 .reachable = 0,
152 .suppressed = 0,
153 }),
154 countLeaks(),
155 );
156}
157
145pub fn countLeakBlocks() CountResult {158pub fn countLeakBlocks() CountResult {
146 var res: CountResult = .{159 var res: CountResult = .{
147 .leaked = 0,160 .leaked = 0,
...@@ -160,6 +173,18 @@ pub fn countLeakBlocks() CountResult {...@@ -160,6 +173,18 @@ pub fn countLeakBlocks() CountResult {
160 return res;173 return res;
161}174}
162175
176test "countLeakBlocks" {
177 testing.expectEqual(
178 @as(CountResult, .{
179 .leaked = 0,
180 .dubious = 0,
181 .reachable = 0,
182 .suppressed = 0,
183 }),
184 countLeakBlocks(),
185 );
186}
187
163/// Get the validity data for addresses zza and copy it188/// Get the validity data for addresses zza and copy it
164/// into the provided zzvbits array. Return values:189/// into the provided zzvbits array. Return values:
165/// 0 if not running on valgrind190/// 0 if not running on valgrind