~xnox/upstart/lp1433013

« back to all changes in this revision

Viewing changes to init/tests/test_job_process.c

  • Committer: Dimitri John Ledkov
  • Date: 2014-07-12 00:40:47 UTC
  • Revision ID: dimitri.ledkov@canonical.com-20140712004047-ei94c53e9mo2qtqk
Split 'with no such file' test into two scenarios - read handler or job_process_handler getting called first.

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
        NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll, \
146
146
                                          NULL))
147
147
 
 
148
#define TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS()       \
 
149
        NIH_MUST (nih_child_add_watch (NULL,                    \
 
150
                                       -1,                      \
 
151
                                       NIH_CHILD_ALL,           \
 
152
                                       test_job_process_handler,\
 
153
                                       NULL));                  \
 
154
        NIH_MUST (nih_child_add_watch (NULL,                    \
 
155
                                       -1,                      \
 
156
                                       NIH_CHILD_ALL,           \
 
157
                                       job_process_handler,     \
 
158
                                       NULL));                  \
 
159
        NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll, \
 
160
                                          NULL))
 
161
 
148
162
 
149
163
#define TEST_CLEAR_CHILD_STATUS()                               \
150
164
        do {                                                    \
506
520
        pid_t            pid;
507
521
        int              i;
508
522
        siginfo_t        siginfo;
 
523
        NihList         *removed_watch;
509
524
 
510
525
        log_unflushed_init ();
511
526
        job_class_init ();
1165
1180
         * job_process_start() raises a ProcessError and the command doesn't
1166
1181
         * have any stored process id for it.
1167
1182
         */
1168
 
        TEST_FEATURE ("with no such file");
 
1183
        TEST_FEATURE ("with no such file (read error)");
1169
1184
        TEST_HASH_EMPTY (job_classes);
1170
1185
 
1171
1186
        TEST_RESET_MAIN_LOOP ();
1172
 
        TEST_INSTALL_CHILD_HANDLERS ();
 
1187
        TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS ();
1173
1188
 
1174
1189
        output = tmpfile ();
1175
1190
 
1209
1224
                nih_free (class);
1210
1225
        }
1211
1226
 
 
1227
        TEST_RESET_MAIN_LOOP ();
 
1228
 
 
1229
        TEST_FEATURE ("with no such file (child abort)");
 
1230
        TEST_HASH_EMPTY (job_classes);
 
1231
 
 
1232
        TEST_RESET_MAIN_LOOP ();
 
1233
        TEST_INSTALL_CHILD_HANDLERS_WITHOUT_JOB_PROCESS ();
 
1234
 
 
1235
        output = tmpfile ();
 
1236
 
 
1237
        TEST_ALLOC_FAIL {
 
1238
                TEST_ALLOC_SAFE {
 
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;
 
1245
 
 
1246
                        job = job_new (class, "foo");
 
1247
                        job->goal = JOB_START;
 
1248
                        job->state = JOB_SPAWNED;
 
1249
 
 
1250
                        nih_hash_add (job_classes, &class->entry);
 
1251
                        TEST_CLEAR_CHILD_STATUS ();
 
1252
                }
 
1253
 
 
1254
                TEST_DIVERT_STDERR (output) {
 
1255
                        job_process_start (job, PROCESS_MAIN);
 
1256
                        pid = job->pid[PROCESS_MAIN];
 
1257
                        TEST_GT (pid, 0);
 
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);
 
1262
                        event_poll ();
 
1263
                }
 
1264
                rewind (output);
 
1265
                
 
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);
 
1271
 
 
1272
                nih_free (class);
 
1273
        }
 
1274
 
1212
1275
        TEST_EQ (rmdir (dirname), 0);
1213
1276
 
1214
1277
        TEST_RESET_MAIN_LOOP ();