Skip to content

[libc] Fix statvfs test case when SYS_statfs64 is used #99827

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

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.stat.mkdirat
libc.src.sys.stat.stat

# sys/statvfs.h
libc.src.sys.statvfs.fstatvfs
libc.src.sys.statvfs.statvfs

# sys/utsname.h entrypoints
libc.src.sys.utsname.uname

Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_select
libc.include.sys_socket
libc.include.sys_stat
libc.include.sys_statvfs
libc.include.sys_syscall
libc.include.sys_time
libc.include.sys_types
Expand Down
12 changes: 9 additions & 3 deletions libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
#include <linux/magic.h>
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;

#ifdef SYS_statfs64
using StatFs = statfs64;
#else
using StatFs = statfs;
#endif

namespace LIBC_NAMESPACE_DECL {
static int fstatfs(int fd, struct statfs *buf) {
static int fstatfs(int fd, StatFs *buf) {
using namespace statfs_utils;
if (cpp::optional<LinuxStatFs> result = linux_fstatfs(fd)) {
if (cpp::optional<StatFs> result = linux_fstatfs(fd)) {
*buf = *result;
return 0;
}
Expand All @@ -29,7 +35,7 @@ struct PathFD {
};

TEST(LlvmLibcSysStatvfsTest, FstatfsBasic) {
struct statfs buf;
StatFs buf;
ASSERT_THAT(LIBC_NAMESPACE::fstatfs(PathFD("/"), &buf), Succeeds());
ASSERT_THAT(LIBC_NAMESPACE::fstatfs(PathFD("/proc"), &buf), Succeeds());
ASSERT_EQ(buf.f_type, static_cast<decltype(buf.f_type)>(PROC_SUPER_MAGIC));
Expand Down
10 changes: 8 additions & 2 deletions libc/test/src/sys/statvfs/linux/statvfs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
#include <linux/magic.h>
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;

#ifdef SYS_statfs64
using StatFs = statfs64;
#else
using StatFs = statfs;
#endif

namespace LIBC_NAMESPACE_DECL {
static int statfs(const char *path, struct statfs *buf) {
static int statfs(const char *path, StatFs *buf) {
using namespace statfs_utils;
if (cpp::optional<LinuxStatFs> result = linux_statfs(path)) {
*buf = *result;
Expand All @@ -18,7 +24,7 @@ static int statfs(const char *path, struct statfs *buf) {
} // namespace LIBC_NAMESPACE_DECL

TEST(LlvmLibcSysStatfsTest, StatfsBasic) {
struct statfs buf;
StatFs buf;
ASSERT_THAT(LIBC_NAMESPACE::statfs("/", &buf), Succeeds());
ASSERT_THAT(LIBC_NAMESPACE::statfs("/proc", &buf), Succeeds());
ASSERT_EQ(buf.f_type, static_cast<decltype(buf.f_type)>(PROC_SUPER_MAGIC));
Expand Down
Loading