From 248a83c9c3e0e7fbceda3f723e93dfcbbe67ee0b Mon Sep 17 00:00:00 2001 From: Stefan Ring Date: Wed, 30 Nov 2011 00:24:30 +0100 Subject: [PATCH] PR162: Added regression test. --- tests/regression/bugzilla/All.java | 3 +- tests/regression/bugzilla/PR131.java | 4 +- tests/regression/bugzilla/PR162.java | 76 ++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 tests/regression/bugzilla/PR162.java diff --git a/tests/regression/bugzilla/All.java b/tests/regression/bugzilla/All.java index 937853d34..ad1c4d2fa 100644 --- a/tests/regression/bugzilla/All.java +++ b/tests/regression/bugzilla/All.java @@ -43,7 +43,8 @@ PR119.class, PR125.class, PR131.class, PR144.class, -PR148.class +PR148.class, +PR162.class }) public class All { diff --git a/tests/regression/bugzilla/PR131.java b/tests/regression/bugzilla/PR131.java index 6ae256a22..dafe228b3 100644 --- a/tests/regression/bugzilla/PR131.java +++ b/tests/regression/bugzilla/PR131.java @@ -1,6 +1,6 @@ -/* tests/regression/bugzilla/PR119.java +/* tests/regression/bugzilla/PR131.java - Copyright (C) 2009 + Copyright (C) 1996-2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. diff --git a/tests/regression/bugzilla/PR162.java b/tests/regression/bugzilla/PR162.java new file mode 100644 index 000000000..9541c4d19 --- /dev/null +++ b/tests/regression/bugzilla/PR162.java @@ -0,0 +1,76 @@ +/* tests/regression/bugzilla/PR162.java + + Copyright (C) 1996-2011 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + +*/ + +// This test is not deterministic. It doesn't always fail, but it's very rare +// that 5 consecutive runs succeed. + +import org.junit.Test; +import static org.junit.Assert.*; + +import java.util.concurrent.Semaphore; + +class M { + public static Semaphore sem = new Semaphore(0); +} + +class testglobal { + public static String the_string = initializeString(); + + static String initializeString() { + M.sem.release(); + try { + Thread.sleep(300); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return "hullabaloo"; + } +} + +class testthread extends Thread { + public int the_length = 0; + public void run() { + try { + M.sem.acquire(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + the_length = testglobal.the_string.length(); + } +} + +public class PR162 { + @Test + public void test() { + testthread t = new testthread(); + t.start(); + int length = testglobal.the_string.length(); + try { + t.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + assertEquals(t.the_length, length); + } +} -- 2.25.1