summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-03-27 17:31:51 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-11 10:18:16 +0100
commitb9aa10efcb03c08a4a655ea2b5559bb069de3fb1 (patch)
treefdffd9f1ab006a58a0208e160887954b75baf721 /tests
parent8b6d910d330394f2480e3e17dd3eb58685c78768 (diff)
downloadlibgit2-b9aa10efcb03c08a4a655ea2b5559bb069de3fb1.tar.gz
process: test SIGTERM detection
We can't reliably detect SIGPIPE on close because of platform differences. Track `pid` and send `SIGTERM` to a function and ensure that we can detect it.
Diffstat (limited to 'tests')
-rw-r--r--tests/util/process/start.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/util/process/start.c b/tests/util/process/start.c
index cb43bf746..5de908776 100644
--- a/tests/util/process/start.c
+++ b/tests/util/process/start.c
@@ -2,6 +2,14 @@
#include "process.h"
#include "vector.h"
+#ifndef GIT_WIN32
+# include <signal.h>
+#endif
+
+#ifndef SIGTERM
+# define SIGTERM 42
+#endif
+
#ifndef SIGPIPE
# define SIGPIPE 42
#endif
@@ -130,7 +138,7 @@ void test_process_start__redirect_stdio(void)
git_process_free(process);
}
-void test_process_start__catch_signal(void)
+void test_process_start__catch_sigterm(void)
{
#ifndef GIT_WIN32
const char *args_array[] = { helloworld_cmd.ptr };
@@ -138,6 +146,35 @@ void test_process_start__catch_signal(void)
git_process *process;
git_process_options opts = GIT_PROCESS_OPTIONS_INIT;
git_process_result result = GIT_PROCESS_RESULT_INIT;
+ p_pid_t pid;
+
+ opts.capture_out = 1;
+
+ cl_git_pass(git_process_new(&process, args_array, ARRAY_SIZE(args_array), NULL, 0, &opts));
+ cl_git_pass(git_process_start(process));
+ cl_git_pass(git_process_id(&pid, process));
+
+ cl_must_pass(kill(pid, SIGTERM));
+
+ cl_git_pass(git_process_wait(&result, process));
+
+ cl_assert_equal_i(GIT_PROCESS_STATUS_ERROR, result.status);
+ cl_assert_equal_i(0, result.exitcode);
+ cl_assert_equal_i(SIGTERM, result.signal);
+
+ git_process_free(process);
+#endif
+}
+
+void test_process_start__catch_sigpipe(void)
+{
+ /* macOS SIGPIPEs here, but not every OS does. */
+#ifdef __APPLE__
+ const char *args_array[] = { helloworld_cmd.ptr };
+
+ git_process *process;
+ git_process_options opts = GIT_PROCESS_OPTIONS_INIT;
+ git_process_result result = GIT_PROCESS_RESULT_INIT;
opts.capture_out = 1;