Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / cmd / dtrace / test / tst / common / usdt / tst.deadstub.ksh
blob3543ec091d101aa8050cb2feee043e947d2aeb03
2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
7 # A full copy of the text of the CDDL should have accompanied this
8 # source. A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
13 # Copyright (c) 2017, Joyent, Inc. All rights reserved.
17 # This test attempts to reproduce a three-way deadlock between mod_lock,
18 # dtrace_lock and P_PR_LOCK that is induced by shmsys having to go through
19 # mod_hold_stub.
21 if [ $# != 1 ]; then
22 echo expected one argument: '<'dtrace-path'>'
23 exit 2
26 dtrace=$1
27 DIR=/var/tmp/dtest.$$
29 mkdir $DIR
30 cd $DIR
32 cat > prov.d <<EOF
33 provider test_prov {
34 probe ripraf();
36 EOF
38 $dtrace -h -s prov.d
39 if [ $? -ne 0 ]; then
40 print -u2 "failed to generate header file"
41 exit 1
44 cat > test.c <<EOF
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <sys/types.h>
48 #include <sys/ipc.h>
49 #include <sys/shm.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include "prov.h"
54 void
55 main(int argc)
57 void *addr;
58 int shmid;
60 if (argc > 1) {
61 TEST_PROV_RIPRAF();
62 exit(0);
65 shmid = shmget(IPC_PRIVATE, sizeof (int), IPC_CREAT | 0666);
67 if (shmid == -1) {
68 perror("shmget: ");
69 exit(1);
72 if ((addr = shmat(shmid, NULL, 0)) == (void *)-1) {
73 perror("shmat: ");
74 exit(1);
77 printf("%p\n", addr);
79 for (;;) {
80 TEST_PROV_RIPRAF();
81 sleep(1);
84 EOF
86 gcc -m32 -c test.c
87 if [ $? -ne 0 ]; then
88 print -u2 "failed to compile test.c"
89 exit 1
92 $dtrace -G -32 -s prov.d test.o
94 if [ $? -ne 0 ]; then
95 print -u2 "failed to create DOF"
96 exit 1
99 gcc -m32 -o test test.o prov.o
101 if [ $? -ne 0 ]; then
102 print -u2 "failed to link final executable"
103 exit 1
107 # Kick off the victim program.
109 ./test &
111 victim=$!
114 # Kick off a shell that will do nothing but read our victim's /proc map
116 ( while true ; do read foo < /proc/$victim/map ; done ) &
117 stubby=$!
120 # Kick off a shell that will do nothing but instrument (and de-instrument)
121 # the victim
123 ( while true; do \
124 $dtrace -q -P test_prov$victim -n BEGIN'{exit(0)}' > /dev/null ; done ) &
125 inst=$!
128 # Finally, kick off a shell that will cause lots of provider registration and
129 # (importantly) de-registration
131 ( while true; do ./test foo ; done) &
132 reg=$!
134 echo $DIR
135 echo victim: $victim
136 echo stubby: $stubby
137 echo inst: $inst
138 echo reg: $reg
140 sleep 120
142 kill $reg
143 sleep 1
144 kill $inst
145 sleep 1
146 kill $stubby
147 sleep 1
148 kill $victim
151 # If we're deadlocked, this DTrace enabling won't work (if we even make it this
152 # far, which seems unlikely). In the spirit of the deadlock, we denote our
153 # success by emiting a classic Faulknerism.
155 raf="Maybe you're not so worthless!"
156 dtrace -qn BEGIN"{printf(\"$raf\"); exit(0)}"
158 cd /
159 /usr/bin/rm -rf $DIR
161 exit 0