Note that test-cgroup-mask, test-cgroup-unit-default and test-unit-name will now
report being skipped instead of reporting success if not run under systemd.
#include "tmpfile-util.h"
#include "user-util.h"
-static int test_add_acls_for_user(void) {
+TEST_RET(add_acls_for_user) {
char fn[] = "/tmp/test-empty.XXXXXX";
_cleanup_close_ int fd = -1;
char *cmd;
uid_t uid;
int r;
- log_info("/* %s */", __func__);
-
fd = mkostemp_safe(fn);
assert_se(fd >= 0);
return 0;
}
-int main(int argc, char **argv) {
- return test_add_acls_for_user();
-}
+DEFINE_TEST_MAIN(LOG_INFO);
log_info("Got mask: %s\n", g_store);
}
-static int test_cgroup_mask(void) {
+TEST_RET(cgroup_mask, .sd_booted = true) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
_cleanup_(manager_freep) Manager *m = NULL;
Unit *son, *daughter, *parent, *root, *grandchild, *parent_deep, *nomem_parent, *nomem_leaf;
assert_se(streq_ptr(b, t));
}
-static void test_cg_mask_to_string(void) {
+TEST(cg_mask_to_string) {
test_cg_mask_to_string_one(0, NULL);
test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset io blkio memory devices pids bpf-firewall bpf-devices bpf-foreign bpf-socket-bind bpf-restrict-network-interfaces");
test_cg_mask_to_string_one(CGROUP_MASK_CPU, "cpu");
test_cg_mask_to_string_one(CGROUP_MASK_IO|CGROUP_MASK_BLKIO, "io blkio");
}
-int main(int argc, char* argv[]) {
- int rc = EXIT_SUCCESS;
-
- test_setup_logging(LOG_DEBUG);
-
- test_cg_mask_to_string();
- TEST_REQ_RUNNING_SYSTEMD(rc = test_cgroup_mask());
-
- return rc;
-}
+DEFINE_TEST_MAIN(LOG_DEBUG);
#include "tests.h"
#include "unit.h"
-static int test_default_memory_low(void) {
+TEST_RET(default_memory_low, .sd_booted = true) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
_cleanup_(manager_freep) Manager *m = NULL;
Unit *root, *dml,
return 0;
}
-int main(int argc, char* argv[]) {
- int rc = EXIT_SUCCESS;
-
- test_setup_logging(LOG_DEBUG);
-
- TEST_REQ_RUNNING_SYSTEMD(rc = test_default_memory_low());
-
- return rc;
-}
+DEFINE_TEST_MAIN(LOG_DEBUG);
assert_se(streq_ptr(unit, result));
}
-static void test_path_decode_unit(void) {
+TEST(path_decode_unit) {
check_p_d_u("getty@tty2.service", 0, "getty@tty2.service");
check_p_d_u("getty@tty2.service/", 0, "getty@tty2.service");
check_p_d_u("getty@tty2.service/xxx", 0, "getty@tty2.service");
assert_se(streq_ptr(unit, result));
}
-static void test_path_get_unit(void) {
+TEST(path_get_unit) {
check_p_g_u("/system.slice/foobar.service/sdfdsaf", 0, "foobar.service");
check_p_g_u("/system.slice/getty@tty5.service", 0, "getty@tty5.service");
check_p_g_u("/system.slice/getty@tty5.service/aaa/bbb", 0, "getty@tty5.service");
assert_se(streq_ptr(unit, result));
}
-static void test_path_get_user_unit(void) {
+TEST(path_get_user_unit) {
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "foobar.service");
check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo.slice/foobar.service", 0, "foobar.service");
check_p_g_u_u("/user.slice/user-1002.slice/session-2.scope/foobar.service/waldo", 0, "foobar.service");
assert_se(streq_ptr(s, result));
}
-static void test_path_get_session(void) {
+TEST(path_get_session) {
check_p_g_s("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, "2");
check_p_g_s("/session-3.scope", 0, "3");
check_p_g_s("/session-.scope", -ENXIO, NULL);
assert_se(uid == result);
}
-static void test_path_get_owner_uid(void) {
+TEST(path_get_owner_uid) {
check_p_g_o_u("/user.slice/user-1000.slice/session-2.scope/foobar.service", 0, 1000);
check_p_g_o_u("/user.slice/user-1006.slice", 0, 1006);
check_p_g_o_u("", -ENXIO, 0);
assert_se(streq_ptr(s, result));
}
-static void test_path_get_slice(void) {
+TEST(path_get_slice) {
check_p_g_slice("/user.slice", 0, "user.slice");
check_p_g_slice("/foobar", 0, SPECIAL_ROOT_SLICE);
check_p_g_slice("/user.slice/user-waldo.slice", 0, "user-waldo.slice");
assert_se(streq_ptr(s, result));
}
-static void test_path_get_user_slice(void) {
+TEST(path_get_user_slice) {
check_p_g_u_slice("/user.slice", -ENXIO, NULL);
check_p_g_u_slice("/foobar", -ENXIO, NULL);
check_p_g_u_slice("/user.slice/user-waldo.slice", -ENXIO, NULL);
check_p_g_u_slice("/foo.slice//foo-bar.slice/user@1000.service/piep.slice//piep-pap.slice//foo.service", 0, "piep-pap.slice");
}
-static void test_get_paths(void) {
+TEST(get_paths, .sd_booted = true) {
_cleanup_free_ char *a = NULL;
assert_se(cg_get_root_path(&a) >= 0);
log_info("Root = %s", a);
}
-static void test_proc(void) {
+TEST(proc) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r;
assert_se(streq(cg_unescape(b), s));
}
-static void test_escape(void) {
+TEST(escape, .sd_booted = true) {
test_escape_one("foobar", "foobar");
test_escape_one(".foobar", "_.foobar");
test_escape_one("foobar.service", "foobar.service");
test_escape_one(".", "_.");
}
-static void test_controller_is_valid(void) {
+TEST(controller_is_valid) {
assert_se(cg_controller_is_valid("foobar"));
assert_se(cg_controller_is_valid("foo_bar"));
assert_se(cg_controller_is_valid("name=foo"));
assert_se(streq_ptr(ret, path));
}
-static void test_slice_to_path(void) {
+TEST(slice_to_path) {
test_slice_to_path_one("foobar.slice", "foobar.slice", 0);
test_slice_to_path_one("foobar-waldo.slice", "foobar.slice/foobar-waldo.slice", 0);
test_slice_to_path_one("foobar-waldo.service", NULL, -EINVAL);
assert_se(streq(s, shifted));
}
-static void test_shift_path(void) {
-
+TEST(shift_path) {
test_shift_path_one("/foobar/waldo", "/", "/foobar/waldo");
test_shift_path_one("/foobar/waldo", "", "/foobar/waldo");
test_shift_path_one("/foobar/waldo", "/foobar", "/waldo");
test_shift_path_one("/foobar/waldo", "/hogehoge", "/foobar/waldo");
}
-static void test_mask_supported(void) {
-
+TEST(mask_supported, .sd_booted = true) {
CGroupMask m;
CGroupController c;
printf("'%s' is supported: %s\n", cgroup_controller_to_string(c), yes_no(m & CGROUP_CONTROLLER_TO_MASK(c)));
}
-static void test_is_cgroup_fs(void) {
+TEST(is_cgroup_fs, .sd_booted = true) {
struct statfs sfs;
assert_se(statfs("/sys/fs/cgroup", &sfs) == 0);
if (is_temporary_fs(&sfs))
assert_se(is_cgroup_fs(&sfs));
}
-static void test_fd_is_cgroup_fs(void) {
+TEST(fd_is_cgroup_fs, .sd_booted = true) {
int fd;
fd = open("/sys/fs/cgroup", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
fd = safe_close(fd);
}
-static void test_cg_tests(void) {
+TEST(cg_tests) {
int all, hybrid, systemd, r;
r = cg_unified();
assert_se(!systemd);
}
-static void test_cg_get_keyed_attribute(void) {
+TEST(cg_get_keyed_attribute) {
_cleanup_free_ char *val = NULL;
char *vals3[3] = {}, *vals3a[3] = {};
int i, r;
}
}
-int main(void) {
- test_setup_logging(LOG_DEBUG);
-
- test_path_decode_unit();
- test_path_get_unit();
- test_path_get_user_unit();
- test_path_get_session();
- test_path_get_owner_uid();
- test_path_get_slice();
- test_path_get_user_slice();
- TEST_REQ_RUNNING_SYSTEMD(test_get_paths());
- test_proc();
- TEST_REQ_RUNNING_SYSTEMD(test_escape());
- test_controller_is_valid();
- test_slice_to_path();
- test_shift_path();
- TEST_REQ_RUNNING_SYSTEMD(test_mask_supported());
- TEST_REQ_RUNNING_SYSTEMD(test_is_cgroup_fs());
- TEST_REQ_RUNNING_SYSTEMD(test_fd_is_cgroup_fs());
- test_cg_tests();
- test_cg_get_keyed_attribute();
-
- return 0;
-}
+DEFINE_TEST_MAIN(LOG_DEBUG);
/* Nontrivial value serves as a placeholder to check that parsing function (didn't) change it */
#define CGROUP_LIMIT_DUMMY 3
-static int test_unit_file_get_set(void) {
+TEST_RET(unit_file_get_set) {
int r;
Hashmap *h;
UnitFileList *p;
assert_se(!!(c->flags & EXEC_COMMAND_IGNORE_FAILURE) == ignore);
}
-static void test_config_parse_exec(void) {
+TEST(config_parse_exec) {
/* int config_parse_exec(
const char *unit,
const char *filename,
exec_command_free_list(c);
}
-static void test_config_parse_log_extra_fields(void) {
+TEST(config_parse_log_extra_fields) {
/* int config_parse_log_extra_fields(
const char *unit,
const char *filename,
log_info("/* %s – bye */", __func__);
}
-static void test_install_printf(void) {
+TEST(install_printf, .sd_booted = true) {
char name[] = "name.service",
path[] = "/run/systemd/system/name.service";
UnitFileInstallInfo i = { .name = name, .path = path, };
return ((uint64_t) 1ULL << (uint64_t) cap);
}
-static void test_config_parse_capability_set(void) {
+TEST(config_parse_capability_set) {
/* int config_parse_capability_set(
const char *unit,
const char *filename,
assert_se(capability_bounding_set == (make_cap(CAP_NET_RAW) | make_cap(CAP_NET_ADMIN)));
}
-static void test_config_parse_rlimit(void) {
+TEST(config_parse_rlimit) {
struct rlimit * rl[_RLIMIT_MAX] = {};
assert_se(config_parse_rlimit(NULL, "fake", 1, "section", 1, "LimitNOFILE", RLIMIT_NOFILE, "55", rl, NULL) >= 0);
rl[RLIMIT_RTTIME] = mfree(rl[RLIMIT_RTTIME]);
}
-static void test_config_parse_pass_environ(void) {
+TEST(config_parse_pass_environ) {
/* int config_parse_pass_environ(
const char *unit,
const char *filename,
assert_se(streq(passenv[0], "normal_name"));
}
-static void test_unit_dump_config_items(void) {
+TEST(unit_dump_config_items) {
unit_dump_config_items(stdout);
}
-static void test_config_parse_memory_limit(void) {
+TEST(config_parse_memory_limit) {
/* int config_parse_memory_limit(
const char *unit,
const char *filename,
}
-static void test_contains_instance_specifier_superset(void) {
+TEST(contains_instance_specifier_superset) {
assert_se(contains_instance_specifier_superset("foobar@a%i"));
assert_se(contains_instance_specifier_superset("foobar@%ia"));
assert_se(contains_instance_specifier_superset("foobar@%n"));
assert_se(!contains_instance_specifier_superset("@%a%b"));
}
-static void test_unit_is_recursive_template_dependency(void) {
+TEST(unit_is_recursive_template_dependency) {
_cleanup_(manager_freep) Manager *m = NULL;
Unit *u;
int r;
assert_se(unit_is_likely_recursive_template_dependency(u, "foobar@foobar@123.mount", "foobar@%n.mount") == 0);
}
-int main(int argc, char *argv[]) {
- _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
- int r;
-
- test_setup_logging(LOG_INFO);
+DEFINE_CUSTOM_TEST_MAIN(
+ LOG_INFO,
- r = enter_cgroup_subroot(NULL);
- if (r == -ENOMEDIUM)
- return log_tests_skipped("cgroupfs not available");
-
- assert_se(runtime_dir = setup_fake_runtime_dir());
+ _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
+ ({
+ if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
- r = test_unit_file_get_set();
- test_config_parse_exec();
- test_config_parse_log_extra_fields();
- test_config_parse_capability_set();
- test_config_parse_rlimit();
- test_config_parse_pass_environ();
- TEST_REQ_RUNNING_SYSTEMD(test_install_printf());
- test_unit_dump_config_items();
- test_config_parse_memory_limit();
- test_contains_instance_specifier_superset();
- test_unit_is_recursive_template_dependency();
+ assert_se(runtime_dir = setup_fake_runtime_dir());
+ }),
- return r;
-}
+ /* no outro */);
#include "tests.h"
#include "util.h"
-static void test_parse_sleep_config(void) {
+TEST(parse_sleep_config) {
_cleanup_(free_sleep_configp) SleepConfig *sleep_config = NULL;
- log_info("/* %s */", __func__);
assert_se(parse_sleep_config(&sleep_config) == 0);
log_debug(" states: %s", hys);
}
-static int test_fiemap(const char *path) {
+static int test_fiemap_one(const char *path) {
_cleanup_free_ struct fiemap *fiemap = NULL;
_cleanup_close_ int fd = -1;
int r;
return 0;
}
-static void test_sleep(void) {
+TEST_RET(fiemap) {
+ int r = 0;
+
+ assert_se(test_fiemap_one(saved_argv[0]) == 0);
+ for (int i = 1; i < saved_argc; i++) {
+ int k = test_fiemap_one(saved_argv[i]);
+ if (r == 0)
+ r = k;
+ }
+
+ return r;
+}
+
+TEST(sleep) {
_cleanup_strv_free_ char
**standby = strv_new("standby"),
**mem = strv_new("mem"),
**freeze = strv_new("freeze");
int r;
- log_info("/* %s */", __func__);
-
printf("Secure boot: %sd\n", enable_disable(is_efi_secure_boot()));
log_info("/= individual sleep modes =/");
log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
}
-int main(int argc, char* argv[]) {
- int i, r = 0, k;
-
- test_setup_logging(LOG_DEBUG);
-
- if (getuid() != 0)
- log_warning("This program is unlikely to work for unprivileged users");
-
- test_parse_sleep_config();
- test_sleep();
-
- if (argc <= 1)
- assert_se(test_fiemap(argv[0]) == 0);
- else
- for (i = 1; i < argc; i++) {
- k = test_fiemap(argv[i]);
- if (r == 0)
- r = k;
- }
-
- return r;
-}
+DEFINE_CUSTOM_TEST_MAIN(
+ LOG_DEBUG,
+ ({
+ if (getuid() != 0)
+ log_warning("This program is unlikely to work for unprivileged users");
+ }),
+ /* no outro */);
assert_se(unit_name_is_valid(name, flags) == expected);
}
-static void test_unit_name_is_valid(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_is_valid) {
test_unit_name_is_valid_one("foo.service", UNIT_NAME_ANY, true);
test_unit_name_is_valid_one("foo.service", UNIT_NAME_PLAIN, true);
test_unit_name_is_valid_one("foo.service", UNIT_NAME_INSTANCE, false);
assert_se(streq_ptr(t, expected));
}
-static void test_unit_name_replace_instance(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_replace_instance) {
test_unit_name_replace_instance_one("foo@.service", "waldo", "foo@waldo.service", 0);
test_unit_name_replace_instance_one("foo@xyz.service", "waldo", "foo@waldo.service", 0);
test_unit_name_replace_instance_one("xyz", "waldo", NULL, -EINVAL);
}
}
-static void test_unit_name_from_path(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_from_path) {
test_unit_name_from_path_one("/waldo", ".mount", "waldo.mount", 0);
test_unit_name_from_path_one("/waldo/quuix", ".mount", "waldo-quuix.mount", 0);
test_unit_name_from_path_one("/waldo/quuix/", ".mount", "waldo-quuix.mount", 0);
}
}
-static void test_unit_name_from_path_instance(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_from_path_instance) {
test_unit_name_from_path_instance_one("waldo", "/waldo", ".mount", "waldo@waldo.mount", 0);
test_unit_name_from_path_instance_one("waldo", "/waldo////quuix////", ".mount", "waldo@waldo-quuix.mount", 0);
test_unit_name_from_path_instance_one("waldo", "/", ".mount", "waldo@-.mount", 0);
assert_se(streq_ptr(path, p));
}
-static void test_unit_name_to_path(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_to_path) {
test_unit_name_to_path_one("home.mount", "/home", 0);
test_unit_name_to_path_one("home-lennart.mount", "/home/lennart", 0);
test_unit_name_to_path_one("home-lennart-.mount", NULL, -EINVAL);
}
}
-static void test_unit_name_mangle(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_mangle) {
test_unit_name_mangle_one(false, "foo.service", "foo.service", 0);
test_unit_name_mangle_one(false, "/home", "home.mount", 1);
test_unit_name_mangle_one(false, "/dev/sda", "dev-sda.device", 1);
test_unit_name_mangle_one(true, "ü*", "\\xc3\\xbc*", 1);
}
-static int test_unit_printf(void) {
+TEST_RET(unit_printf, .sd_booted = true) {
_cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *gid = NULL, *group = NULL, *uid = NULL, *user = NULL, *shell = NULL, *home = NULL;
_cleanup_(manager_freep) Manager *m = NULL;
Unit *u;
int r;
- log_info("/* %s */", __func__);
-
assert_se(specifier_machine_id('m', NULL, NULL, NULL, &mid) >= 0 && mid);
assert_se(specifier_boot_id('b', NULL, NULL, NULL, &bid) >= 0 && bid);
assert_se(host = gethostname_malloc());
return 0;
}
-static void test_unit_instance_is_valid(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_instance_is_valid) {
assert_se(unit_instance_is_valid("fooBar"));
assert_se(unit_instance_is_valid("foo-bar"));
assert_se(unit_instance_is_valid("foo.stUff"));
assert_se(!unit_instance_is_valid("foo/bar"));
}
-static void test_unit_prefix_is_valid(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_prefix_is_valid) {
assert_se(unit_prefix_is_valid("fooBar"));
assert_se(unit_prefix_is_valid("foo-bar"));
assert_se(unit_prefix_is_valid("foo.stUff"));
assert_se(!unit_prefix_is_valid("@foo-bar"));
}
-static void test_unit_name_change_suffix(void) {
+TEST(unit_name_change_suffix) {
char *t;
- log_info("/* %s */", __func__);
-
assert_se(unit_name_change_suffix("foo.mount", ".service", &t) == 0);
assert_se(streq(t, "foo.service"));
free(t);
free(t);
}
-static void test_unit_name_build(void) {
+TEST(unit_name_build) {
char *t;
- log_info("/* %s */", __func__);
-
assert_se(unit_name_build("foo", "bar", ".service", &t) == 0);
assert_se(streq(t, "foo@bar.service"));
free(t);
free(t);
}
-static void test_slice_name_is_valid(void) {
- log_info("/* %s */", __func__);
-
+TEST(slice_name_is_valid) {
assert_se( slice_name_is_valid(SPECIAL_ROOT_SLICE));
assert_se( slice_name_is_valid("foo.slice"));
assert_se( slice_name_is_valid("foo-bar.slice"));
assert_se(!slice_name_is_valid("foo@bar.service"));
}
-static void test_build_subslice(void) {
+TEST(build_subslice) {
char *a;
char *b;
- log_info("/* %s */", __func__);
-
assert_se(slice_build_subslice(SPECIAL_ROOT_SLICE, "foo", &a) >= 0);
assert_se(slice_build_subslice(a, "bar", &b) >= 0);
free(a);
assert_se(streq_ptr(s, expect));
}
-static void test_build_parent_slice(void) {
- log_info("/* %s */", __func__);
-
+TEST(build_parent_slice) {
test_build_parent_slice_one(SPECIAL_ROOT_SLICE, NULL, 0);
test_build_parent_slice_one("foo.slice", SPECIAL_ROOT_SLICE, 1);
test_build_parent_slice_one("foo-bar.slice", "foo.slice", 1);
test_build_parent_slice_one("@.slice", NULL, -EINVAL);
}
-static void test_unit_name_to_instance(void) {
+TEST(unit_name_to_instance) {
UnitNameFlags r;
char *instance;
- log_info("/* %s */", __func__);
-
r = unit_name_to_instance("foo@bar.service", &instance);
assert_se(r == UNIT_NAME_INSTANCE);
assert_se(streq(instance, "bar"));
assert_se(!instance);
}
-static void test_unit_name_escape(void) {
+TEST(unit_name_escape) {
_cleanup_free_ char *r;
- log_info("/* %s */", __func__);
-
r = unit_name_escape("ab+-c.a/bc@foo.service");
assert_se(r);
assert_se(streq(r, "ab\\x2b\\x2dc.a-bc\\x40foo.service"));
assert_se(streq_ptr(f, expected));
}
-static void test_unit_name_template(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_template) {
test_u_n_t_one("foo@bar.service", "foo@.service", 0);
test_u_n_t_one("foo.mount", NULL, -EINVAL);
}
assert_se(streq_ptr(path, p));
}
-static void test_unit_name_path_unescape(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_path_unescape) {
test_unit_name_path_unescape_one("foo", "/foo", 0);
test_unit_name_path_unescape_one("foo-bar", "/foo/bar", 0);
test_unit_name_path_unescape_one("foo-.bar", "/foo/.bar", 0);
assert_se(streq_ptr(k, output));
}
-static void test_unit_name_to_prefix(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_to_prefix) {
test_unit_name_to_prefix_one("foobar.service", 0, "foobar");
test_unit_name_to_prefix_one("", -EINVAL, NULL);
test_unit_name_to_prefix_one("foobar", -EINVAL, NULL);
assert_se(streq_ptr(k, output));
}
-static void test_unit_name_from_dbus_path(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_from_dbus_path) {
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/dbus_2esocket", 0, "dbus.socket");
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/_2d_2emount", 0, "-.mount");
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/_2d_2eslice", 0, "-.slice");
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/wpa_5fsupplicant_2eservice", 0, "wpa_supplicant.service");
}
-static void test_unit_name_prefix_equal(void) {
- log_info("/* %s */", __func__);
-
+TEST(unit_name_prefix_equal) {
assert_se(unit_name_prefix_equal("a.service", "a.service"));
assert_se(unit_name_prefix_equal("a.service", "a.mount"));
assert_se(unit_name_prefix_equal("a@b.service", "a.service"));
assert_se(!unit_name_prefix_equal("a", "a"));
}
-int main(int argc, char* argv[]) {
+DEFINE_CUSTOM_TEST_MAIN(
+ LOG_INFO,
+
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
- int r, rc = 0;
-
- test_setup_logging(LOG_INFO);
-
- r = enter_cgroup_subroot(NULL);
- if (r == -ENOMEDIUM)
- return log_tests_skipped("cgroupfs not available");
-
- assert_se(runtime_dir = setup_fake_runtime_dir());
-
- test_unit_name_is_valid();
- test_unit_name_replace_instance();
- test_unit_name_from_path();
- test_unit_name_from_path_instance();
- test_unit_name_mangle();
- test_unit_name_to_path();
- TEST_REQ_RUNNING_SYSTEMD(rc = test_unit_printf());
- test_unit_instance_is_valid();
- test_unit_prefix_is_valid();
- test_unit_name_change_suffix();
- test_unit_name_build();
- test_slice_name_is_valid();
- test_build_subslice();
- test_build_parent_slice();
- test_unit_name_to_instance();
- test_unit_name_escape();
- test_unit_name_template();
- test_unit_name_path_unescape();
- test_unit_name_to_prefix();
- test_unit_name_from_dbus_path();
- test_unit_name_prefix_equal();
-
- return rc;
-}
+ ({
+ if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
+
+ assert_se(runtime_dir = setup_fake_runtime_dir());
+ }),
+
+ /* no outro */);
* always rejected with "Current command vanished from the unit file", and we don't leak anything. */
}
-static void test_deserialize_exec_command(void) {
+TEST(deserialize_exec_command) {
_cleanup_(manager_freep) Manager *m = NULL;
int r;
- log_info("/* %s */", __func__);
-
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
if (manager_errno_skip_test(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");
test_deserialize_exec_command_one(m, "control-command", "ExecWhat 11 /a/b c d e", -EINVAL);
}
-int main(int argc, char *argv[]) {
- _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
- int r;
-
- test_setup_logging(LOG_DEBUG);
+DEFINE_CUSTOM_TEST_MAIN(
+ LOG_DEBUG,
- r = enter_cgroup_subroot(NULL);
- if (r == -ENOMEDIUM)
- return log_tests_skipped("cgroupfs not available");
-
- assert_se(runtime_dir = setup_fake_runtime_dir());
+ _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
+ ({
+ if (enter_cgroup_subroot(NULL) == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
- test_deserialize_exec_command();
+ assert_se(runtime_dir = setup_fake_runtime_dir());
+ }),
- return EXIT_SUCCESS;
-}
+ /* no outro */);