public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls: newuname01: Convert to the new library.
@ 2026-03-04 16:14 Cyril Hrubis
  2026-03-05  1:51 ` Li Wang via ltp
  2026-03-12 13:26 ` Andrea Cervesato via ltp
  0 siblings, 2 replies; 6+ messages in thread
From: Cyril Hrubis @ 2026-03-04 16:14 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 .../kernel/syscalls/newuname/newuname01.c     | 186 ++++--------------
 1 file changed, 39 insertions(+), 147 deletions(-)

diff --git a/testcases/kernel/syscalls/newuname/newuname01.c b/testcases/kernel/syscalls/newuname/newuname01.c
index 2b9349e35..6a4f1a50c 100644
--- a/testcases/kernel/syscalls/newuname/newuname01.c
+++ b/testcases/kernel/syscalls/newuname/newuname01.c
@@ -1,161 +1,53 @@
-/******************************************************************************/
-/* Copyright (c) Crackerjack Project., 2007                                   */
-/*                                                                            */
-/* 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    */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* File:        newuname01.c                                           */
-/*                                                                            */
-/* Description: This tests the newuname() syscall                      */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* newuname01 [-c n] [-e][-i n] [-I x] [-p x] [-t]                     */
-/*      where,  -c n : Run n copies concurrently.                             */
-/*              -e   : Turn on errno logging.                                 */
-/*              -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.                                */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   newuname01                                             */
-/* History:     Porting from Crackerjack to LTP is done by                    */
-/*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
-/******************************************************************************/
-#include <unistd.h>
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Linux Test Project, 2024
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Verify that uname() succeeds and correctly identifies the system as Linux.
+ * The rest of the values, when possible, are matched againts the strings from
+ * /proc/sys/kernel/. The only value we cannot easily assert is the machine
+ * field which is the architecture the kernel was compiled for, which would
+ * require special handling per each architecture.
+ */
+
+#define _GNU_SOURCE
 #include <sys/utsname.h>
-#include <errno.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-
-#include "test.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-char *TCID = "newuname01";
-int testno;
-int TST_TOTAL = 1;
+static struct utsname *name;
 
-/* Extern Global Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    cleanup                                                       */
-/*                                                                            */
-/* Description: Performs all one time clean up for this test on successful    */
-/*              completion,  premature exit or  failure. Closes all temporary */
-/*              files, removes all temporary directories exits the test with  */
-/*              appropriate return code by calling tst_exit() function.       */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
-/*              On success - Exits calling tst_exit(). With '0' return code.  */
-/*                                                                            */
-/******************************************************************************/
-void cleanup(void)
+static void run(void)
 {
+	char proc_val[1024] = {};
 
-	tst_rmdir();
+	TST_EXP_PASS(tst_syscall(__NR_uname, name), "uname(name)");
 
-	tst_exit();
-}
+	if (!TST_PASS)
+		return;
 
-/* Local  Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    setup                                                         */
-/*                                                                            */
-/* Description: Performs all one time setup for this test. This function is   */
-/*              typically used to capture signals, create temporary dirs      */
-/*              and temporary files that may be used in the course of this    */
-/*              test.                                                         */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits by calling cleanup().                      */
-/*              On success - returns 0.                                       */
-/*                                                                            */
-/******************************************************************************/
-void setup(void)
-{
-	/* Capture signals if any */
-	/* Create temporary directories */
-	TEST_PAUSE;
-	tst_tmpdir();
-}
+	TST_EXP_EQ_STR(name->sysname, "Linux");
 
