open08.c: Use TST_EXP_FAIL2() and SAFE_CLOSE()
PATCH v2 1/1 open08.c: Use TST_EXP_FAIL2() and SAFE_CLOSE()
Make use of TST_EXP_FAIL2() macro with testcase descriptions
--- testcases/kernel/syscalls/open/open08.c | 36 ++++++++----------------- 1 file changed, 11 insertions(+), 25 deletions(-)
testcases/kernel/syscalls/open/open08.c +11 -25
@@ -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 ); }
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
Quoted 1 line
Make use of
TST_EXP_FAIL2()macro with testcase descriptions
+1
Also +1 for static :).
...
Quoted 10 lines
+++
b/testcases/kernel/syscalls/open/open08.ctestcases/kernel/syscalls/open/open08.c +1
-3@@ -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},
testcases/kernel/syscalls/open/open08.c static struct test_case_t { · line 44
Quoted 10 lines
testcases/kernel/syscalls/open/open08.c +6
-3- {&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"} };
Instead of text descriptions I'd just print flags:
#define FLAGS_DESC(x) .flags = x, .desc = #x
static struct test_case_t {
char **fname;
int flags;
const char *desc;
int error;
} tcases[] = { {&existing_fname, FLAGS_DESC(O_CREAT | O_EXCL), EEXIST}, {&dir_fname, FLAGS_DESC(O_RDWR), EISDIR}, {&existing_fname, FLAGS_DESC(O_DIRECTORY), ENOTDIR}, {&toolong_fname, FLAGS_DESC(O_RDWR), ENAMETOOLONG}, {&user2_fname, FLAGS_DESC(O_WRONLY), EACCES}, {&unmapped_fname, FLAGS_DESC(O_CREAT), EFAULT},
};
# ./open08 tst_test.c:1526: TINFO: Timeout per run is 0h 00m 30s open08.c:52: TPASS: O_CREAT | O_EXCL : EEXIST (17) open08.c:52: TPASS: O_RDWR : EISDIR (21) open08.c:52: TPASS: O_DIRECTORY : ENOTDIR (20) open08.c:52: TPASS: O_RDWR : ENAMETOOLONG (36) open08.c:52: TPASS: O_WRONLY : EACCES (13) open08.c:52: TPASS: O_CREAT : EFAULT (14)
If you agree, I can merge it with this change.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Petr,
Quoted 58 lines · IST Petr Vorel
Hi Avinesh,
Quoted 1 line
Make use of
TST_EXP_FAIL2()macro with testcase descriptions+1
Also +1 for static :).
...
Quoted 10 lines
+++
b/testcases/kernel/syscalls/open/open08.ctestcases/kernel/syscalls/open/open08.c +1
-3@@ -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},testcases/kernel/syscalls/open/open08.c static struct test_case_t { · line 44
Quoted 10 lines
testcases/kernel/syscalls/open/open08.c +6
-3- {&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"} };Reviewed-by Petr Vorel <[email protected]>Instead of text descriptions I'd just print flags:
#define
FLAGS_DESC(x).flags = x, .desc = #xstatic struct test_case_t { char **fname; int flags; const char *desc; int error; } tcases[] = {{
&existing_fname,FLAGS_DESC(O_CREAT | O_EXCL), EEXIST}, {&dir_fname,FLAGS_DESC(O_RDWR), EISDIR}, {&existing_fname,FLAGS_DESC(O_DIRECTORY), ENOTDIR}, {&toolong_fname,FLAGS_DESC(O_RDWR), ENAMETOOLONG}, {&user2_fname,FLAGS_DESC(O_WRONLY), EACCES}, {&unmapped_fname,FLAGS_DESC(O_CREAT), EFAULT},
};# ./open08 tst_test.c:1526: TINFO: Timeout per run is 0h 00m 30s open08.c:52: TPASS: O_CREAT | O_EXCL : EEXIST (17) open08.c:52: TPASS: O_RDWR : EISDIR (21) open08.c:52: TPASS: O_DIRECTORY : ENOTDIR (20) open08.c:52: TPASS: O_RDWR : ENAMETOOLONG (36) open08.c:52: TPASS: O_WRONLY : EACCES (13) open08.c:52: TPASS: O_CREAT : EFAULT (14)
Quoted 1 line
If you agree, I can merge it with this change.
Yes, this is nice, please go ahead.
Quoted 4 lines
Kind regards,
Petr
Thanks,
Avinesh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
Quoted 2 lines
Quoted 1 line
If you agree, I can merge it with this change.
Yes, this is nice, please go ahead.
Good, merged. Thanks!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp