From: Paul Floyd Date: Wed, 20 Aug 2025 18:40:07 +0000 (+0200) Subject: FreeBSD regtest: add a test for readlinkat X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=40c8447eb91026e4dddbbd58de7364b82cad3b20;p=thirdparty%2Fvalgrind.git FreeBSD regtest: add a test for readlinkat --- diff --git a/.gitignore b/.gitignore index e48a2ab0e..569a8fd5c 100644 --- a/.gitignore +++ b/.gitignore @@ -2329,6 +2329,7 @@ /none/tests/freebsd/bug498317 none/tests/freebsd/bug499212 /none/tests/freebsd/osrel +/none/tests/freebsd/readlinkat /none/tests/freebsd/swapcontext /none/tests/freebsd/fexecve /none/tests/freebsd/hello_world diff --git a/none/tests/freebsd/Makefile.am b/none/tests/freebsd/Makefile.am index 0bbbffdad..a575f4097 100644 --- a/none/tests/freebsd/Makefile.am +++ b/none/tests/freebsd/Makefile.am @@ -55,6 +55,8 @@ EXTRA_DIST = \ ksh_test.stdout.exp \ open_client.vgtest \ open_client.stderr.exp \ + readlinkat.vgtest \ + readlinkat.stderr.exp \ sanity_level_thread.vgtest \ sanity_level_thread.stderr.exp \ swapcontext.vgtest \ @@ -71,8 +73,9 @@ EXTRA_DIST = \ usrstack.stdout.exp check_PROGRAMS = \ - auxv bug452274 bug498317 bug499212 fexecve hello_world open_client osrel \ - proc_pid_file sanity_level_thread swapcontext umtx_shm_creat usrstack + auxv bug452274 bug498317 bug499212 fexecve hello_world open_client \ + osrel proc_pid_file readlinkat sanity_level_thread swapcontext \ + umtx_shm_creat usrstack AM_CFLAGS += $(AM_FLAG_M3264_PRI) AM_CXXFLAGS += $(AM_FLAG_M3264_PRI) @@ -84,6 +87,7 @@ swapcontext_CFLAGS = ${AM_CFLAGS} hello_world_SOURCES = hello_world.cpp open_client_SOURCES = open_client.cpp proc_pid_file_SOURCES = proc_pid_file.cpp +readlinkat_SOURCES = readlinkat.cpp sanity_level_thread_SOURCES = sanity_level_thread.cpp sanity_level_thread_LDFLAGS = ${AM_LDFLAGS} -pthread diff --git a/none/tests/freebsd/readlinkat.cpp b/none/tests/freebsd/readlinkat.cpp new file mode 100644 index 000000000..8b33a8b63 --- /dev/null +++ b/none/tests/freebsd/readlinkat.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + char path[MAXPATHLEN]; + char linkedPath[MAXPATHLEN]; + char currentDirectory[MAXPATHLEN]; + char parentDirectory[MAXPATHLEN]; + + getcwd(currentDirectory, MAXPATHLEN); + + ssize_t res = readlinkat(AT_FDCWD, "readlinkat_link.cpp", linkedPath, MAXPATHLEN); + if (res == -1) + { + std::cerr << "Error: readlinkat test 1 failed\n"; + } + if (!strcmp(linkedPath, "readlink.cpp")) + { + std::cerr << "Error: readlinkat test 1 unexpected resolved path - " << linkedPath << '\n'; + } + + int dotdot; + if ((dotdot = open("..", O_DIRECTORY | O_RDONLY)) == -1) + { + throw std::runtime_error("failed to open ."); + } + else + { + res = readlinkat(dotdot, "freebsd/readlinkat_link.cpp", linkedPath, MAXPATHLEN); + if (res == -1) + { + std::cerr << "Error: readlinkat test 2 failed\n"; + } + if (!strcmp(linkedPath, "readlink.cpp")) + { + std::cerr << "Error: readlinkat test 2 unexpected resolved path - " << linkedPath << '\n'; + } + } + close(dotdot); + + chdir(".."); + res = readlinkat(AT_FDCWD, "freebsd/readlinkat_link.cpp", linkedPath, MAXPATHLEN); + if (res == -1) + { + std::cerr << "Error: readlinkat test 3 failed\n"; + } + if (!strcmp(linkedPath, "readlink.cpp")) + { + std::cerr << "Error: readlinkat test 3 unexpected resolved path - " << linkedPath << '\n'; + } +} diff --git a/none/tests/freebsd/readlinkat.stderr.exp b/none/tests/freebsd/readlinkat.stderr.exp new file mode 100644 index 000000000..e69de29bb diff --git a/none/tests/freebsd/readlinkat.vgtest b/none/tests/freebsd/readlinkat.vgtest new file mode 100644 index 000000000..4942f8ca9 --- /dev/null +++ b/none/tests/freebsd/readlinkat.vgtest @@ -0,0 +1,4 @@ +prereq: rm -f readlinkat_link.cpp && ln -s readlinkat.cpp readlinkat_link.cpp +prog: readlinkat +vgopts: -q +post: rm -f readlinkat_link.cpp