~xnox/upstart/upstart-async-run-dead-code

« back to all changes in this revision

Viewing changes to init/tests/test_job.c

  • Committer: James Hunt
  • Date: 2014-06-04 15:39:15 UTC
  • mfrom: (1628 upstart)
  • mto: This revision was merged to the branch mainline in revision 1630.
  • Revision ID: james.hunt@ubuntu.com-20140604153915-bi501sph2duo73f6
* Sync with lp:upstart.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
#include "conf.h"
61
61
#include "control.h"
62
62
#include "state.h"
 
63
#include "test_util_common.h"
63
64
 
 
65
void
 
66
job_quit_with_state (void *data, NihMainLoopFunc *loop)
 
67
{
 
68
    Job *job;
 
69
    job = (Job *)data;
 
70
    nih_main_loop_exit (job->state);
 
71
}
64
72
 
65
73
char *argv0;
66
74
 
165
173
                        TEST_EQ_P (job->log[i], NULL);
166
174
                }
167
175
 
 
176
                TEST_NE_P (job->process_data, NULL);
 
177
                TEST_ALLOC_SIZE (job->log, sizeof (JobProcessData *) * PROCESS_LAST);
 
178
                for (i = 0; i < PROCESS_LAST; i++) {
 
179
                        TEST_EQ_P (job->process_data[i], NULL);
 
180
                }
 
181
 
168
182
                event_operator_reset (job->stop_on);
169
183
 
170
184
                nih_free (job);
701
715
        char            *path, *job_path = NULL, *state;
702
716
        int              status;
703
717
 
 
718
        nih_error_init ();
 
719
        nih_main_loop_init ();
 
720
        event_init ();
 
721
 
704
722
        TEST_FUNCTION ("job_change_state");
705
723
        program_name = "test";
706
724
        output = tmpfile ();
1059
1077
                job->failed_process = PROCESS_INVALID;
1060
1078
                job->exit_status = 0;
1061
1079
 
1062
 
                job_change_state (job, JOB_PRE_START);
 
1080
                job_change_state (job, JOB_PRE_STARTING);
1063
1081
 
1064
1082
                TEST_EQ (job->goal, JOB_START);
1065
1083
                TEST_EQ (job->state, JOB_PRE_START);
1110
1128
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
1111
1129
                        event_block (cause);
1112
1130
                        nih_list_add (&job->blocking, &blocked->entry);
 
1131
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
1113
1132
                }
1114
1133
 
1115
1134
                job->goal = JOB_START;
1125
1144
                job->failed_process = PROCESS_INVALID;
1126
1145
                job->exit_status = 0;
1127
1146
 
1128
 
                job_change_state (job, JOB_PRE_START);
 
1147
                job_change_state (job, JOB_PRE_STARTING);
 
1148
                while (nih_main_loop () < JOB_RUNNING) {}
1129
1149
 
1130
1150
                TEST_EQ (job->goal, JOB_START);
1131
1151
                TEST_EQ (job->state, JOB_RUNNING);
1184
1204
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
1185
1205
                        event_block (cause);
1186
1206
                        nih_list_add (&job->blocking, &blocked->entry);
 
1207
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
1187
1208
                }
1188
1209
 
1189
1210
                job->goal = JOB_START;
1200
1221
                job->exit_status = 0;
1201
1222
 
1202
1223
                TEST_DIVERT_STDERR (output) {
1203
 
                        job_change_state (job, JOB_PRE_START);
 
1224
                        job_change_state (job, JOB_PRE_STARTING);
 
1225
                        while (nih_main_loop() < JOB_STOPPING) {}
1204
1226
                }
1205
1227
                rewind (output);
1206
1228
 
1207
1229
                TEST_EQ (job->goal, JOB_STOP);
1208
1230
                TEST_EQ (job->state, JOB_STOPPING);
 
1231
                TEST_FALSE (job->process_data[PROCESS_PRE_START]->valid);
1209
1232
                TEST_EQ (job->pid[PROCESS_PRE_START], 0);
1210
1233
 
1211
1234
                TEST_EQ (cause->blockers, 0);
