3 local darwin = require 'darwin'
4 local proc = require 'proc'
5 local zprint = require 'zprint'
7 if darwin.geteuid() ~= 0 then
8 io.stderr:write(arg[0], ': must be run as root (under sudo)\n')
12 local function test_output(zpout)
13 -- These should be present in the output of zprint.
14 local expectations = {
20 name = 'VM_KERN_MEMORY_DIAG',
23 name = 'VM_KERN_COUNT_WIRED_STATIC_KERNELCACHE',
25 region = 'zone_views',
26 -- This ties the kernel's hands when it comes to naming.
27 name = 'data.kalloc.16[raw]',
31 local found_all = true
32 for i = 1, #expectations do
33 local region = expectations[i].region
34 local name = expectations[i].name
35 local iter = zprint[region]
37 io.stderr:write('zprint library has no iterator for ', region, '\n')
42 for elt in zprint[region](zpout) do
43 if elt.name == name then
49 io.stdout:write('PASS: found ', name, ' in ', region, '\n')
51 io.stdout:write('FAIL: could not find ', name, ' in ', region, '\n')
58 local function run_zprint(args)
63 table.insert(args, 1, 'zprint')
64 local zpout, err, status, code = proc.run(args)
66 io.stderr:write(arg[0], ': failed to run zprint: ', err, '\n')
71 io.stderr:write(arg[0], ': zprint ', status, 'ed with code ', tostring(code),
72 ', stderr = ', err, '\n')
78 local function run_and_test(...)
79 local zpout = run_zprint(table.pack(...))
80 local passed = test_output(zpout)
86 print("TEST: zprint output")
88 print("\nTEST: zprint -t output")