getcwd01: Implement .test_variants
PATCH 1/1 getcwd01: Implement .test_variants
--- testcases/kernel/syscalls/getcwd/getcwd01.c | 81 ++++++++++++++------- 1 file changed, 55 insertions(+), 26 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd01.c +55 -26
@@ -1,23 +1,12 @@// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2023 Wei Gao <[email protected]> */ /* * 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. -* -* 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. +* Testcase to test that getcwd() sets errno correctly. */ #include <errno.h>
@@ -27,28 +16,68 @@#include "lapi/syscalls.h" static char buffer[5 ]; - -static struct t_case { +struct getcwd_variants { +void (*getcwd)(char *buf,size_t size,int exp_err);char *buf;size_t size;int exp_err; -} tcases[] = { - {(void *)-1 ,PATH_MAX ,EFAULT }, - {NULL , (size_t )-1 ,EFAULT }, - {buffer,0 ,ERANGE }, - {buffer,1 ,ERANGE }, - {NULL ,1 ,ERANGE } }; +static void verify_getcwd_raw_syscall (char *buf,size_t size,int exp_err); +static void verify_getcwd (char *buf,size_t size,int exp_err); + +static struct getcwd_variants variants[] = { +#ifdef __GLIBC__ + { .getcwd = verify_getcwd, .buf = NULL, .size = (size_t)-1, .exp_err = ENOMEM}, + { .getcwd = verify_getcwd, .buf = NULL, .size = 1, .exp_err = ERANGE}, +#endif + { .getcwd = verify_getcwd, .buf = (void *)-1, .size = PATH_MAX, .exp_err = EFAULT}, + { .getcwd = verify_getcwd, .buf = buffer, .size = 0, .exp_err = EINVAL}, + { .getcwd = verify_getcwd, .buf = buffer, .size = 1, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = buffer, .size = 0, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = (void *)-1, .size = PATH_MAX, .exp_err = EFAULT}, + { .getcwd = verify_getcwd_raw_syscall, .buf = NULL, .size = (size_t)-1, .exp_err = EFAULT}, + { .getcwd = verify_getcwd_raw_syscall, .buf = buffer, .size = 0, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = buffer, .size = 1, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = NULL, .size = 1, .exp_err = ERANGE}, +}; + +static void verify_getcwd(char *buf, size_t size, int exp_err) +{ + char *res; + + errno = 0; + res = getcwd(buf, size); + TST_ERR = errno; + if (res) { + tst_res(TFAIL, "getcwd() succeeded unexpectedly"); + return; + } + + if (TST_ERR != exp_err) { + tst_res(TFAIL | TTERRNO, "getcwd() failed unexpectedly, expected %s", + tst_strerrno(exp_err)); + return; + } + + tst_res(TPASS | TTERRNO, "getcwd() failed as expected"); + +} + +static void verify_getcwd_raw_syscall(char *buf, size_t size, int exp_err) +{ + + TST_EXP_FAIL2(tst_syscall(__NR_getcwd, buf, size), exp_err); +} -static void verify_getcwd (unsigned int n) +static void verify(void) { -struct t_case *tc = &tcases[n]; + struct getcwd_variants *tv = &variants[tst_variant]; -TST_EXP_FAIL2 (tst_syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err); + tv->getcwd(tv->buf, tv->size, tv->exp_err); } static struct tst_test test = { - .tcnt =ARRAY_SIZE (tcases), - .test = verify_getcwd + .test_variants = ARRAY_SIZE(variants), + .test_all = verify, };
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
Quoted 8 lines
/*
* 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.
Quoted 8 lines
- *
- * 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.
+ * Testcase to test thatgetcwd()sets errno correctly.
We prefer to keep info about tested errno (you can write errno or errnos if they are different for syscall into it).
* 1) getcwd(2) fails if buf points to a bad address (EFAULT)
* 2) getcwd(2) fails if the size is invalid (ERANGE)
Quoted 27 lines
#include <
errno.h>testcases/kernel/syscalls/getcwd/getcwd01.c +9
-8@@ -27,28 +16,68 @@#include "lapi/syscalls.h" static char buffer[5 ]; - -static struct t_case { +struct getcwd_variants { +void (*getcwd)(char *buf,size_t size,int exp_err);char *buf;size_t size;int exp_err; -} tcases[] = { - {(void *)-1 ,PATH_MAX ,EFAULT }, - {NULL , (size_t )-1 ,EFAULT }, - {buffer,0 ,ERANGE }, - {buffer,1 ,ERANGE }, - {NULL ,1 ,ERANGE } }; +static void verify_getcwd_raw_syscall (char *buf,size_t size,int exp_err); +static void verify_getcwd (char *buf,size_t size,int exp_err); + +static struct getcwd_variants variants[] = { +#ifdef __GLIBC__ + { .getcwd = verify_getcwd, .buf = NULL, .size = (size_t)-1, .exp_err = ENOMEM}, + { .getcwd = verify_getcwd, .buf = NULL, .size = 1, .exp_err = ERANGE},
testcases/kernel/syscalls/getcwd/getcwd01.c line 42
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +10
-0+#endif + { .getcwd = verify_getcwd, .buf = (void *)-1, .size = PATH_MAX, .exp_err = EFAULT}, + { .getcwd = verify_getcwd, .buf = buffer, .size = 0, .exp_err = EINVAL}, + { .getcwd = verify_getcwd, .buf = buffer, .size = 1, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = buffer, .size = 0, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = (void *)-1, .size = PATH_MAX, .exp_err = EFAULT}, + { .getcwd = verify_getcwd_raw_syscall, .buf = NULL, .size = (size_t)-1, .exp_err = EFAULT}, + { .getcwd = verify_getcwd_raw_syscall, .buf = buffer, .size = 0, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = buffer, .size = 1, .exp_err = ERANGE}, + { .getcwd = verify_getcwd_raw_syscall, .buf = NULL, .size = 1, .exp_err = ERANGE},
Well, this is works, but we don't use test variants this way. We define .test_variants in struct tst_test. Please have look how getdents01.c for example.
Why it's important (besides consistency of how we write tests)? We parse test_variants in our documentation.
https://github.com/linux-test-project/ltp/releases/download/20230929/metadata.20230929.html
=> see metadata.html#test_variants in your locally downloaded file, or run:
cd metadata && make && chromium ../docparse/*.html
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 getcwd01: Implement .test_variants
In reply to Wei Gao via ltp--- testcases/kernel/syscalls/getcwd/getcwd.h | 80 +++++++++++++++++++++ testcases/kernel/syscalls/getcwd/getcwd01.c | 35 ++++++--- 2 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 testcases/kernel/syscalls/getcwd/getcwd.h
testcases/kernel/syscalls/getcwd/getcwd.h new file +80 -0
@@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2013 Cyril Hrubis <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef GETCWD_H +#define GETCWD_H + +#include <stdint.h> +#include "config.h" +#include "lapi/syscalls.h" + +static inline void +check_getcwd (char *buf,size_t size,int exp_err) +{ +char *res; + + errno =0 ; + res =getcwd (buf, size); +TST_ERR = errno; +if (res) { +tst_res (TFAIL ,"getcwd() succeeded unexpectedly" ); +return ; + } + +if (TST_ERR != exp_err) { +tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , +tst_strerrno (exp_err)); +return ; + } + +tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +} + +static inline void +tst_getcwd (char *buf,size_t size,int exp_err,int exp_err2) +{ +switch (tst_variant) { +case 0 : +TST_EXP_FAIL2 (tst_syscall (__NR_getcwd, buf, size), exp_err); +break ; +case 1 : +#ifdef __GLIBC__ +check_getcwd (buf, size, exp_err2); +#endif +break ; + } +} + +static inline void +getcwd_info (void ) +{ +switch (tst_variant) { +case 0 : +tst_res (TINFO ,"Testing getcwd with raw syscall" ); +break ; +case 1 : +tst_res (TINFO ,"Testing getcwd with wrap syscall" ); +break ; + } +} + +#define TEST_VARIANTS 2 + +#endif /* GETCWD_H */
testcases/kernel/syscalls/getcwd/getcwd01.c +25 -10
@@ -13,18 +13,26 @@* 5) getcwd(2) fails if buf points to NULL and the size is set to 1. * * Expected Result: +* 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 +* 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> #include <unistd.h> #include <limits.h> #include "tst_test.h" -#include "lapi/syscalls.h" +#include "getcwd.h" static char buffer[5 ];
@@ -32,23 +40,30 @@ static struct t_case {char *buf;size_t size;int exp_err; +int exp_err2; } 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 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); + tst_getcwd(tc->buf, tc->size, tc->exp_err, tc->exp_err2); +} + +static void setup(void) +{ + getcwd_info(); } static struct tst_test test = { + .setup = setup, .tcnt = ARRAY_SIZE(tcases), - .test = verify_getcwd + .test = run, + .test_variants = TEST_VARIANTS, };
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
testcases/kernel/syscalls/getcwd/getcwd.h
Quoted 12 lines
Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/getcwd/getcwd.h | 80 +++++++++++++++++++++ testcases/kernel/syscalls/getcwd/getcwd01.c | 35 ++++++--- 2 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 testcases/kernel/syscalls/getcwd/getcwd.htestcases/kernel/syscalls/getcwd/getcwd.h new file +0
-0
First, I don't think it's a good idea to create getcwd.h, when code is used only in single source. It should be in getcwd01.c. And looking into other getcwd0*.c sources, I would use test_variants only in this source.
testcases/kernel/syscalls/getcwd/getcwd.h line 4
Quoted 5 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +4
-0@@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2013 Cyril Hrubis <[email protected]>
Why these two copyrights?
Quoted 4 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +4
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or
testcases/kernel/syscalls/getcwd/getcwd.h line 18
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +10
-0+* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
You know that SPDX is used to replaced this verbose license text, right?
testcases/kernel/syscalls/getcwd/getcwd.h line 22
Quoted 4 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +4
-0+*/ + +#ifndef GETCWD_H +#define GETCWD_H
We usually add trailing __ to avoid theoretical clash with third party headers. (GETCWD_H__).
testcases/kernel/syscalls/getcwd/getcwd.h line 29
Quoted 6 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +6
-0+#include <stdint.h> +#include "config.h" +#include "lapi/syscalls.h" + +static inline void +check_getcwd (char *buf,size_t size,int exp_err)
This should be on single line. If you copy pasted it from something, that was probably where signature was much longer than 80 char, this is even less than 80 chars.
testcases/kernel/syscalls/getcwd/getcwd.h line 34
Quoted 5 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +5
-0+{ +char *res; + + errno =0 ; + res =getcwd (buf, size);
Why so complicated code? Why not just use TST_EXP_FAIL2() as you do in tst_getcwd()? That would be way fewer lines of code. There is no problem to use TST_EXP_FAIL2() with libc syscall wrappers.
Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +7
-0+TST_ERR = errno; +if (res) { +tst_res (TFAIL ,"getcwd() succeeded unexpectedly" ); +return ; + } + +if (TST_ERR != exp_err) {
testcases/kernel/syscalls/getcwd/getcwd.h line 51
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +10
-0+tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , +tst_strerrno (exp_err)); +return ; + } + +tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +} + +static inline void +tst_getcwd (char *buf,size_t size,int exp_err,int exp_err2)
And here as well: this should be on single line.
testcases/kernel/syscalls/getcwd/getcwd.h line 52
Quoted 2 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +2
-0+{ +switch (tst_variant) {
Please, do not use switch for 2 variants, if is much readable in this case.
testcases/kernel/syscalls/getcwd/getcwd.h line 58
Quoted 5 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +5
-0+case 0 : +TST_EXP_FAIL2 (tst_syscall (__NR_getcwd, buf, size), exp_err); +break ; +case 1 : +#ifdef __GLIBC__
#1084 [1] reported problem on MUSL only. Your original patch [2] to fix #1084 skipped only 2 of tests, which used NULL buffer. Why now skip everything? Please skip only these two and put comment about musl and #1084 to be obvious why you do that. You could also add note to the git commit message. Not documenting this will raise questions in the future.
Also, looking that into bionic [3], it's compatible with glibc and uclibc{,-ng} (I'll verify it with Edward Liaw from Google), thus I would check like in run(unsigned int n):
static void run(unsigned int n)
{
struct t_case *tc = &tcases[n];
/* 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_err2); }
Or we could skip NULL buffer test on all libc.
[1] https://github.com/linux-test-project/ltp/issues/1084
[2] https://lore.kernel.org/ltp/[email protected]/
[3] https://android.googlesource.com/platform/bionic.git/+/refs/tags/android-14.0.0_r18/libc/bionic/getcwd.cpp
testcases/kernel/syscalls/getcwd/getcwd.h line 66
Quoted 8 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +8
-0+check_getcwd (buf, size, exp_err2); +#endif +break ; + } +} + +static inline void +getcwd_info (void )
This should be on single line.
testcases/kernel/syscalls/getcwd/getcwd.h line 75
Quoted 9 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +9
-0+{ +switch (tst_variant) { +case 0 : +tst_res (TINFO ,"Testing getcwd with raw syscall" ); +break ; +case 1 : +tst_res (TINFO ,"Testing getcwd with wrap syscall" ); +break ; + }
Instead of this, I would add direct TINFO messages to the setup function in getcwd01.c. Again, once this is used in 2 sources, it makes sense to have custom function to it, otherwise not.
And we should rethink, how to simplify using test_variants on these simple cases (I did some proposal in the past, I should get back to it; the problem is with that some tests use clock_adjtime.h, which is a bit complicate than this raw syscall vs. libc wrapper simple use case).
testcases/kernel/syscalls/getcwd/getcwd.h line 78
Quoted 3 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +3
-0+} + +#define TEST_VARIANTS 2
Instead of this define I would just put 2 into .test_variants = (again, only used in single file).
testcases/kernel/syscalls/getcwd/getcwd01.c line 16
Quoted 11 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +2
-0+ +#endif /* GETCWD_H */ testcases/kernel/syscalls/getcwd/getcwd01.c +1
-0@@ -13,18 +13,26 @@* 5) getcwd(2) fails if buf points to NULL and the size is set to 1. * * Expected Result: +* linux syscall
Well, I told you several times, that list requires separating by blank line otherwise it breaks formatting. Could you please add it and check generated docparse before sending a patch:
cd metadata && make && chromium ../docparse/*.html
We should check for it in metaparse.c or in testinfo.pl.
testcases/kernel/syscalls/getcwd/getcwd01.c line 23
Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +2
-0* 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
FYI #ifdef __GLIBC__ means glibc and uclibc{,-ng}. Also, again missing blank line before list.
Quoted 17 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +6
-1+* 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> #include <unistd.h> #include <limits.h> #include "tst_test.h" -#include "lapi/syscalls.h" +#include "getcwd.h" static char buffer[5 ];
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 43
Quoted 4 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-0@@ -32,23 +40,30 @@ static struct t_case {char *buf;size_t size;int exp_err; +int exp_err2;
Maybe exp_err_kernel and exp_err_libc would actually describe the purpose.
Quoted 6 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +0
-5} tcases[] = { - {(void *)-1, PATH_MAX, EFAULT}, - {NULL, (size_t)-1, EFAULT}, - {buffer, 0, ERANGE}, - {buffer, 1, ERANGE}, - {NULL, 1, ERANGE}
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 52
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +6
-2+ {(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 void verify_getcwd (unsigned int n) +static void run (unsigned int n)
nit: this can stay verify_getcwd().
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 61
Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +6
-1{struct t_case *tc = &tcases[n]; -TST_EXP_FAIL2 (tst_syscall (__NR_getcwd, tc->buf, tc->size), tc->exp_err); +tst_getcwd (tc->buf, tc->size, tc->exp_err, tc->exp_err2); +} + +static void setup (void ) +{ +getcwd_info ();
There is no point to use wrappers like this (I guess I have told you on different patch). We would specify .setup = getcwd_info, in the struct tst_test. But as I wrote above, better would be to move content of getcwd_info() to setup function.
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 68
Quoted 8 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +3
-1}static struct tst_test test = { + .setup = setup, .tcnt =ARRAY_SIZE (tcases), - .test = verify_getcwd + .test = run, + .test_variants =TEST_VARIANTS ,
.test_variants = 2,
testcases/kernel/syscalls/getcwd/getcwd01.c static struct t_case { · line 69
Quoted 1 line
testcases/kernel/syscalls/getcwd/getcwd01.c +0
-0};
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Li, Cyril,
...
Quoted 32 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static inline void +tst_getcwd(char *buf, size_t size, int exp_err, int exp_err2)And here as well: this should be on single line.
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + switch (tst_variant) {Please, do not use switch for 2 variants, if is much readable in this case.
testcases/kernel/syscalls/getcwd/getcwd.h line 58
Quoted 5 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +5
-0+case 0 : +TST_EXP_FAIL2 (tst_syscall (__NR_getcwd, buf, size), exp_err); +break ; +case 1 : +#ifdef __GLIBC__#1084 [1] reported problem on MUSL only. Your original patch [2] to fix #1084 skipped only 2 of tests, which used NULL buffer. Why now skip everything? Please skip only these two and put comment about musl and #1084 to be obvious why you do that. You could also add note to the git commit message. Not documenting this will raise questions in the future.
Also, looking that into bionic [3], it's compatible with glibc and uclibc{,-ng} (I'll verify it with Edward Liaw from Google), thus I would check like in run(unsigned int n):
static void run(unsigned int n)
{ struct t_case *tc = &tcases[n]; /* 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; }
Quoted 1 line
#endif
@Li @Cyril: are you ok to test libc getcwd() wrapper implementations on NULL buffer in getcwd01.c? Or we just skip NULL buffer test on all libc? I would be ok to test it, because change in the implementation can influence lots of user space software, although glibc or any other libc can obviously change it's behavior.
Kind regards,
Petr
Quoted 8 lines
tst_getcwd(tc->buf, tc->size, tc->exp_err, tc->exp_err2); }Or we could skip NULL buffer test on all libc.
[1] https://github.com/linux-test-project/ltp/issues/1084
[2] https://lore.kernel.org/ltp/[email protected]/
[3] https://android.googlesource.com/platform/bionic.git/+/refs/tags/android-14.0.0_r18/libc/bionic/getcwd.cpp
...
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 5 lines
@Li @Cyril: are you ok to test libc
getcwd()wrapper implementations on NULL buffer ingetcwd01.c? Or we just skip NULL buffer test on all libc? I would be ok to test it, because change in the implementation can influence lots of user space software, although glibc or any other libc can obviously change it's behavior.
I guess that the easiest solution is to run the test in a child and pass the test both on EFAULT and child being killed by SIGSEGV. Any special cases and ifdefs are assuming something that is not promised and will have to be changed sooner or later.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril, all,
Quoted 11 lines
Hi!
Quoted 5 lines
@Li @Cyril: are you ok to test libc
getcwd()wrapper implementations on NULL buffer ingetcwd01.c? Or we just skip NULL buffer test on all libc? I would be ok to test it, because change in the implementation can influence lots of user space software, although glibc or any other libc can obviously change it's behavior.I guess that the easiest solution is to run the test in a child and pass the test both on EFAULT and child being killed by SIGSEGV. Any special cases and ifdefs are assuming something that is not promised and will have to be changed sooner or later.
Good point. I guess something like testcases/kernel/syscalls/mmap/mmap05.c approach right? Wei, could you try that?
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 9 lines · Petr Vorel
Hi Cyril, all,
Quoted 6 lines
Hi!
Quoted 5 lines
@Li @Cyril: are you ok to test libc
getcwd()wrapper implementations on NULL buffer ingetcwd01.c? Or we just skip NULL buffer test on all libc? I would be ok to test it, because change in the implementation can influence lots of user space software, although glibc or any other libc can obviously change it's behavior.
Quoted 7 lines
Quoted 4 lines
I guess that the easiest solution is to run the test in a child and pass the test both on EFAULT and child being killed by SIGSEGV. Any special cases and ifdefs are assuming something that is not promised and will have to be changed sooner or later.
Good point. I guess something like
testcases/kernel/syscalls/mmap/mmap05.capproach right? Wei, could you try that?
Sure! Will check mmap05.c firstly.
Quoted 3 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 10 lines · Wei Gao via ltp
Quoted 9 lines · Petr Vorel
Hi Cyril, all,
Quoted 6 lines
Hi!
Quoted 5 lines
@Li @Cyril: are you ok to test libc
getcwd()wrapper implementations on NULL buffer ingetcwd01.c? Or we just skip NULL buffer test on all libc? I would be ok to test it, because change in the implementation can influence lots of user space software, although glibc or any other libc can obviously change it's behavior.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
I guess that the easiest solution is to run the test in a child and pass the test both on EFAULT and child being killed by SIGSEGV. Any special cases and ifdefs are assuming something that is not promised and will have to be changed sooner or later.
Good point. I guess something like
testcases/kernel/syscalls/mmap/mmap05.capproach right? Wei, could you try that?Sure! Will check
mmap05.cfirstly.
I have checked mmap05.c, got idea how to check SIGSEGV, but in current case NULL buffer will not trigger any SIGSEGV in musl(I have tested on musl env today). Correct me if i have misunderstanding.
BTW:I will continue update patch base Petr's former comments.
Quoted 6 lines
Quoted 3 lines
Kind regards,
PetrSignature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 10 lines · Petr Vorel
Hi Wei,
testcases/kernel/syscalls/getcwd/getcwd.h line 34
Quoted 5 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +5
-0+{ +char *res; + + errno =0 ; + res =getcwd (buf, size);Why so complicated code? Why not just use
TST_EXP_FAIL2()as you do intst_getcwd()? That would be way fewer lines of code. There is no problem to useTST_EXP_FAIL2()with libc syscall wrappers.
Current TST_EXP_FAIL2 can not handle getcwd (will return NULL). I remember in another email thread you mention maybe we need TST_EXP_FAIL_PTR.
Quoted 22 lines
Quoted 22 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +15
-0+TST_ERR = errno; +if (res) { +tst_res (TFAIL ,"getcwd() succeeded unexpectedly" ); +return ; + } + +if (TST_ERR != exp_err) { +tst_res (TFAIL |TTERRNO ,"getcwd() failed unexpectedly, expected %s" , +tst_strerrno (exp_err)); +return ; + } + +tst_res (TPASS |TTERRNO ,"getcwd() failed as expected" ); +} +testcases/kernel/syscalls/getcwd/getcwd01.c +0
-0@@ -13,18 +13,26 @@* 5) getcwd(2) fails if buf points to NULL and the size is set to 1.
Quoted 8 lines
testcases/kernel/syscalls/getcwd/getcwd01.c line 16
Quoted 3 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +1
-0* * Expected Result: +* linux syscall Well, I told you several times, that list requires separating by blank line otherwise it breaks formatting. Could you please add it and check generated docparse before sending a patch:
cd metadata && make && chromium ../docparse/*.html
We should check for it inmetaparse.cor in testinfo.pl.
The original code seems can not correctly handled by docparse since format is wrong, so acutally no any description item will appear in metadata file, same issue for getcwd02/03/04. I will update to correct format in getcwd01 next patch.
Quoted 15 lines
testcases/kernel/syscalls/getcwd/getcwd01.c line 23
Quoted 7 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +2
-0* 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 FYI #ifdef
__GLIBC__means glibc and uclibc{,-ng}. Also, again missing blank line before list.Quoted 6 lines
testcases/kernel/syscalls/getcwd/getcwd01.c +5
-0+* 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. */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
Quoted 11 lines · Petr Vorel
Quoted 10 lines
Hi Wei,
testcases/kernel/syscalls/getcwd/getcwd.h line 34
Quoted 5 lines
testcases/kernel/syscalls/getcwd/getcwd.h new file +5
-0+{ +char *res; + + errno =0 ; + res =getcwd (buf, size);Why so complicated code? Why not just use
TST_EXP_FAIL2()as you do intst_getcwd()? That would be way fewer lines of code. There is no problem to useTST_EXP_FAIL2()with libc syscall wrappers.
Quoted 2 lines
Current
TST_EXP_FAIL2can not handle getcwd (will return NULL). I remember in another email thread you mention maybe we needTST_EXP_FAIL_PTR.
Good point, thanks for working on it. It will use TESTPTR().
...
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/getcwd/getcwd01.c line 16
Quoted 6 lines
+++
b/testcases/kernel/syscalls/getcwd/getcwd01.ctestcases/kernel/syscalls/getcwd/getcwd01.c +1
-0@@ -13,18 +13,26 @@* 5) getcwd(2) fails if buf points to NULL and the size is set to 1. * * Expected Result: +* linux syscall Well, I told you several times, that list requires separating by blank line otherwise it breaks formatting. Could you please add it and check generated docparse before sending a patch:
cd metadata && make && chromium ../docparse/*.html
We should check for it inmetaparse.cor in testinfo.pl.
Quoted 3 lines
The original code seems can not correctly handled by docparse since format is wrong, so acutally no any description item will appear in metadata file, same issue for getcwd02/03/04. I will update to correct format in getcwd01 next patch.
Thank you!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 getcwd01: Implement .test_variants
In reply to Wei Gao via ltp--- testcases/kernel/syscalls/getcwd/getcwd01.c | 101 ++++++++++++++++---- 1 file changed, 81 insertions(+), 20 deletions(-)
NOTE:
Postpond create TST_EXP_FAIL_PTR in this patch since i saw some change request on this area:
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Also this patch will be continue updated base Cyril's feedback on new proposal(pass the test both on EFAULT and child being killed by SIGSEGV)
testcases/kernel/syscalls/getcwd/getcwd01.c +81 -20
@@ -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,71 @@ 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 check_getcwd(char *buf, size_t size, int exp_err) +{ + char *res; + + errno = 0; + res = getcwd(buf, size); + TST_ERR = errno; + if (res) { + tst_res(TFAIL, "getcwd() succeeded unexpectedly"); + return; + } + + if (TST_ERR != exp_err) { + tst_res(TFAIL | TTERRNO, "getcwd() failed unexpectedly, expected %s", + tst_strerrno(exp_err)); + return; + } -static void verify_getcwd(unsigned int n) + tst_res(TPASS | TTERRNO, "getcwd() failed as expected"); + +} + +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 + check_getcwd(buf, size, exp_err_libc); +} + +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, };
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp