summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-16 18:25:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-16 18:25:59 +0000
commit1e34d75027c0773e21b35688c27034d5af5e635c (patch)
tree7f3e33142d7a4d06037846454f08b1b0350b2a95 /src/test
parentAdding upstream version 256.4. (diff)
downloadsystemd-1e34d75027c0773e21b35688c27034d5af5e635c.tar.xz
systemd-1e34d75027c0773e21b35688c27034d5af5e635c.zip
Adding upstream version 256.5.upstream/256.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-conf-parser.c8
-rw-r--r--src/test/test-fs-util.c76
-rw-r--r--src/test/test-id128.c332
-rw-r--r--src/test/test-log.c14
-rw-r--r--src/test/test-macro.c15
5 files changed, 229 insertions, 216 deletions
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c
index 4e236bd..5643053 100644
--- a/src/test/test-conf-parser.c
+++ b/src/test/test-conf-parser.c
@@ -7,6 +7,7 @@
#include "log.h"
#include "macro.h"
#include "mkdir.h"
+#include "rm-rf.h"
#include "string-util.h"
#include "strv.h"
#include "tests.h"
@@ -393,19 +394,16 @@ TEST(config_parse) {
}
TEST(config_parse_standard_file_with_dropins_full) {
- _cleanup_(rmdir_and_freep) char *root = NULL;
+ _cleanup_(rm_rf_physical_and_freep) char *root = NULL;
_cleanup_close_ int rfd = -EBADF;
int r;
- assert_se(mkdtemp_malloc(NULL, &root) >= 0);
+ ASSERT_OK(rfd = mkdtemp_open("/tmp/test-config-parse-XXXXXX", 0, &root));
assert_se(mkdir_p_root(root, "/etc/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
assert_se(mkdir_p_root(root, "/run/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
assert_se(mkdir_p_root(root, "/usr/lib/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
assert_se(mkdir_p_root(root, "/usr/local/lib/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
- rfd = open(root, O_CLOEXEC|O_DIRECTORY);
- assert_se(rfd >= 0);
-
assert_se(write_string_file_at(rfd, "usr/lib/kernel/install.conf", /* this one is ignored */
"A=!!!", WRITE_STRING_FILE_CREATE) == 0);
assert_se(write_string_file_at(rfd, "usr/local/lib/kernel/install.conf",
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index d44e043..f2fa51f 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -606,71 +606,67 @@ TEST(open_mkdir_at) {
}
TEST(openat_report_new) {
- _cleanup_free_ char *j = NULL;
- _cleanup_(rm_rf_physical_and_freep) char *d = NULL;
- _cleanup_close_ int fd = -EBADF;
+ _cleanup_(rm_rf_physical_and_freep) char *t = NULL;
+ _cleanup_close_ int tfd = -EBADF, fd = -EBADF;
bool b;
- assert_se(mkdtemp_malloc(NULL, &d) >= 0);
-
- j = path_join(d, "test");
- assert_se(j);
+ ASSERT_OK((tfd = mkdtemp_open(NULL, 0, &t)));
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(b);
+ ASSERT_TRUE(b);
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(!b);
+ ASSERT_FALSE(b);
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(!b);
+ ASSERT_FALSE(b);
- assert_se(unlink(j) >= 0);
+ ASSERT_OK_ERRNO(unlinkat(tfd, "test", 0));
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(b);
+ ASSERT_TRUE(b);
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(!b);
+ ASSERT_FALSE(b);
- assert_se(unlink(j) >= 0);
+ ASSERT_OK_ERRNO(unlinkat(tfd, "test", 0));
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT, 0666, NULL);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, NULL);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(!b);
+ ASSERT_FALSE(b);
- fd = openat_report_new(AT_FDCWD, j, O_RDWR, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(!b);
+ ASSERT_FALSE(b);
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT|O_EXCL, 0666, &b);
- assert_se(fd == -EEXIST);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT|O_EXCL, 0666, &b);
+ ASSERT_ERROR(fd, EEXIST);
- assert_se(unlink(j) >= 0);
+ ASSERT_OK_ERRNO(unlinkat(tfd, "test", 0));
- fd = openat_report_new(AT_FDCWD, j, O_RDWR, 0666, &b);
- assert_se(fd == -ENOENT);
+ fd = openat_report_new(tfd, "test", O_RDWR, 0666, &b);
+ ASSERT_ERROR(fd, ENOENT);
- fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT|O_EXCL, 0666, &b);
- assert_se(fd >= 0);
+ fd = openat_report_new(tfd, "test", O_RDWR|O_CREAT|O_EXCL, 0666, &b);
+ ASSERT_OK(fd);
fd = safe_close(fd);
- assert_se(b);
+ ASSERT_TRUE(b);
}
TEST(xopenat_full) {
diff --git a/src/test/test-id128.c b/src/test/test-id128.c
index 48fdbba..a6ed640 100644
--- a/src/test/test-id128.c
+++ b/src/test/test-id128.c
@@ -28,31 +28,31 @@ TEST(id128) {
_cleanup_free_ char *b = NULL;
_cleanup_close_ int fd = -EBADF;
- assert_se(sd_id128_randomize(&id) == 0);
+ ASSERT_OK(sd_id128_randomize(&id));
printf("random: %s\n", sd_id128_to_string(id, t));
- assert_se(sd_id128_from_string(t, &id2) == 0);
- assert_se(sd_id128_equal(id, id2));
- assert_se(sd_id128_in_set(id, id));
- assert_se(sd_id128_in_set(id, id2));
- assert_se(sd_id128_in_set(id, id2, id));
- assert_se(sd_id128_in_set(id, ID128_WALDI, id));
- assert_se(!sd_id128_in_set(id));
- assert_se(!sd_id128_in_set(id, ID128_WALDI));
- assert_se(!sd_id128_in_set(id, ID128_WALDI, ID128_WALDI));
+ ASSERT_OK(sd_id128_from_string(t, &id2) == 0);
+ ASSERT_EQ_ID128(id, id2);
+ ASSERT_TRUE(sd_id128_in_set(id, id));
+ ASSERT_TRUE(sd_id128_in_set(id, id2));
+ ASSERT_TRUE(sd_id128_in_set(id, id2, id));
+ ASSERT_TRUE(sd_id128_in_set(id, ID128_WALDI, id));
+ ASSERT_FALSE(sd_id128_in_set(id));
+ ASSERT_FALSE(sd_id128_in_set(id, ID128_WALDI));
+ ASSERT_FALSE(sd_id128_in_set(id, ID128_WALDI, ID128_WALDI));
if (sd_booted() > 0 && sd_id128_get_machine(NULL) >= 0) {
- assert_se(sd_id128_get_machine(&id) == 0);
+ ASSERT_OK(sd_id128_get_machine(&id));
printf("machine: %s\n", sd_id128_to_string(id, t));
- assert_se(sd_id128_get_boot(&id) == 0);
+ ASSERT_OK(sd_id128_get_boot(&id));
printf("boot: %s\n", sd_id128_to_string(id, t));
}
printf("waldi: %s\n", sd_id128_to_string(ID128_WALDI, t));
ASSERT_STREQ(t, STR_WALDI);
- assert_se(asprintf(&b, SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)) == 32);
+ ASSERT_EQ(asprintf(&b, SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)), 32);
printf("waldi2: %s\n", b);
ASSERT_STREQ(t, b);
@@ -60,137 +60,137 @@ TEST(id128) {
ASSERT_STREQ(q, UUID_WALDI);
b = mfree(b);
- assert_se(asprintf(&b, SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)) == 36);
+ ASSERT_EQ(asprintf(&b, SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)), 36);
printf("waldi4: %s\n", b);
ASSERT_STREQ(q, b);
- assert_se(sd_id128_from_string(STR_WALDI, &id) >= 0);
- assert_se(sd_id128_equal(id, ID128_WALDI));
-
- assert_se(sd_id128_from_string(UUID_WALDI, &id) >= 0);
- assert_se(sd_id128_equal(id, ID128_WALDI));
-
- assert_se(sd_id128_from_string("", &id) < 0);
- assert_se(sd_id128_from_string("01020304-0506-0708-090a-0b0c0d0e0f101", &id) < 0);
- assert_se(sd_id128_from_string("01020304-0506-0708-090a-0b0c0d0e0f10-", &id) < 0);
- assert_se(sd_id128_from_string("01020304-0506-0708-090a0b0c0d0e0f10", &id) < 0);
- assert_se(sd_id128_from_string("010203040506-0708-090a-0b0c0d0e0f10", &id) < 0);
-
- assert_se(id128_from_string_nonzero(STR_WALDI, &id) == 0);
- assert_se(id128_from_string_nonzero(STR_NULL, &id) == -ENXIO);
- assert_se(id128_from_string_nonzero("01020304-0506-0708-090a-0b0c0d0e0f101", &id) < 0);
- assert_se(id128_from_string_nonzero("01020304-0506-0708-090a-0b0c0d0e0f10-", &id) < 0);
- assert_se(id128_from_string_nonzero("01020304-0506-0708-090a0b0c0d0e0f10", &id) < 0);
- assert_se(id128_from_string_nonzero("010203040506-0708-090a-0b0c0d0e0f10", &id) < 0);
-
- assert_se(id128_is_valid(STR_WALDI));
- assert_se(id128_is_valid(UUID_WALDI));
- assert_se(!id128_is_valid(""));
- assert_se(!id128_is_valid("01020304-0506-0708-090a-0b0c0d0e0f101"));
- assert_se(!id128_is_valid("01020304-0506-0708-090a-0b0c0d0e0f10-"));
- assert_se(!id128_is_valid("01020304-0506-0708-090a0b0c0d0e0f10"));
- assert_se(!id128_is_valid("010203040506-0708-090a-0b0c0d0e0f10"));
+ ASSERT_OK(sd_id128_from_string(STR_WALDI, &id));
+ ASSERT_EQ_ID128(id, ID128_WALDI);
+
+ ASSERT_OK(sd_id128_from_string(UUID_WALDI, &id));
+ ASSERT_EQ_ID128(id, ID128_WALDI);
+
+ ASSERT_FAIL(sd_id128_from_string("", &id));
+ ASSERT_FAIL(sd_id128_from_string("01020304-0506-0708-090a-0b0c0d0e0f101", &id));
+ ASSERT_FAIL(sd_id128_from_string("01020304-0506-0708-090a-0b0c0d0e0f10-", &id));
+ ASSERT_FAIL(sd_id128_from_string("01020304-0506-0708-090a0b0c0d0e0f10", &id));
+ ASSERT_FAIL(sd_id128_from_string("010203040506-0708-090a-0b0c0d0e0f10", &id));
+
+ ASSERT_OK(id128_from_string_nonzero(STR_WALDI, &id));
+ ASSERT_ERROR(id128_from_string_nonzero(STR_NULL, &id), ENXIO);
+ ASSERT_FAIL(id128_from_string_nonzero("01020304-0506-0708-090a-0b0c0d0e0f101", &id));
+ ASSERT_FAIL(id128_from_string_nonzero("01020304-0506-0708-090a-0b0c0d0e0f10-", &id));
+ ASSERT_FAIL(id128_from_string_nonzero("01020304-0506-0708-090a0b0c0d0e0f10", &id));
+ ASSERT_FAIL(id128_from_string_nonzero("010203040506-0708-090a-0b0c0d0e0f10", &id));
+
+ ASSERT_TRUE(id128_is_valid(STR_WALDI));
+ ASSERT_TRUE(id128_is_valid(UUID_WALDI));
+ ASSERT_FALSE(id128_is_valid(""));
+ ASSERT_FALSE(id128_is_valid("01020304-0506-0708-090a-0b0c0d0e0f101"));
+ ASSERT_FALSE(id128_is_valid("01020304-0506-0708-090a-0b0c0d0e0f10-"));
+ ASSERT_FALSE(id128_is_valid("01020304-0506-0708-090a0b0c0d0e0f10"));
+ ASSERT_FALSE(id128_is_valid("010203040506-0708-090a-0b0c0d0e0f10"));
fd = open_tmpfile_unlinkable(NULL, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
+ ASSERT_OK(fd);
/* First, write as UUID */
- assert_se(sd_id128_randomize(&id) >= 0);
- assert_se(id128_write_fd(fd, ID128_FORMAT_UUID, id) >= 0);
+ ASSERT_OK(sd_id128_randomize(&id));
+ ASSERT_OK(id128_write_fd(fd, ID128_FORMAT_UUID, id));
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2) == -EUCLEAN);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2), EUCLEAN);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_UUID, &id2) >= 0);
- assert_se(sd_id128_equal(id, id2));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_UUID, &id2));
+ ASSERT_EQ_ID128(id, id2);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, &id2) >= 0);
- assert_se(sd_id128_equal(id, id2));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_ANY, &id2));
+ ASSERT_EQ_ID128(id, id2);
/* Second, write as plain */
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK_ERRNO(ftruncate(fd, 0));
- assert_se(sd_id128_randomize(&id) >= 0);
- assert_se(id128_write_fd(fd, ID128_FORMAT_PLAIN, id) >= 0);
+ ASSERT_OK(sd_id128_randomize(&id));
+ ASSERT_OK(id128_write_fd(fd, ID128_FORMAT_PLAIN, id));
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_UUID, &id2) == -EUCLEAN);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET) == 0);
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_UUID, &id2), EUCLEAN);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2) >= 0);
- assert_se(sd_id128_equal(id, id2));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2));
+ ASSERT_EQ_ID128(id, id2);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, &id2) >= 0);
- assert_se(sd_id128_equal(id, id2));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_ANY, &id2));
+ ASSERT_EQ_ID128(id, id2);
/* Third, write plain without trailing newline */
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK_ERRNO(ftruncate(fd, 0));
- assert_se(sd_id128_randomize(&id) >= 0);
- assert_se(write(fd, sd_id128_to_string(id, t), 32) == 32);
+ ASSERT_OK(sd_id128_randomize(&id));
+ ASSERT_EQ(write(fd, sd_id128_to_string(id, t), 32), 32);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_UUID, &id2) == -EUCLEAN);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_UUID, &id2), EUCLEAN);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2) >= 0);
- assert_se(sd_id128_equal(id, id2));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2));
+ ASSERT_EQ_ID128(id, id2);
/* Fourth, write UUID without trailing newline */
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK_ERRNO(ftruncate(fd, 0));
- assert_se(sd_id128_randomize(&id) >= 0);
- assert_se(write(fd, sd_id128_to_uuid_string(id, q), 36) == 36);
+ ASSERT_OK(sd_id128_randomize(&id));
+ ASSERT_EQ(write(fd, sd_id128_to_uuid_string(id, q), 36), 36);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2) == -EUCLEAN);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_PLAIN, &id2), EUCLEAN);
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_UUID, &id2) >= 0);
- assert_se(sd_id128_equal(id, id2));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_UUID, &id2));
+ ASSERT_EQ_ID128(id, id2);
/* Fifth, tests for "uninitialized" */
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
- assert_se(write(fd, "uninitialized", STRLEN("uninitialized")) == STRLEN("uninitialized"));
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -ENOPKG);
-
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
- assert_se(write(fd, "uninitialized\n", STRLEN("uninitialized\n")) == STRLEN("uninitialized\n"));
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -ENOPKG);
-
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
- assert_se(write(fd, "uninitialized\nfoo", STRLEN("uninitialized\nfoo")) == STRLEN("uninitialized\nfoo"));
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -EUCLEAN);
-
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(ftruncate(fd, 0) >= 0);
- assert_se(write(fd, "uninit", STRLEN("uninit")) == STRLEN("uninit"));
- assert_se(lseek(fd, 0, SEEK_SET) == 0);
- assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -EUCLEAN);
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK_ERRNO(ftruncate(fd, 0));
+ ASSERT_EQ(write(fd, "uninitialized", STRLEN("uninitialized")), (ssize_t) STRLEN("uninitialized"));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_ANY, NULL), ENOPKG);
+
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK_ERRNO(ftruncate(fd, 0));
+ ASSERT_EQ(write(fd, "uninitialized\n", STRLEN("uninitialized\n")), (ssize_t) STRLEN("uninitialized\n"));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_ANY, NULL), ENOPKG);
+
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK_ERRNO(ftruncate(fd, 0));
+ ASSERT_EQ(write(fd, "uninitialized\nfoo", STRLEN("uninitialized\nfoo")), (ssize_t) STRLEN("uninitialized\nfoo"));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_ANY, NULL), EUCLEAN);
+
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_OK_ERRNO(ftruncate(fd, 0));
+ ASSERT_EQ(write(fd, "uninit", STRLEN("uninit")), (ssize_t) STRLEN("uninit"));
+ ASSERT_OK_ERRNO(lseek(fd, 0, SEEK_SET));
+ ASSERT_ERROR(id128_read_fd(fd, ID128_FORMAT_ANY, NULL), EUCLEAN);
/* build/systemd-id128 -a f03daaeb1c334b43a732172944bf772e show 51df0b4bc3b04c9780e299b98ca373b8 */
- assert_se(sd_id128_get_app_specific(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8),
- SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id) >= 0);
- assert_se(sd_id128_equal(id, SD_ID128_MAKE(1d,ee,59,54,e7,5c,4d,6f,b9,6c,c6,c0,4c,a1,8a,86)));
+ ASSERT_OK(sd_id128_get_app_specific(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8),
+ SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id));
+ ASSERT_EQ_ID128(id, SD_ID128_MAKE(1d,ee,59,54,e7,5c,4d,6f,b9,6c,c6,c0,4c,a1,8a,86));
if (sd_booted() > 0 && sd_id128_get_machine(NULL) >= 0) {
- assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id) >= 0);
- assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id2) >= 0);
- assert_se(sd_id128_equal(id, id2));
- assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8), &id2) >= 0);
- assert_se(!sd_id128_equal(id, id2));
+ ASSERT_OK(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id));
+ ASSERT_OK(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id2));
+ ASSERT_EQ_ID128(id, id2);
+ ASSERT_OK(sd_id128_get_machine_app_specific(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8), &id2));
+ ASSERT_NE_ID128(id, id2);
}
/* Check return values */
@@ -214,7 +214,7 @@ TEST(sd_id128_get_invocation) {
if (r < 0)
log_warning_errno(r, "Failed to get invocation ID, ignoring: %m");
else {
- assert(!sd_id128_equal(id, appid));
+ ASSERT_NE_ID128(id, appid);
log_info("Per-App Invocation ID: " SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(appid));
}
@@ -223,8 +223,8 @@ TEST(sd_id128_get_invocation) {
if (r < 0)
log_warning_errno(r, "Failed to get invocation ID, ignoring: %m");
else {
- assert(!sd_id128_equal(id, appid2));
- assert(!sd_id128_equal(appid, appid2));
+ ASSERT_NE_ID128(id, appid2);
+ ASSERT_NE_ID128(appid, appid2);
log_info("Per-App Invocation ID 2: " SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(appid2));
}
@@ -233,9 +233,9 @@ TEST(sd_id128_get_invocation) {
if (r < 0)
log_warning_errno(r, "Failed to get invocation ID, ignoring: %m");
else {
- assert(!sd_id128_equal(id, appid3));
- assert(sd_id128_equal(appid, appid3));
- assert(!sd_id128_equal(appid2, appid3));
+ ASSERT_NE_ID128(id, appid3);
+ ASSERT_EQ_ID128(appid, appid3);
+ ASSERT_NE_ID128(appid2, appid3);
log_info("Per-App Invocation ID 3: " SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(appid3));
}
}
@@ -256,7 +256,7 @@ TEST(benchmark_sd_id128_get_machine_app_specific) {
for (unsigned i = 0; i < iterations; i++) {
id.qwords[1] = i;
- assert_se(sd_id128_get_machine_app_specific(id, &id2) >= 0);
+ ASSERT_OK(sd_id128_get_machine_app_specific(id, &id2));
}
q = now(CLOCK_MONOTONIC) - t;
@@ -271,79 +271,79 @@ TEST(id128_at) {
sd_id128_t id, i;
tfd = mkdtemp_open(NULL, O_PATH, &t);
- assert_se(tfd >= 0);
- assert_se(mkdirat(tfd, "etc", 0755) >= 0);
- assert_se(symlinkat("etc", tfd, "etc2") >= 0);
- assert_se(symlinkat("machine-id", tfd, "etc/hoge-id") >= 0);
+ ASSERT_OK(tfd);
+ ASSERT_OK_ERRNO(mkdirat(tfd, "etc", 0755));
+ ASSERT_OK_ERRNO(symlinkat("etc", tfd, "etc2"));
+ ASSERT_OK_ERRNO(symlinkat("machine-id", tfd, "etc/hoge-id"));
- assert_se(sd_id128_randomize(&id) == 0);
+ ASSERT_OK(sd_id128_randomize(&id));
- assert_se(id128_write_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, id) >= 0);
+ ASSERT_OK(id128_write_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, id));
if (geteuid() == 0)
- assert_se(id128_write_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, id) >= 0);
+ ASSERT_OK(id128_write_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, id));
else
- assert_se(id128_write_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, id) == -EACCES);
- assert_se(unlinkat(tfd, "etc/machine-id", 0) >= 0);
- assert_se(id128_write_at(tfd, "etc2/machine-id", ID128_FORMAT_PLAIN, id) >= 0);
- assert_se(unlinkat(tfd, "etc/machine-id", 0) >= 0);
- assert_se(id128_write_at(tfd, "etc/hoge-id", ID128_FORMAT_PLAIN, id) >= 0);
- assert_se(unlinkat(tfd, "etc/machine-id", 0) >= 0);
- assert_se(id128_write_at(tfd, "etc2/hoge-id", ID128_FORMAT_PLAIN, id) >= 0);
+ ASSERT_ERROR(id128_write_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, id), EACCES);
+ ASSERT_OK_ERRNO(unlinkat(tfd, "etc/machine-id", 0));
+ ASSERT_OK(id128_write_at(tfd, "etc2/machine-id", ID128_FORMAT_PLAIN, id));
+ ASSERT_OK_ERRNO(unlinkat(tfd, "etc/machine-id", 0));
+ ASSERT_OK(id128_write_at(tfd, "etc/hoge-id", ID128_FORMAT_PLAIN, id));
+ ASSERT_OK_ERRNO(unlinkat(tfd, "etc/machine-id", 0));
+ ASSERT_OK(id128_write_at(tfd, "etc2/hoge-id", ID128_FORMAT_PLAIN, id));
/* id128_read_at() */
i = SD_ID128_NULL; /* Not necessary in real code, but for testing that the id is really assigned. */
- assert_se(id128_read_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read_at(tfd, "etc/machine-id", ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
i = SD_ID128_NULL;
- assert_se(id128_read_at(tfd, "etc2/machine-id", ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read_at(tfd, "etc2/machine-id", ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
i = SD_ID128_NULL;
- assert_se(id128_read_at(tfd, "etc/hoge-id", ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read_at(tfd, "etc/hoge-id", ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
i = SD_ID128_NULL;
- assert_se(id128_read_at(tfd, "etc2/hoge-id", ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read_at(tfd, "etc2/hoge-id", ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
/* id128_read() */
- assert_se(p = path_join(t, "/etc/machine-id"));
+ ASSERT_NOT_NULL(p = path_join(t, "/etc/machine-id"));
i = SD_ID128_NULL;
- assert_se(id128_read(p, ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
free(p);
- assert_se(p = path_join(t, "/etc2/machine-id"));
+ ASSERT_NOT_NULL(p = path_join(t, "/etc2/machine-id"));
i = SD_ID128_NULL;
- assert_se(id128_read(p, ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
free(p);
- assert_se(p = path_join(t, "/etc/hoge-id"));
+ ASSERT_NOT_NULL(p = path_join(t, "/etc/hoge-id"));
i = SD_ID128_NULL;
- assert_se(id128_read(p, ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
free(p);
- assert_se(p = path_join(t, "/etc2/hoge-id"));
+ ASSERT_NOT_NULL(p = path_join(t, "/etc2/hoge-id"));
i = SD_ID128_NULL;
- assert_se(id128_read(p, ID128_FORMAT_PLAIN, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));
+ ASSERT_EQ_ID128(id, i);
/* id128_get_machine_at() */
i = SD_ID128_NULL;
- assert_se(id128_get_machine_at(tfd, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_get_machine_at(tfd, &i));
+ ASSERT_EQ_ID128(id, i);
/* id128_get_machine() */
i = SD_ID128_NULL;
- assert_se(id128_get_machine(t, &i) >= 0);
- assert_se(sd_id128_equal(id, i));
+ ASSERT_OK(id128_get_machine(t, &i));
+ ASSERT_EQ_ID128(id, i);
}
TEST(ID128_REFUSE_NULL) {
@@ -352,18 +352,18 @@ TEST(ID128_REFUSE_NULL) {
sd_id128_t id;
tfd = mkdtemp_open(NULL, O_PATH, &t);
- assert_se(tfd >= 0);
+ ASSERT_OK(tfd);
- assert_se(id128_write_at(tfd, "zero-id", ID128_FORMAT_PLAIN | ID128_REFUSE_NULL, (sd_id128_t) {}) == -ENOMEDIUM);
- assert_se(unlinkat(tfd, "zero-id", 0) >= 0);
- assert_se(id128_write_at(tfd, "zero-id", ID128_FORMAT_PLAIN, (sd_id128_t) {}) >= 0);
+ ASSERT_ERROR(id128_write_at(tfd, "zero-id", ID128_FORMAT_PLAIN | ID128_REFUSE_NULL, (sd_id128_t) {}), ENOMEDIUM);
+ ASSERT_OK_ERRNO(unlinkat(tfd, "zero-id", 0));
+ ASSERT_OK(id128_write_at(tfd, "zero-id", ID128_FORMAT_PLAIN, (sd_id128_t) {}));
- assert_se(sd_id128_randomize(&id) == 0);
- assert_se(!sd_id128_equal(id, SD_ID128_NULL));
- assert_se(id128_read_at(tfd, "zero-id", ID128_FORMAT_PLAIN, &id) >= 0);
- assert_se(sd_id128_equal(id, SD_ID128_NULL));
+ ASSERT_OK(sd_id128_randomize(&id));
+ ASSERT_NE_ID128(id, SD_ID128_NULL);
+ ASSERT_OK(id128_read_at(tfd, "zero-id", ID128_FORMAT_PLAIN, &id));
+ ASSERT_EQ_ID128(id, SD_ID128_NULL);
- assert_se(id128_read_at(tfd, "zero-id", ID128_FORMAT_PLAIN | ID128_REFUSE_NULL, &id) == -ENOMEDIUM);
+ ASSERT_ERROR(id128_read_at(tfd, "zero-id", ID128_FORMAT_PLAIN | ID128_REFUSE_NULL, &id), ENOMEDIUM);
}
DEFINE_TEST_MAIN(LOG_INFO);
diff --git a/src/test/test-log.c b/src/test/test-log.c
index 97eb5e0..57cab63 100644
--- a/src/test/test-log.c
+++ b/src/test/test-log.c
@@ -13,11 +13,6 @@
#include "strv.h"
#include "tests.h"
-assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(EINVAL)));
-assert_cc(!IS_SYNTHETIC_ERRNO(EINVAL));
-assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(0)));
-assert_cc(!IS_SYNTHETIC_ERRNO(0));
-
#define X10(x) x x x x x x x x x x
#define X100(x) X10(X10(x))
#define X1000(x) X100(X10(x))
@@ -227,6 +222,15 @@ static void test_log_prefix(void) {
int main(int argc, char* argv[]) {
test_setup_logging(LOG_DEBUG);
+ ASSERT_TRUE(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(EINVAL)));
+ ASSERT_TRUE(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(-EINVAL)));
+ assert_cc(!IS_SYNTHETIC_ERRNO(EINVAL));
+ assert_cc(!IS_SYNTHETIC_ERRNO(-EINVAL));
+ ASSERT_TRUE(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(0)));
+ assert_cc(!IS_SYNTHETIC_ERRNO(0));
+ ASSERT_EQ(ERRNO_VALUE(EINVAL), EINVAL);
+ ASSERT_EQ(ERRNO_VALUE(SYNTHETIC_ERRNO(-EINVAL)), EINVAL);
+
test_assert_return_is_critical();
test_file();
diff --git a/src/test/test-macro.c b/src/test/test-macro.c
index 9e2875d..3d5b0cf 100644
--- a/src/test/test-macro.c
+++ b/src/test/test-macro.c
@@ -4,6 +4,7 @@
#include <sys/stat.h>
#include "errno-util.h"
+#include "id128-util.h"
#include "log.h"
#include "macro.h"
#include "tests.h"
@@ -1122,6 +1123,11 @@ TEST(ASSERT) {
ASSERT_SIGNAL(ASSERT_OK_ERRNO(-1), SIGABRT);
ASSERT_SIGNAL(ASSERT_OK_ERRNO(-ENOANO), SIGABRT);
+ ASSERT_FAIL(-ENOENT);
+ ASSERT_FAIL(-EPERM);
+ ASSERT_SIGNAL(ASSERT_FAIL(0), SIGABRT);
+ ASSERT_SIGNAL(ASSERT_FAIL(255), SIGABRT);
+
ASSERT_ERROR(-ENOENT, ENOENT);
ASSERT_ERROR(RET_NERRNO(mkdir("/i/will/fail/with/enoent", 666)), ENOENT);
ASSERT_SIGNAL(ASSERT_ERROR(0, ENOENT), SIGABRT);
@@ -1181,6 +1187,15 @@ TEST(ASSERT) {
ASSERT_LT(-1, 1);
ASSERT_SIGNAL(ASSERT_LT(0, 0), SIGABRT);
ASSERT_SIGNAL(ASSERT_LT(1, -1), SIGABRT);
+
+ ASSERT_EQ_ID128(SD_ID128_NULL, SD_ID128_NULL);
+ ASSERT_NE_ID128(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8),
+ SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e));
+ ASSERT_SIGNAL(
+ ASSERT_EQ_ID128(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8),
+ SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e)),
+ SIGABRT);
+ ASSERT_SIGNAL(ASSERT_NE_ID128(SD_ID128_NULL, SD_ID128_NULL), SIGABRT);
}
DEFINE_TEST_MAIN(LOG_INFO);