11module test_subprocess
22 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
45
56 implicit none
67
@@ -15,6 +16,7 @@ subroutine collect_suite(testsuite)
1516 new_unittest(' test_run_synchronous' , test_run_synchronous), &
1617 new_unittest(' test_run_asynchronous' , test_run_asynchronous), &
1718 new_unittest(' test_process_kill' , test_process_kill), &
19+ new_unittest(' test_process_send_signal' , test_process_send_signal), &
1820 new_unittest(' test_process_state' , test_process_state) &
1921 ]
2022 end subroutine collect_suite
@@ -94,6 +96,44 @@ subroutine test_process_kill(error)
9496 call check(error, process% completed, " Process should be marked as completed after being killed" )
9597 end subroutine test_process_kill
9698
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+
97137 ! > Test updating and checking process state
98138 subroutine test_process_state (error )
99139 type (error_type), allocatable , intent (out ) :: error
0 commit comments