mirror of
https://github.com/systemd/systemd.git
synced 2025-08-04 12:22:23 +03:00
More assert macros (#35471)
This commit is contained in:
@ -29,17 +29,16 @@ TEST_RET(add_acls_for_user) {
|
||||
return log_tests_skipped_errno(r, "Could not find %s binary: %m", s);
|
||||
}
|
||||
|
||||
fd = mkostemp_safe(fn);
|
||||
assert_se(fd >= 0);
|
||||
ASSERT_OK(fd = mkostemp_safe(fn));
|
||||
|
||||
/* Use the mode that user journal files use */
|
||||
assert_se(fchmod(fd, 0640) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(fchmod(fd, 0640));
|
||||
|
||||
cmd = strjoina("ls -l ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
if (getuid() == 0 && !userns_has_single_user()) {
|
||||
const char *nobody = NOBODY_USER_NAME;
|
||||
@ -57,21 +56,19 @@ TEST_RET(add_acls_for_user) {
|
||||
assert_se(r >= 0);
|
||||
|
||||
cmd = strjoina("ls -l ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
/* set the acls again */
|
||||
|
||||
r = fd_add_uid_acl_permission(fd, uid, ACL_READ);
|
||||
assert_se(r >= 0);
|
||||
ASSERT_OK(fd_add_uid_acl_permission(fd, uid, ACL_READ));
|
||||
|
||||
cmd = strjoina("ls -l ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -89,56 +86,55 @@ TEST_RET(fd_acl_make_read_only) {
|
||||
return log_tests_skipped_errno(r, "Could not find %s binary: %m", s);
|
||||
}
|
||||
|
||||
fd = mkostemp_safe(fn);
|
||||
assert_se(fd >= 0);
|
||||
ASSERT_OK(fd = mkostemp_safe(fn));
|
||||
|
||||
/* make it more exciting */
|
||||
(void) fd_add_uid_acl_permission(fd, 1, ACL_READ|ACL_WRITE|ACL_EXECUTE);
|
||||
|
||||
ASSERT_OK_ERRNO(fstat(fd, &st));
|
||||
assert_se(FLAGS_SET(st.st_mode, 0200));
|
||||
ASSERT_TRUE(FLAGS_SET(st.st_mode, 0200));
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
cmd = strjoina("stat ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
log_info("read-only");
|
||||
assert_se(fd_acl_make_read_only(fd));
|
||||
ASSERT_OK_POSITIVE(fd_acl_make_read_only(fd));
|
||||
|
||||
ASSERT_OK_ERRNO(fstat(fd, &st));
|
||||
assert_se((st.st_mode & 0222) == 0000);
|
||||
ASSERT_EQ(st.st_mode & 0222, 0000u);
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
cmd = strjoina("stat ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
log_info("writable");
|
||||
assert_se(fd_acl_make_writable(fd));
|
||||
ASSERT_OK_POSITIVE(fd_acl_make_writable(fd));
|
||||
|
||||
ASSERT_OK_ERRNO(fstat(fd, &st));
|
||||
assert_se((st.st_mode & 0222) == 0200);
|
||||
ASSERT_EQ(st.st_mode & 0222, 0200u);
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
cmd = strjoina("stat ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
log_info("read-only");
|
||||
assert_se(fd_acl_make_read_only(fd));
|
||||
ASSERT_OK_POSITIVE(fd_acl_make_read_only(fd));
|
||||
|
||||
ASSERT_OK_ERRNO(fstat(fd, &st));
|
||||
assert_se((st.st_mode & 0222) == 0000);
|
||||
ASSERT_EQ(st.st_mode & 0222, 0000u);
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
cmd = strjoina("stat ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
ASSERT_OK_ZERO_ERRNO(system(cmd));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,26 +22,24 @@ TEST(destroy_callback) {
|
||||
int r, n_called = 0;
|
||||
|
||||
r = bus_open_system_watch_bind_with_description(&bus, "test-bus");
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to connect to bus: %m");
|
||||
return;
|
||||
}
|
||||
if (r < 0)
|
||||
return (void) log_error_errno(r, "Failed to connect to bus: %m");
|
||||
|
||||
r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.systemd.test-bus-util", 0, callback, &n_called);
|
||||
assert_se(r == 1);
|
||||
ASSERT_OK_EQ(sd_bus_request_name_async(bus, &slot, "org.freedesktop.systemd.test-bus-util", 0, callback, &n_called),
|
||||
1);
|
||||
|
||||
assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0);
|
||||
assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0);
|
||||
ASSERT_EQ(sd_bus_slot_get_destroy_callback(slot, NULL), 0);
|
||||
ASSERT_EQ(sd_bus_slot_get_destroy_callback(slot, &t), 0);
|
||||
|
||||
assert_se(sd_bus_slot_set_destroy_callback(slot, destroy_callback) == 0);
|
||||
assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 1);
|
||||
assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 1);
|
||||
ASSERT_EQ(sd_bus_slot_set_destroy_callback(slot, destroy_callback), 0);
|
||||
ASSERT_EQ(sd_bus_slot_get_destroy_callback(slot, NULL), 1);
|
||||
ASSERT_EQ(sd_bus_slot_get_destroy_callback(slot, &t), 1);
|
||||
assert_se(t == destroy_callback);
|
||||
|
||||
/* Force cleanup so we can look at n_called */
|
||||
assert_se(n_called == 0);
|
||||
ASSERT_EQ(n_called, 0);
|
||||
sd_bus_slot_unref(slot);
|
||||
assert_se(n_called == 1);
|
||||
ASSERT_EQ(n_called, 1);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -14,28 +14,28 @@
|
||||
TEST(cg_split_spec) {
|
||||
char *c, *p;
|
||||
|
||||
assert_se(cg_split_spec("foobar:/", &c, &p) == 0);
|
||||
ASSERT_OK_ZERO(cg_split_spec("foobar:/", &c, &p));
|
||||
ASSERT_STREQ(c, "foobar");
|
||||
ASSERT_STREQ(p, "/");
|
||||
c = mfree(c);
|
||||
p = mfree(p);
|
||||
|
||||
assert_se(cg_split_spec("foobar:", &c, &p) == 0);
|
||||
ASSERT_OK_ZERO(cg_split_spec("foobar:", &c, &p));
|
||||
c = mfree(c);
|
||||
p = mfree(p);
|
||||
|
||||
assert_se(cg_split_spec("foobar:asdfd", &c, &p) < 0);
|
||||
assert_se(cg_split_spec(":///", &c, &p) < 0);
|
||||
assert_se(cg_split_spec(":", &c, &p) < 0);
|
||||
assert_se(cg_split_spec("", &c, &p) < 0);
|
||||
assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0);
|
||||
ASSERT_FAIL(cg_split_spec("foobar:asdfd", &c, &p));
|
||||
ASSERT_FAIL(cg_split_spec(":///", &c, &p));
|
||||
ASSERT_FAIL(cg_split_spec(":", &c, &p));
|
||||
ASSERT_FAIL(cg_split_spec("", &c, &p));
|
||||
ASSERT_FAIL(cg_split_spec("fo/obar:/", &c, &p));
|
||||
|
||||
assert_se(cg_split_spec("/", &c, &p) >= 0);
|
||||
ASSERT_OK(cg_split_spec("/", &c, &p));
|
||||
ASSERT_NULL(c);
|
||||
ASSERT_STREQ(p, "/");
|
||||
p = mfree(p);
|
||||
|
||||
assert_se(cg_split_spec("foo", &c, &p) >= 0);
|
||||
ASSERT_OK(cg_split_spec("foo", &c, &p));
|
||||
ASSERT_STREQ(c, "foo");
|
||||
ASSERT_NULL(p);
|
||||
c = mfree(c);
|
||||
@ -49,10 +49,10 @@ TEST(cg_create) {
|
||||
log_tests_skipped("cgroupfs is not mounted");
|
||||
return;
|
||||
}
|
||||
assert_se(r >= 0);
|
||||
ASSERT_OK(r);
|
||||
|
||||
_cleanup_free_ char *here = NULL;
|
||||
assert_se(cg_pid_get_path_shifted(0, NULL, &here) >= 0);
|
||||
ASSERT_OK(cg_pid_get_path_shifted(0, NULL, &here));
|
||||
|
||||
const char *test_a = prefix_roota(here, "/test-a"),
|
||||
*test_b = prefix_roota(here, "/test-b"),
|
||||
@ -72,29 +72,29 @@ TEST(cg_create) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert_se(r == 1);
|
||||
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_a) == 0);
|
||||
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_b) == 1);
|
||||
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_c) == 1);
|
||||
assert_se(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_b, 0) == 0);
|
||||
ASSERT_OK_EQ(r, 1);
|
||||
ASSERT_OK_ZERO(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_a));
|
||||
ASSERT_OK_EQ(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_b), 1);
|
||||
ASSERT_OK_EQ(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_c), 1);
|
||||
ASSERT_OK_ZERO(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_b, 0));
|
||||
|
||||
assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path) == 0);
|
||||
ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path));
|
||||
ASSERT_STREQ(path, test_b);
|
||||
free(path);
|
||||
|
||||
assert_se(cg_attach(SYSTEMD_CGROUP_CONTROLLER, test_a, 0) == 0);
|
||||
ASSERT_OK_ZERO(cg_attach(SYSTEMD_CGROUP_CONTROLLER, test_a, 0));
|
||||
|
||||
assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path) == 0);
|
||||
assert_se(path_equal(path, test_a));
|
||||
ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path));
|
||||
ASSERT_TRUE(path_equal(path, test_a));
|
||||
free(path);
|
||||
|
||||
assert_se(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_d, 0) == 1);
|
||||
ASSERT_OK_EQ(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_d, 0), 1);
|
||||
|
||||
assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path) == 0);
|
||||
assert_se(path_equal(path, test_d));
|
||||
ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path));
|
||||
ASSERT_TRUE(path_equal(path, test_d));
|
||||
free(path);
|
||||
|
||||
assert_se(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, test_d, NULL, &path) == 0);
|
||||
ASSERT_OK_ZERO(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, test_d, NULL, &path));
|
||||
log_debug("test_d: %s", path);
|
||||
const char *full_d;
|
||||
if (cg_all_unified())
|
||||
@ -103,24 +103,24 @@ TEST(cg_create) {
|
||||
full_d = strjoina("/sys/fs/cgroup/unified", test_d);
|
||||
else
|
||||
full_d = strjoina("/sys/fs/cgroup/systemd", test_d);
|
||||
assert_se(path_equal(path, full_d));
|
||||
ASSERT_TRUE(path_equal(path, full_d));
|
||||
free(path);
|
||||
|
||||
assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, test_a) > 0);
|
||||
assert_se(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, test_b) > 0);
|
||||
assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_a) > 0);
|
||||
assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b) == 0);
|
||||
ASSERT_OK_POSITIVE(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, test_a));
|
||||
ASSERT_OK_POSITIVE(cg_is_empty(SYSTEMD_CGROUP_CONTROLLER, test_b));
|
||||
ASSERT_OK_POSITIVE(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_a));
|
||||
ASSERT_OK_ZERO(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b));
|
||||
|
||||
assert_se(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL) == 0);
|
||||
assert_se(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL) > 0);
|
||||
ASSERT_OK_ZERO(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL));
|
||||
ASSERT_OK_POSITIVE(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL));
|
||||
|
||||
assert_se(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b, SYSTEMD_CGROUP_CONTROLLER, test_a, 0) > 0);
|
||||
ASSERT_OK_POSITIVE(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b, SYSTEMD_CGROUP_CONTROLLER, test_a, 0));
|
||||
|
||||
assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_a) == 0);
|
||||
assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b) > 0);
|
||||
ASSERT_OK_ZERO(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_a));
|
||||
ASSERT_OK_POSITIVE(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, test_b));
|
||||
|
||||
assert_se(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL) > 0);
|
||||
assert_se(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL) == 0);
|
||||
ASSERT_OK_POSITIVE(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL));
|
||||
ASSERT_OK_ZERO(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL));
|
||||
|
||||
ASSERT_OK(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, true));
|
||||
}
|
||||
@ -140,15 +140,15 @@ TEST(id) {
|
||||
log_tests_skipped("cgroupfs is not mounted");
|
||||
return;
|
||||
}
|
||||
assert_se(r > 0);
|
||||
ASSERT_OK_POSITIVE(r);
|
||||
|
||||
fd = cg_path_open(SYSTEMD_CGROUP_CONTROLLER, "/");
|
||||
assert_se(fd >= 0);
|
||||
ASSERT_OK(fd);
|
||||
|
||||
assert_se(fd_get_path(fd, &p) >= 0);
|
||||
assert_se(path_equal(p, "/sys/fs/cgroup"));
|
||||
ASSERT_OK(fd_get_path(fd, &p));
|
||||
ASSERT_TRUE(path_equal(p, "/sys/fs/cgroup"));
|
||||
|
||||
assert_se(cg_fd_get_cgroupid(fd, &id) >= 0);
|
||||
ASSERT_OK(cg_fd_get_cgroupid(fd, &id));
|
||||
|
||||
fd2 = cg_cgroupid_open(fd, id);
|
||||
|
||||
@ -157,16 +157,16 @@ TEST(id) {
|
||||
else if (ERRNO_IS_NEG_NOT_SUPPORTED(fd2))
|
||||
log_notice("Skipping open-by-cgroup-id test because syscall is missing or blocked.");
|
||||
else {
|
||||
assert_se(fd2 >= 0);
|
||||
ASSERT_OK(fd2);
|
||||
|
||||
assert_se(fd_get_path(fd2, &p2) >= 0);
|
||||
assert_se(path_equal(p2, "/sys/fs/cgroup"));
|
||||
ASSERT_OK(fd_get_path(fd2, &p2));
|
||||
ASSERT_TRUE(path_equal(p2, "/sys/fs/cgroup"));
|
||||
|
||||
assert_se(cg_fd_get_cgroupid(fd2, &id2) >= 0);
|
||||
ASSERT_OK(cg_fd_get_cgroupid(fd2, &id2));
|
||||
|
||||
assert_se(id == id2);
|
||||
ASSERT_EQ(id, id2);
|
||||
|
||||
assert_se(inode_same_at(fd, NULL, fd2, NULL, AT_EMPTY_PATH) > 0);
|
||||
ASSERT_OK_EQ(inode_same_at(fd, NULL, fd2, NULL, AT_EMPTY_PATH), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user