xref: /freebsd-src/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/uctf/tst.userstrings.ksh (revision 9268022b74279434ed6300244e3f977e56a8ceb5)
18e648814SRui Paulo#! /usr/bin/ksh
28e648814SRui Paulo#
38e648814SRui Paulo#
48e648814SRui Paulo# This file and its contents are supplied under the terms of the
58e648814SRui Paulo# Common Development and Distribution License ("CDDL"), version 1.0.
68e648814SRui Paulo# You may only use this file in accordance with the terms of version
78e648814SRui Paulo# 1.0 of the CDDL.
88e648814SRui Paulo#
98e648814SRui Paulo# A full copy of the text of the CDDL should have accompanied this
108e648814SRui Paulo# source.  A copy of the CDDL is also available via the Internet at
118e648814SRui Paulo# http://www.illumos.org/license/CDDL.
128e648814SRui Paulo#
138e648814SRui Paulo
148e648814SRui Paulo#
158e648814SRui Paulo# Copyright (c) 2013 Joyent, Inc. All rights reserved.
168e648814SRui Paulo#
178e648814SRui Paulo
188e648814SRui Paulo#
198e648814SRui Paulo# This test is checking that we can read members and that pointers inside
208e648814SRui Paulo# members point to valid data that is intelligible, eg. strings.
218e648814SRui Paulo#
228e648814SRui Paulo
238e648814SRui Pauloif [ $# != 1 ]; then
248e648814SRui Paulo        echo expected one argument: '<'dtrace-path'>'
258e648814SRui Paulo        exit 2
268e648814SRui Paulofi
278e648814SRui Paulo
288e648814SRui Paulodtrace=$1
298e648814SRui Pauloexe="tst.chasestrings.exe"
308e648814SRui Paulo
31*a5ddd965SMark Johnstonelfdump -c "./$exe" | grep -Fq 'sh_name: .SUNW_ctf'
328e648814SRui Pauloif [[ $? -ne 0 ]]; then
338e648814SRui Paulo	echo "CTF does not exist in $exe, that's a bug" >&2
348e648814SRui Paulo	exit 1
358e648814SRui Paulofi
368e648814SRui Paulo
378e648814SRui Paulo./$exe &
388e648814SRui Paulopid=$!
398e648814SRui Paulo
408e648814SRui Paulo$dtrace -qs /dev/stdin <<EOF
418e648814SRui Paulopid$pid::has_princess:entry
428e648814SRui Paulo/next == 0/
438e648814SRui Paulo{
448e648814SRui Paulo	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
458e648814SRui Paulo	    stringof(args[0]->zi_gamename), args[0]->zi_ndungeons,
468e648814SRui Paulo	    stringof(args[0]->zi_villain), args[0]->zi_haszelda);
478e648814SRui Paulo	next = 1;
488e648814SRui Paulo}
498e648814SRui Paulo
508e648814SRui Paulopid$pid::has_dungeons:entry
518e648814SRui Paulo/next == 1/
528e648814SRui Paulo{
538e648814SRui Paulo	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
548e648814SRui Paulo	    stringof(args[0]->zi_gamename), args[0]->zi_ndungeons,
558e648814SRui Paulo	    stringof(args[0]->zi_villain), args[0]->zi_haszelda);
568e648814SRui Paulo	next = 2;
578e648814SRui Paulo}
588e648814SRui Paulo
598e648814SRui Paulopid$pid::has_villain:entry
608e648814SRui Paulo/next == 2/
618e648814SRui Paulo{
628e648814SRui Paulo	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
638e648814SRui Paulo	    stringof(args[0]->zi_gamename), args[0]->zi_ndungeons,
648e648814SRui Paulo	    stringof(args[0]->zi_villain), args[0]->zi_haszelda);
658e648814SRui Paulo	exit(0);
668e648814SRui Paulo}
678e648814SRui PauloEOF
688e648814SRui Paulorc=$?
698e648814SRui Paulo
708e648814SRui Paulokill -9 $pid
718e648814SRui Paulo
728e648814SRui Pauloexit $rc
73