]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
FreeBSD regtest: add a test for readlinkat
authorPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 20 Aug 2025 18:40:07 +0000 (20:40 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 20 Aug 2025 18:40:07 +0000 (20:40 +0200)
.gitignore
none/tests/freebsd/Makefile.am
none/tests/freebsd/readlinkat.cpp [new file with mode: 0644]
none/tests/freebsd/readlinkat.stderr.exp [new file with mode: 0644]
none/tests/freebsd/readlinkat.vgtest [new file with mode: 0644]

index e48a2ab0ed169d6deb8d567091733a738f85705c..569a8fd5c763adabe92fdcdc93002b38eda2ad6b 100644 (file)
 /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
index 0bbbffdad6c2a3d07ae9ec5207ba91ba4ff436ae..a575f409754c5a90c2372a900e9440308a66740e 100644 (file)
@@ -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 (file)
index 0000000..8b33a8b
--- /dev/null
@@ -0,0 +1,56 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <iostream>
+#include <cstring>
+
+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 (file)
index 0000000..e69de29
diff --git a/none/tests/freebsd/readlinkat.vgtest b/none/tests/freebsd/readlinkat.vgtest
new file mode 100644 (file)
index 0000000..4942f8c
--- /dev/null
@@ -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