Skip to contentSkip to conversation

Rewrite utstest suite

PATCH Superseded Andrea Cervesato via ltp 2 participants 5 messages Oct 31, 2022 Library code

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Rewrite utstest suite

Added new tests and removed utstest which looked broken.

Andrea Cervesato (2):
Add SAFE_SETHOSTNAME macro
Rewrite utsname testing suite

 include/safe_net_fn.h                         |   3 +
 include/tst_safe_net.h                        |   3 +
 lib/safe_net.c                                |  17 +
 runtest/containers                            |   7 +
 .../kernel/containers/utsname/.gitignore      |   5 +-
 testcases/kernel/containers/utsname/Makefile  |  23 +-
 .../containers/utsname/runutstests_noltp.sh   |  41 --
 testcases/kernel/containers/utsname/utsname.h | 116 ++++++
 .../kernel/containers/utsname/utsname01.c     |  74 ++++
 .../kernel/containers/utsname/utsname02.c     |  97 +++++
 .../kernel/containers/utsname/utsname03.c     | 111 ++++++
 .../kernel/containers/utsname/utsname04.c     |  66 ++++
 testcases/kernel/containers/utsname/utstest.c | 356 ------------------
 13 files changed, 501 insertions(+), 418 deletions(-)
 delete mode 100755 testcases/kernel/containers/utsname/runutstests_noltp.sh
 create mode 100644 testcases/kernel/containers/utsname/utsname.h
 create mode 100644 testcases/kernel/containers/utsname/utsname01.c
 create mode 100644 testcases/kernel/containers/utsname/utsname02.c
 create mode 100644 testcases/kernel/containers/utsname/utsname03.c
 create mode 100644 testcases/kernel/containers/utsname/utsname04.c
 delete mode 100644 testcases/kernel/containers/utsname/utstest.c
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 1/2 Add SAFE_SETHOSTNAME macro

---
Add safe_sethostname missing definition inside header file

 include/safe_net_fn.h  |  3 +++
 include/tst_safe_net.h |  3 +++
 lib/safe_net.c         | 17 +++++++++++++++++
 3 files changed, 23 insertions(+)
include/safe_net_fn.h +3 -0
index ff81b1337..6c63cb2cf 100644
@@ -73,6 +73,9 @@ int safe_getsockname(const char *file, const int lineno,
 int safe_gethostname(const char *file, const int lineno,
 		     char *name, size_t size);
 
+int safe_sethostname(const char *file, const int lineno,
+		     const char *name, size_t size);
+
 int tst_getsockport(const char *file, const int lineno, int sockfd);
 
 unsigned short tst_get_unused_port(const char *file, const int lineno,
include/tst_safe_net.h +3 -0
index e85b79a3e..98f0256fd 100644
@@ -68,6 +68,9 @@
 #define SAFE_GETHOSTNAME(name, size) \
 	safe_gethostname(__FILE__, __LINE__, name, size)
 
+#define SAFE_SETHOSTNAME(name, size) \
+	safe_sethostname(__FILE__, __LINE__, name, size)
+
 #define TST_GETSOCKPORT(sockfd) \
 	tst_getsockport(__FILE__, __LINE__, sockfd)
 
lib/safe_net.c +17 -0
index 1717f0745..5dec0de11 100644
@@ -469,6 +469,23 @@ int safe_gethostname(const char *file, const int lineno,
 	return rval;
 }
 
+int safe_sethostname(const char *file, const int lineno,
+		     const char *name, size_t size)
+{
+	int rval = sethostname(name, size);
+
+	if (rval == -1) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+			"sethostname(%p, %zu) failed", name, size);
+	} else if (rval) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+			"Invalid sethostname(%p, %zu) return value %d", name,
+			size, rval);
+	}
+
+	return rval;
+}
+
 /*
  * @return port in network byte order.
  */
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 2/2 Rewrite utsname testing suite

In reply to Andrea Cervesato via ltp

Deleted utstest.c and created the following new tests:
- utsname01
- utsname02
- utsname03
- utsname04

