Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/lib/ir_framework/Scenario.java
64507 views
1
/*
2
* Copyright (c) 2021, 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
package compiler.lib.ir_framework;
25
26
import compiler.lib.ir_framework.shared.TestRunException;
27
28
import java.util.*;
29
import java.util.stream.Collectors;
30
31
/**
32
* This class represents a scenario that can be executed by the {@link TestFramework}.
33
* <p>
34
* A JTreg test should use the test framework with {@code @run driver} (without directly specify any additional flags).
35
* If a test should run with additional flags, use {@link TestFramework#runWithFlags(String...)} or
36
* {@link TestFramework#addFlags(String...)}. If, however, the test should be run with different settings (equivalent
37
* to having multiple {@code @run} entries in a normal JTreg test), use scenarios. A scenario will be run with the
38
* scenario specific VM flags, if any, and optionally specified VM flags with {@link TestFramework#addFlags(String...)}
39
* whereas scenario VM flags will have precedence.
40
* <p>
41
* There is also the possibility to specify additional VM flags for all scenarios by using {@code DScenarioFlags}.
42
*
43
* @see TestFramework
44
*/
45
public class Scenario {
46
private static final String ADDITIONAL_SCENARIO_FLAGS_PROPERTY = System.getProperty("ScenarioFlags", "");
47
private static final String SCENARIOS_PROPERTY = System.getProperty("Scenarios", "");
48
private static final List<String> ADDITIONAL_SCENARIO_FLAGS;
49
private static final Set<Integer> ENABLED_SCENARIOS;
50
51
private final List<String> flags;
52
private final int index;
53
private final boolean enabled;
54
private String testVMOutput;
55
56
static {
57
if (!SCENARIOS_PROPERTY.isEmpty()) {
58
var split = SCENARIOS_PROPERTY.split("\\s*,\\s*");
59
try {
60
ENABLED_SCENARIOS = Arrays.stream(split).map(Integer::parseInt).collect(Collectors.toSet());
61
} catch (NumberFormatException e) {
62
throw new TestRunException("Provided a scenario index in the -DScenario comma-separated list which is not "
63
+ "a number: " + SCENARIOS_PROPERTY);
64
}
65
} else {
66
ENABLED_SCENARIOS = Collections.emptySet();
67
}
68
69
ADDITIONAL_SCENARIO_FLAGS = ADDITIONAL_SCENARIO_FLAGS_PROPERTY.isEmpty() ? Collections.emptyList() :
70
Arrays.asList(ADDITIONAL_SCENARIO_FLAGS_PROPERTY.split("\\s*,\\s*"));
71
}
72
73
/**
74
* Create a scenario with {@code index} that will be run with the additional VM flags specified in {@code flags}
75
* (or without any if null or parameter not provided).
76
* <p>
77
* The scenario {@code index} must be unique to be distinguishable in the stdout and stderr output and when specifying
78
* {@code -DScenarios} (see {@link Scenario}).
79
*
80
* @param index the unique scenario index.
81
* @param flags the scenario flags or null (i.e. no parameter specified) if no flags should be used.
82
*/
83
public Scenario(int index, String... flags) {
84
this.index = index;
85
if (flags != null) {
86
this.flags = new ArrayList<>(Arrays.asList(flags));
87
this.flags.addAll(ADDITIONAL_SCENARIO_FLAGS);
88
} else {
89
this.flags = new ArrayList<>();
90
}
91
this.enabled = ENABLED_SCENARIOS.isEmpty() || ENABLED_SCENARIOS.contains(index);
92
}
93
94
/**
95
* Add additional VM flags to this scenario.
96
*
97
* @param flags the additional scenario VM flags.
98
*/
99
public void addFlags(String... flags) {
100
if (flags != null) {
101
this.flags.addAll(Arrays.asList(flags));
102
}
103
}
104
105
/**
106
* Get all scenario specific VM flags as defined in {@link #Scenario(int, String...)}.
107
*
108
* @return the scenario VM flags.
109
*/
110
public List<String> getFlags() {
111
return flags;
112
}
113
114
/**
115
* Get the unique scenario index as defined in {@link #Scenario(int, String...)}.
116
*
117
* @return the scenario index.
118
*/
119
public int getIndex() {
120
return index;
121
}
122
123
/**
124
* Get the test VM output (stdout + stderr) of this scenario from the last execution of the framework.
125
*
126
* @return the test VM output.
127
*/
128
public String getTestVMOutput() {
129
return testVMOutput;
130
}
131
132
/**
133
* Set the test VM output, called by the framework.
134
*/
135
void setTestVMOutput(String testVMOutput) {
136
this.testVMOutput = testVMOutput;
137
}
138
139
/**
140
* Returns a boolean indicating if this scenario will be executed by the test framework. This only depends on
141
* the property flag {@code -DScenarios} (see {@link Scenario}). This is only used by the framework internally.
142
*
143
* @return {@code true} if {@code -DScenarios} is either not set or if {@code -DScenarios} specifies the scenario
144
* index set by {@link #Scenario(int, String...)}.
145
* {@code false} otherwise.
146
*/
147
boolean isEnabled() {
148
return enabled;
149
}
150
}
151
152