selftests/nolibc: chdir_root: restore current path after test
authorZhangjin Wu <falcon@tinylab.org>
Fri, 7 Jul 2023 18:42:01 +0000 (02:42 +0800)
committerWilly Tarreau <w@1wt.eu>
Wed, 23 Aug 2023 02:38:02 +0000 (04:38 +0200)
The PWD environment variable has the path of the nolibc-test program,
the current path must be the same as it, otherwise, the test cases will
fail with relative path (e.g. ./nolibc-test).

Since only chdir_root really changes the current path, let's restore it
with the PWD environment variable.

Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
tools/testing/selftests/nolibc/nolibc-test.c

index ad1f635..64fca7c 100644 (file)
@@ -703,7 +703,7 @@ int run_syscall(int min, int max)
                CASE_TEST(sbrk_0);            EXPECT_PTRNE(1, sbrk(0), (void *)-1); break;
                CASE_TEST(sbrk);              if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(1, (p2 == (void *)-1) || p2 == p1); break;
                CASE_TEST(brk);               EXPECT_SYSZR(1, brk(sbrk(0))); break;
-               CASE_TEST(chdir_root);        EXPECT_SYSZR(1, chdir("/")); break;
+               CASE_TEST(chdir_root);        EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break;
                CASE_TEST(chdir_dot);         EXPECT_SYSZR(1, chdir(".")); break;
                CASE_TEST(chdir_blah);        EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break;
                CASE_TEST(chmod_net);         EXPECT_SYSZR(proc, chmod("/proc/self/net", 0555)); break;