1
1
module test_subprocess
2
2
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
3
- use stdlib_system, only: process_type, run, runasync, is_running, wait, update, elapsed, is_windows, kill
3
+ use stdlib_system, only: process_type, run, runasync, is_running, wait, update, elapsed, is_windows, &
4
+ kill, send_signal
4
5
5
6
implicit none
6
7
@@ -15,6 +16,7 @@ subroutine collect_suite(testsuite)
15
16
new_unittest(' test_run_synchronous' , test_run_synchronous), &
16
17
new_unittest(' test_run_asynchronous' , test_run_asynchronous), &
17
18
new_unittest(' test_process_kill' , test_process_kill), &
19
+ new_unittest(' test_process_send_signal' , test_process_send_signal), &
18
20
new_unittest(' test_process_state' , test_process_state) &
19
21
]
20
22
end subroutine collect_suite
@@ -94,6 +96,44 @@ subroutine test_process_kill(error)
94
96
call check(error, process% completed, " Process should be marked as completed after being killed" )
95
97
end subroutine test_process_kill
96
98
99
+ subroutine test_process_send_signal (error )
100
+ type (error_type), allocatable , intent (out ) :: error
101
+ type (process_type) :: process
102
+ logical :: success
103
+
104
+ ! As the function does nothing on windows
105
+ if (is_windows()) return
106
+
107
+ ! Start a long-running process asynchronously
108
+ process = runasync(" ping -c 10 127.0.0.1" )
109
+
110
+ ! Ensure the process starts running
111
+ call check(error, .not. process% completed, " Process should not be completed immediately after starting" )
112
+ if (allocated (error)) return
113
+
114
+ call check(error, is_running(process), " Process should be running immediately after starting" )
115
+ if (allocated (error)) return
116
+
117
+ ! send SIGWINCH(28) to process, this should not cause the process to exit
118
+ call send_signal(process, 28 , success)
119
+ call check(error, success, " Failed to send signal SIGWINCH to the process" )
120
+ if (allocated (error)) return
121
+
122
+ ! Verify the process is still running
123
+ call check(error, .not. process% completed, " Process should not exit after SIGWINCH signal" )
124
+ if (allocated (error)) return
125
+
126
+ ! send SIGKILL to process
127
+ call send_signal(process, 9 , success)
128
+ call check(error, success, " Failed to send signal SIGKILL to the process" )
129
+ if (allocated (error)) return
130
+
131
+ ! Verify the process is no longer running
132
+ call check(error, .not. process% completed, " Process should be completed after being killed" )
133
+ if (allocated (error)) return
134
+
135
+ end subroutine test_process_send_signal
136
+
97
137
! > Test updating and checking process state
98
138
subroutine test_process_state (error )
99
139
type (error_type), allocatable , intent (out ) :: error
0 commit comments