1269
1292
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
1270
1293
                        event_block (cause);
1271
1294
                        nih_list_add (&job->blocking, &blocked->entry);
 
1295
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
1272
1296
                }
1273
1297
 
1274
1298
                job->goal = JOB_START;
1284
1308
                job->failed_process = PROCESS_INVALID;
1285
1309
                job->exit_status = 0;
1286
1310
 
1287
 
                job_change_state (job, JOB_SPAWNED);
 
1311
                job_change_state (job, JOB_SPAWNING);
 
1312
                while (nih_main_loop() < JOB_RUNNING) {}
1288
1313
 
1289
1314
                TEST_EQ (job->goal, JOB_START);
1290
1315
                TEST_EQ (job->state, JOB_RUNNING);
1337
1362
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
1338
1363
                        event_block (cause);
1339
1364
                        nih_list_add (&job->blocking, &blocked->entry);
 
1365
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
1340
1366
                }
1341
1367
 
1342
1368
                job->goal = JOB_START;
1352
1378
                job->failed_process = PROCESS_INVALID;
1353
1379
                job->exit_status = 0;
1354
1380
 
1355
 
                job_change_state (job, JOB_SPAWNED);
 
1381
                job_change_state (job, JOB_SPAWNING);
 
1382
                while (nih_main_loop() < JOB_RUNNING) {}
1356
1383
 
1357
1384
                TEST_EQ (job->goal, JOB_START);
1358
1385
                TEST_EQ (job->state, JOB_RUNNING);
1417
1444
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
1418
1445
                        event_block (cause);
1419
1446
                        nih_list_add (&job->blocking, &blocked->entry);
 
1447
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
1420
1448
                }
1421
1449
 
1422
1450
                job->goal = JOB_START;
1432
1460
                job->failed_process = PROCESS_INVALID;
1433
1461
                job->exit_status = 0;
1434
1462
 
1435
 
                job_change_state (job, JOB_SPAWNED);
 
1463
                job_change_state (job, JOB_SPAWNING);
 
1464
                while (nih_main_loop() < JOB_RUNNING) {}
1436
1465
 
1437
1466
                TEST_EQ (job->goal, JOB_START);
1438
1467
                TEST_EQ (job->state, JOB_RUNNING);
1507
1536
                job->failed_process = PROCESS_INVALID;
1508
1537
                job->exit_status = 0;
1509
1538
 
1510
 
                job_change_state (job, JOB_SPAWNED);
 
1539
                job_change_state (job, JOB_SPAWNING);
1511
1540
 
1512
1541
                TEST_EQ (job->goal, JOB_START);
1513
1542
                TEST_EQ (job->state, JOB_RUNNING);
1556
1585
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
1557
1586
                        event_block (cause);
1558
1587
                        nih_list_add (&job->blocking, &blocked->entry);
 
1588
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
1559
1589
                }
1560
1590
 
1561
1591
                job->goal = JOB_START;
1572
1602
                job->exit_status = 0;
1573
1603
 
1574
1604
                TEST_DIVERT_STDERR (output) {
1575
 
                        job_change_state (job, JOB_SPAWNED);
 
1605
                        job_change_state (job, JOB_SPAWNING);
 
1606
                        while (nih_main_loop() < JOB_STOPPING) {}
1576
1607
                }
1577
1608
                rewind (output);
1578
1609
 
1579
1610
                TEST_EQ (job->goal, JOB_STOP);
1580
1611
                TEST_EQ (job->state, JOB_STOPPING);
 
1612
                TEST_FALSE (job->process_data[PROCESS_MAIN]->valid);
1581
1613
                TEST_EQ (job->pid[PROCESS_MAIN], 0);
1582
1614
 
1583
1615
                TEST_EQ (cause->blockers, 0);
1658
1690
                job->failed_process = PROCESS_INVALID;
1659
1691
                job->exit_status = 0;
1660
1692
 
1661
 
                job_change_state (job, JOB_SPAWNED);
 
1693
                job_change_state (job, JOB_SPAWNING);
1662
1694
 