---
 runtest/containers                            |   7 +
 .../kernel/containers/utsname/.gitignore      |   5 +-
 testcases/kernel/containers/utsname/Makefile  |  23 +-
 .../containers/utsname/runutstests_noltp.sh   |  41 --
 testcases/kernel/containers/utsname/utsname.h | 116 ++++++
 .../kernel/containers/utsname/utsname01.c     |  74 ++++
 .../kernel/containers/utsname/utsname02.c     |  97 +++++
 .../kernel/containers/utsname/utsname03.c     | 111 ++++++
 .../kernel/containers/utsname/utsname04.c     |  66 ++++
 testcases/kernel/containers/utsname/utstest.c | 356 ------------------
 10 files changed, 478 insertions(+), 418 deletions(-)
 delete mode 100755 testcases/kernel/containers/utsname/runutstests_noltp.sh
 create mode 100644 testcases/kernel/containers/utsname/utsname.h
 create mode 100644 testcases/kernel/containers/utsname/utsname01.c
 create mode 100644 testcases/kernel/containers/utsname/utsname02.c
 create mode 100644 testcases/kernel/containers/utsname/utsname03.c
 create mode 100644 testcases/kernel/containers/utsname/utsname04.c
 delete mode 100644 testcases/kernel/containers/utsname/utstest.c
runtest/containers +7 -0
index 2637b62fe..36d9378af 100644
@@ -73,6 +73,13 @@ utstest_clone_3 utstest clone 3
 utstest_clone_4 utstest clone 4
 utstest_clone_5 utstest clone 5
 
+utsname01 utsname01
+utsname02 utsname02
+utsname03_clone utsname03 -m clone
+utsname03_unshare utsname03 -m unshare
+utsname04_clone utsname04 -m clone
+utsname04_unshare utsname04 -m unshare
+
 mountns01 mountns01
 mountns02 mountns02
 mountns03 mountns03
testcases/kernel/containers/utsname/.gitignore +4 -1
index 0e1f41dc8..945ed280e 100644
@@ -1 +1,4 @@
-/utstest
+/utsname01
+/utsname02
+/utsname03
+/utsname04
testcases/kernel/containers/utsname/Makefile +3 -20
index 5efcbf648..9c0158c01 100644
@@ -1,28 +1,11 @@
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 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    ##
-##                                                                            ##
-################################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
 
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
-LDLIBS			:= -lclone -lpthread -lrt $(LDLIBS)
+LDLIBS			:= -lclone $(LDLIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/containers/utsname/runutstests_noltp.sh deleted +0 -41

41 lines not on this page · raw message

testcases/kernel/containers/utsname/utsname.h new file +116 -0

116 lines not on this page · raw message

testcases/kernel/containers/utsname/utsname01.c new file +74 -0

74 lines not on this page · raw message

testcases/kernel/containers/utsname/utsname02.c new file +97 -0

97 lines not on this page · raw message

testcases/kernel/containers/utsname/utsname03.c new file +111 -0

111 lines not on this page · raw message

testcases/kernel/containers/utsname/utsname04.c new file +66 -0

66 lines not on this page · raw message

testcases/kernel/containers/utsname/utstest.c deleted +0 -356

356 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v2 2/2] Rewrite utsname testing suite

Hi Andrea,

testcases/kernel/containers/utsname/utsname01.c line 17

Quoted 6 lines
testcases/kernel/containers/utsname/utsname01.c new file +6 -0
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "utsname.h"
+
+#define HLEN 100

Could this definition be in utsname.h?
Also, although getconf HOST_NAME_MAX returns 64 on my machine, maybe using from HOST_NAME_MAX would be safer (that can be up to 255).
Also maybe HOSTLEN (readability)?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v2 2/2] Rewrite utsname testing suite

Hi

Quoted 12 lines · Petr Vorel

Hi Andrea,

testcases/kernel/containers/utsname/utsname01.c line 17

Quoted 6 lines
testcases/kernel/containers/utsname/utsname01.c new file +6 -0
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "utsname.h"
+
+#define HLEN 100

Could this definition be in utsname.h?
Also, although getconf HOST_NAME_MAX returns 64 on my machine, maybe using from HOST_NAME_MAX would be safer (that can be up to 255).
Also maybe HOSTLEN (readability)?

It makes sense to use HOST_NAME_MAX. I will use it in the next patches

Quoted 3 lines

Kind regards,
Petr

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp