[LTP] [PATCH v3 2/2] getcwd01: Implement .test_variants
Wei Gao
wegao@suse.com
Wed Jan 17 13:52:27 CET 2024
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/getcwd/getcwd01.c | 80 +++++++++++++++------
1 file changed, 60 insertions(+), 20 deletions(-)
NOTE: Cyril give solution for run the test in a child and pass
the test both on EFAULT and child being killed by SIGSEGV. But
currently i have no idea how to do it since no SIGSEGV will hapeen
if NULL buffer give to getcwd. This file just used for give a real
user case for TST_EXP_FAIL_PTR.
diff --git a/testcases/kernel/syscalls/getcwd/getcwd01.c b/testcases/kernel/syscalls/getcwd/getcwd01.c
index 218bf4ef2..879c36206 100644
--- a/testcases/kernel/syscalls/getcwd/getcwd01.c
+++ b/testcases/kernel/syscalls/getcwd/getcwd01.c
@@ -3,21 +3,34 @@
* Copyright (c) International Business Machines Corp., 2001
*/
-/*
- * DESCRIPTION
+/*\
+ * [Description]
+ *
* Testcase to test that getcwd(2) sets errno correctly.
- * 1) getcwd(2) fails if buf points to a bad address.
- * 2) getcwd(2) fails if the size is invalid.
- * 3) getcwd(2) fails if the size is set to 0.
- * 4) getcwd(2) fails if the size is set to 1.
- * 5) getcwd(2) fails if buf points to NULL and the size is set to 1.
+ *
+ * 1. getcwd(2) fails if buf points to a bad address.
+ * 2. getcwd(2) fails if the size is invalid.
+ * 3. getcwd(2) fails if the size is set to 0.
+ * 4. getcwd(2) fails if the size is set to 1.
+ * 5. getcwd(2) fails if buf points to NULL and the size is set to 1.
*
* Expected Result:
- * 1) getcwd(2) should return NULL and set errno to EFAULT.
- * 2) getcwd(2) should return NULL and set errno to EFAULT.
- * 3) getcwd(2) should return NULL and set errno to ERANGE.
- * 4) getcwd(2) should return NULL and set errno to ERANGE.
- * 5) getcwd(2) should return NULL and set errno to ERANGE.
+ *
+ * linux syscall
+ *
+ * 1. getcwd(2) should return NULL and set errno to EFAULT.
+ * 2. getcwd(2) should return NULL and set errno to EFAULT.
+ * 3. getcwd(2) should return NULL and set errno to ERANGE.
+ * 4. getcwd(2) should return NULL and set errno to ERANGE.
+ * 5. getcwd(2) should return NULL and set errno to ERANGE.
+ *
+ * glibc and uclibc{,-ng}.
+ *
+ * 1. getcwd(2) should return NULL and set errno to EFAULT.
+ * 2. getcwd(2) should return NULL and set errno to ENOMEM.
+ * 3. getcwd(2) should return NULL and set errno to EINVAL.
+ * 4. getcwd(2) should return NULL and set errno to ERANGE.
+ * 5. getcwd(2) should return NULL and set errno to ERANGE.
*/
#include <errno.h>
@@ -32,23 +45,50 @@ static struct t_case {
char *buf;
size_t size;
int exp_err;
+ int exp_err_libc;
} tcases[] = {
- {(void *)-1, PATH_MAX, EFAULT},
- {NULL, (size_t)-1, EFAULT},
- {buffer, 0, ERANGE},
- {buffer, 1, ERANGE},
- {NULL, 1, ERANGE}
+ {(void *)-1, PATH_MAX, EFAULT, EFAULT},
+ {NULL, (size_t)-1, EFAULT, ENOMEM},
+ {buffer, 0, ERANGE, EINVAL},
+ {buffer, 1, ERANGE, ERANGE},
+ {NULL, 1, ERANGE, ERANGE},
};
+static inline void tst_getcwd(char *buf, size_t size, int exp_err, int exp_err_libc)
+{
+
+ if (tst_variant == 0)
+ TST_EXP_FAIL2(tst_syscall(__NR_getcwd, buf, size), exp_err);
+ else
+ TST_EXP_FAIL_PTR(getcwd(buf, size), exp_err_libc);
+}
-static void verify_getcwd(unsigned int n)
+static void run(unsigned int n)
{
struct t_case *tc = &tcases[n];
- TST_EXP_FAIL2(tst_syscall(__NR_getcwd, tc->buf, tc->size), tc->exp_err);
+ /* https://github.com/linux-test-project/ltp/issues/1084 */
+#if !defined(__GLIBC__) && !defined(__ANDROID__)
+ if (tst_variant && !tc->buf) {
+ tst_res(TCONF, "NULL buffer test skipped on MUSL due different implementation");
+ return;
+ }
+#endif
+
+ tst_getcwd(tc->buf, tc->size, tc->exp_err, tc->exp_err_libc);
+}
+
+static void setup(void)
+{
+ if (tst_variant == 0)
+ tst_res(TINFO, "Testing getcwd with raw syscall");
+ else
+ tst_res(TINFO, "Testing getcwd with wrap syscall");
}
static struct tst_test test = {
+ .setup = setup,
.tcnt = ARRAY_SIZE(tcases),
- .test = verify_getcwd
+ .test = run,
+ .test_variants = 2,
};
--
2.35.3
More information about the ltp
mailing list