165
165
void test_upstart_full_serialise_with_apparmor_upgrade (const char *path);
166
166
void test_reload_signal_state (const char *path);
167
167
void test_job_environ_upgrade (const char *path);
169
#ifdef ENABLE_CGROUPS
170
void test_cgroup_state (const char *path);
171
#endif /* ENABLE_CGROUPS */
168
void test_cgroup_and_process_data_state (const char *path);
173
170
ConfSource * conf_source_from_path (const char *path,
174
171
ConfSourceType type,
215
212
{ "upstart-session-infinity.json", test_session_upgrade_stale },
216
213
{ "upstart-1.9.json", test_reload_signal_state },
217
214
{ "upstart-1.11.json", test_job_environ_upgrade },
219
#ifdef ENABLE_CGROUPS
220
{ "upstart-1.13.json", test_cgroup_state },
221
#endif /* ENABLE_CGROUPS */
215
{ "upstart-1.13.json", test_cgroup_and_process_data_state },
4567
4561
session_init ();
4570
#ifdef ENABLE_CGROUPS
4573
* test_cgroup_state:
4565
* test_cgroup_and_process_data_state:
4575
4567
* @path: full path to JSON data file to deserialise.
4577
* Test that Upstart can deserialise both cgroup stanzas and the cgroup
4569
* Test that Upstart can deserialise:
4571
* - cgroup stanzas (if cgroups enabled).
4572
* - the cgroup manager address (if cgroups enabled).
4573
* - JobProcessData encoded as "process_data" in JSON.
4581
test_cgroup_state (const char *path)
4576
test_cgroup_and_process_data_state (const char *path)
4578
#ifdef ENABLE_CGROUPS
4583
4579
nih_local char *cgroup_address = NULL;
4584
4580
const char *address;
4581
json_object *json_value = NULL;
4582
#endif /* ENABLE_CGROUPS */
4585
4584
nih_local char *json_string = NULL;
4585
nih_local char *processed_json_string = NULL;
4586
4586
json_object *json = NULL;
4587
json_object *json_value = NULL;
4588
4587
struct stat statbuf;
4589
int fds[2] = { -1, -1 };
4590
nih_local char *read_fd_str = NULL;
4591
4592
nih_assert (path);
4601
4602
TEST_LIST_EMPTY (conf_sources);
4602
4603
TEST_HASH_EMPTY (job_classes);
4605
#ifdef ENABLE_CGROUPS
4604
4606
cgroup_manager_address = NULL;
4607
#endif /* ENABLE_CGROUPS */
4606
4609
/* Check data file exists */
4607
4610
TEST_EQ (stat (path, &statbuf), 0);
4609
4612
json_string = nih_file_read (NULL, path, &len);
4610
4613
TEST_NE_P (json_string, NULL);
4615
/* The JSON contains a "process_data" object that represents a
4616
* JobProcessData object denoting a job process whose child
4617
* setup phase is still "in-flight" (ongoing).
4619
* The problem is that when the JobProcessData object is
4620
* reconstructed, Upstart will attempt to operate on the
4621
* job_process_fd file descriptor so that fd must be valid at
4622
* the time the test is run.
4624
* The solution is to create a valid fd and rewrite the JSON to
4625
* specify that valid fd.
4627
assert0 (pipe (fds));
4629
read_fd_str = nih_sprintf (NULL, "%d", fds[0]);
4630
TEST_NE_P (read_fd_str, NULL);
4632
/* Replace @CHROOT_PATH@ with our temporary path */
4633
processed_json_string = search_and_replace (NULL, json_string,
4636
TEST_NE_P (processed_json_string, NULL);
4612
4638
/* Read the json, checking for expected content */
4613
json = json_object_from_file (path);
4639
json = json_tokener_parse (processed_json_string);
4614
4640
TEST_NE_P (json, NULL);
4642
#ifdef ENABLE_CGROUPS
4616
4643
/* Ensure it's there */
4617
4644
TEST_TRUE (json_object_object_get_ex (json, "cgroup_manager_address", &json_value));
4623
4650
/* free the JSON */
4624
4651
json_object_put (json);
4652
#endif /* ENABLE_CGROUPS */
4626
4654
/* Recreate state from JSON data file */
4627
assert0 (state_from_string (json_string));
4655
assert0 (state_from_string (processed_json_string));
4657
#ifdef ENABLE_CGROUPS
4629
4658
TEST_NE_P (cgroup_manager_address, NULL);
4630
4659
TEST_EQ_STR (cgroup_manager_address, cgroup_address);
4660
#endif /* ENABLE_CGROUPS */
4632
4662
TEST_LIST_EMPTY (sessions);
4633
4663
TEST_LIST_NOT_EMPTY (events);