All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v1] Rewrite getcontext01.c test using new LTP API
@ 2022-02-16 10:40 Andrea Cervesato
  2022-02-16 11:49 ` Petr Vorel
  0 siblings, 1 reply; 2+ messages in thread
From: Andrea Cervesato @ 2022-02-16 10:40 UTC (permalink / raw)
  To: ltp

Removed old LTP API from getcontext01.c test and check if getcontext is
present in the current system. The check is useful in those systems
where libmusl is used by default.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 configure.ac                                  |  1 +
 .../kernel/syscalls/getcontext/getcontext01.c | 93 +++++--------------
 2 files changed, 24 insertions(+), 70 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8d2c5b1c4..41a21a636 100644
--- a/configure.ac
+++ b/configure.ac
@@ -97,6 +97,7 @@ AC_CHECK_FUNCS_ONCE([ \
     fspick \
     fstatat \
     getauxval \
+    getcontext \
     getdents \
     getdents64 \
     io_pgetevents \
diff --git a/testcases/kernel/syscalls/getcontext/getcontext01.c b/testcases/kernel/syscalls/getcontext/getcontext01.c
index 48e78907f..fe9971362 100644
--- a/testcases/kernel/syscalls/getcontext/getcontext01.c
+++ b/testcases/kernel/syscalls/getcontext/getcontext01.c
@@ -1,89 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Wipro Technologies Ltd, 2005.  All Rights Reserved.
- *  Author: Prashant P Yendigeri <prashant.yendigeri@wipro.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *               Author: Prashant P Yendigeri <prashant.yendigeri@wipro.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-#include <features.h>
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <ucontext.h>
-
-#include "test.h"
-
-char *TCID = "getcontext01";
+/*\
+ * [Description]
+ *
+ * Test getting user context functionality.
+ */
 
-#if !defined(__UCLIBC__)
+#include "config.h"
+#include "tst_test.h"
 
-static void setup(void);
-static void cleanup(void);
+#ifdef HAVE_GETCONTEXT
 
-int TST_TOTAL = 1;
+#include <ucontext.h>
 
-static void test_getcontext(void)
+static void run(void)
 {
 	ucontext_t ptr;
 
 	TEST(getcontext(&ptr));
 
-	if (TEST_RETURN == -1) {
-		if (errno == ENOSYS)
-			tst_resm(TCONF, "getcontext not implemented in libc");
-		else
-			tst_resm(TFAIL | TTERRNO, "getcontext failed");
-	} else if (TEST_RETURN == 0) {
-		tst_resm(TPASS, "getcontext passed");
-	} else {
-		tst_resm(TFAIL, "Unexpected return value %li", TEST_RETURN);
-	}
-}
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
+	if (TST_RET < 0)
+		tst_res(TFAIL, "getcontext: %s", tst_strerrno(TST_ERR));
 
-		test_getcontext();
-	}
-
-	cleanup();
-	tst_exit();
+	if (TST_RET == 0)
+		tst_res(TPASS, "getcontext passed");
+	else
+		tst_res(TFAIL, "Unexpected return value %li", TST_RET);
 }
 
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test_all = run,
+};
 
 #else /* systems that dont support obsolete getcontext */
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "system doesn't have getcontext support");
-}
+TST_TEST_TCONF("system doesn't have getcontext support");
 #endif
-- 
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH v1] Rewrite getcontext01.c test using new LTP API
  2022-02-16 10:40 [LTP] [PATCH v1] Rewrite getcontext01.c test using new LTP API Andrea Cervesato
@ 2022-02-16 11:49 ` Petr Vorel
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2022-02-16 11:49 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi Andrea,

> Removed old LTP API from getcontext01.c test and check if getcontext is
> present in the current system. The check is useful in those systems
> where libmusl is used by default.
nit: "libmusl": it's musl libc or just musl (https://musl.libc.org/about.html).
I got really confused you mean some other library on the top of musl
(e.g. there is musl-fts implementation https://github.com/void-linux/musl-fts
because musl refuses to implement fts.h).

> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
> ---
>  configure.ac                                  |  1 +
>  .../kernel/syscalls/getcontext/getcontext01.c | 93 +++++--------------
>  2 files changed, 24 insertions(+), 70 deletions(-)

> diff --git a/configure.ac b/configure.ac
> index 8d2c5b1c4..41a21a636 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -97,6 +97,7 @@ AC_CHECK_FUNCS_ONCE([ \
>      fspick \
>      fstatat \
>      getauxval \
> +    getcontext \
I was surprised that getcontext is still not in musl (but it's in ucontext.h header),
but it's deliberate:
https://wiki.musl-libc.org/open-issues.html#ucontext.h

Also not sure if it's in bionic
(https://android.googlesource.com/platform/bionic).

Thus ack using autotools (I'm trying to remove old unneeded check to speedup
configure runtime).

It might be worth to add .test_variants to test raw syscall,
but that'd be another effort (no need to bother with it now).

>  	TEST(getcontext(&ptr));
...

> +	if (TST_RET < 0)
> +		tst_res(TFAIL, "getcontext: %s", tst_strerrno(TST_ERR));

...
> +	if (TST_RET == 0)
> +		tst_res(TPASS, "getcontext passed");
> +	else
> +		tst_res(TFAIL, "Unexpected return value %li", TST_RET);
>  }


For this code:
	if (TST_RET < 0)
		tst_res(TFAIL, "getcontext: %s", tst_strerrno(TST_ERR));

I'd personally add else if here below:
	if (TST_RET == 0)
		tst_res(TPASS, "getcontext passed");
	else
		tst_res(TFAIL, "Unexpected return value %li", TST_RET);

But how about instead of all this just using
TST_EXP_PASS(getcontext(&ptr));

...
> +static struct tst_test test = {
> +	.test_all = run,
> +};

>  #else /* systems that dont support obsolete getcontext */
I'm going to remove this useless comment before merge ^
> -int main(void)
> -{
> -	tst_brkm(TCONF, NULL, "system doesn't have getcontext support");
> -}
> +TST_TEST_TCONF("system doesn't have getcontext support");
>  #endif

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-16 11:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 10:40 [LTP] [PATCH v1] Rewrite getcontext01.c test using new LTP API Andrea Cervesato
2022-02-16 11:49 ` 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.