Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: stat tests improvements #226

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 12 additions & 93 deletions libc/misc/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;

Expand All @@ -441,27 +374,21 @@ 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);
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);
Expand All @@ -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;
Expand Down Expand Up @@ -851,19 +770,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);
Expand Down
Loading