From 92a16921bf330912927f1cef3e970fd81238fc26 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 8 Dec 2019 13:28:30 -0800 Subject: [PATCH] Add a test to verify that processes get the right pgrps in pipelines --- src/fish_test_helper.cpp | 4 ++++ tests/checks/pipeline-pgroup.fish | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/checks/pipeline-pgroup.fish diff --git a/src/fish_test_helper.cpp b/src/fish_test_helper.cpp index 5f3035a5b..9f6cd7b94 100644 --- a/src/fish_test_helper.cpp +++ b/src/fish_test_helper.cpp @@ -52,6 +52,8 @@ static void print_pid_then_sleep() { usleep(1000000 / .5); //.5 secs } +static void print_pgrp() { fprintf(stdout, "%d\n", getpgrp()); } + int main(int argc, char *argv[]) { if (argc <= 1) { fprintf(stderr, "No commands given.\n"); @@ -68,6 +70,8 @@ int main(int argc, char *argv[]) { print_stdout_stderr(); } else if (!strcmp(argv[i], "print_pid_then_sleep")) { print_pid_then_sleep(); + } else if (!strcmp(argv[i], "print_pgrp")) { + print_pgrp(); } else { fprintf(stderr, "%s: Unknown command: %s\n", argv[0], argv[i]); return EXIT_FAILURE; diff --git a/tests/checks/pipeline-pgroup.fish b/tests/checks/pipeline-pgroup.fish new file mode 100644 index 000000000..7939adb45 --- /dev/null +++ b/tests/checks/pipeline-pgroup.fish @@ -0,0 +1,30 @@ +# RUN: env fth=%fish_test_helper %fish %s + +# Ensure that lots of nested jobs all end up in the same pgroup. + +function save_pgroup -a var_name + $fth print_pgrp | read -g $var_name +end + +# Here everything should live in the pgroup of the first fish_test_helper. +$fth print_pgrp | read -g global_group | save_pgroup g1 | begin; save_pgroup g2; end + +[ "$global_group" -eq "$g1" ] && [ "$g1" -eq "$g2" ] +and echo "All pgroups agreed" +or echo "Pgroups disagreed. Should be in $global_group but found $g1 and $g2" +# CHECK: All pgroups agreed + +# Here everything should live in fish's pgroup. +# Unfortunately we don't know what fish's pgroup is (it may not be fish's pid). +# So run it twice and verify that everything agrees; this implies that it could +# not have used any of the pids of the child procs. +function nothing ; end +nothing | $fth print_pgrp | read -g a0 | save_pgroup a1 | begin; save_pgroup a2; end +nothing | $fth print_pgrp | read -g b0 | save_pgroup b1 | begin; save_pgroup b2; end + +[ "$a0" -eq "$a1" ] && [ "$a1" -eq "$a2" ] \ + && [ "$b0" -eq "$b1" ] && [ "$b1" -eq "$b2" ] \ + && [ "$a0" -eq "$b0" ] +and echo "All pgroups agreed" +or echo "Pgroups disagreed. Found $a0 $a1 $a2, and $b0 $b1 $b2" +# CHECK: All pgroups agreed