1178476Sjb/*
2178476Sjb * CDDL HEADER START
3178476Sjb *
4178476Sjb * The contents of this file are subject to the terms of the
5178476Sjb * Common Development and Distribution License (the "License").
6178476Sjb * You may not use this file except in compliance with the License.
7178476Sjb *
8178476Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9178476Sjb * or http://www.opensolaris.org/os/licensing.
10178476Sjb * See the License for the specific language governing permissions
11178476Sjb * and limitations under the License.
12178476Sjb *
13178476Sjb * When distributing Covered Code, include this CDDL HEADER in each
14178476Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15178476Sjb * If applicable, add the following below this CDDL HEADER, with the
16178476Sjb * fields enclosed by brackets "[]" replaced with your own identifying
17178476Sjb * information: Portions Copyright [yyyy] [name of copyright owner]
18178476Sjb *
19178476Sjb * CDDL HEADER END
20178476Sjb */
21178476Sjb
22178476Sjb/*
23178476Sjb * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24178476Sjb * Use is subject to license terms.
25178476Sjb *
26178476Sjb * ident	"%Z%%M%	%I%	%E% SMI"
27178476Sjb */
28178476Sjb
29178476Sjbimport org.opensolaris.os.dtrace.*;
30178476Sjb
31178476Sjb/**
32178476Sjb * Regression test for the LocalConsumer state machine.  Calls Consumer
33178476Sjb * methods before and after open(), compile(), enable(), go(), stop(),
34178476Sjb * and close() to verify that the calls succeed as expected or fail with
35178476Sjb * the expected Java exception.
36178476Sjb */
37178476Sjbpublic class TestStateMachine {
38178476Sjb    static Program program;
39178476Sjb
40178476Sjb    static void
41178476Sjb    exit(int status)
42178476Sjb    {
43178476Sjb	exit(status, null);
44178476Sjb    }
45178476Sjb
46178476Sjb    static void
47178476Sjb    exit(int status, String msg)
48178476Sjb    {
49178476Sjb	if (msg != null) {
50178476Sjb	    System.out.println(msg);
51178476Sjb	}
52178476Sjb	System.out.flush();
53178476Sjb	System.err.flush();
54178476Sjb	System.exit(status);
55178476Sjb    }
56178476Sjb
57178476Sjb    static void
58178476Sjb    printState(Consumer consumer)
59178476Sjb    {
60178476Sjb	System.out.println("open: " + consumer.isOpen());
61178476Sjb	System.out.println("enabled: " + consumer.isEnabled());
62178476Sjb	System.out.println("closed: " + consumer.isClosed());
63178476Sjb    }
64178476Sjb
65178476Sjb    static void
66178476Sjb    beforeOpen(Consumer consumer)
67178476Sjb    {
68178476Sjb	System.out.println("before open");
69178476Sjb	printState(consumer);
70178476Sjb
71178476Sjb	// compile
72178476Sjb	try {
73178476Sjb	    consumer.compile("syscall:::entry");
74178476Sjb	    exit(1, "compile before open");
75178476Sjb	} catch (IllegalStateException e) {
76178476Sjb	    System.out.println(e);
77178476Sjb	} catch (Exception e) {
78178476Sjb	    e.printStackTrace();
79178476Sjb	    exit(1, "compile before open");
80178476Sjb	}
81178476Sjb
82178476Sjb	// enable
83178476Sjb	try {
84178476Sjb	    consumer.enable();
85178476Sjb	    exit(1, "enable before open");
86178476Sjb	} catch (IllegalStateException e) {
87178476Sjb	    System.out.println(e);
88178476Sjb	} catch (Exception e) {
89178476Sjb	    e.printStackTrace();
90178476Sjb	    exit(1, "enable before open");
91178476Sjb	}
92178476Sjb
93178476Sjb	// getOption, setOption, unsetOption
94178476Sjb	try {
95178476Sjb	    consumer.getOption(Option.bufsize);
96178476Sjb	    exit(1, "getOption before open");
97178476Sjb	} catch (IllegalStateException e) {
98178476Sjb	    System.out.println(e);
99178476Sjb	} catch (Exception e) {
100178476Sjb	    e.printStackTrace();
101178476Sjb	    exit(1, "getOption before open");
102178476Sjb	}
103178476Sjb	try {
104178476Sjb	    consumer.setOption(Option.bufsize, Option.mb(1));
105178476Sjb	    exit(1, "setOption before open");
106178476Sjb	} catch (IllegalStateException e) {
107178476Sjb	    System.out.println(e);
108178476Sjb	} catch (Exception e) {
109178476Sjb	    e.printStackTrace();
110178476Sjb	    exit(1, "setOption before open");
111178476Sjb	}
112178476Sjb	try {
113178476Sjb	    consumer.unsetOption(Option.quiet);
114178476Sjb	    exit(1, "unsetOption before open");
115178476Sjb	} catch (IllegalStateException e) {
116178476Sjb	    System.out.println(e);
117178476Sjb	} catch (Exception e) {
118178476Sjb	    e.printStackTrace();
119178476Sjb	    exit(1, "unsetOption before open");
120178476Sjb	}
121178476Sjb
122178476Sjb	// createProcess, grabProcess
123178476Sjb	try {
124178476Sjb	    consumer.createProcess("date");
125178476Sjb	    exit(1, "createProcess before open");
126178476Sjb	} catch (IllegalStateException e) {
127178476Sjb	    System.out.println(e);
128178476Sjb	} catch (Exception e) {
129178476Sjb	    e.printStackTrace();
130178476Sjb	    exit(1, "createProcess before open");
131178476Sjb	}
132178476Sjb	try {
133178476Sjb	    consumer.grabProcess(1);
134178476Sjb	    exit(1, "grabProcess before open");
135178476Sjb	} catch (IllegalStateException e) {
136178476Sjb	    System.out.println(e);
137178476Sjb	} catch (Exception e) {
138178476Sjb	    e.printStackTrace();
139178476Sjb	    exit(1, "grabProcess before open");
140178476Sjb	}
141178476Sjb
142178476Sjb	// listProbes
143178476Sjb	try {
144178476Sjb	    consumer.listProbes(ProbeDescription.EMPTY);
145178476Sjb	    exit(1, "listProbes before open");
146178476Sjb	} catch (IllegalStateException e) {
147178476Sjb	    System.out.println(e);
148178476Sjb	} catch (Exception e) {
149178476Sjb	    e.printStackTrace();
150178476Sjb	    exit(1, "listProbes before open");
151178476Sjb	}
152178476Sjb
153178476Sjb	// getAggregate
154178476Sjb	try {
155178476Sjb	    consumer.getAggregate();
156178476Sjb	    exit(1, "getAggregate before open");
157178476Sjb	} catch (IllegalStateException e) {
158178476Sjb	    System.out.println(e);
159178476Sjb	} catch (Exception e) {
160178476Sjb	    e.printStackTrace();
161178476Sjb	    exit(1, "getAggregate before open");
162178476Sjb	}
163178476Sjb
164178476Sjb	// getVersion
165178476Sjb	try {
166178476Sjb	    consumer.getVersion(); // allowed
167178476Sjb	} catch (Exception e) {
168178476Sjb	    e.printStackTrace();
169178476Sjb	    exit(1, "getVersion before open");
170178476Sjb	}
171178476Sjb    }
172178476Sjb
173178476Sjb    static void
174178476Sjb    beforeCompile(Consumer consumer)
175178476Sjb    {
176178476Sjb	System.out.println("before compile");
177178476Sjb	printState(consumer);
178178476Sjb
179178476Sjb	// open
180178476Sjb	try {
181178476Sjb	    consumer.open();
182178476Sjb	    exit(1, "open after open");
183178476Sjb	} catch (IllegalStateException e) {
184178476Sjb	    System.out.println(e);
185178476Sjb	} catch (Exception e) {
186178476Sjb	    e.printStackTrace();
187178476Sjb	    exit(1, "open after open");
188178476Sjb	}
189178476Sjb
190178476Sjb	// enable
191178476Sjb	try {
192178476Sjb	    consumer.enable();
193178476Sjb	    exit(1, "enable before compile");
194178476Sjb	} catch (IllegalStateException e) {
195178476Sjb	    System.out.println(e);
196178476Sjb	} catch (Exception e) {
197178476Sjb	    e.printStackTrace();
198178476Sjb	    exit(1, "enable before compile");
199178476Sjb	}
200178476Sjb    }
201178476Sjb
202178476Sjb    static void
203178476Sjb    beforeEnable(Consumer consumer)
204178476Sjb    {
205178476Sjb	System.out.println("before enable");
206178476Sjb	printState(consumer);
207178476Sjb
208178476Sjb	// go
209178476Sjb	try {
210178476Sjb	    consumer.go();
211178476Sjb	    exit(1, "go before enable");
212178476Sjb	} catch (IllegalStateException e) {
213178476Sjb	    System.out.println(e);
214178476Sjb	} catch (Exception e) {
215178476Sjb	    e.printStackTrace();
216178476Sjb	    exit(1, "go before enable");
217178476Sjb	}
218178476Sjb    }
219178476Sjb
220178476Sjb    static void
221178476Sjb    beforeGo(Consumer consumer)
222178476Sjb    {
223178476Sjb	System.out.println("before go");
224178476Sjb	printState(consumer);
225178476Sjb
226178476Sjb	// getAggregate
227178476Sjb	try {
228178476Sjb	    consumer.getAggregate();
229178476Sjb	    exit(1, "getAggregate before go");
230178476Sjb	} catch (IllegalStateException e) {
231178476Sjb	    System.out.println(e);
232178476Sjb	} catch (Exception e) {
233178476Sjb	    e.printStackTrace();
234178476Sjb	    exit(1, "getAggregate before go");
235178476Sjb	}
236178476Sjb
237178476Sjb	// lookupKernelFunction, lookupUserFunction
238178476Sjb	try {
239178476Sjb	    consumer.lookupKernelFunction(1);
240178476Sjb	    exit(1, "lookupKernelFunction before go");
241178476Sjb	} catch (IllegalStateException e) {
242178476Sjb	    System.out.println(e);
243178476Sjb	} catch (Exception e) {
244178476Sjb	    e.printStackTrace();
245178476Sjb	    exit(1, "lookupKernelFunction before go");
246178476Sjb	}
247178476Sjb	try {
248178476Sjb	    consumer.lookupUserFunction(1, 1);
249178476Sjb	    exit(1, "lookupUserFunction before go");
250178476Sjb	} catch (IllegalStateException e) {
251178476Sjb	    System.out.println(e);
252178476Sjb	} catch (Exception e) {
253178476Sjb	    e.printStackTrace();
254178476Sjb	    exit(1, "lookupUserFunction before go");
255178476Sjb	}
256178476Sjb
257178476Sjb	// stop
258178476Sjb	try {
259178476Sjb	    consumer.stop();
260178476Sjb	    exit(1, "stop before go");
261178476Sjb	} catch (IllegalStateException e) {
262178476Sjb	    System.out.println(e);
263178476Sjb	} catch (Exception e) {
264178476Sjb	    e.printStackTrace();
265178476Sjb	    exit(1, "stop before go");
266178476Sjb	}
267178476Sjb    }
268178476Sjb
269178476Sjb    static void
270178476Sjb    afterGo(Consumer consumer, Program program)
271178476Sjb    {
272178476Sjb	System.out.println("after go");
273178476Sjb	printState(consumer);
274178476Sjb
275178476Sjb	// go
276178476Sjb	try {
277178476Sjb	    consumer.go();
278178476Sjb	    exit(1, "go after go");
279178476Sjb	} catch (IllegalStateException e) {
280178476Sjb	    System.out.println(e);
281178476Sjb	} catch (Exception e) {
282178476Sjb	    e.printStackTrace();
283178476Sjb	    exit(1, "go after go");
284178476Sjb	}
285178476Sjb
286178476Sjb	// createProcess, grabProcess
287178476Sjb	try {
288178476Sjb	    consumer.createProcess("date");
289178476Sjb	    exit(1, "createProcess after go");
290178476Sjb	} catch (IllegalStateException e) {
291178476Sjb	    System.out.println(e);
292178476Sjb	} catch (Exception e) {
293178476Sjb	    e.printStackTrace();
294178476Sjb	    exit(1, "createProcess after go");
295178476Sjb	}
296178476Sjb	try {
297178476Sjb	    consumer.grabProcess(1);
298178476Sjb	    exit(1, "grabProcess after go");
299178476Sjb	} catch (IllegalStateException e) {
300178476Sjb	    System.out.println(e);
301178476Sjb	} catch (Exception e) {
302178476Sjb	    e.printStackTrace();
303178476Sjb	    exit(1, "grabProcess after go");
304178476Sjb	}
305178476Sjb
306178476Sjb	// listProbes
307178476Sjb	try {
308178476Sjb	    consumer.listProbes(ProbeDescription.EMPTY);
309178476Sjb	    exit(1, "listProbes after go");
310178476Sjb	} catch (IllegalStateException e) {
311178476Sjb	    System.out.println(e);
312178476Sjb	} catch (Exception e) {
313178476Sjb	    e.printStackTrace();
314178476Sjb	    exit(1, "listProbes after go");
315178476Sjb	}
316178476Sjb
317178476Sjb	// compile
318178476Sjb	try {
319178476Sjb	    consumer.compile("syscall:::entry");
320178476Sjb	    exit(1, "compile after go");
321178476Sjb	} catch (IllegalStateException e) {
322178476Sjb	    System.out.println(e);
323178476Sjb	} catch (Exception e) {
324178476Sjb	    e.printStackTrace();
325178476Sjb	    exit(1, "compile after go");
326178476Sjb	}
327178476Sjb
328178476Sjb	// enable
329178476Sjb	try {
330178476Sjb	    consumer.enable();
331178476Sjb	    exit(1, "enable after go");
332178476Sjb	} catch (IllegalStateException e) {
333178476Sjb	    System.out.println(e);
334178476Sjb	} catch (Exception e) {
335178476Sjb	    e.printStackTrace();
336178476Sjb	    exit(1, "enable after go");
337178476Sjb	}
338178476Sjb
339178476Sjb	// getAggregate
340178476Sjb	try {
341178476Sjb	    consumer.getAggregate();
342178476Sjb	} catch (Exception e) {
343178476Sjb	    e.printStackTrace();
344178476Sjb	    exit(1, "getAggregate after go");
345178476Sjb	}
346178476Sjb
347178476Sjb	// getProgramInfo
348178476Sjb	try {
349178476Sjb	    consumer.getProgramInfo(program);
350178476Sjb	} catch (Exception e) {
351178476Sjb	    e.printStackTrace();
352178476Sjb	    exit(1, "getProgramInfo after go");
353178476Sjb	}
354178476Sjb
355178476Sjb	// getOption, setOption, unsetOption
356178476Sjb	try {
357178476Sjb	    consumer.getOption(Option.quiet);
358178476Sjb	    consumer.setOption(Option.quiet);
359178476Sjb	    consumer.unsetOption(Option.quiet);
360178476Sjb	} catch (Exception e) {
361178476Sjb	    e.printStackTrace();
362178476Sjb	    exit(1, "get, set, unset option after go");
363178476Sjb	}
364178476Sjb    }
365178476Sjb
366178476Sjb    static void
367178476Sjb    afterStop(Consumer consumer, Program program)
368178476Sjb    {
369178476Sjb	System.out.println("after stop");
370178476Sjb	printState(consumer);
371178476Sjb
372178476Sjb	// stop
373178476Sjb	try {
374178476Sjb	    consumer.stop();
375178476Sjb	    exit(1, "stop after stop");
376178476Sjb	} catch (IllegalStateException e) {
377178476Sjb	    System.out.println(e);
378178476Sjb	} catch (Exception e) {
379178476Sjb	    e.printStackTrace();
380178476Sjb	    exit(1, "stop after stop");
381178476Sjb	}
382178476Sjb
383178476Sjb	// getAggregate
384178476Sjb	try {
385178476Sjb	    consumer.getAggregate();
386178476Sjb	} catch (Exception e) {
387178476Sjb	    e.printStackTrace();
388178476Sjb	    exit(1, "getAggregate after stop");
389178476Sjb	}
390178476Sjb
391178476Sjb	// getProgramInfo
392178476Sjb	try {
393178476Sjb	    consumer.getProgramInfo(program);
394178476Sjb	} catch (Exception e) {
395178476Sjb	    e.printStackTrace();
396178476Sjb	    exit(1, "getProgramInfo after stop");
397178476Sjb	}
398178476Sjb
399178476Sjb	// getOption, setOption, unsetOption
400178476Sjb	try {
401178476Sjb	    consumer.getOption(Option.quiet);
402178476Sjb	    consumer.setOption(Option.quiet);
403178476Sjb	    consumer.unsetOption(Option.quiet);
404178476Sjb	} catch (Exception e) {
405178476Sjb	    e.printStackTrace();
406178476Sjb	    exit(1, "get, set, unset option after stop");
407178476Sjb	}
408178476Sjb    }
409178476Sjb
410178476Sjb    static void
411178476Sjb    afterClose(Consumer consumer, Program program)
412178476Sjb    {
413178476Sjb	System.out.println("after close");
414178476Sjb	printState(consumer);
415178476Sjb
416178476Sjb	// open
417178476Sjb	try {
418178476Sjb	    consumer.open();
419178476Sjb	    exit(1, "open after close");
420178476Sjb	} catch (IllegalStateException e) {
421178476Sjb	    System.out.println(e);
422178476Sjb	} catch (Exception e) {
423178476Sjb	    e.printStackTrace();
424178476Sjb	    exit(1, "open after close");
425178476Sjb	}
426178476Sjb
427178476Sjb	// compile
428178476Sjb	try {
429178476Sjb	    consumer.compile("syscall:::entry");
430178476Sjb	    exit(1, "compile after close");
431178476Sjb	} catch (IllegalStateException e) {
432178476Sjb	    System.out.println(e);
433178476Sjb	} catch (Exception e) {
434178476Sjb	    e.printStackTrace();
435178476Sjb	    exit(1, "compile after close");
436178476Sjb	}
437178476Sjb
438178476Sjb	// enable
439178476Sjb	try {
440178476Sjb	    consumer.enable();
441178476Sjb	    exit(1, "enable after close");
442178476Sjb	} catch (IllegalStateException e) {
443178476Sjb	    System.out.println(e);
444178476Sjb	} catch (Exception e) {
445178476Sjb	    e.printStackTrace();
446178476Sjb	    exit(1, "enable after close");
447178476Sjb	}
448178476Sjb
449178476Sjb	// getOption, setOption, unsetOption
450178476Sjb	try {
451178476Sjb	    consumer.getOption(Option.bufsize);
452178476Sjb	    exit(1, "getOption after close");
453178476Sjb	} catch (IllegalStateException e) {
454178476Sjb	    System.out.println(e);
455178476Sjb	} catch (Exception e) {
456178476Sjb	    e.printStackTrace();
457178476Sjb	    exit(1, "getOption after close");
458178476Sjb	}
459178476Sjb	try {
460178476Sjb	    consumer.setOption(Option.bufsize, Option.mb(1));
461178476Sjb	    exit(1, "setOption after close");
462178476Sjb	} catch (IllegalStateException e) {
463178476Sjb	    System.out.println(e);
464178476Sjb	} catch (Exception e) {
465178476Sjb	    e.printStackTrace();
466178476Sjb	    exit(1, "setOption after close");
467178476Sjb	}
468178476Sjb	try {
469178476Sjb	    consumer.unsetOption(Option.quiet);
470178476Sjb	    exit(1, "unsetOption after close");
471178476Sjb	} catch (IllegalStateException e) {
472178476Sjb	    System.out.println(e);
473178476Sjb	} catch (Exception e) {
474178476Sjb	    e.printStackTrace();
475178476Sjb	    exit(1, "unsetOption after close");
476178476Sjb	}
477178476Sjb
478178476Sjb	// createProcess, grabProcess
479178476Sjb	try {
480178476Sjb	    consumer.createProcess("date");
481178476Sjb	    exit(1, "createProcess after close");
482178476Sjb	} catch (IllegalStateException e) {
483178476Sjb	    System.out.println(e);
484178476Sjb	} catch (Exception e) {
485178476Sjb	    e.printStackTrace();
486178476Sjb	    exit(1, "createProcess after close");
487178476Sjb	}
488178476Sjb	try {
489178476Sjb	    consumer.grabProcess(1);
490178476Sjb	    exit(1, "grabProcess after close");
491178476Sjb	} catch (IllegalStateException e) {
492178476Sjb	    System.out.println(e);
493178476Sjb	} catch (Exception e) {
494178476Sjb	    e.printStackTrace();
495178476Sjb	    exit(1, "grabProcess after close");
496178476Sjb	}
497178476Sjb
498178476Sjb	// listProbes
499178476Sjb	try {
500178476Sjb	    consumer.listProbes(ProbeDescription.EMPTY);
501178476Sjb	    exit(1, "listProbes after close");
502178476Sjb	} catch (IllegalStateException e) {
503178476Sjb	    System.out.println(e);
504178476Sjb	} catch (Exception e) {
505178476Sjb	    e.printStackTrace();
506178476Sjb	    exit(1, "listProbes after close");
507178476Sjb	}
508178476Sjb
509178476Sjb	// getAggregate
510178476Sjb	try {
511178476Sjb	    consumer.getAggregate();
512178476Sjb	    exit(1, "getAggregate after close");
513178476Sjb	} catch (IllegalStateException e) {
514178476Sjb	    System.out.println(e);
515178476Sjb	} catch (Exception e) {
516178476Sjb	    e.printStackTrace();
517178476Sjb	    exit(1, "getAggregate after close");
518178476Sjb	}
519178476Sjb
520178476Sjb	// getVersion
521178476Sjb	try {
522178476Sjb	    consumer.getVersion(); // allowed
523178476Sjb	} catch (Exception e) {
524178476Sjb	    e.printStackTrace();
525178476Sjb	    exit(1, "getVersion after close");
526178476Sjb	}
527178476Sjb
528178476Sjb	// go
529178476Sjb	try {
530178476Sjb	    consumer.go();
531178476Sjb	    exit(1, "go after close");
532178476Sjb	} catch (IllegalStateException e) {
533178476Sjb	    System.out.println(e);
534178476Sjb	} catch (Exception e) {
535178476Sjb	    e.printStackTrace();
536178476Sjb	    exit(1, "go after close");
537178476Sjb	}
538178476Sjb
539178476Sjb	// lookupKernelFunction, lookupUserFunction
540178476Sjb	try {
541178476Sjb	    consumer.lookupKernelFunction(1);
542178476Sjb	    exit(1, "lookupKernelFunction after close");
543178476Sjb	} catch (IllegalStateException e) {
544178476Sjb	    System.out.println(e);
545178476Sjb	} catch (Exception e) {
546178476Sjb	    e.printStackTrace();
547178476Sjb	    exit(1, "lookupKernelFunction after close");
548178476Sjb	}
549178476Sjb	try {
550178476Sjb	    consumer.lookupUserFunction(1, 1);
551178476Sjb	    exit(1, "lookupUserFunction after close");
552178476Sjb	} catch (IllegalStateException e) {
553178476Sjb	    System.out.println(e);
554178476Sjb	} catch (Exception e) {
555178476Sjb	    e.printStackTrace();
556178476Sjb	    exit(1, "lookupUserFunction after close");
557178476Sjb	}
558178476Sjb
559178476Sjb	// stop
560178476Sjb	try {
561178476Sjb	    consumer.stop();
562178476Sjb	    exit(1, "stop after close");
563178476Sjb	} catch (IllegalStateException e) {
564178476Sjb	    System.out.println(e);
565178476Sjb	} catch (Exception e) {
566178476Sjb	    e.printStackTrace();
567178476Sjb	    exit(1, "stop after close");
568178476Sjb	}
569178476Sjb
570178476Sjb	// getProgramInfo
571178476Sjb	try {
572178476Sjb	    consumer.getProgramInfo(program);
573178476Sjb	    exit(1, "getProgramInfo after close");
574178476Sjb	} catch (IllegalStateException e) {
575178476Sjb	    System.out.println(e);
576178476Sjb	} catch (Exception e) {
577178476Sjb	    e.printStackTrace();
578178476Sjb	    exit(1, "getProgramInfo after close");
579178476Sjb	}
580178476Sjb    }
581178476Sjb
582178476Sjb    public static void
583178476Sjb    main(String[] args)
584178476Sjb    {
585178476Sjb	final Consumer consumer = new LocalConsumer();
586178476Sjb	consumer.addConsumerListener(new ConsumerAdapter() {
587178476Sjb	    public void consumerStarted(ConsumerEvent e) {
588178476Sjb		System.out.println("consumerStarted, running: " +
589178476Sjb			consumer.isRunning());
590178476Sjb		afterGo(consumer, program);
591178476Sjb	    }
592178476Sjb	    public void consumerStopped(ConsumerEvent e) {
593178476Sjb		System.out.println("consumerStopped, running: " +
594178476Sjb			consumer.isRunning());
595178476Sjb	    }
596178476Sjb	});
597178476Sjb
598178476Sjb	try {
599178476Sjb	    beforeOpen(consumer);
600178476Sjb	    consumer.open();
601178476Sjb	    beforeCompile(consumer);
602178476Sjb	    program = consumer.compile(
603178476Sjb		    "syscall:::entry { @[execname] = count(); } " +
604178476Sjb		    "tick-101ms { printa(@); }");
605178476Sjb	    beforeEnable(consumer);
606178476Sjb	    consumer.enable();
607178476Sjb	    beforeGo(consumer);
608178476Sjb	    System.out.println("before go, running: " + consumer.isRunning());
609178476Sjb	    consumer.go();
610178476Sjb	    // Avoid race, call afterGo() in ConsumerListener
611178476Sjb	    try {
612178476Sjb		Thread.currentThread().sleep(300);
613178476Sjb	    } catch (InterruptedException e) {
614178476Sjb		e.printStackTrace();
615178476Sjb		exit(1);
616178476Sjb	    }
617178476Sjb	    consumer.stop();
618178476Sjb	    System.out.println("after stop, running: " + consumer.isRunning());
619178476Sjb	    afterStop(consumer, program);
620178476Sjb	    consumer.close();
621178476Sjb	    afterClose(consumer, program);
622178476Sjb	} catch (DTraceException e) {
623178476Sjb	    e.printStackTrace();
624178476Sjb	    exit(1);
625178476Sjb	}
626178476Sjb    }
627178476Sjb}
628