1663
1695
                TEST_EQ (job->goal, JOB_START);
1664
1696
                TEST_EQ (job->state, JOB_SPAWNED);
1727
1759
                job->failed_process = PROCESS_INVALID;
1728
1760
                job->exit_status = 0;
1729
1761
 
1730
 
                job_change_state (job, JOB_POST_START);
 
1762
                job_change_state (job, JOB_POST_STARTING);
1731
1763
 
1732
1764
                TEST_EQ (job->goal, JOB_START);
1733
1765
                TEST_EQ (job->state, JOB_POST_START);
1794
1826
                job->failed_process = PROCESS_INVALID;
1795
1827
                job->exit_status = 0;
1796
1828
 
1797
 
                job_change_state (job, JOB_POST_START);
 
1829
                job_change_state (job, JOB_POST_STARTING);
1798
1830
 
1799
1831
                TEST_EQ (job->goal, JOB_START);
1800
1832
                TEST_EQ (job->state, JOB_RUNNING);
1842
1874
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
1843
1875
                        event_block (cause);
1844
1876
                        nih_list_add (&job->blocking, &blocked->entry);
 
1877
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
1845
1878
                }
1846
1879
 
1847
1880
                job->goal = JOB_START;
1858
1891
                job->exit_status = 0;
1859
1892
 
1860
1893
                TEST_DIVERT_STDERR (output) {
1861
 
                        job_change_state (job, JOB_POST_START);
 
1894
                        job_change_state (job, JOB_POST_STARTING);
 
1895
                        while (nih_main_loop () < JOB_RUNNING) { }
1862
1896
                }
1863
1897
                rewind (output);
1864
1898
 
2058
2092
                job->failed_process = PROCESS_INVALID;
2059
2093
                job->exit_status = 0;
2060
2094
 
2061
 
                job_change_state (job, JOB_PRE_STOP);
 
2095
                job_change_state (job, JOB_PRE_STOPPING);
2062
2096
 
2063
2097
                TEST_EQ (job->goal, JOB_STOP);
2064
2098
                TEST_EQ (job->state, JOB_PRE_STOP);
2125
2159
                job->failed_process = PROCESS_INVALID;
2126
2160
                job->exit_status = 0;
2127
2161
 
2128
 
                job_change_state (job, JOB_PRE_STOP);
 
2162
                job_change_state (job, JOB_PRE_STOPPING);
2129
2163
 
2130
2164
                TEST_EQ (job->goal, JOB_STOP);
2131
2165
                TEST_EQ (job->state, JOB_STOPPING);
2198
2232
                job->failed_process = PROCESS_INVALID;
2199
2233
                job->exit_status = 0;
2200
2234
 
2201
 
                job_change_state (job, JOB_PRE_STOP);
 
2235
                job_change_state (job, JOB_PRE_STOPPING);
2202
2236
 
2203
2237
                TEST_EQ (job->goal, JOB_STOP);
2204
2238
                TEST_EQ (job->state, JOB_STOPPING);
2283
2317
                job->failed_process = PROCESS_INVALID;
2284
2318
                job->exit_status = 0;
2285
2319
 
2286
 
                job_change_state (job, JOB_PRE_STOP);
 
2320
                job_change_state (job, JOB_PRE_STOPPING);
2287
2321
 
2288
2322
                TEST_EQ (job->goal, JOB_STOP);
2289
2323
                TEST_EQ (job->state, JOB_STOPPING);
2348
2382
                        blocked = blocked_new (job, BLOCKED_EVENT, cause);
2349
2383
                        event_block (cause);
2350
2384
                        nih_list_add (&job->blocking, &blocked->entry);
 
2385
                        TEST_NE_P (nih_main_loop_add_func (job, job_quit_with_state, job), NULL);
2351
2386
                }
2352
2387
 
2353
2388
                job->goal = JOB_STOP;
2364
2399
                job->exit_status = 0;
2365
2400
 
