xref: /illumos-gate/usr/src/test/util-tests/tests/mdb/shell/tst.head.ksh (revision 3d4e20a23e1894c03df6b83e39a88625f74ee0e4)
1#!/usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2026 Oxide Computer Company
15#
16
17#
18# A quote-delimited shell command can also stand at the head of a dcmd
19# pipeline ("! 'command' | dcmd"), with no producing dcmd before it. The
20# command's output is parsed as the address list for the following dcmd. As
21# in tst.filter, ::map echoes each incoming address in the default
22# (hexadecimal) radix.
23#
24
25export SHELL=/bin/sh
26
27function check {
28	typeset desc="$1" expect="$2" got="$3"
29
30	if [[ "$got" != "$expect" ]]; then
31		print -u2 "FAIL [$desc]: expected [$expect], got [$got]"
32		exit 1
33	fi
34}
35
36#
37# The shell command emits one address per line, which become the addresses
38# consumed by ::map. The semicolons are part of the quoted command, not
39# debugger command separators.
40#
41out=$($MDB <<'EOF'
42! 'echo 1; echo 2; echo 3' | ::map .
43EOF
44)
45check "multi" $'1\n2\n3' "$out"
46
47#
48# A single decimal address, to confirm the output is reparsed through the
49# normal address syntax (0t42 is decimal 42, printed back in hexadecimal).
50#
51out=$($MDB <<'EOF'
52! 'echo 0t42' | ::map .
53EOF
54)
55check "decimal" "2a" "$out"
56
57#
58# An awk program at the head of the pipeline, quoted with \'.
59#
60out=$($MDB <<'EOF'
61! 'awk \'BEGIN { print 1; print 2 }\'' | ::map .
62EOF
63)
64check "awk" $'1\n2' "$out"
65
66#
67# A command that produces no output leaves the pipeline with nothing to
68# consume, so the following dcmd does not run at all.
69#
70out=$($MDB <<'EOF'
71! 'true' | ::map .
72EOF
73)
74check "empty" "" "$out"
75
76exit 0
77