From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] open08.c: Use TST_EXP_FAIL2() and SAFE_CLOSE()
Date: Sun, 10 Jul 2022 16:14:49 +0530 [thread overview]
Message-ID: <20220710104449.10387-1-akumar@suse.de> (raw)
Make use of TST_EXP_FAIL2() macro with testcase descriptions
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
testcases/kernel/syscalls/open/open08.c | 36 ++++++++-----------------
1 file changed, 11 insertions(+), 25 deletions(-)
diff --git a/testcases/kernel/syscalls/open/open08.c b/testcases/kernel/syscalls/open/open08.c
index 890fe2818..0742324c9 100644
--- a/testcases/kernel/syscalls/open/open08.c
+++ b/testcases/kernel/syscalls/open/open08.c
@@ -33,34 +33,20 @@ static struct test_case_t {
char **fname;
int flags;
int error;
+ const char *desc;
} tcases[] = {
- {&existing_fname, O_CREAT | O_EXCL, EEXIST},
- {&dir_fname, O_RDWR, EISDIR},
- {&existing_fname, O_DIRECTORY, ENOTDIR},
- {&toolong_fname, O_RDWR, ENAMETOOLONG},
- {&user2_fname, O_WRONLY, EACCES},
- {&unmapped_fname, O_CREAT, EFAULT}
+ {&existing_fname, O_CREAT | O_EXCL, EEXIST, "open() existing file with 'O_CREAT | O_EXCL'"},
+ {&dir_fname, O_RDWR, EISDIR, "open() existing directory with write access"},
+ {&existing_fname, O_DIRECTORY, ENOTDIR, "open() non-directory pathname with O_DIRECTORY"},
+ {&toolong_fname, O_RDWR, ENAMETOOLONG, "open() too long pathname"},
+ {&user2_fname, O_WRONLY, EACCES, "open() file without requested access rights"},
+ {&unmapped_fname, O_CREAT, EFAULT, "open() pathname with bad address"}
};
-void verify_open(unsigned int i)
+static void verify_open(unsigned int i)
{
- TEST(open(*tcases[i].fname, tcases[i].flags,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "call succeeded unexpectedly");
- return;
- }
-
- if (TST_ERR == tcases[i].error) {
- tst_res(TPASS, "expected failure - "
- "errno = %d : %s", TST_ERR,
- strerror(TST_ERR));
- } else {
- tst_res(TFAIL, "unexpected error - %d : %s - "
- "expected %d", TST_ERR,
- strerror(TST_ERR), tcases[i].error);
- }
+ TST_EXP_FAIL2(open(*tcases[i].fname, tcases[i].flags, 0644),
+ tcases[i].error, "%s", tcases[i].desc);
}
static void setup(void)
@@ -79,7 +65,7 @@ static void setup(void)
SAFE_SETUID(ltpuser->pw_uid);
fildes = SAFE_CREAT(existing_fname, 0600);
- close(fildes);
+ SAFE_CLOSE(fildes);
unmapped_fname = tst_get_bad_addr(NULL);
}
--
2.36.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2022-07-10 10:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-10 10:44 Avinesh Kumar [this message]
2022-07-11 6:40 ` [LTP] [PATCH v2] open08.c: Use TST_EXP_FAIL2() and SAFE_CLOSE() Petr Vorel
2022-07-11 8:59 ` Avinesh Kumar
2022-07-11 14:59 ` Petr Vorel
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=20220710104449.10387-1-akumar@suse.de \
--to=akumar@suse.de \
--cc=ltp@lists.linux.it \
/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