[LTP] [PATCH v1] Rewrite getcontext01.c test using new LTP API
Andrea Cervesato
andrea.cervesato@suse.de
Wed Feb 16 11:40:26 CET 2022
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
More information about the ltp
mailing list