PR162: Added regression test.
[cacao.git] / tests / regression / bugzilla / PR162.java
1 /* tests/regression/bugzilla/PR162.java
2
3    Copyright (C) 1996-2011
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25 // This test is not deterministic. It doesn't always fail, but it's very rare
26 // that 5 consecutive runs succeed.
27
28 import org.junit.Test;
29 import static org.junit.Assert.*;
30
31 import java.util.concurrent.Semaphore;
32
33 class M {
34         public static Semaphore sem = new Semaphore(0);
35 }
36
37 class testglobal {
38         public static String the_string = initializeString();
39
40         static String initializeString() {
41                 M.sem.release();
42                 try {
43                         Thread.sleep(300);
44                 } catch (InterruptedException e) {
45                         e.printStackTrace();
46                 }
47                 return "hullabaloo";
48         }
49 }
50
51 class testthread extends Thread {
52         public int the_length = 0;
53         public void run() {
54                 try {
55                         M.sem.acquire();
56                 } catch (InterruptedException e) {
57                         e.printStackTrace();
58                 }
59                 the_length = testglobal.the_string.length();
60         }
61 }
62
63 public class PR162 {
64         @Test
65         public void test() {
66                 testthread t = new testthread();
67                 t.start();
68                 int length = testglobal.the_string.length();
69                 try {
70                         t.join();
71                 } catch (InterruptedException e) {
72                         e.printStackTrace();
73                 }
74                 assertEquals(t.the_length, length);
75         }
76 }