46344
|
1 |
/*
|
|
2 |
* Copyright (c) 2017, 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 |
package org.graalvm.compiler.graph.test;
|
|
24 |
|
|
25 |
import org.graalvm.compiler.api.test.Graal;
|
46640
|
26 |
import org.graalvm.compiler.debug.DebugHandlersFactory;
|
|
27 |
import org.graalvm.compiler.debug.DebugContext;
|
46344
|
28 |
import org.graalvm.compiler.options.OptionValues;
|
46640
|
29 |
import org.junit.After;
|
46344
|
30 |
|
|
31 |
public abstract class GraphTest {
|
|
32 |
|
|
33 |
static OptionValues getOptions() {
|
|
34 |
return Graal.getRequiredCapability(OptionValues.class);
|
|
35 |
}
|
46640
|
36 |
|
|
37 |
private final ThreadLocal<DebugContext> cachedDebug = new ThreadLocal<>();
|
|
38 |
|
|
39 |
protected DebugContext getDebug(OptionValues options) {
|
|
40 |
DebugContext cached = cachedDebug.get();
|
|
41 |
if (cached != null) {
|
|
42 |
if (cached.getOptions() == options) {
|
|
43 |
return cached;
|
|
44 |
}
|
|
45 |
throw new AssertionError("At most one " + DebugContext.class.getName() + " object should be created per test");
|
|
46 |
}
|
|
47 |
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
|
|
48 |
cachedDebug.set(debug);
|
|
49 |
return debug;
|
|
50 |
}
|
|
51 |
|
|
52 |
protected DebugContext getDebug() {
|
|
53 |
return getDebug(getOptions());
|
|
54 |
}
|
|
55 |
|
|
56 |
@After
|
|
57 |
public void afterTest() {
|
|
58 |
DebugContext cached = cachedDebug.get();
|
|
59 |
if (cached != null) {
|
|
60 |
cached.closeDumpHandlers(true);
|
|
61 |
}
|
|
62 |
}
|
46344
|
63 |
}
|