comparison graal/com.oracle.max.graal.jtt/src/com/oracle/max/graal/jtt/threads/Object_wait04.java @ 4587:5b04b33dac74

add jtt tests, converted from the maxine repository using ConvertJTT
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 14 Feb 2012 16:27:59 +0100
parents
children
comparison
equal deleted inserted replaced
4586:05a6d48a6ace 4587:5b04b33dac74
1 /*
2 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 /*
24 */
25 package com.oracle.max.graal.jtt.threads;
26
27 import org.junit.*;
28
29 public class Object_wait04 implements Runnable {
30
31 static volatile boolean done;
32 static final Object object = new Object();
33 static int sleep;
34
35 public static boolean test(int i) throws InterruptedException {
36 done = false;
37 sleep = i * 50;
38 synchronized (object) {
39 new Thread(new Object_wait04()).start();
40 dowait(i);
41 }
42 return done;
43 }
44
45 private static void dowait(int i) throws InterruptedException {
46 if (i == 0) {
47 while (!done) {
48 object.wait(100);
49 }
50 } else {
51 synchronized (object) {
52 dowait(i - 1);
53 }
54 }
55 }
56
57 public void run() {
58 try {
59 Thread.sleep(sleep);
60 } catch (InterruptedException ex) {
61
62 }
63 synchronized (object) {
64 done = true;
65 object.notifyAll();
66 }
67 }
68
69 @Test
70 public void run0() throws Throwable {
71 Assert.assertEquals(true, test(0));
72 }
73
74 @Test
75 public void run1() throws Throwable {
76 Assert.assertEquals(true, test(1));
77 }
78
79 @Test
80 public void run2() throws Throwable {
81 Assert.assertEquals(true, test(2));
82 }
83
84 @Test
85 public void run3() throws Throwable {
86 Assert.assertEquals(true, test(3));
87 }
88
89 @Test
90 public void run4() throws Throwable {
91 Assert.assertEquals(true, test(4));
92 }
93
94 @Test
95 public void run5() throws Throwable {
96 Assert.assertEquals(true, test(5));
97 }
98
99 }