1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/usr/local/bin/recon
local darwin = require 'darwin'
local proc = require 'proc'
local zprint = require 'zprint'
if darwin.geteuid() ~= 0 then
io.stderr:write(arg[0], ': must be run as root (under sudo)\n')
os.exit(1)
end
local function test_output(zpout)
-- These should be present in the output of zprint.
local expectations = {
{
region = 'zones',
name = 'vm.pages',
}, {
region = 'tags',
name = 'VM_KERN_MEMORY_DIAG',
}, {
region = 'maps',
name = 'VM_KERN_COUNT_WIRED_STATIC_KERNELCACHE',
}, {
region = 'zone_views',
-- This ties the kernel's hands when it comes to naming.
name = 'data.kalloc.16[raw]',
}
}
local found_all = true
for i = 1, #expectations do
local region = expectations[i].region
local name = expectations[i].name
local iter = zprint[region]
if not iter then
io.stderr:write('zprint library has no iterator for ', region, '\n')
os.exit(4)
end
local found = false
for elt in zprint[region](zpout) do
if elt.name == name then
found = true
break
end
end
if found then
io.stdout:write('PASS: found ', name, ' in ', region, '\n')
else
io.stdout:write('FAIL: could not find ', name, ' in ', region, '\n')
found_all = false
end
end
return found_all
end
local function run_zprint(args)
if not args then
args = {}
end
table.insert(args, 1, 'zprint')
local zpout, err, status, code = proc.run(args)
if not zpout then
io.stderr:write(arg[0], ': failed to run zprint: ', err, '\n')
os.exit(2)
end
if code ~= 0 then
io.stderr:write(arg[0], ': zprint ', status, 'ed with code ', tostring(code),
', stderr = ', err, '\n')
os.exit(3)
end
return zpout
end
local function run_and_test(...)
local zpout = run_zprint(table.pack(...))
local passed = test_output(zpout)
if not passed then
os.exit(5)
end
end
print("TEST: zprint output")
run_and_test()
print("\nTEST: zprint -t output")
run_and_test("-t")
|