2366
2401
                TEST_DIVERT_STDERR (output) {
2367
 
                        job_change_state (job, JOB_PRE_STOP);
 
2402
                        job_change_state (job, JOB_PRE_STOPPING);
 
2403
                        while (nih_main_loop () < JOB_STOPPING) {}
2368
2404
                }
2369
2405
                rewind (output);
2370
2406
 
3100
3136
                job->failed_process = PROCESS_INVALID;
3101
3137
                job->exit_status = 0;
3102
3138
 
3103
 
                job_change_state (job, JOB_POST_STOP);
 
3139
                job_change_state (job, JOB_POST_STOPPING);
3104
3140
 
3105
3141
                TEST_EQ (job->goal, JOB_STOP);
3106
3142
                TEST_EQ (job->state, JOB_POST_STOP);
3168
3204
 
3169
3205
                TEST_FREE_TAG (job);
3170
3206
 
3171
 
                job_change_state (job, JOB_POST_STOP);
 
3207
                job_change_state (job, JOB_POST_STOPPING);
3172
3208
 
3173
3209
                TEST_FREE (job);
3174
3210
 
3228
3264
                TEST_FREE_TAG (job);
3229
3265
 
3230
3266
                TEST_DIVERT_STDERR (output) {
3231
 
                        job_change_state (job, JOB_POST_STOP);
 
3267
                        job_change_state (job, JOB_POST_STOPPING);
 
3268
                        TEST_WATCH_LOOP ();
3232
3269
                }
3233
3270
                rewind (output);
3234
3271
 
4000
4037
 
4001
4038
 
4002
4039
        /* Check that the next state if we're starting a starting job is
 
4040
         * sec-spawning.
 
4041
         */
 
4042
        TEST_FEATURE ("with starting job and a goal of start");
 
4043
        job->goal = JOB_START;
 
4044
        job->state = JOB_STARTING;
 
4045
 
 
4046
        TEST_EQ (job_next_state (job), JOB_SECURITY_SPAWNING);
 
4047
 
 
4048
        /* Check that the next state if we're starting a sec-spawning job is
4003
4049
         * security.
4004
4050
         */
4005
4051
        TEST_FEATURE ("with starting job and a goal of start");
4006
4052
        job->goal = JOB_START;
4007
 
        job->state = JOB_STARTING;
 
4053
        job->state = JOB_SECURITY_SPAWNING;
4008
4054
 
4009
4055
        TEST_EQ (job_next_state (job), JOB_SECURITY);
4010
4056
 
4011
4057
        /* Check that the next state if we're starting a security job is
4012
 
         * pre-start.
 
4058
         * pre-starting.
4013
4059
         */
4014
4060
        TEST_FEATURE ("with security job and a goal of start");
4015
4061
        job->goal = JOB_START;
4016
4062
        job->state = JOB_SECURITY;
4017
4063
 
4018
 
        TEST_EQ (job_next_state (job), JOB_PRE_START);
 
4064
        TEST_EQ (job_next_state (job), JOB_PRE_STARTING);
4019
4065
 
4020
4066
        /* Check that the next state if we're stopping an security job is
4021
4067
         * stopping.
4026
4072
 
4027
4073
        TEST_EQ (job_next_state (job), JOB_STOPPING);
4028
4074
 
 
4075
        /* Check that the next state if we're starting a pre-starting job is
 
4076
         * pre-start.
 
4077
         */
 
4078
        TEST_FEATURE ("with pre-stating job and a goal of start");
 
4079
        job->goal = JOB_START;
 
4080
        job->state = JOB_PRE_STARTING;
 
4081
 
 
4082
        TEST_EQ (job_next_state (job), JOB_PRE_START);
 
4083
 
 
4084
        /* Check that the next state if we're stopping a pre-starting job is
 
4085
         * stopping.
 
4086
         */
 
4087
        TEST_FEATURE ("with pre-starting job and a goal of stop");
 
4088
        job->goal = JOB_STOP;
 
4089
        job->state = JOB_PRE_STARTING;
 
4090
 
 
4091
        TEST_EQ (job_next_state (job), JOB_STOPPING);
 
4092
 
 
4093
 
