mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
test-xattr-util.c: migrate to new assertion macros (#38025)
We recently added a new set of assertion macros such as ASSERT_GE, ASSERT_OK, ASSERT_EQ, ... which show not only the expression that failed but also the values of the arguments of the expression. Let's use them.
This commit is contained in:
@@ -23,33 +23,30 @@ TEST(getxattr_at_malloc) {
|
||||
const char *x;
|
||||
int r;
|
||||
|
||||
fd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", O_RDONLY|O_NOCTTY, &t);
|
||||
assert_se(fd >= 0);
|
||||
ASSERT_OK(fd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", O_RDONLY|O_NOCTTY, &t));
|
||||
x = strjoina(t, "/test");
|
||||
assert_se(touch(x) >= 0);
|
||||
ASSERT_OK(touch(x));
|
||||
|
||||
r = setxattr(x, "user.foo", "bar", 3, 0);
|
||||
if (r < 0 && ERRNO_IS_NOT_SUPPORTED(errno))
|
||||
return (void) log_tests_skipped_errno(errno, "no xattrs supported on /var/tmp");
|
||||
assert_se(r >= 0);
|
||||
ASSERT_OK_ERRNO(r);
|
||||
|
||||
ASSERT_OK(getxattr_at_malloc(fd, "test", "user.foo", 0, &value, /* ret_size= */ NULL));
|
||||
assert_se(memcmp(value, "bar", 3) == 0);
|
||||
ASSERT_EQ(memcmp(value, "bar", 3), 0);
|
||||
value = mfree(value);
|
||||
|
||||
ASSERT_OK(getxattr_at_malloc(AT_FDCWD, x, "user.foo", 0, &value, /* ret_size= */ NULL));
|
||||
assert_se(memcmp(value, "bar", 3) == 0);
|
||||
ASSERT_EQ(memcmp(value, "bar", 3), 0);
|
||||
value = mfree(value);
|
||||
|
||||
safe_close(fd);
|
||||
fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
|
||||
assert_se(fd >= 0);
|
||||
ASSERT_OK_ERRNO(fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY));
|
||||
r = getxattr_at_malloc(fd, "usr", "user.idontexist", 0, &value, /* ret_size= */ NULL);
|
||||
assert_se(ERRNO_IS_NEG_XATTR_ABSENT(r));
|
||||
ASSERT_TRUE(ERRNO_IS_NEG_XATTR_ABSENT(r));
|
||||
|
||||
safe_close(fd);
|
||||
fd = open(x, O_PATH|O_CLOEXEC);
|
||||
assert_se(fd >= 0);
|
||||
ASSERT_OK_ERRNO(fd = open(x, O_PATH|O_CLOEXEC));
|
||||
ASSERT_OK(getxattr_at_malloc(fd, NULL, "user.foo", 0, &value, /* ret_size= */ NULL));
|
||||
ASSERT_STREQ(value, "bar");
|
||||
value = mfree(value);
|
||||
@@ -69,8 +66,7 @@ TEST(getcrtime) {
|
||||
usec_t usec, k;
|
||||
int r;
|
||||
|
||||
fd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", 0, &t);
|
||||
assert_se(fd >= 0);
|
||||
ASSERT_OK(fd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", 0, &t));
|
||||
|
||||
r = fd_getcrtime(fd, &usec);
|
||||
if (r < 0)
|
||||
@@ -82,9 +78,9 @@ TEST(getcrtime) {
|
||||
|
||||
r = fd_setcrtime(fd, 1519126446UL * USEC_PER_SEC);
|
||||
if (!IN_SET(r, -EOPNOTSUPP, -ENOTTY)) {
|
||||
assert_se(fd_getcrtime(fd, &usec) >= 0);
|
||||
assert_se(k < 1519126446UL * USEC_PER_SEC ||
|
||||
usec == 1519126446UL * USEC_PER_SEC);
|
||||
ASSERT_OK(fd_getcrtime(fd, &usec));
|
||||
ASSERT_TRUE(k < 1519126446UL * USEC_PER_SEC ||
|
||||
usec == 1519126446UL * USEC_PER_SEC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,10 +130,9 @@ TEST(xsetxattr) {
|
||||
const char *x;
|
||||
int r;
|
||||
|
||||
dfd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", O_PATH, &t);
|
||||
assert_se(dfd >= 0);
|
||||
ASSERT_OK(dfd = mkdtemp_open("/var/tmp/test-xattrtestXXXXXX", O_PATH, &t));
|
||||
x = strjoina(t, "/test");
|
||||
assert_se(touch(x) >= 0);
|
||||
ASSERT_OK(touch(x));
|
||||
|
||||
/* by full path */
|
||||
r = xsetxattr(AT_FDCWD, x, 0, "user.foo", "fullpath");
|
||||
|
||||
Reference in New Issue
Block a user