~jamesodhunt/ubuntu/vivid/upstart/bug-1447756

« back to all changes in this revision

Viewing changes to init/tests/test_state.c

  • Committer: James Hunt
  • Date: 2013-08-27 09:17:21 UTC
  • mfrom: (1436.2.3)
  • mto: This revision was merged to the branch mainline in revision 1492.
  • Revision ID: james.hunt@ubuntu.com-20130827091721-w8t6f1i3lil6wrix
New upstream release (LP: #1199778, #1200264, #1201865).

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
void test_upstart_with_apparmor_upgrade (const char *path);
157
157
void test_upstart_full_serialise_without_apparmor_upgrade (const char *path);
158
158
void test_upstart_full_serialise_with_apparmor_upgrade (const char *path);
 
159
void test_reload_signal_state (const char *path);
159
160
 
160
161
ConfSource * conf_source_from_path (const char *path,
161
162
                                    ConfSourceType type,
200
201
        { "upstart-session.json", test_session_upgrade_midflight },
201
202
        { "upstart-session2.json", test_session_upgrade_exists },
202
203
        { "upstart-session-infinity.json", test_session_upgrade_stale },
 
204
        { "upstart-reload-signal.json", test_reload_signal_state },
203
205
        { NULL, NULL }
204
206
};
205
207
 
584
586
        if (obj_num_check (a, b, kill_signal))
585
587
                goto fail;
586
588
 
 
589
        if (obj_num_check (a, b, reload_signal))
 
590
                goto fail;
 
591
 
587
592
        if (obj_num_check (a, b, respawn))
588
593
                goto fail;
589
594
 
2281
2286
 
2282
2287
        class = file->job = job_class_new (NULL, "bar", NULL);
2283
2288
        TEST_NE_P (class, NULL);
 
2289
        class->reload_signal = SIGUSR1;
2284
2290
        TEST_HASH_EMPTY (job_classes);
2285
2291
        TEST_TRUE (job_class_consider (class));
2286
2292
        TEST_HASH_NOT_EMPTY (job_classes);
4422
4428
 
4423
4429
 
4424
4430
/**
 
4431
 * test_reload_signal_state:
 
4432
 *
 
4433
 * @path: full path to JSON data file to deserialise.
 
4434
 *
 
4435
 * Test that Upstart is able to deserialise the 1.9-format JSON with the
 
4436
 * addition of the reload signal stanza.
 
4437
 **/
 
4438
void
 
4439
test_reload_signal_state (const char *path)
 
4440
{
 
4441
        nih_local char   *json_string = NULL;
 
4442
        struct stat       statbuf;
 
4443
        size_t            len;
 
4444
 
 
4445
        nih_assert (path);
 
4446
 
 
4447
        conf_init ();
 
4448
        session_init ();
 
4449
        event_init ();
 
4450
        control_init ();
 
4451
        job_class_init ();
 
4452
 
 
4453
        TEST_LIST_EMPTY (sessions);
 
4454
        TEST_LIST_EMPTY (events);
 
4455
        TEST_LIST_EMPTY (conf_sources);
 
4456
        TEST_HASH_EMPTY (job_classes);
 
4457
 
 
4458
        /* Check data file exists */
 
4459
        TEST_EQ (stat (path, &statbuf), 0);
 
4460
 
 
4461
        json_string = nih_file_read (NULL, path, &len);
 
4462
        TEST_NE_P (json_string, NULL);
 
4463
 
 
4464
        /* Recreate state from JSON data file */
 
4465
        assert0 (state_from_string (json_string));
 
4466
 
 
4467
        TEST_LIST_EMPTY (sessions);
 
4468
        TEST_LIST_NOT_EMPTY (events);
 
4469
        TEST_HASH_NOT_EMPTY (job_classes);
 
4470
        TEST_LIST_NOT_EMPTY (conf_sources);
 
4471
 
 
4472
        NIH_HASH_FOREACH (job_classes, iter) {
 
4473
                JobClass *class = (JobClass *)iter;
 
4474
                if (strcmp (class->name, "whoopsie") == 0) {
 
4475
                        TEST_EQ (class->reload_signal, SIGUSR1);
 
4476
                } else
 
4477
                        TEST_EQ (class->reload_signal, SIGHUP);
 
4478
        }
 
4479
 
 
4480
        nih_free (conf_sources);
 
4481
        nih_free (job_classes);
 
4482
        nih_free (events);
 
4483
        nih_free (sessions);
 
4484
 
 
4485
        conf_sources = NULL;
 
4486
        job_classes = NULL;
 
4487
        events = NULL;
 
4488
        sessions = NULL;
 
4489
 
 
4490
        conf_init ();
 
4491
        job_class_init ();
 
4492
        event_init ();
 
4493
        session_init ();
 
4494
 
 
4495
}
 
4496
 
 
4497
/**
4425
4498
 * conf_source_from_path:
4426
4499
 *
4427
4500
 * @path: path to consider,