1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
12 import net
.multiphasicapps
.tac
.TestRunnable
;
15 * Tests interrupted, monitors, and threads as well.
19 public class TestVMInterrupt
22 /** The object to lock on. */
23 protected final Object lock
=
26 /** The order of things, is a check for locks. */
27 protected volatile int order
;
36 Thread self
= Thread
.currentThread();
39 this.secondary("a-before-lock", order
++);
41 // Lock on this object
42 synchronized (this.lock
)
45 this.secondary("a-after-lock", order
++);
47 // Setup thread to run
48 Thread runner
= new Thread(new __Runner__(
49 self
), "VMInterruptChild");
53 this.secondary("a-thread-created", order
++);
54 this.secondary("a-before-wait", self
.isInterrupted());
56 // Wait for a notification
59 this.lock
.wait(20000);
62 this.secondary("a-was-not-interrupted", order
++);
64 catch (InterruptedException e
)
67 this.secondary("a-was-interrupted", order
++);
71 this.secondary("a-after-wait", self
.isInterrupted());
75 this.secondary("a-done", order
++);
79 * Performs the second part of the test run.
83 final class __Runner__
86 /** The thread to signal. */
87 protected final Thread signal
;
90 * Initializes the runner.
92 * @param __t The thread to signal.
93 * @throws NullPointerException On null arguments.
96 public __Runner__(Thread __t
)
97 throws NullPointerException
100 throw new NullPointerException("NARG");
113 synchronized (TestVMInterrupt
.this.lock
)
116 TestVMInterrupt
.this.secondary("b-in-lock",
117 TestVMInterrupt
.this.order
++);
120 this.signal
.interrupt();
123 TestVMInterrupt
.this.secondary("b-interrupt-a",
124 TestVMInterrupt
.this.order
++);
130 TestVMInterrupt
.this.secondary("b-dosleep",
131 TestVMInterrupt
.this.order
++);
133 // Sleep for a bit longer than the main thread
137 TestVMInterrupt
.this.secondary("b-sleepdone",
138 TestVMInterrupt
.this.order
++);
140 catch (InterruptedException e
)
142 TestVMInterrupt
.this.secondary("b-interrupted",
143 TestVMInterrupt
.this.order
++);
147 TestVMInterrupt
.this.secondary("b-about-to-unlock",
148 TestVMInterrupt
.this.order
++);