diff options
author | Cameron Katri <me@cameronkatri.com> | 2021-05-09 14:20:58 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2021-05-09 14:20:58 -0400 |
commit | 5fd83771641d15c418f747bd343ba6738d3875f7 (patch) | |
tree | 5abf0f78f680d9837dbd93d4d4c3933bb7509599 /system_cmds/zprint.tproj/test_zprint.lua | |
download | apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.gz apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.zst apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.zip |
Import macOS userland
adv_cmds-176
basic_cmds-55
bootstrap_cmds-116.100.1
developer_cmds-66
diskdev_cmds-667.40.1
doc_cmds-53.60.1
file_cmds-321.40.3
mail_cmds-35
misc_cmds-34
network_cmds-606.40.1
patch_cmds-17
remote_cmds-63
shell_cmds-216.60.1
system_cmds-880.60.2
text_cmds-106
Diffstat (limited to 'system_cmds/zprint.tproj/test_zprint.lua')
-rw-r--r-- | system_cmds/zprint.tproj/test_zprint.lua | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/system_cmds/zprint.tproj/test_zprint.lua b/system_cmds/zprint.tproj/test_zprint.lua new file mode 100644 index 0000000..b46d6ca --- /dev/null +++ b/system_cmds/zprint.tproj/test_zprint.lua @@ -0,0 +1,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") |