* [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API
@ 2022-02-16 11:10 Andrea Cervesato
2022-02-16 12:59 ` Petr Vorel
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Andrea Cervesato @ 2022-02-16 11:10 UTC (permalink / raw)
To: ltp
confstr01.c test has been rewritten to support new LTP API and fix
compiling issues when it's compiled under systems using libmusl by
default.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
testcases/kernel/syscalls/confstr/confstr01.c | 191 ++++++++----------
1 file changed, 82 insertions(+), 109 deletions(-)
diff --git a/testcases/kernel/syscalls/confstr/confstr01.c b/testcases/kernel/syscalls/confstr/confstr01.c
index 0fc4c46d5..17b9bd06c 100644
--- a/testcases/kernel/syscalls/confstr/confstr01.c
+++ b/testcases/kernel/syscalls/confstr/confstr01.c
@@ -1,136 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2002
- *
- * 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
+ * Copyright (c) International Business Machines Corp., 2002
+ * 11/20/2002 Port to LTP robbiew@us.ibm.com
+ * 06/30/2001 Port to Linux nsharoff@us.ibm.com
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
*/
-/* 11/20/2002 Port to LTP robbiew@us.ibm.com */
-/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
-
-/*
- * NAME
- * confstr1.c - test for confstr(3C) - Get configuration-defined string
- * values.
- *
- * CALLS
- * confstr(3C)
- *
- * RESTRICTIONS
- * MUST RUN AS ROOT
+/*\
+ * [Description]
*
+ * Test constr functionality.
*/
#define _XOPEN_SOURCE 500
+#include <stdlib.h>
#include <unistd.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
static struct test_case_t {
int value;
char *name;
} test_cases[] = {
- {_CS_PATH, "PATH"},
- {_CS_XBS5_ILP32_OFF32_CFLAGS, "XBS5_ILP32_OFF32_CFLAGS"},
- {_CS_XBS5_ILP32_OFF32_LDFLAGS, "XBS5_ILP32_OFF32_LDFLAGS"},
- {_CS_XBS5_ILP32_OFF32_LIBS, "XBS5_ILP32_OFF32_LIBS"},
- {_CS_XBS5_ILP32_OFF32_LINTFLAGS, "XBS5_ILP32_OFF32_LINTFLAGS"},
- {_CS_XBS5_ILP32_OFFBIG_CFLAGS, "XBS5_ILP32_OFFBIG_CFLAGS"},
- {_CS_XBS5_ILP32_OFFBIG_LDFLAGS, "XBS5_ILP32_OFFBIG_LDFLAGS"},
- {_CS_XBS5_ILP32_OFFBIG_LIBS, "XBS5_ILP32_OFFBIG_LIBS"},
- {_CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "XBS5_ILP32_OFFBIG_LINTFLAGS"},
- {_CS_XBS5_LP64_OFF64_CFLAGS, "XBS5_LP64_OFF64_CFLAGS"},
- {_CS_XBS5_LP64_OFF64_LDFLAGS, "XBS5_LP64_OFF64_LDFLAGS"},
- {_CS_XBS5_LP64_OFF64_LIBS, "XBS5_LP64_OFF64_LIBS"},
- {_CS_XBS5_LP64_OFF64_LINTFLAGS, "XBS5_LP64_OFF64_LINTFLAGS"},
- {_CS_XBS5_LPBIG_OFFBIG_CFLAGS, "XBS5_LPBIG_OFFBIG_CFLAGS"},
- {_CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "XBS5_LPBIG_OFFBIG_LDFLAGS"},
- {_CS_XBS5_LPBIG_OFFBIG_LIBS, "XBS5_LPBIG_OFFBIG_LIBS"},
- {_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS"},
- {_CS_GNU_LIBC_VERSION, "GNU_LIBC_VERSION"},
- {_CS_GNU_LIBPTHREAD_VERSION, "GNU_LIBPTHREAD_VERSION"},
+ { _CS_PATH, "PATH" },
+ { _CS_GNU_LIBC_VERSION, "GNU_LIBC_VERSION" },
+ { _CS_GNU_LIBPTHREAD_VERSION, "GNU_LIBPTHREAD_VERSION" },
+
+/* checking for obsolete configurations */
+#ifdef _CS_XBS5_ILP32_OFF32_CFLAGS
+ { _CS_XBS5_ILP32_OFF32_CFLAGS, "XBS5_ILP32_OFF32_CFLAGS" },
+#endif
+#ifdef _CS_XBS5_ILP32_OFF32_LDFLAGS
+ { _CS_XBS5_ILP32_OFF32_LDFLAGS, "XBS5_ILP32_OFF32_LDFLAGS" },
+#endif
+#ifdef _CS_XBS5_ILP32_OFF32_LIBS
+ { _CS_XBS5_ILP32_OFF32_LIBS, "XBS5_ILP32_OFF32_LIBS" },
+#endif
+#ifdef _CS_XBS5_ILP32_OFF32_LINTFLAGS
+ { _CS_XBS5_ILP32_OFF32_LINTFLAGS, "XBS5_ILP32_OFF32_LINTFLAGS" },
+#endif
+#ifdef _CS_XBS5_ILP32_OFFBIG_CFLAGS
+ { _CS_XBS5_ILP32_OFFBIG_CFLAGS, "XBS5_ILP32_OFFBIG_CFLAGS" },
+#endif
+#ifdef _CS_XBS5_ILP32_OFFBIG_LDFLAGS
+ { _CS_XBS5_ILP32_OFFBIG_LDFLAGS, "XBS5_ILP32_OFFBIG_LDFLAGS" },
+#endif
+#ifdef _CS_XBS5_ILP32_OFFBIG_LIBS
+ { _CS_XBS5_ILP32_OFFBIG_LIBS, "XBS5_ILP32_OFFBIG_LIBS" },
+#endif
+#ifdef _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
+ { _CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "XBS5_ILP32_OFFBIG_LINTFLAGS" },
+#endif
+#ifdef _CS_XBS5_LP64_OFF64_CFLAGS
+ { _CS_XBS5_LP64_OFF64_CFLAGS, "XBS5_LP64_OFF64_CFLAGS" },
+#endif
+#ifdef _CS_XBS5_LP64_OFF64_LDFLAGS
+ { _CS_XBS5_LP64_OFF64_LDFLAGS, "XBS5_LP64_OFF64_LDFLAGS" },
+#endif
+#ifdef _CS_XBS5_LP64_OFF64_LIBS
+ { _CS_XBS5_LP64_OFF64_LIBS, "XBS5_LP64_OFF64_LIBS" },
+#endif
+#ifdef _CS_XBS5_LP64_OFF64_LINTFLAGS
+ { _CS_XBS5_LP64_OFF64_LINTFLAGS, "XBS5_LP64_OFF64_LINTFLAGS" },
+#endif
+#ifdef _CS_XBS5_LPBIG_OFFBIG_CFLAGS
+ { _CS_XBS5_LPBIG_OFFBIG_CFLAGS, "XBS5_LPBIG_OFFBIG_CFLAGS" },
+#endif
+#ifdef _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
+ { _CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "XBS5_LPBIG_OFFBIG_LDFLAGS" },
+#endif
+#ifdef _CS_XBS5_LPBIG_OFFBIG_LIBS
+ { _CS_XBS5_LPBIG_OFFBIG_LIBS, "XBS5_LPBIG_OFFBIG_LIBS" },
+#endif
+#ifdef _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
+ { _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS" },
+#endif
};
-char *TCID = "confstr01";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int argc, char *argv[])
+static void run(unsigned int i)
{
- int lc;
- int i;
char *buf;
int len;
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
+ TEST(confstr(test_cases[i].value, NULL, (size_t)0));
- for (lc = 0; TEST_LOOPING(lc); lc++) {
+ if (TST_RET) {
+ len = TST_RET;
+ buf = SAFE_MALLOC(len);
- tst_count = 0;
+ TEST(confstr(test_cases[i].value, buf, len));
- for (i = 0; i < TST_TOTAL; i++) {
-
- TEST(confstr(test_cases[i].value, NULL, (size_t)0));
-
- if (TEST_RETURN != 0) {
- len = TEST_RETURN;
- buf = SAFE_MALLOC(cleanup, len);
- TEST(confstr(test_cases[i].value, buf, len));
-
- if (TEST_RETURN != len || buf[len-1] != '\0') {
- tst_brkm(TBROK, cleanup,
- "confstr :%s failed",
- test_cases[i].name);
- } else {
- tst_resm(TPASS, "confstr %s = '%s'",
- test_cases[i].name, buf);
- }
- free(buf);
- } else {
- if (TEST_ERRNO == EINVAL) {
- tst_resm(TCONF,
- "confstr %s not supported",
- test_cases[i].name);
- } else {
- tst_resm(TFAIL,
- "confstr %s failed",
- test_cases[i].name);
- }
- }
+ if (buf[len - 1] != '\0') {
+ tst_brk(TFAIL, "confstr: %s, %s", test_cases[i].name,
+ tst_strerrno(TST_ERR));
+ } else {
+ tst_res(TPASS, "confstr %s = '%s'", test_cases[i].name, buf);
}
- }
-
- cleanup();
-
- tst_exit();
-}
-static void setup(void)
-{
- TEST_PAUSE;
+ free(buf);
+ } else {
+ tst_brk(TFAIL, "confstr: %s, %s", test_cases[i].name, tst_strerrno(TST_ERR));
+ }
}
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .test = run,
+ .tcnt = ARRAY_SIZE(test_cases),
+};
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API
2022-02-16 11:10 [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API Andrea Cervesato
@ 2022-02-16 12:59 ` Petr Vorel
2022-02-17 8:10 ` Petr Vorel
2022-04-05 13:51 ` Petr Vorel
2 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2022-02-16 12:59 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
thanks for looking into this.
I was looking into the test in the past. The reason I haven't sent it is that
some of the definitions are in the legacy definition:
https://pubs.opengroup.org/onlinepubs/000095399/functions/confstr.html
in newer it's not:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html
...
> static struct test_case_t {
> int value;
> char *name;
> } test_cases[] = {
> - {_CS_PATH, "PATH"},
> - {_CS_XBS5_ILP32_OFF32_CFLAGS, "XBS5_ILP32_OFF32_CFLAGS"},
> - {_CS_XBS5_ILP32_OFF32_LDFLAGS, "XBS5_ILP32_OFF32_LDFLAGS"},
> - {_CS_XBS5_ILP32_OFF32_LIBS, "XBS5_ILP32_OFF32_LIBS"},
> - {_CS_XBS5_ILP32_OFF32_LINTFLAGS, "XBS5_ILP32_OFF32_LINTFLAGS"},
> - {_CS_XBS5_ILP32_OFFBIG_CFLAGS, "XBS5_ILP32_OFFBIG_CFLAGS"},
> - {_CS_XBS5_ILP32_OFFBIG_LDFLAGS, "XBS5_ILP32_OFFBIG_LDFLAGS"},
> - {_CS_XBS5_ILP32_OFFBIG_LIBS, "XBS5_ILP32_OFFBIG_LIBS"},
> - {_CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "XBS5_ILP32_OFFBIG_LINTFLAGS"},
> - {_CS_XBS5_LP64_OFF64_CFLAGS, "XBS5_LP64_OFF64_CFLAGS"},
> - {_CS_XBS5_LP64_OFF64_LDFLAGS, "XBS5_LP64_OFF64_LDFLAGS"},
> - {_CS_XBS5_LP64_OFF64_LIBS, "XBS5_LP64_OFF64_LIBS"},
> - {_CS_XBS5_LP64_OFF64_LINTFLAGS, "XBS5_LP64_OFF64_LINTFLAGS"},
> - {_CS_XBS5_LPBIG_OFFBIG_CFLAGS, "XBS5_LPBIG_OFFBIG_CFLAGS"},
> - {_CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "XBS5_LPBIG_OFFBIG_LDFLAGS"},
> - {_CS_XBS5_LPBIG_OFFBIG_LIBS, "XBS5_LPBIG_OFFBIG_LIBS"},
> - {_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS"},
> - {_CS_GNU_LIBC_VERSION, "GNU_LIBC_VERSION"},
> - {_CS_GNU_LIBPTHREAD_VERSION, "GNU_LIBPTHREAD_VERSION"},
> + { _CS_PATH, "PATH" },
> + { _CS_GNU_LIBC_VERSION, "GNU_LIBC_VERSION" },
man CONFSTR(3) shows
_CS_GNU_LIBC_VERSION (GNU C library only; since glibc 2.3.2)
And indeed it fails on musl:
confstr01.c:102: TFAIL: confstr: GNU_LIBC_VERSION, EINVAL
But musl defines in include/unistd.h:
#define _CS_GNU_LIBC_VERSION 2
to allow to compile but in src/conf/confstr.c is check which causes EINVAL:
https://git.etalabs.net/cgit/musl/tree/src/conf/confstr.c
size_t confstr(int name, char *buf, size_t len)
{
const char *s = "";
if (!name) {
s = "/bin:/usr/bin";
} else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>33U) {
errno = EINVAL;
return 0;
}
// snprintf is overkill but avoid wasting code size to implement
// this completely useless function and its truncation semantics
return snprintf(buf, len, "%s", s) + 1;
}
IMHO this one should be wrapped with #ifdef __GLIBC__.
Also not sure how about uclibc (it defines __GLIBC__ and it has compatible
headers, but sometimes things aren't implemented). It defines
_CS_GNU_LIBC_VERSION as "GNU_LIBC_VERSION", but code which is in posix/confstr.c
is missing. I might force myself to check it after work time.
...
> + TEST(confstr(test_cases[i].value, NULL, (size_t)0));
> + if (TST_RET) {
> + len = TST_RET;
> + buf = SAFE_MALLOC(len);
> + TEST(confstr(test_cases[i].value, buf, len));
> + if (buf[len - 1] != '\0') {
> + tst_brk(TFAIL, "confstr: %s, %s", test_cases[i].name,
> + tst_strerrno(TST_ERR));
> + } else {
> + tst_res(TPASS, "confstr %s = '%s'", test_cases[i].name, buf);
> }
> + } else {
> + tst_brk(TFAIL, "confstr: %s, %s", test_cases[i].name, tst_strerrno(TST_ERR));
> + }
Again, to use some TST_EXP_*() macros?
Maybe:
TST_EXP_POSITIVE(confstr(test_cases[i].value, NULL, (size_t)0));
if (!TST_PASS)
return;
len = TST_RET;
buf = SAFE_MALLOC(len);
TEST(confstr(test_cases[i].value, buf, len));
if (buf[len - 1] != '\0') {
tst_brk(TFAIL, "confstr: %s, %s", test_cases[i].name,
tst_strerrno(TST_ERR));
} else {
tst_res(TPASS, "confstr %s = '%s'", test_cases[i].name, buf);
}
free(buf);
=> code is simpler and works also on musl.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API
2022-02-16 11:10 [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API Andrea Cervesato
2022-02-16 12:59 ` Petr Vorel
@ 2022-02-17 8:10 ` Petr Vorel
2022-04-05 13:51 ` Petr Vorel
2 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2022-02-17 8:10 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi,
> #define _XOPEN_SOURCE 500
> +#include <stdlib.h>
> #include <unistd.h>
> +#include "tst_test.h"
When including headers like this we get warning due _XOPEN_SOURCE 500
rm -f -f -r confstr01 *.o *.pyc .cache.mk *.dwo .*.dwo
In file included from ../../../../include/tst_safe_net.h:15,
from ../../../../include/tst_test.h:100,
from confstr01.c:19:
../../../../include/tst_net.h:32:74: warning: ‘struct addrinfo’ declared inside parameter list will not be visible outside of this definition or declaration
32 | const char *port, const struct addrinfo *hints,
We need to load <stdlib.h> before _XOPEN_SOURCE 500.
IMHO _XOPEN_SOURCE 500 is for <unistd.h>, which defines these _CS_XBS5* definitions,
thus safe to do.
500 (X/Open 5) is for POSIX 1995. IMHO we should update (as a separate effort).
@Cyril don't we want to test POSIX 2008 (700)? Or even 2017 (not sure how to
define it?)
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API
2022-02-16 11:10 [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API Andrea Cervesato
2022-02-16 12:59 ` Petr Vorel
2022-02-17 8:10 ` Petr Vorel
@ 2022-04-05 13:51 ` Petr Vorel
2 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2022-04-05 13:51 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
FYI: I sent another version of this patchset:
https://patchwork.ozlabs.org/project/ltp/list/?series=293599
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-05 13:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-16 11:10 [LTP] [PATCH v1] Rewrite confstr01.c test using new LTP API Andrea Cervesato
2022-02-16 12:59 ` Petr Vorel
2022-02-17 8:10 ` Petr Vorel
2022-04-05 13:51 ` Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.