Skip to content

Commit

Permalink
cleanup approval tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmiddha committed Dec 26, 2024
1 parent 8654fbb commit c31c809
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/fstrace-debug",
"args": ["bash", "${workspaceFolder}/test2/1.sh"],
"args": ["${workspaceFolder}/build/tests_syscalls_openat2.c"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ add_compile_options(-Wall -Wextra -Wpedantic -Wimplicit-fallthrough)
# Build fstrace
add_executable(fstrace src/fstrace.cc)

# target_compile_options(fstrace PRIVATE --coverage)
# target_link_options(fstrace PRIVATE --coverage)

set(DEBUG_FD 1)
target_compile_definitions(fstrace PRIVATE DEBUGFD=${DEBUG_FD})

Expand Down Expand Up @@ -77,7 +80,7 @@ include(GoogleTest)
gtest_discover_tests(approval-tests)

set(SOURCE_DIR "tests/syscalls")
file(GLOB SOURCES "${SOURCE_DIR}/**/*.c" "${SOURCE_DIR}/**/*.cpp")
file(GLOB SOURCES "${SOURCE_DIR}/*.c" "${SOURCE_DIR}/*.cpp")
foreach(SOURCE_FILE ${SOURCES})
file(RELATIVE_PATH REL_PATH "${CMAKE_SOURCE_DIR}" "${SOURCE_FILE}")
string(REPLACE "/" "_" TARGET_NAME ${REL_PATH})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RF ./tests_syscalls_open_basic.c
RF ./tests_syscalls_open.c
RX /etc/ld.so.preload
RF /etc/ld.so.cache
RF /etc/ld.so.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
RF ./tests_syscalls_openat2_fdcwd.c
RF ./tests_syscalls_openat2.c
RX /etc/ld.so.preload
RF /etc/ld.so.cache
RF /etc/ld.so.cache
RF /lib/x86_64-linux-gnu/libc.so.6
RF /tmp
RD /tmp/

9 changes: 4 additions & 5 deletions tests/approval-tests/approval-tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ std::string getFsTraceOutput(const char *cmd)
return result;
}

TEST(Syscalls, OpenAt2_FDCWD)
TEST(SyscallTests, OpenAt2)
{
std::string output = getFsTraceOutput("./tests_syscalls_openat2_fdcwd.c");
std::string output = getFsTraceOutput("./tests_syscalls_openat2.c");
ApprovalTests::Approvals::verify(output);
}


TEST(Syscalls, Open)
TEST(SyscallTests, Open)
{
std::string output = getFsTraceOutput("./tests_syscalls_open_basic.c");
std::string output = getFsTraceOutput("./tests_syscalls_open.c");
ApprovalTests::Approvals::verify(output);
}
File renamed without changes.
55 changes: 55 additions & 0 deletions tests/syscalls/openat2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fcntl.h>
#include <linux/openat2.h>
#include <unistd.h>
#include <sys/syscall.h>

// int openat2(int dirfd, const char *pathname, const struct open_how *how, size_t size);

int dirfd1()
{
int dirfd = open("/tmp", O_RDONLY);

const char *pathname = "/tmp";
struct open_how how = {.flags = O_PATH, .mode = 0};
int size = sizeof(struct open_how);
syscall(SYS_openat2, dirfd, pathname, &how, size);
}

int dirfd2()
{
int dirfd = open("/tmp", O_RDONLY);
const char *pathname = "./";
struct open_how how = {.flags = O_PATH, .mode = 0};
int size = sizeof(struct open_how);
syscall(SYS_openat2, dirfd, pathname, &how, size);
}

int atfdcwd1()
{
int dirfd = AT_FDCWD;
const char *pathname = "/tmp";
struct open_how how = {.flags = O_PATH, .mode = 0};
int size = sizeof(struct open_how);
syscall(SYS_openat2, dirfd, pathname, &how, size);
}

int atfdcwd2()
{
int dirfd = AT_FDCWD;
chdir("/tmp");
const char *pathname = "./";
struct open_how how = {.flags = O_PATH, .mode = 0};
int size = sizeof(struct open_how);
syscall(SYS_openat2, dirfd, pathname, &how, size);
}

int main()
{
// dirfd1();
dirfd2();
// atfdcwd1();
// atfdcwd2();
return 0;
}
19 changes: 0 additions & 19 deletions tests/syscalls/openat2/fdcwd.c

This file was deleted.

0 comments on commit c31c809

Please sign in to comment.