-int main(int ac, char **av)
-{
-	struct utsname name;
-	int lc;
+	SAFE_FILE_SCANF("/proc/sys/kernel/hostname", "%1023[^\n]", proc_val);
+	TST_EXP_EQ_STR(name->nodename, proc_val);
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	SAFE_FILE_SCANF("/proc/sys/kernel/osrelease", "%1023[^\n]", proc_val);
+	TST_EXP_EQ_STR(name->release, proc_val);
 
-	setup();
+	SAFE_FILE_SCANF("/proc/sys/kernel/version", "%1023[^\n]", proc_val);
+	TST_EXP_EQ_STR(name->version, proc_val);
 
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			TEST(tst_syscall(__NR_uname, &name));
-			if (TEST_RETURN == -1) {
-				tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s",
-					 TCID, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TPASS,
-					 "newuname call succeed: return value = %ld ",
-					 TEST_RETURN);
-				TEST(strcmp(name.sysname, "Linux"));	//Linux ?
-				if (TEST_RETURN == 0) {
-					tst_resm(TINFO, "This system is %s",
-						 name.sysname);
-					tst_resm(TINFO,
-						 "The system infomation is :");
-					tst_resm(TINFO,
-						 "System is %s on %s hardware",
-						 name.sysname, name.machine);
-
-					tst_resm(TINFO, "Nodename is %s",
-						 name.nodename);
-					tst_resm(TINFO, "Version is %s, %s",
-						 name.release, name.version);
-					tst_resm(TINFO, "Domainname is %s ",
-						 *(&name.machine + 1));
-					cleanup();
-					tst_exit();
-				} else {
-					tst_resm(TFAIL,
-						 "%s failed - errno = %d : %s",
-						 TCID, TEST_ERRNO,
-						 strerror(TEST_ERRNO));
-					tst_resm(TINFO,
-						 "This system is not Linux");
-					cleanup();
-					tst_exit();
-				}
-
-			}
+	SAFE_FILE_SCANF("/proc/sys/kernel/domainname", "%1023[^\n]", proc_val);
+	TST_EXP_EQ_STR(name->domainname, proc_val);
+}
 
-		}
+static struct tst_test test = {
+	.test_all = run,
+	.bufs = (struct tst_buffers []) {
+		{&name, .size = sizeof(*name)},
+		{}
 	}
-	tst_exit();
-}
+};
-- 
2.52.0


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

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

* Re: [LTP] [PATCH] syscalls: newuname01: Convert to the new library.
  2026-03-04 16:14 [LTP] [PATCH] syscalls: newuname01: Convert to the new library Cyril Hrubis
@ 2026-03-05  1:51 ` Li Wang via ltp
  2026-03-05 14:25   ` Cyril Hrubis
  2026-03-12 13:26 ` Andrea Cervesato via ltp
  1 sibling, 1 reply; 6+ messages in thread
From: Li Wang via ltp @ 2026-03-05  1:51 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

> + * Verify that uname() succeeds and correctly identifies the system as Linux.
> + * The rest of the values, when possible, are matched againts the strings from
                                                           ^ against

> -int main(int ac, char **av)
> -{
> -	struct utsname name;
> -	int lc;
> +	SAFE_FILE_SCANF("/proc/sys/kernel/hostname", "%1023[^\n]", proc_val);
> +	TST_EXP_EQ_STR(name->nodename, proc_val);
>  
> -	tst_parse_opts(ac, av, NULL, NULL);
> +	SAFE_FILE_SCANF("/proc/sys/kernel/osrelease", "%1023[^\n]", proc_val);
> +	TST_EXP_EQ_STR(name->release, proc_val);
>  
> -	setup();
> +	SAFE_FILE_SCANF("/proc/sys/kernel/version", "%1023[^\n]", proc_val);
> +	TST_EXP_EQ_STR(name->version, proc_val);

We'd better clear proc_val between reads:

  proc_val[0] = '\0';


Otherwise looks good:

Reviewed-by: Li Wang <liwang@redhat.com>

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH] syscalls: newuname01: Convert to the new library.
  2026-03-05  1:51 ` Li Wang via ltp
@ 2026-03-05 14:25   ` Cyril Hrubis
  2026-03-06  2:58     ` Li Wang via ltp
  0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2026-03-05 14:25 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

