[LTP] [PATCH 3/3] syscalls: sysinfo02: Convert to the new library

Cyril Hrubis chrubis@suse.cz
Wed Mar 4 15:12:36 CET 2026


Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/sysinfo/sysinfo02.c | 138 ++----------------
 1 file changed, 15 insertions(+), 123 deletions(-)

diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo02.c b/testcases/kernel/syscalls/sysinfo/sysinfo02.c
index 4ce06e0a7..5bbbdc35c 100644
--- a/testcases/kernel/syscalls/sysinfo/sysinfo02.c
+++ b/testcases/kernel/syscalls/sysinfo/sysinfo02.c
@@ -1,137 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   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., 2001
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
  */
 
-/*
- * Test Name :	sysinfo02
- *
- * Test description
- *  Verify that sysinfo() returns the correct error for an invalid address structure.
- *
- * Expected Result :
- *  sysinfo() returns value 0 on success and the sysinfo structure should
- *  be filled with the system information.
- *
- * Algorithm:
- *  Setup :
- *   Setup for signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- * Test:
- *  Loop if the proper option is given.
- *  Execute the system call.
- *  Pass an invalid address to the structure.
- *  Check return code, if system call failed (return=-1)
- *	Test case passed, Issue functionality pass message
- *  Otherwise,
- *	Issue Functionality-Fail message.
- * Cleanup:
- *  Print errno log and/or timing stats if options given
- *  Delete the temporary directory created.
- *
- * USAGE:  <for command-line>
- *	sysinfo02 [-c n] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions:
- *  None
- *
+/*\
+ * Verify that sysinfo() returns EFAULT for an invalid address structure.
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/signal.h>
 #include <sys/sysinfo.h>
-#include <stdint.h>
-
-#include "test.h"
-
-#define INVALID_ADDRESS ((uintptr_t)-1)
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+static struct sysinfo *bad_info;
 
-char *TCID = "sysinfo02";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct sysinfo *sysinfo_buf;
-	int lc;
-
-	sysinfo_buf = (void *)INVALID_ADDRESS;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* Global setup */
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		TEST(sysinfo(sysinfo_buf));
-		/* check return code */
-		if (TEST_RETURN != 0 && TEST_ERRNO == EFAULT) {
-			/* Test succeeded as it was supposed to return -1 */
-			tst_resm(TPASS,
-				 "Test to check the error code %d PASSED",
-				 TEST_ERRNO);
-		} else {
-			/* Test Failed */
-			tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1 "
-				 "returned %d/n", TEST_ERRNO);
-		}
-	}
-	cleanup();
-	tst_exit();
-
+	bad_info = tst_get_bad_addr(NULL);
 }
 
-/*
- * setup()
- *	performs one time setup
- *
- */
-void setup(void)
+static void run(void)
 {
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	umask(0);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(sysinfo(bad_info), EFAULT);
 }
 
-/*
- * cleanup()
- *
- */
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+};
-- 
2.52.0



More information about the ltp mailing list