From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Daniel Palmer <daniel@thingy.jp>
Cc: w@1wt.eu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] selftests/nolibc: Add test for getcwd() and readlink()
Date: Sat, 2 May 2026 15:43:54 +0200 [thread overview]
Message-ID: <92e2cc56-2e7f-4af0-bb14-fdb4abb305b1@weissschuh.net> (raw)
In-Reply-To: <20260502072527.1805108-4-daniel@thingy.jp>
May 2, 2026 09:25:45 Daniel Palmer <daniel@thingy.jp>:
> Add a test for getcwd() that uses readlink() so tests that
> at the same time.
>
> This is very basic, just getting what should be the same
> string via getcwd() and readlink() and then checking they
> are the same.
>
> Signed-off-by: Daniel Palmer <daniel@thingy.jp>
> ---
> tools/testing/selftests/nolibc/nolibc-test.c | 26 ++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 08610cacf030..54513fb9a16a 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -849,6 +849,31 @@ static int test_dirent(void)
> return 0;
> }
>
> +static int test_getcwd(void)
> +{
> + char cwd_syscall[1024];
> + char cwd_proc[1024];
> + ssize_t len;
> +
> + /* Read where the link /proc/self/cwd points */
> + len = readlink("/proc/self/cwd", cwd_proc, sizeof(cwd_proc) - 1);
> + if (len <= 0)
> + return -1;
> +
> + /* Terminate the string from readlink() */
> + cwd_proc[len] = '\0';
> +
> + /* Get the cwd via syscall */
> + if (getcwd(cwd_syscall, sizeof(cwd_syscall)) == NULL)
> + return -1;
> +
> + /* Fail if they aren't the same */
> + if (strcmp(cwd_proc, cwd_syscall) != 0)
> + return -1;
> +
> + return 0;
> +}
> +
> int test_getrandom(void)
> {
> uint64_t rng = 0;
> @@ -1477,6 +1502,7 @@ int run_syscall(int min, int max)
> CASE_TEST(clock_getres); EXPECT_SYSZR(1, clock_getres(CLOCK_MONOTONIC, &ts)); break;
> CASE_TEST(clock_gettime); EXPECT_SYSZR(1, clock_gettime(CLOCK_MONOTONIC, &ts)); break;
> CASE_TEST(clock_settime); EXPECT_SYSER(1, clock_settime(CLOCK_MONOTONIC, &ts), -1, EINVAL); break;
> + CASE_TEST(getcwd); EXPECT_SYSZR(1, test_getcwd()); break;
EXPECT_SYSZR(proc, ...)
> CASE_TEST(getpid); EXPECT_SYSNE(1, getpid(), -1); break;
> CASE_TEST(getppid); EXPECT_SYSNE(1, getppid(), -1); break;
> CASE_TEST(gettid); EXPECT_SYSNE(has_gettid, gettid(), -1); break;
> --
> 2.53.0
prev parent reply other threads:[~2026-05-02 13:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-02 7:25 [PATCH 0/3] nolibc: Add " Daniel Palmer
2026-05-02 7:25 ` [PATCH 1/3] tools/nolibc: unistd: Add getcwd() Daniel Palmer
2026-05-02 13:41 ` Thomas Weißschuh
2026-05-05 9:07 ` Daniel Palmer
2026-05-02 7:25 ` [PATCH 2/3] tools/nolibc: unistd: Add readlink() Daniel Palmer
2026-05-02 13:42 ` Thomas Weißschuh
2026-05-02 7:25 ` [PATCH 3/3] selftests/nolibc: Add test for getcwd() and readlink() Daniel Palmer
2026-05-02 13:43 ` Thomas Weißschuh [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=92e2cc56-2e7f-4af0-bb14-fdb4abb305b1@weissschuh.net \
--to=linux@weissschuh.net \
--cc=daniel@thingy.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®