145
145
NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll, \
148
#define TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS() \
149
NIH_MUST (nih_child_add_watch (NULL, \
152
test_job_process_handler,\
154
NIH_MUST (nih_child_add_watch (NULL, \
157
job_process_handler, \
159
NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll, \
149
163
#define TEST_CLEAR_CHILD_STATUS() \
1165
1180
* job_process_start() raises a ProcessError and the command doesn't
1166
1181
* have any stored process id for it.
1168
TEST_FEATURE ("with no such file");
1183
TEST_FEATURE ("with no such file (read error)");
1169
1184
TEST_HASH_EMPTY (job_classes);
1171
1186
TEST_RESET_MAIN_LOOP ();
1172
TEST_INSTALL_CHILD_HANDLERS ();
1187
TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS ();
1174
1189
output = tmpfile ();
1209
1224
nih_free (class);
1227
TEST_RESET_MAIN_LOOP ();
1229
TEST_FEATURE ("with no such file (child abort)");
1230
TEST_HASH_EMPTY (job_classes);
1232
TEST_RESET_MAIN_LOOP ();
1233
TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS ();
1235
output = tmpfile ();
1239
TEST_HASH_EMPTY (job_classes);
1240
class = job_class_new (NULL, "test", NULL);
1241
class->console = CONSOLE_NONE;
1242
class->process[PROCESS_MAIN] = process_new (class);
1243
class->process[PROCESS_MAIN]->script = FALSE;
1244
class->process[PROCESS_MAIN]->command = filename;
1246
job = job_new (class, "foo");
1247
job->goal = JOB_START;
1248
job->state = JOB_SPAWNED;
1250
nih_hash_add (job_classes, &class->entry);
1251
TEST_CLEAR_CHILD_STATUS ();
1254
TEST_DIVERT_STDERR (output) {
1255
job_process_start (job, PROCESS_MAIN);
1256
pid = job->pid[PROCESS_MAIN];
1258
waitpid (pid, &status, 0);
1259
TEST_TRUE (WIFEXITED (status));
1260
TEST_EQ (WEXITSTATUS (status), 255);
1261
job_process_handler (NULL, pid, NIH_CHILD_EXITED, 255);
1266
TEST_EQ (job->pid[PROCESS_MAIN], 0);
1267
TEST_GT (sprintf (buffer, "test: test (foo) main process (%i) terminated with status 255\n", pid), 0);
1268
TEST_FILE_EQ (output, buffer);
1269
TEST_FILE_END (output);
1270
TEST_FILE_RESET (output);
1212
1275
TEST_EQ (rmdir (dirname), 0);
1214
1277
TEST_RESET_MAIN_LOOP ();