Skip to content

Commit

Permalink
Further fix the ABORT directive handling
Browse files Browse the repository at this point in the history
And update the tests accordingly.
  • Loading branch information
ctrueden committed Feb 6, 2025
1 parent 78b591b commit c68dbe5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
17 changes: 9 additions & 8 deletions src/c/jaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int main(const int argc, const char *argv[]) {
free(command);
if (run_result != SUCCESS) return run_result;

CHECK_ARGS("JAUNCH", "out", out_argc, 2, 99999, out_argv);
CHECK_ARGS("JAUNCH", "out", out_argc, 1, 99999, out_argv);
// Maximum # of lines to treat as valid. ^^^^^
// We could of course leave this unbounded, but pragmatically, the value
// will probably never exceed this size -- it is more likely that a
Expand All @@ -170,6 +170,13 @@ int main(const int argc, const char *argv[]) {
while (index < out_argc) {
// Prepare the (argc, argv) for the next directive.
const char *directive = (const char *)(out_argv[index]);

// Honor the special ABORT directive immediately (no further parsing).
if (strcmp(directive, "ABORT") == 0) {
const size_t extra = out_argc - index - 1;
if (extra > 0) error("Ignoring %zu trailing output lines.", extra);
break;
}
if (index == out_argc - 1) {
error("Invalid trailing directive: %s", directive);
break;
Expand All @@ -180,13 +187,7 @@ int main(const int argc, const char *argv[]) {
index += 2 + dir_argc; // Advance index past this directive block.

// Call the directive's associated function.
if (strcmp(directive, "ABORT") == 0) {
if (dir_argc > 0) error("Ignoring %zu extra ABORT lines.", dir_argc);
const size_t extra = out_argc - index;
if (extra > 0) error("Ignoring %zu trailing output lines.", extra);
break;
}
else if (strcmp(directive, "JVM") == 0) {
if (strcmp(directive, "JVM") == 0) {
exit_code = launch(launch_jvm, dir_argc, dir_argv);
if (exit_code != SUCCESS) break;
}
Expand Down
3 changes: 0 additions & 3 deletions test/common.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Test: Help text with --help
--system
do not try to run bundled runtime
ABORT
0
--End of expected output--

Test: Help text with -h
Expand Down Expand Up @@ -88,7 +87,6 @@ Test: Help text with -h
--system
do not try to run bundled runtime
ABORT
0
--End of expected output--

Test: Debug output
Expand All @@ -102,7 +100,6 @@ Test: dry-run
$ ./jaunch/jaunch-linux-x64 hello --dry-run
[DRY-RUN] /*/bin/java -Djava.class.path=/*/demo HelloSwing (glob)
ABORT
0

Test: print-app-dir
$ ./jaunch/jaunch-linux-x64 hello --print-app-dir
Expand Down
2 changes: 1 addition & 1 deletion test/jaunch.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Test 1: help text
For more details, check out the nearby TOML files. Happy Jaunching!

[1]
--End Test 1 epected output--
--End Test 1 expected output--

Test 2: using jaunch to launch an absent application

Expand Down
6 changes: 0 additions & 6 deletions test/jvm.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ Tests:
$ ./jaunch/jaunch-linux-x64 hi --print-java-home
/* (glob)
ABORT
0

This is highly variable with java version & build
$ ./jaunch/jaunch-linux-x64 hi --print-java-info 2> /dev/null
ABORT
0

Memory tests: Verify that all the aliases pass the heap size
$ ./jaunch/jaunch-linux-x64 hi --print-class-path
<none>
ABORT
0

$ ./jaunch/jaunch-linux-x64 hi --heap 2g
JVM
Expand Down Expand Up @@ -106,19 +103,16 @@ Move the .class file back
$ ./jaunch/jaunch-linux-x64 hi --ext . --dry-run
[DRY-RUN] /*/bin/java -Djava.ext.dirs=. -Djava.class.path=/*/demo HelloWorld (glob)
ABORT
0

Verify --headless would pass the correct flags
$ ./jaunch/jaunch-linux-x64 hi --headless --dry-run
[DRY-RUN] /*java -Djava.awt.headless=true -Dapple.awt.UIElement=true -Djava.class.path=/*/demo HelloWorld (glob)
ABORT
0

Verify --debugger would pass the correct flags
$ ./jaunch/jaunch-linux-x64 hi --debugger 8000 --dry-run
[DRY-RUN] /*/bin/java -agentlib:jdwp=transport=dt_socket,server=y,address=localhost:8000 -Djava.class.path=/*/demo HelloWorld (glob)
ABORT
0

For testing --java-home, we use an invalid path and just verify it's in the search space
$ ./jaunch/jaunch-linux-x64 hi --java-home . --debug 2>&1 | grep -A1 "Root paths to search for Java"
Expand Down

0 comments on commit c68dbe5

Please sign in to comment.