xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/uctf/tst.chasestrings.ksh (revision a386cc11a86ecb60f5a48078d22c1500e2ad003e)
1*a386cc11SRobert Mustacchi#! /usr/bin/ksh
2*a386cc11SRobert Mustacchi#
3*a386cc11SRobert Mustacchi#
4*a386cc11SRobert Mustacchi# This file and its contents are supplied under the terms of the
5*a386cc11SRobert Mustacchi# Common Development and Distribution License ("CDDL"), version 1.0.
6*a386cc11SRobert Mustacchi# You may only use this file in accordance with the terms of version
7*a386cc11SRobert Mustacchi# 1.0 of the CDDL.
8*a386cc11SRobert Mustacchi#
9*a386cc11SRobert Mustacchi# A full copy of the text of the CDDL should have accompanied this
10*a386cc11SRobert Mustacchi# source.  A copy of the CDDL is also available via the Internet at
11*a386cc11SRobert Mustacchi# http://www.illumos.org/license/CDDL.
12*a386cc11SRobert Mustacchi#
13*a386cc11SRobert Mustacchi
14*a386cc11SRobert Mustacchi#
15*a386cc11SRobert Mustacchi# Copyright (c) 2013 Joyent, Inc. All rights reserved.
16*a386cc11SRobert Mustacchi#
17*a386cc11SRobert Mustacchi
18*a386cc11SRobert Mustacchi#
19*a386cc11SRobert Mustacchi# This test is checking that we can read members and that pointers inside
20*a386cc11SRobert Mustacchi# members point to valid data that is intelligible, eg. strings.
21*a386cc11SRobert Mustacchi#
22*a386cc11SRobert Mustacchi
23*a386cc11SRobert Mustacchiif [ $# != 1 ]; then
24*a386cc11SRobert Mustacchi        echo expected one argument: '<'dtrace-path'>'
25*a386cc11SRobert Mustacchi        exit 2
26*a386cc11SRobert Mustacchifi
27*a386cc11SRobert Mustacchi
28*a386cc11SRobert Mustacchidtrace=$1
29*a386cc11SRobert Mustacchit="zelda_info_t"
30*a386cc11SRobert Mustacchiexe="tst.chasestrings.exe"
31*a386cc11SRobert Mustacchi
32*a386cc11SRobert Mustacchielfdump "./$exe" | grep -q '.SUNW_ctf'
33*a386cc11SRobert Mustacchiif [[ $? -ne 0 ]]; then
34*a386cc11SRobert Mustacchi	echo "CTF does not exist in $exe, that's a bug" >&2
35*a386cc11SRobert Mustacchi	exit 1
36*a386cc11SRobert Mustacchifi
37*a386cc11SRobert Mustacchi
38*a386cc11SRobert Mustacchi./$exe &
39*a386cc11SRobert Mustacchipid=$!
40*a386cc11SRobert Mustacchi
41*a386cc11SRobert Mustacchi$dtrace -qs /dev/stdin <<EOF
42*a386cc11SRobert Mustacchipid$pid::has_princess:entry
43*a386cc11SRobert Mustacchi/next == 0/
44*a386cc11SRobert Mustacchi{
45*a386cc11SRobert Mustacchi	this->t = (pid$pid\`$t *)(copyin(arg0, sizeof (pid$pid\`$t)));
46*a386cc11SRobert Mustacchi	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
47*a386cc11SRobert Mustacchi	    copyinstr((uintptr_t)this->t->zi_gamename), this->t->zi_ndungeons,
48*a386cc11SRobert Mustacchi	    copyinstr((uintptr_t)this->t->zi_villain), this->t->zi_haszelda);
49*a386cc11SRobert Mustacchi	next = 1;
50*a386cc11SRobert Mustacchi}
51*a386cc11SRobert Mustacchi
52*a386cc11SRobert Mustacchipid$pid::has_dungeons:entry
53*a386cc11SRobert Mustacchi/next == 1/
54*a386cc11SRobert Mustacchi{
55*a386cc11SRobert Mustacchi	this->t = (pid$pid\`$t *)(copyin(arg0, sizeof (pid$pid\`$t)));
56*a386cc11SRobert Mustacchi	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
57*a386cc11SRobert Mustacchi	    copyinstr((uintptr_t)this->t->zi_gamename), this->t->zi_ndungeons,
58*a386cc11SRobert Mustacchi	    copyinstr((uintptr_t)this->t->zi_villain), this->t->zi_haszelda);
59*a386cc11SRobert Mustacchi	next = 2;
60*a386cc11SRobert Mustacchi}
61*a386cc11SRobert Mustacchi
62*a386cc11SRobert Mustacchipid$pid::has_villain:entry
63*a386cc11SRobert Mustacchi/next == 2/
64*a386cc11SRobert Mustacchi{
65*a386cc11SRobert Mustacchi	this->t = (pid$pid\`$t *)(copyin(arg0, sizeof (pid$pid\`$t)));
66*a386cc11SRobert Mustacchi	printf("game: %s, dungeon: %d, villain: %s, zelda: %d\n",
67*a386cc11SRobert Mustacchi	    copyinstr((uintptr_t)this->t->zi_gamename), this->t->zi_ndungeons,
68*a386cc11SRobert Mustacchi	    copyinstr((uintptr_t)this->t->zi_villain), this->t->zi_haszelda);
69*a386cc11SRobert Mustacchi	exit(0);
70*a386cc11SRobert Mustacchi}
71*a386cc11SRobert MustacchiEOF
72*a386cc11SRobert Mustacchirc=$?
73*a386cc11SRobert Mustacchi
74*a386cc11SRobert Mustacchikill -9 $pid
75*a386cc11SRobert Mustacchi
76*a386cc11SRobert Mustacchiexit $rc
77