Hi!1
> > +	SAFE_FILE_SCANF("/proc/sys/kernel/hostname", "%1023[^\n]", proc_val);
> > +	TST_EXP_EQ_STR(name->nodename, proc_val);
> >  
> > -	tst_parse_opts(ac, av, NULL, NULL);
> > +	SAFE_FILE_SCANF("/proc/sys/kernel/osrelease", "%1023[^\n]", proc_val);
> > +	TST_EXP_EQ_STR(name->release, proc_val);
> >  
> > -	setup();
> > +	SAFE_FILE_SCANF("/proc/sys/kernel/version", "%1023[^\n]", proc_val);
> > +	TST_EXP_EQ_STR(name->version, proc_val);
> 
> We'd better clear proc_val between reads:
> 
>   proc_val[0] = '\0';

I'm looking at safe_file_scanf() code and it calls tst_brkm_() in any
case that no conversion was done. So the buffer should be either be
filled with new data or the test should exit with an error. Do I miss
something?

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH] syscalls: newuname01: Convert to the new library.
  2026-03-05 14:25   ` Cyril Hrubis
@ 2026-03-06  2:58     ` Li Wang via ltp
  0 siblings, 0 replies; 6+ messages in thread
From: Li Wang via ltp @ 2026-03-06  2:58 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

On Thu, Mar 05, 2026 at 03:25:44PM +0100, Cyril Hrubis wrote:
> Hi!1
> > > +	SAFE_FILE_SCANF("/proc/sys/kernel/hostname", "%1023[^\n]", proc_val);
> > > +	TST_EXP_EQ_STR(name->nodename, proc_val);
> > >  
> > > -	tst_parse_opts(ac, av, NULL, NULL);
> > > +	SAFE_FILE_SCANF("/proc/sys/kernel/osrelease", "%1023[^\n]", proc_val);
> > > +	TST_EXP_EQ_STR(name->release, proc_val);
> > >  
> > > -	setup();
> > > +	SAFE_FILE_SCANF("/proc/sys/kernel/version", "%1023[^\n]", proc_val);
> > > +	TST_EXP_EQ_STR(name->version, proc_val);
> > 
> > We'd better clear proc_val between reads:
> > 
> >   proc_val[0] = '\0';
> 
> I'm looking at safe_file_scanf() code and it calls tst_brkm_() in any
> case that no conversion was done. So the buffer should be either be
> filled with new data or the test should exit with an error. Do I miss
> something?

You're right, I somehow overlooked the SAFE_ macro, which will cause an
error if the read fails. Please ignore this comment.

-- 
Regards,
Li Wang


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

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

* Re: [LTP] [PATCH] syscalls: newuname01: Convert to the new library.
  2026-03-04 16:14 [LTP] [PATCH] syscalls: newuname01: Convert to the new library Cyril Hrubis
  2026-03-05  1:51 ` Li Wang via ltp
@ 2026-03-12 13:26 ` Andrea Cervesato via ltp
  2026-04-07 12:08   ` Cyril Hrubis
  1 sibling, 1 reply; 6+ messages in thread
From: Andrea Cervesato via ltp @ 2026-03-12 13:26 UTC (permalink / raw)
  To: Cyril Hrubis, ltp

Hi!

Feel free to merge.

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

* Re: [LTP] [PATCH] syscalls: newuname01: Convert to the new library.
  2026-03-12 13:26 ` Andrea Cervesato via ltp
@ 2026-04-07 12:08   ` Cyril Hrubis
  0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2026-04-07 12:08 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
I've adjusted the doc comment so that uname() points to
:manpage:uname(2) and pushed. Thanks for the reviews.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

end of thread, other threads:[~2026-04-07 12:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 16:14 [LTP] [PATCH] syscalls: newuname01: Convert to the new library Cyril Hrubis
2026-03-05  1:51 ` Li Wang via ltp
2026-03-05 14:25   ` Cyril Hrubis
2026-03-06  2:58     ` Li Wang via ltp
2026-03-12 13:26 ` Andrea Cervesato via ltp
2026-04-07 12:08   ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox