| 1 | program test_job_waits |
| 2 | use fgof_jobs, only : & |
| 3 | attach_job, & |
| 4 | clear_job_handle, & |
| 5 | complete_job, & |
| 6 | configure_job, & |
| 7 | job_continue_result, & |
| 8 | job_exit_result, & |
| 9 | job_is_finished, & |
| 10 | job_is_running, & |
| 11 | job_is_stopped, & |
| 12 | job_needs_cleanup, & |
| 13 | job_owns_process_group, & |
| 14 | job_signal_result, & |
| 15 | job_stop_result, & |
| 16 | make_job_spec, & |
| 17 | observe_wait_result |
| 18 | use fgof_jobs_types, only : job_handle, job_result, job_spec |
| 19 | implicit none |
| 20 | |
| 21 | type(job_spec) :: spec |
| 22 | type(job_handle) :: handle |
| 23 | type(job_result) :: result_value |
| 24 | |
| 25 | spec = make_job_spec("shell-job") |
| 26 | handle = clear_job_handle() |
| 27 | call configure_job(handle, spec) |
| 28 | call attach_job(handle, 41) |
| 29 | if (.not. job_owns_process_group(handle)) error stop "new process-group jobs should own their process group by default" |
| 30 | if (.not. job_needs_cleanup(handle)) error stop "attached jobs should start needing cleanup" |
| 31 | |
| 32 | result_value = job_stop_result(19) |
| 33 | call observe_wait_result(handle, result_value) |
| 34 | if (job_is_running(handle)) error stop "stop results should clear running state" |
| 35 | if (.not. job_is_stopped(handle)) error stop "stop results should mark the handle stopped" |
| 36 | if (job_is_finished(handle)) error stop "stop results should not mark the handle finished" |
| 37 | if (.not. job_needs_cleanup(handle)) error stop "stopped jobs should still need later cleanup or wait handling" |
| 38 | if (handle%result%pid /= 41) error stop "wait results without pid should inherit the attached pid" |
| 39 | if (handle%result%process_group /= 41) error stop "wait results without process group should inherit the attached group" |
| 40 | |
| 41 | result_value = job_continue_result() |
| 42 | call observe_wait_result(handle, result_value) |
| 43 | if (.not. job_is_running(handle)) error stop "continue results should resume running state" |
| 44 | if (job_is_stopped(handle)) error stop "continue results should clear stopped state" |
| 45 | if (job_is_finished(handle)) error stop "continue results should not mark the handle finished" |
| 46 | if (.not. job_needs_cleanup(handle)) error stop "continued jobs should still need later cleanup or wait handling" |
| 47 | |
| 48 | result_value = job_exit_result(3) |
| 49 | call complete_job(handle, result_value) |
| 50 | if (job_is_running(handle)) error stop "exit completion should clear running state" |
| 51 | if (job_is_stopped(handle)) error stop "exit completion should clear stopped state" |
| 52 | if (.not. job_is_finished(handle)) error stop "exit completion should mark the handle finished" |
| 53 | if (job_needs_cleanup(handle)) error stop "terminal exit completion should clear cleanup state" |
| 54 | if (.not. handle%result%exited) error stop "exit completion should preserve exit classification" |
| 55 | if (handle%result%exit_code /= 3) error stop "exit completion should preserve exit code" |
| 56 | |
| 57 | handle = clear_job_handle() |
| 58 | spec = make_job_spec("pipeline-child", new_process_group=.false.) |
| 59 | call configure_job(handle, spec) |
| 60 | call attach_job(handle, 80, process_group=12, owns_process=.true.) |
| 61 | if (job_owns_process_group(handle)) error stop "non-leader jobs should not own process groups by default" |
| 62 | if (.not. job_needs_cleanup(handle)) error stop "process ownership alone should still require cleanup" |
| 63 | |
| 64 | result_value = job_signal_result(15, pid=80, process_group=12) |
| 65 | call complete_job(handle, result_value) |
| 66 | if (.not. job_is_finished(handle)) error stop "signal completion should mark the handle finished" |
| 67 | if (.not. handle%result%signaled) error stop "signal completion should preserve signal classification" |
| 68 | if (handle%result%signal /= 15) error stop "signal completion should preserve signal values" |
| 69 | end program test_job_waits |
| 70 |