From 79b66944e053c39f4aa8df865c26752976a8dda7 Mon Sep 17 00:00:00 2001 From: Mateusz Bloch Date: Thu, 20 Jul 2023 10:46:09 +0200 Subject: [PATCH 1/2] libc: fix checking times in stat tests JIRA CI-302 --- libc/misc/stat.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libc/misc/stat.c b/libc/misc/stat.c index c7db27d8..757ccd88 100644 --- a/libc/misc/stat.c +++ b/libc/misc/stat.c @@ -851,19 +851,19 @@ TEST(stat_nlink_size_blk_tim, tim) TEST_ASSERT_EQUAL_INT(0, stat(tempPath, &buffer)); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_ctim.tv_sec); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_atim.tv_sec); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_mtim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_ctim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_atim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_mtim.tv_sec); TEST_ASSERT_EQUAL_INT(0, lstat(tempPath, &buffer)); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_ctim.tv_sec); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_atim.tv_sec); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_mtim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_ctim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_atim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_mtim.tv_sec); TEST_ASSERT_EQUAL_INT(0, fstat(temp_fd, &buffer)); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_ctim.tv_sec); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_atim.tv_sec); - TEST_ASSERT_EQUAL_INT(currentTime, buffer.st_mtim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_ctim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_atim.tv_sec); + TEST_ASSERT_INT_WITHIN(1, currentTime, buffer.st_mtim.tv_sec); close(temp_fd); remove(tempPath); From cd69155cda53927f4b6414fd53d8caf10a4f1fb9 Mon Sep 17 00:00:00 2001 From: Mateusz Bloch Date: Fri, 21 Jul 2023 10:37:10 +0200 Subject: [PATCH 2/2] libc: enable permissions check in stat tests JIRA CI-302 --- libc/misc/stat.c | 87 ++---------------------------------------------- 1 file changed, 3 insertions(+), 84 deletions(-) diff --git a/libc/misc/stat.c b/libc/misc/stat.c index 757ccd88..f0785f28 100644 --- a/libc/misc/stat.c +++ b/libc/misc/stat.c @@ -89,10 +89,6 @@ TEST_TEAR_DOWN(stat_mode) TEST(stat_mode, none) { -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifdef __phoenix__ - TEST_IGNORE_MESSAGE("#743 issue"); -#endif struct stat buffer; fd = open(path, O_CREAT, 00000); @@ -113,10 +109,6 @@ TEST(stat_mode, none) TEST(stat_mode, gid) { -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifdef __phoenix__ - TEST_IGNORE_MESSAGE("#743 issue"); -#endif struct stat buffer; fd = open(path, O_CREAT, S_ISGID); @@ -137,10 +129,6 @@ TEST(stat_mode, gid) TEST(stat_mode, uid) { -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifdef __phoenix__ - TEST_IGNORE_MESSAGE("#743 issue"); -#endif struct stat buffer; fd = open(path, O_CREAT, S_ISUID); @@ -161,10 +149,6 @@ TEST(stat_mode, uid) TEST(stat_mode, uid_gid) { -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifdef __phoenix__ - TEST_IGNORE_MESSAGE("#743 issue"); -#endif struct stat buffer; fd = open(path, O_CREAT, S_ISUID | S_ISGID); @@ -185,10 +169,6 @@ TEST(stat_mode, uid_gid) TEST(stat_mode, vtx) { -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifdef __phoenix__ - TEST_IGNORE_MESSAGE("#743 issue"); -#endif struct stat buffer; fd = open(path, O_CREAT, S_ISVTX); @@ -209,10 +189,6 @@ TEST(stat_mode, vtx) TEST(stat_mode, permissions_all) { -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifdef __phoenix__ - TEST_IGNORE_MESSAGE("#743 issue"); -#endif struct stat buffer; int permissions_set; mode_t mask; @@ -243,8 +219,6 @@ TEST(stat_mode, permissions_all) TEST(stat_mode, reg_type) { struct stat buffer; -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ int permissions_set; mode_t mask; @@ -254,61 +228,39 @@ TEST(stat_mode, reg_type) mask = umask(0); permissions_set = (NONE_MODE | 0666) & ~mask; umask(mask); -#endif fd = open(path, O_CREAT, 0666); TEST_ASSERT_EQUAL_INT(0, stat(path, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif TEST_ASSERT_EQUAL_INT(0, lstat(path, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif TEST_ASSERT_EQUAL_INT(0, fstat(fd, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif close(fd); remove(path); fd = open(path, O_CREAT, 0000); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ permissions_set = NONE_MODE & ~mask; -#endif TEST_ASSERT_EQUAL_INT(0, stat(path, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif TEST_ASSERT_EQUAL_INT(0, lstat(path, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif TEST_ASSERT_EQUAL_INT(0, fstat(fd, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif close(fd); remove(path); @@ -352,12 +304,11 @@ TEST(stat_mode, dir_type) remove(tempPath); } + TEST(stat_mode, symlink_type) { int sym_fd; struct stat buffer; -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ int permissions_set; mode_t mask; @@ -367,7 +318,6 @@ TEST(stat_mode, symlink_type) mask = umask(0); permissions_set = (NONE_MODE | 0666) & ~mask; umask(mask); -#endif fd = open(path, O_CREAT, 0666); @@ -377,18 +327,12 @@ TEST(stat_mode, symlink_type) TEST_ASSERT_EQUAL_INT(0, stat(symPath, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif sym_fd = open(symPath, O_RDONLY); TEST_ASSERT_EQUAL_INT(0, fstat(sym_fd, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif close(sym_fd); unlink(symPath); @@ -398,27 +342,18 @@ TEST(stat_mode, symlink_type) /* Testing with the lowest possible permissions, have to be 0400 to be accessible by fstat() */ fd = open(path, O_CREAT, 0400); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ permissions_set = (NONE_MODE | 0400) & ~mask; -#endif TEST_ASSERT_EQUAL_INT(0, symlink(path, symPath)); TEST_ASSERT_EQUAL_INT(0, stat(symPath, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif sym_fd = open(symPath, O_RDONLY); TEST_ASSERT_EQUAL_INT(0, fstat(sym_fd, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif close(sym_fd); unlink(symPath); @@ -430,8 +365,6 @@ TEST(stat_mode, symlink_type) TEST(stat_mode, symlink_lstat) { struct stat buffer; -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ int permissions_set; mode_t mask; @@ -441,7 +374,7 @@ TEST(stat_mode, symlink_lstat) mask = umask(0); permissions_set = (NONE_MODE | 0666) & ~mask; umask(mask); -#endif + fd = open(path, O_CREAT, 0666); unlink(symPath); @@ -449,19 +382,13 @@ TEST(stat_mode, symlink_lstat) TEST_ASSERT_EQUAL_INT(0, lstat(path, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); permissions_set = LINK_MODE; -#endif TEST_ASSERT_EQUAL_INT(0, lstat(symPath, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFLNK); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif close(fd); remove(path); @@ -471,34 +398,26 @@ TEST(stat_mode, symlink_lstat) fd = open(path, O_CREAT, 0000); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ permissions_set = (NONE_MODE | 0000) & ~mask; -#endif TEST_ASSERT_EQUAL_INT(0, symlink(path, symPath)); TEST_ASSERT_EQUAL_INT(0, lstat(path, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFREG); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); permissions_set = LINK_MODE; -#endif TEST_ASSERT_EQUAL_INT(0, lstat(symPath, &buffer)); TEST_ASSERT_TRUE((buffer.st_mode & S_IFMT) == S_IFLNK); -/* Disabled because of #743 issue: https://github.com/phoenix-rtos/phoenix-rtos-project/issues/743 */ -#ifndef __phoenix__ TEST_ASSERT_EQUAL_INT(permissions_set, buffer.st_mode); -#endif close(fd); remove(path); unlink(symPath); } + TEST(stat_mode, symloop_max) { struct stat buffer;