| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gate/tests.h" | ||
| 2 | #include "test_process.h" | ||
| 3 | #include "gate/processes.h" | ||
| 4 | #include "gate/times.h" | ||
| 5 | |||
| 6 | #if defined(GATE_SYS_WIN) | ||
| 7 | static gate_string_t const shell_exe = GATE_STRING_INIT_STATIC("cmd.exe"); | ||
| 8 | #else | ||
| 9 | static gate_string_t const shell_exe = GATE_STRING_INIT_STATIC("/bin/sh"); | ||
| 10 | #endif | ||
| 11 | |||
| 12 | 1 | GATE_TEST_FUNCTION(test_processes) | |
| 13 | { | ||
| 14 | 1 | gate_process_handle_t proc_handle = NULL; | |
| 15 | 1 | gate_process_id_t proc_id = 0; | |
| 16 | 1 | gate_process_stream_t* proc_stream = NULL; | |
| 17 | gate_result_t result; | ||
| 18 | char buffer[1024]; | ||
| 19 | 1 | gate_size_t received = 0; | |
| 20 | gate_timecounter_t now; | ||
| 21 | gate_timecounter_t timeout; | ||
| 22 | |||
| 23 | |||
| 24 | 1 | GATE_TEST_UNIT_BEGIN(test_processes); | |
| 25 | |||
| 26 | 1 | result = gate_process_start_ex(&shell_exe, NULL, 0, NULL, NULL, 0, GATE_PROCESS_START_NEWTERMINAL, | |
| 27 | NULL, NULL, NULL, | ||
| 28 | &proc_handle, &proc_id, &proc_stream); | ||
| 29 | |||
| 30 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_OK(result); |
| 31 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_NOT_EQUAL(proc_stream, NULL); |
| 32 | |||
| 33 | 1 | result = gate_process_wait(&proc_handle, 0); | |
| 34 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(result, GATE_RESULT_TIMEOUT); |
| 35 | |||
| 36 | 1 | gate_timecounter_now(&now); | |
| 37 | 1 | timeout = gate_timecounter_add(now, 2000000); | |
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 4254229 times.
✓ Branch 1 taken 1 times.
|
4254231 | for(; |
| 40 | 4254230 | gate_timecounter_diff(timeout, now) >= 0; | |
| 41 | 4254229 | gate_timecounter_now(&now)) | |
| 42 | { | ||
| 43 | 4254229 | result = gate_stream_peek((gate_stream_t*)proc_stream, buffer, sizeof(buffer), &received); | |
| 44 |
3/4✓ Branch 0 taken 4254229 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4254228 times.
|
4254229 | if(GATE_SUCCEEDED(result) && (received > 0)) |
| 45 | { | ||
| 46 | 1 | result = gate_stream_read((gate_stream_t*)proc_stream, buffer, sizeof(buffer), &received); | |
| 47 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | 1 | result = gate_stream_write_block((gate_stream_t*)proc_stream, "exit\r\n", 6, &received); | |
| 52 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
| 53 | |||
| 54 | 1 | gate_timecounter_now(&now); | |
| 55 | 1 | timeout = gate_timecounter_add(now, 2000000); | |
| 56 | |||
| 57 |
2/2✓ Branch 0 taken 1741784 times.
✓ Branch 1 taken 1 times.
|
1741786 | for(; |
| 58 | 1741785 | gate_timecounter_diff(timeout, now) >= 0; | |
| 59 | 1741784 | gate_timecounter_now(&now)) | |
| 60 | { | ||
| 61 | 1741784 | result = gate_stream_peek((gate_stream_t*)proc_stream, buffer, sizeof(buffer), &received); | |
| 62 |
4/4✓ Branch 0 taken 197 times.
✓ Branch 1 taken 1741587 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 196 times.
|
1741784 | if(GATE_SUCCEEDED(result) && (received > 0)) |
| 63 | { | ||
| 64 | 1 | result = gate_stream_read((gate_stream_t*)proc_stream, buffer, sizeof(buffer), &received); | |
| 65 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if(received == 0) |
| 67 | { | ||
| 68 | ✗ | break; | |
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | 1 | result = gate_process_wait(&proc_handle, 1000); | |
| 74 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
| 75 | |||
| 76 | 1 | gate_process_terminate(&proc_handle, true); | |
| 77 | 1 | gate_process_close(&proc_handle); | |
| 78 | |||
| 79 | 1 | gate_object_release(proc_stream); | |
| 80 | |||
| 81 | 1 | GATE_TEST_UNIT_END; | |
| 82 | } | ||
| 83 |