mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Tests/Kernel: Add test cases for proper types in dirent for various FSes
This commit is contained in:
parent
a10e63f08e
commit
90152dc859
Notes:
sideshowbarker
2024-07-17 00:16:31 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/90152dc859 Pull-request: https://github.com/SerenityOS/serenity/pull/22598 Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 100 additions and 0 deletions
|
@ -41,6 +41,7 @@ set(LIBTEST_BASED_SOURCES
|
|||
TestEmptyPrivateInodeVMObject.cpp
|
||||
TestEmptySharedInodeVMObject.cpp
|
||||
TestExt2FS.cpp
|
||||
TestFileSystemDirentTypes.cpp
|
||||
TestInvalidUIDSet.cpp
|
||||
TestSharedInodeVMObject.cpp
|
||||
TestPosixFallocate.cpp
|
||||
|
|
99
Tests/Kernel/TestFileSystemDirentTypes.cpp
Normal file
99
Tests/Kernel/TestFileSystemDirentTypes.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/API/POSIX/dirent.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
TEST_CASE(test_sysfs_root_directory)
|
||||
{
|
||||
auto dirfd = open("/sys/", O_RDONLY | O_DIRECTORY);
|
||||
auto cleanup_guard = ScopeGuard([&] {
|
||||
close(dirfd);
|
||||
});
|
||||
|
||||
DIR* dir = fdopendir(dirfd);
|
||||
EXPECT(dir != nullptr);
|
||||
|
||||
auto cleanup_dir_guard = ScopeGuard([&] {
|
||||
closedir(dir);
|
||||
});
|
||||
|
||||
auto* _dirent = readdir(dir);
|
||||
EXPECT(_dirent != nullptr);
|
||||
// NOTE: We should see '.'
|
||||
EXPECT_EQ(_dirent->d_type, DT_DIR);
|
||||
|
||||
_dirent = readdir(dir);
|
||||
EXPECT(_dirent != nullptr);
|
||||
// NOTE: We should see '..'
|
||||
EXPECT_EQ(_dirent->d_type, DT_DIR);
|
||||
|
||||
while (true) {
|
||||
_dirent = readdir(dir);
|
||||
if (_dirent == nullptr)
|
||||
break;
|
||||
// NOTE: We should only see a directory entry in the /sys directory
|
||||
EXPECT_EQ(_dirent->d_type, DT_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(test_devpts_root_directory)
|
||||
{
|
||||
auto dirfd = open("/dev/pts/", O_RDONLY | O_DIRECTORY);
|
||||
auto cleanup_guard = ScopeGuard([&] {
|
||||
close(dirfd);
|
||||
});
|
||||
|
||||
DIR* dir = fdopendir(dirfd);
|
||||
EXPECT(dir != nullptr);
|
||||
|
||||
auto cleanup_dir_guard = ScopeGuard([&] {
|
||||
closedir(dir);
|
||||
});
|
||||
|
||||
auto* _dirent = readdir(dir);
|
||||
EXPECT(_dirent != nullptr);
|
||||
// NOTE: We should see '.'
|
||||
EXPECT_EQ(_dirent->d_type, DT_DIR);
|
||||
|
||||
_dirent = readdir(dir);
|
||||
EXPECT(_dirent != nullptr);
|
||||
// NOTE: We should see '..'
|
||||
EXPECT_EQ(_dirent->d_type, DT_DIR);
|
||||
}
|
||||
|
||||
TEST_CASE(test_procfs_root_directory)
|
||||
{
|
||||
auto dirfd = open("/proc/", O_RDONLY | O_DIRECTORY);
|
||||
auto cleanup_guard = ScopeGuard([&] {
|
||||
close(dirfd);
|
||||
});
|
||||
|
||||
DIR* dir = fdopendir(dirfd);
|
||||
EXPECT(dir != nullptr);
|
||||
|
||||
auto cleanup_dir_guard = ScopeGuard([&] {
|
||||
closedir(dir);
|
||||
});
|
||||
|
||||
auto* _dirent = readdir(dir);
|
||||
EXPECT(_dirent != nullptr);
|
||||
// NOTE: We should see '.' now
|
||||
EXPECT_EQ(_dirent->d_type, DT_DIR);
|
||||
|
||||
_dirent = readdir(dir);
|
||||
EXPECT(_dirent != nullptr);
|
||||
// NOTE: We should see '..' now
|
||||
EXPECT_EQ(_dirent->d_type, DT_DIR);
|
||||
|
||||
_dirent = readdir(dir);
|
||||
EXPECT(_dirent != nullptr);
|
||||
// NOTE: We should see 'self' now
|
||||
EXPECT_EQ(_dirent->d_type, DT_LNK);
|
||||
}
|
Loading…
Reference in a new issue