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