From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] getcwd01: Use syscall directly check invalid argument
Date: Thu, 28 Sep 2023 20:45:18 -0400 [thread overview]
Message-ID: <20230929004518.29632-1-wegao@suse.com> (raw)
In-Reply-To: <20230928084408.21125-1-wegao@suse.com>
Fixes: #1084
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/getcwd/getcwd01.c | 27 ++++++---------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/testcases/kernel/syscalls/getcwd/getcwd01.c b/testcases/kernel/syscalls/getcwd/getcwd01.c
index 65d827873..ac35383a4 100644
--- a/testcases/kernel/syscalls/getcwd/getcwd01.c
+++ b/testcases/kernel/syscalls/getcwd/getcwd01.c
@@ -14,8 +14,8 @@
*
* Expected Result:
* 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.
+ * 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.
*
@@ -24,6 +24,7 @@
#include <errno.h>
#include <unistd.h>
#include <limits.h>
+#include "lapi/syscalls.h"
#include "tst_test.h"
static char buffer[5];
@@ -34,32 +35,18 @@ static struct t_case {
int exp_err;
} tcases[] = {
{(void *)-1, PATH_MAX, EFAULT},
- {NULL, (size_t)-1, ENOMEM},
- {buffer, 0, EINVAL},
+ {NULL, (size_t)-1, EFAULT},
+ {buffer, 0, ERANGE},
{buffer, 1, ERANGE},
{NULL, 1, ERANGE}
};
+
static void verify_getcwd(unsigned int n)
{
struct t_case *tc = &tcases[n];
- char *res;
-
- errno = 0;
- res = getcwd(tc->buf, tc->size);
- TST_ERR = errno;
- if (res) {
- tst_res(TFAIL, "getcwd() succeeded unexpectedly");
- return;
- }
-
- if (TST_ERR != tc->exp_err) {
- tst_res(TFAIL | TTERRNO, "getcwd() failed unexpectedly, expected %s",
- tst_strerrno(tc->exp_err));
- return;
- }
- tst_res(TPASS | TTERRNO, "getcwd() failed as expected");
+ TST_EXP_FAIL2(syscall(__NR_getcwd, tc->buf, tc->size), tc->exp_err);
}
static struct tst_test test = {
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-09-29 0:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 1:08 [LTP] [PATCH v1] getcwd01: Only check buffer NULL on glibc Wei Gao via ltp
2023-09-28 7:06 ` Richard Palethorpe
2023-09-28 8:44 ` [LTP] [PATCH v2] getcwd01: Use syscall directly check invalid argument Wei Gao via ltp
2023-09-28 17:55 ` Petr Vorel
2023-09-29 0:49 ` Wei Gao via ltp
2023-09-29 0:45 ` Wei Gao via ltp [this message]
2023-11-28 10:52 ` [LTP] [PATCH v3] " Petr Vorel
2023-12-01 3:52 ` Wei Gao via ltp
2023-11-28 10:53 ` Petr Vorel
2023-12-01 3:15 ` [LTP] [PATCH v4] " Wei Gao via ltp
2023-12-01 10:14 ` Petr Vorel
2023-12-04 0:06 ` Wei Gao via ltp
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=20230929004518.29632-1-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=wegao@suse.com \
/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