From 5fd83771641d15c418f747bd343ba6738d3875f7 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Sun, 9 May 2021 14:20:58 -0400 Subject: 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 --- system_cmds/zprint.tproj/test_zprint.lua | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 system_cmds/zprint.tproj/test_zprint.lua (limited to 'system_cmds/zprint.tproj/test_zprint.lua') 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") -- cgit v1.2.3