Skip to content

Commit d712c42

Browse files
committed
SmokeTestAll: utilize command-line arguments
1 parent 2ddef4f commit d712c42

4 files changed

Lines changed: 132 additions & 12 deletions

File tree

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ model {
369369
}
370370

371371
dependencies {
372+
testImplementation(libs.jcommander) // to parse command-line arguments
372373
testImplementation(libs.jsnaploader) // to identify the OS and CPU
373374
testImplementation(libs.junit4) // framework for automated testing
374375
testRuntimeOnly(libs.log4j.impl)
@@ -488,6 +489,7 @@ tasks.register('runRagdollSinglePile', JavaExec) {
488489
mainClass = 'testjoltjni.app.performancetest.PerformanceTest'
489490
}
490491
tasks.register('runSmokeTestAll', JavaExec) {
492+
args '-n', '99'
491493
dependsOn('unpackHairStraight', 'unpackJoltAssets')
492494
description = 'Performs a "smoke test" of each of the Samples tests.'
493495
mainClass = 'testjoltjni.app.samples.SmokeTestAll'

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ checkstyle = "13.4.2"
77

88
[libraries]
99

10+
jcommander = "org.jcommander:jcommander:1.85"
1011
jsnaploader = "io.github.electrostat-lab:snaploader:1.1.1-stable"
1112
junit4 = "junit:junit:4.13.2"
1213
log4j-impl = "org.apache.logging.log4j:log4j-slf4j2-impl:2.25.4"

src/test/java/testjoltjni/app/samples/SmokeTestAll.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ of this software and associated documentation files (the "Software"), to deal
2121
*/
2222
package testjoltjni.app.samples;
2323

24+
import com.beust.jcommander.JCommander;
2425
import com.github.stephengold.joltjni.*;
2526
import com.github.stephengold.joltjni.enumerate.EPhysicsUpdateError;
2627
import com.github.stephengold.joltjni.std.OfStream;
@@ -47,14 +48,6 @@ of this software and associated documentation files (the "Software"), to deal
4748
* @author Stephen Gold sgold@sonic.net
4849
*/
4950
final public class SmokeTestAll {
50-
// *************************************************************************
51-
// constants
52-
53-
/**
54-
* default number of physics steps to simulate during each invocation of
55-
* {@code smokeTest()}
56-
*/
57-
final private static int defaultNumSteps = 66;
5851
// *************************************************************************
5952
// fields
6053

@@ -78,19 +71,33 @@ final public class SmokeTestAll {
7871
* allocator shared by all physics test objects
7972
*/
8073
private static TempAllocator tempAllocator;
74+
/**
75+
* parameters parsed from the command line
76+
*/
77+
final private static TestParameters globalParameters = new TestParameters();
8178
// *************************************************************************
8279
// new methods exposed
8380

8481
/**
8582
* Main entry point for the SmokeTestAll application.
8683
*
87-
* @param arguments array of command-line arguments (not {@code null})
84+
* @param arguments the command-line arguments (not {@code null})
8885
*/
8986
public static void main(String... arguments) {
90-
//TestUtils.traceAllocations = true;
87+
// Parse the command-line arguments:
88+
JCommander jCommander = new JCommander(globalParameters);
89+
jCommander.parse(arguments);
90+
jCommander.setProgramName("SmokeTestAll");
91+
if (globalParameters.helpOnly()) {
92+
jCommander.usage();
93+
System.exit(0);
94+
}
95+
96+
TestUtils.traceAllocations = globalParameters.traceAllocations();
9197
TestUtils.loadNativeLibrary();
9298
TestUtils.initializeNativeLibrary();
9399

100+
// Log the configuration:
94101
System.out.println(Jolt.getConfigurationString());
95102
System.out.print(" built-in compute systems:");
96103
System.out.print(Jolt.implementsComputeCpu() ? " CPU" : "");
@@ -219,7 +226,7 @@ private static PhysicsSystem newPhysicsSystem(int maxBodies) {
219226
* @param test the Test object to use (not {@code null})
220227
*/
221228
private static void smokeTest(Test test) {
222-
smokeTest(test, defaultNumSteps);
229+
smokeTest(test, globalParameters.numSteps());
223230
}
224231

225232
/**
@@ -259,16 +266,29 @@ private static void smokeTest(Test test, int numSteps) {
259266
test.Initialize();
260267

261268
// Single-step the physics numSteps times:
262-
for (int i = 0; i < numSteps; ++i) {
269+
for (int stepIndex = 1; stepIndex <= numSteps; ++stepIndex) {
270+
if (globalParameters.verboseLogging()) {
271+
System.out.printf(
272+
"---- step #%d%n pre-update%n", stepIndex);
273+
System.out.flush();
274+
}
263275
PreUpdateParams params = new PreUpdateParams();
264276
params.mDeltaTime = 0.02f;
265277
test.PrePhysicsUpdate(params);
266278

279+
if (globalParameters.verboseLogging()) {
280+
System.out.printf(" update%n");
281+
System.out.flush();
282+
}
267283
int collisionSteps = 1;
268284
int errors = physicsSystem.update(params.mDeltaTime, collisionSteps,
269285
tempAllocator, jobSystem);
270286
assert errors == EPhysicsUpdateError.None : errors;
271287

288+
if (globalParameters.verboseLogging()) {
289+
System.out.printf(" post-update%n");
290+
System.out.flush();
291+
}
272292
test.PostPhysicsUpdate(params.mDeltaTime);
273293
}
274294

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright (c) 2026 Stephen Gold
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
package testjoltjni.app.samples;
23+
24+
import com.beust.jcommander.Parameter;
25+
26+
/**
27+
* Command-line parameters of the SmokeTestAll application.
28+
*
29+
* @author Stephen Gold sgold@sonic.net
30+
*/
31+
class TestParameters {
32+
// *************************************************************************
33+
// fields
34+
35+
/**
36+
* whether to simply display the usage message and exit
37+
*/
38+
@Parameter(names = {"-h", "--help"},
39+
description = "Display this usage message and then exit.")
40+
private boolean helpOnly;
41+
/**
42+
* number of physics steps to simulate for each test
43+
*/
44+
@Parameter(names = {"-n", "--numSteps"},
45+
description = "Number of physics steps to simulate for each test.")
46+
private int numSteps = 1;
47+
/**
48+
* whether to trace heap allocations in the JNI glue code
49+
*/
50+
@Parameter(names = {"-t", "--traceAllocations"},
51+
description = "Trace heap allocations in JNI glue code.")
52+
private boolean traceAllocations;
53+
/**
54+
* whether log output should be verbose
55+
*/
56+
@Parameter(names = {"-v", "--verbose"},
57+
description = "Generate additional log output.")
58+
private boolean verboseLogging;
59+
// *************************************************************************
60+
// new methods exposed
61+
62+
/**
63+
* Test whether to display the usage message and then exit.
64+
*
65+
* @return {@code true} to display the message, otherwise {@code false}
66+
*/
67+
boolean helpOnly() {
68+
return helpOnly;
69+
}
70+
71+
/**
72+
* Return the number of physics steps to simulate for each test.
73+
*
74+
* @return the number
75+
*/
76+
int numSteps() {
77+
return numSteps;
78+
}
79+
80+
/**
81+
* Test whether to trace heap allocations in the JNI glue code.
82+
*
83+
* @return {@code true} to trace, otherwise {@code false}
84+
*/
85+
boolean traceAllocations() {
86+
return traceAllocations;
87+
}
88+
89+
/**
90+
* Test whether the verbose-logging option was specified.
91+
*
92+
* @return true if specified, otherwise false
93+
*/
94+
boolean verboseLogging() {
95+
return verboseLogging;
96+
}
97+
}

0 commit comments

Comments
 (0)