- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathScenario.java
150 lines (136 loc) · 5.78 KB
/
Scenario.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
packagecompiler.lib.ir_framework;
importcompiler.lib.ir_framework.shared.TestRunException;
importjava.util.*;
importjava.util.stream.Collectors;
/**
* This class represents a scenario that can be executed by the {@link TestFramework}.
* <p>
* A JTreg test should use the test framework with {@code @run driver} (without directly specify any additional flags).
* If a test should run with additional flags, use {@link TestFramework#runWithFlags(String...)} or
* {@link TestFramework#addFlags(String...)}. If, however, the test should be run with different settings (equivalent
* to having multiple {@code @run} entries in a normal JTreg test), use scenarios. A scenario will be run with the
* scenario specific VM flags, if any, and optionally specified VM flags with {@link TestFramework#addFlags(String...)}
* whereas scenario VM flags will have precedence.
* <p>
* There is also the possibility to specify additional VM flags for all scenarios by using {@code DScenarioFlags}.
*
* @see TestFramework
*/
publicclassScenario {
privatestaticfinalStringADDITIONAL_SCENARIO_FLAGS_PROPERTY = System.getProperty("ScenarioFlags", "");
privatestaticfinalStringSCENARIOS_PROPERTY = System.getProperty("Scenarios", "");
privatestaticfinalList<String> ADDITIONAL_SCENARIO_FLAGS;
privatestaticfinalSet<Integer> ENABLED_SCENARIOS;
privatefinalList<String> flags;
privatefinalintindex;
privatefinalbooleanenabled;
privateStringtestVMOutput;
static {
if (!SCENARIOS_PROPERTY.isEmpty()) {
varsplit = SCENARIOS_PROPERTY.split("\\s*,\\s*");
try {
ENABLED_SCENARIOS = Arrays.stream(split).map(Integer::parseInt).collect(Collectors.toSet());
} catch (NumberFormatExceptione) {
thrownewTestRunException("Provided a scenario index in the -DScenario comma-separated list which is not "
+ "a number: " + SCENARIOS_PROPERTY);
}
} else {
ENABLED_SCENARIOS = Collections.emptySet();
}
ADDITIONAL_SCENARIO_FLAGS = ADDITIONAL_SCENARIO_FLAGS_PROPERTY.isEmpty() ? Collections.emptyList() :
Arrays.asList(ADDITIONAL_SCENARIO_FLAGS_PROPERTY.split("\\s*,\\s*"));
}
/**
* Create a scenario with {@code index} that will be run with the additional VM flags specified in {@code flags}
* (or without any if null or parameter not provided).
* <p>
* The scenario {@code index} must be unique to be distinguishable in the stdout and stderr output and when specifying
* {@code -DScenarios} (see {@link Scenario}).
*
* @param index the unique scenario index.
* @param flags the scenario flags or null (i.e. no parameter specified) if no flags should be used.
*/
publicScenario(intindex, String... flags) {
this.index = index;
if (flags != null) {
this.flags = newArrayList<>(Arrays.asList(flags));
this.flags.addAll(ADDITIONAL_SCENARIO_FLAGS);
} else {
this.flags = newArrayList<>();
}
this.enabled = ENABLED_SCENARIOS.isEmpty() || ENABLED_SCENARIOS.contains(index);
}
/**
* Add additional VM flags to this scenario.
*
* @param flags the additional scenario VM flags.
*/
publicvoidaddFlags(String... flags) {
if (flags != null) {
this.flags.addAll(Arrays.asList(flags));
}
}
/**
* Get all scenario specific VM flags as defined in {@link #Scenario(int, String...)}.
*
* @return the scenario VM flags.
*/
publicList<String> getFlags() {
returnflags;
}
/**
* Get the unique scenario index as defined in {@link #Scenario(int, String...)}.
*
* @return the scenario index.
*/
publicintgetIndex() {
returnindex;
}
/**
* Get the test VM output (stdout + stderr) of this scenario from the last execution of the framework.
*
* @return the test VM output.
*/
publicStringgetTestVMOutput() {
returntestVMOutput;
}
/**
* Set the test VM output, called by the framework.
*/
voidsetTestVMOutput(StringtestVMOutput) {
this.testVMOutput = testVMOutput;
}
/**
* Returns a boolean indicating if this scenario will be executed by the test framework. This only depends on
* the property flag {@code -DScenarios} (see {@link Scenario}). This is only used by the framework internally.
*
* @return {@code true} if {@code -DScenarios} is either not set or if {@code -DScenarios} specifies the scenario
* index set by {@link #Scenario(int, String...)}.
* {@code false} otherwise.
*/
booleanisEnabled() {
returnenabled;
}
}