4029
4094
        /* Check that the next state if we're stopping a pre-start job is
4030
4095
         * stopping.
4031
4096
         */
4043
4108
        job->goal = JOB_START;
4044
4109
        job->state = JOB_PRE_START;
4045
4110
 
 
4111
        TEST_EQ (job_next_state (job), JOB_SPAWNING);
 
4112
 
 
4113
        /* Check that the next state if we're starting a spawning job is
 
4114
         * spawned.
 
4115
         */
 
4116
        TEST_FEATURE ("with pre-start job and a goal of start");
 
4117
        job->goal = JOB_START;
 
4118
        job->state = JOB_SPAWNING;
 
4119
 
4046
4120
        TEST_EQ (job_next_state (job), JOB_SPAWNED);
4047
4121
 
4048
4122
 
4057
4131
 
4058
4132
 
4059
4133
        /* Check that the next state if we're starting a spawned job is
 
4134
         * post-starting.
 
4135
         */
 
4136
        TEST_FEATURE ("with spawned job and a goal of start");
 
4137
        job->goal = JOB_START;
 
4138
        job->state = JOB_SPAWNED;
 
4139
 
 
4140
        TEST_EQ (job_next_state (job), JOB_POST_STARTING);
 
4141
 
 
4142
 
 
4143
        /* Check that the next state if we're starting a post-staring job is
4060
4144
         * post-start.
4061
4145
         */
4062
 
        TEST_FEATURE ("with spawned job and a goal of start");
 
4146
        TEST_FEATURE ("with post-starting job and a goal of start");
4063
4147
        job->goal = JOB_START;
4064
 
        job->state = JOB_SPAWNED;
 
4148
        job->state = JOB_POST_STARTING;
4065
4149
 
4066
4150
        TEST_EQ (job_next_state (job), JOB_POST_START);
4067
4151
 
4106
4190
        job->state = JOB_RUNNING;
4107
4191
        job->pid[PROCESS_MAIN] = 1;
4108
4192
 
 
4193
        TEST_EQ (job_next_state (job), JOB_PRE_STOPPING);
 
4194
 
 
4195
        /* Check that the next state if we're stopping a job with pre-stop is
 
4196
         * pre-stop.  This is the "normal" stop process, as called from the
 
4197
         * goal change event.
 
4198
         */
 
4199
        TEST_FEATURE ("with pre-stopping job and a goal of stop");
 
4200
        job->goal = JOB_STOP;
 
4201
        job->state = JOB_PRE_STOPPING;
 
4202
        job->pid[PROCESS_MAIN] = 1;
 
4203
 
4109
4204
        TEST_EQ (job_next_state (job), JOB_PRE_STOP);
4110
4205
 
4111
4206
 
4193
4288
        job->goal = JOB_START;
4194
4289
        job->state = JOB_KILLED;
4195
4290
 
 
4291
        TEST_EQ (job_next_state (job), JOB_POST_STOPPING);
 
4292
 
 
4293
 
 
4294
        /* Check that the next state if we're starting a post-stopping
 
4295
         * job is post-stop.
 
4296
         */
 
4297
        TEST_FEATURE ("with post-stopping job and a goal of start");
 
4298
        job->goal = JOB_START;
 
4299
        job->state = JOB_POST_STOPPING;
 
4300
 
4196
4301
        TEST_EQ (job_next_state (job), JOB_POST_STOP);
4197
4302
 
4198
4303
 
4203
4308
        job->goal = JOB_STOP;
4204
4309
        job->state = JOB_KILLED;
4205
4310
 
 
4311
        TEST_EQ (job_next_state (job), JOB_POST_STOPPING);
 
4312
 
 
4313
 
 
4314
        /* Check that the next state if we're stopping a post-stopping
 
4315
         * job is post-stop.
 
4316
         */
 
4317
        TEST_FEATURE ("with post-stopping job and a goal of stop");
 
4318
        job->goal = JOB_STOP;
 
4319
        job->state = JOB_POST_STOPPING;
 
4320
 
4206
4321
        TEST_EQ (job_next_state (job), JOB_POST_STOP);
4207
4322
 
4208
4323