Skip to contentSkip to conversation

lib: add safe_gethostname()

PATCH New Alexey Kodanev 2 participants 5 messages Jun 28, 2016 – Aug 18, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 lib: add safe_gethostname()

---
v2: remove cleanup()

 include/safe_net_fn.h  |    3 +++
 include/tst_safe_net.h |    3 +++
 lib/safe_net.c         |   14 ++++++++++++++
 3 files changed, 20 insertions(+), 0 deletions(-)
include/safe_net_fn.h +3 -0
index e85842b..22a40d6 100644
@@ -45,4 +45,7 @@ int safe_getsockname(const char *file, const int lineno,
 		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
 		     socklen_t *addrlen);
 
+int safe_gethostname(const char *file, const int lineno,
+		     char *name, size_t size);
+
 #endif /* SAFE_NET_FN_H__ */
include/tst_safe_net.h +3 -0
index 98dcfa5..3ba410a 100644
@@ -43,4 +43,7 @@
 	safe_getsockname(__FILE__, __LINE__, NULL, sockfd, addr, \
 			 addrlen)
 
+#define SAFE_GETHOSTNAME(name, size) \
+	safe_gethostname(__FILE__, __LINE__, name, size)
+
 #endif /* TST_SAFE_NET_H__ */
lib/safe_net.c +14 -0
index 98a79cf..cae77b5 100644
@@ -183,3 +183,17 @@ int safe_getsockname(const char *file, const int lineno,
 
 	return rval;
 }
+
+int safe_gethostname(const char *file, const int lineno,
+		     char *name, size_t size)
+{
+	int rval = gethostname(name, size);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, NULL,
+			 "%s:%d: gethostname(%p, %zu) failed",
+			 file, lineno, name, size);
+	}
+
+	return rval;
+}
Signature · 1 line
1.7.1
#1 lore raw

PATCH v2 2/2 network/nfs05: rewrite the test, make use of new library

* remove dynamic allocation of memory, use asprintf in few places;
* run built binaries and check that they print correct message;
* run tst_run_cmd() to call make/make clean;
* clean directories with tst_rmdir library.

---
v2: * added run_targets() to run built binaries and check their output
* correct generated C files and Makefiles
* fix makefile: include testcases.mk
* added check for gcc and make commands

 testcases/network/nfs/nfs_stress/Makefile          |    2 +-
 testcases/network/nfs/nfs_stress/nfs05             |   10 +-
 testcases/network/nfs/nfs_stress/nfs05_make_tree.c |  934 ++++----------------
 3 files changed, 194 insertions(+), 752 deletions(-)
testcases/network/nfs/nfs_stress/Makefile +1 -1
index 0e6aebc..308230f 100644
@@ -16,7 +16,7 @@
 
 top_srcdir		?= ../../../..
 
-include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/testcases.mk
 
 nfs04_create_file: CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
 nfs05_make_tree: LDLIBS += -lpthread
testcases/network/nfs/nfs_stress/nfs05 +8 -2
index 0e15c8c..23a34c7 100755
@@ -31,11 +31,17 @@ THREAD_NUM=${THREAD_NUM:-"8"}
 . nfs_lib.sh
 . test_net.sh
 
+tst_check_cmds make gcc
+
 nfs_setup
 
 tst_resm TINFO "start nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM"
-ROD nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM
+TMPDIR=$(pwd) nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM
 
-tst_resm TPASS "test finished"
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "'make' test failed"
+else
+	tst_resm TPASS "'make' test finished"
+fi
 
 tst_exit
testcases/network/nfs/nfs_stress/nfs05_make_tree.c +185 -749

973 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/2 network/nfs05: rewrite the test, make use of new library

Hi!

testcases/network/nfs/nfs_stress/nfs05 THREAD_NUM=${THREAD_NUM:-"8"} · line 39

Quoted 3 lines

tst_resm TINFO "start nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM"

testcases/network/nfs/nfs_stress/nfs05 +1 -1
-ROD nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM
+TMPDIR=$(pwd) nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM

Hmm, the tst_tmpdir is created and mounted in the nfs_setup right?

Why can't we just let the nfs05_make_tree work with current directory and omit the needs_tmpdir = 1 from it's source? It's not like the nfs05_make_tree binary is supposed to be executed directly, so it's OK if it starts to create files in PWD.

Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH v2 2/2 network/nfs05: rewrite the test, make use of new library

Hi,

Quoted 10 lines · Cyril Hrubis

Hi!

testcases/network/nfs/nfs_stress/nfs05 THREAD_NUM=${THREAD_NUM:-"8"} · line 39

Quoted 3 lines

tst_resm TINFO "start nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM"

testcases/network/nfs/nfs_stress/nfs05 +1 -1
-ROD nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM
+TMPDIR=$(pwd) nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM

Hmm, the tst_tmpdir is created and mounted in the nfs_setup right?

Why can't we just let the nfs05_make_tree work with current directory and omit the needs_tmpdir = 1 from it's source? It's not like the nfs05_make_tree binary is supposed to be executed directly, so it's OK if it starts to create files in PWD.

You are right, it's not used other than inside nfs05 script so the flag can be
safely removed along with "TMPDIR=$(pwd)".

Thanks,
Alexey

#4 lore raw

PATCH v2 2/2 network/nfs05: rewrite the test, make use of new library

Hi,

Both patches applied.

Thanks,
Alexey