xref: /illumos-gate/usr/src/test/util-tests/tests/mdb/shell/tst.source.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# Exercise the "!<" shell input escape, which runs a shell command and then
19*3d4e20a2SAndy Fiddaman# evaluates its standard output as debugger commands. Both the bare form and
20*3d4e20a2SAndy Fiddaman# the pipeline form (where dcmd output is first sent to the command) are
21*3d4e20a2SAndy Fiddaman# covered. ::echo appends a trailing space after the last word, which is
22*3d4e20a2SAndy Fiddaman# trimmed before comparing.
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# Bare form: the command emits a debugger command, which is then sourced and
38*3d4e20a2SAndy Fiddaman# run.
39*3d4e20a2SAndy Fiddaman#
40*3d4e20a2SAndy Fiddamanout=$($MDB <<'EOF'
41*3d4e20a2SAndy Fiddaman!< echo '::echo sourced'
42*3d4e20a2SAndy FiddamanEOF
43*3d4e20a2SAndy Fiddaman)
44*3d4e20a2SAndy Fiddamanout=${out% }
45*3d4e20a2SAndy Fiddamancheck "source" "sourced" "$out"
46*3d4e20a2SAndy Fiddaman
47*3d4e20a2SAndy Fiddaman#
48*3d4e20a2SAndy Fiddaman# Pipeline form: the output of the dcmd is fed to the shell command, whose
49*3d4e20a2SAndy Fiddaman# output is collected and then sourced once the pipeline has completed.
50*3d4e20a2SAndy Fiddaman#
51*3d4e20a2SAndy Fiddamanout=$($MDB <<'EOF'
52*3d4e20a2SAndy Fiddaman::echo 10 20 30 !< awk '{print "::echo total " $1+$2+$3}'
53*3d4e20a2SAndy FiddamanEOF
54*3d4e20a2SAndy Fiddaman)
55*3d4e20a2SAndy Fiddamanout=${out% }
56*3d4e20a2SAndy Fiddamancheck "source-pipe" "total 60" "$out"
57*3d4e20a2SAndy Fiddaman
58*3d4e20a2SAndy Fiddamanexit 0
59