All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot()
@ 2014-10-13 12:10 Jan Stancek
  2014-10-13 12:10 ` [LTP] [PATCH 2/2 v3] ldd01: remove all -m32/-m64 logic Jan Stancek
  2014-10-14 15:47 ` [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot() Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Stancek @ 2014-10-13 12:10 UTC (permalink / raw)
  To: ltp-list

LTP_DATAROOT (test.sh) and tst_dataroot (libltp) define directory
which holds test data files.

If LTPROOT is defined, it is $LTPROOT/testcases/data/$TCID
otherwise it's $CWD/datafiles (where CWD is current working
directory, before any call to tst_tmdir())

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .gitignore                      |    1 +
 doc/test-writing-guidelines.txt |   27 ++++++++++----
 include/tst_resource.h          |    3 ++
 lib/tests/tst_dataroot.c        |   76 +++++++++++++++++++++++++++++++++++++++
 lib/tst_resource.c              |   67 ++++++++++++++++++++++++++++++----
 testcases/lib/test.sh           |    3 ++
 6 files changed, 162 insertions(+), 15 deletions(-)
 create mode 100644 lib/tests/tst_dataroot.c

diff --git a/.gitignore b/.gitignore
index 1256236..bc63db7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,3 +68,4 @@ logfile.*
 /lib/tests/tst_device
 /lib/tests/tst_record_childstatus
 /lib/tests/trerrno
+/lib/tests/tst_dataroot
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index a59fdd9..165551a 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -180,13 +180,26 @@ IMPORTANT: The runtest files should have one entry per a test. Creating a
 2.1.2 Datafiles
 ^^^^^^^^^^^^^^^
 
-If your test needs datafiles to work, these should be generally put into a
-subdirectory named test name ('TCID' see below) and install it into the
-'testcases/data/' directory. The datafiles can be accessed as
-'$LTPROOT/testcases/data/TCID/...'. See
-'testcases/network/rpc/basic_tests/rpc01/' for example.
-
-NOTE: There may be some convenience interface added later.
+If your test needs datafiles to work, these should be put into a subdirectory
+named "datafiles" and installed into the 'testcases/data/$TCID' directory.
+
+You can obtain path to datafiles via $LTP_DATAROOT provided by test.sh
+  '$LTP_DATAROOT/...'
+or via C function tst_dataroot() provided by libltp
+  const char *dataroot = tst_dataroot();
+
+Datafiles can also be accessed as '$LTPROOT/testcases/data/$TCID/...',
+but $LTP_DATAROOT and tst_dataroot() are preffered as these can be used
+when running testcases directly in git tree as well as from install
+location.
+
+The path is constructed according to these rules:
+1. if $LTPROOT is set, return '$LTPROOT/testcases/data/$TCID'
+2. else if tst_tmpdir() was called return '$STARTWD/datafiles'
+   (where $STARTWD is initial working directory as recorded by tst_tmdir())
+3. else return '$CWD/datafiles'
+
+See 'testcases/commands/ade/ldd/ldd01' for example.
 
 2.1.3 Subexecutables
 ^^^^^^^^^^^^^^^^^^^^
diff --git a/include/tst_resource.h b/include/tst_resource.h
index a02a313..94c24b7 100644
--- a/include/tst_resource.h
+++ b/include/tst_resource.h
@@ -41,6 +41,9 @@
 
 #include "test.h"
 
+void tst_dataroot_init(void);
+const char *tst_dataroot(void);
+
 /*
  * Copy a file to the CWD. The destination is apended to CWD.
  */
diff --git a/lib/tests/tst_dataroot.c b/lib/tests/tst_dataroot.c
new file mode 100644
index 0000000..e40a992
--- /dev/null
+++ b/lib/tests/tst_dataroot.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2014 Linux Test Project, Inc.
+ *
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like.  Any license provided herein, whether implied or
+ * otherwise, applies only to this software file.  Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include "test.h"
+#include "safe_macros.h"
+#include "usctest.h"
+
+#define OUTPUT_FNAME "output"
+#define LTPROOT "/opt/ltp"
+
+char *TCID = "dataroot";
+int TST_TOTAL = 1;
+
+static void cmp_paths(const char *p1, const char *p2, const char *s)
+{
+	if (strncmp(p1, p2, PATH_MAX) == 0)
+		tst_resm(TPASS, "%s", s);
+	else
+		tst_resm(TFAIL, "%s, %s != %s", s, p1, p2);
+}
+
+int main(void)
+{
+	const char *dataroot;
+	char curdir[PATH_MAX], tmp[PATH_MAX];
+
+	if (getcwd(curdir, PATH_MAX) == NULL)
+		tst_brkm(TBROK, NULL, "getcwd");
+
+	/* LTPROOT */
+	setenv("LTPROOT", LTPROOT, 1);
+	tst_dataroot_init();
+	dataroot = tst_dataroot();
+	snprintf(tmp, PATH_MAX, "%s/testcases/data/%s", LTPROOT, TCID);
+	cmp_paths(dataroot, tmp, "LTPROOT, no tmpdir, "
+		"dataroot == $LTPROOT/testcases/data/$TCID");
+
+	/* no LTPROOT, no tmpdir */
+	unsetenv("LTPROOT");
+	tst_dataroot_init();
+	dataroot = tst_dataroot();
+	snprintf(tmp, PATH_MAX, "%s/datafiles", curdir);
+	cmp_paths(dataroot, tmp, "no LTPROOT, no tmpdir, "
+		"dataroot == $CWD/datafiles");
+
+	/* no LTPROOT, tmpdir */
+	tst_tmpdir();
+	tst_dataroot_init();
+	dataroot = tst_dataroot();
+	snprintf(tmp, PATH_MAX, "%s/datafiles", curdir);
+	cmp_paths(dataroot, tmp, "no LTPROOT, tmpdir, "
+		"dataroot == $STARTWD/datafiles");
+
+	tst_rmdir();
+	tst_exit();
+}
+
diff --git a/lib/tst_resource.c b/lib/tst_resource.c
index 54d4795..7c8deee 100644
--- a/lib/tst_resource.c
+++ b/lib/tst_resource.c
@@ -21,9 +21,61 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include <pthread.h>
 #include "tst_resource.h"
 #include "ltp_priv.h"
 
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX	MAXPATHLEN
+#else
+#define PATH_MAX	1024
+#endif
+#endif
+
+static pthread_mutex_t tmutex = PTHREAD_MUTEX_INITIALIZER;
+static char dataroot[PATH_MAX];
+extern char *TCID;
+
+void tst_dataroot_init(void)
+{
+	const char *ltproot = getenv("LTPROOT");
+	char curdir[PATH_MAX];
+	const char *startdir;
+	int ret;
+
+	/* 1. if LTPROOT is set, use $LTPROOT/testcases/data/$TCID
+	 * 2. else if startwd is set by tst_tmdir(), use $STARWD/datafiles
+	 * 3. else use $CWD/datafiles */
+	if (ltproot) {
+		ret = snprintf(dataroot, PATH_MAX, "%s/testcases/data/%s",
+			ltproot, TCID);
+	} else {
+		startdir = tst_get_startwd();
+		if (startdir[0] == 0) {
+			if (getcwd(curdir, PATH_MAX) == NULL)
+				tst_brkm(TBROK | TERRNO, NULL,
+					"tst_dataroot getcwd");
+			startdir = curdir;
+		}
+		ret = snprintf(dataroot, PATH_MAX, "%s/datafiles", startdir);
+	}
+
+	if (ret < 0 || ret >= PATH_MAX)
+		tst_brkm(TBROK, NULL, "tst_dataroot snprintf: %d", ret);
+}
+
+const char *tst_dataroot(void)
+{
+	if (dataroot[0] == 0) {
+		pthread_mutex_lock(&tmutex);
+		if (dataroot[0] == 0)
+			tst_dataroot_init();
+		pthread_mutex_unlock(&tmutex);
+	}
+	return dataroot;
+}
+
 static int file_copy(const char *file, const int lineno,
                      void (*cleanup_fn)(void), const char *path,
 		     const char *filename, const char *dest)
@@ -56,15 +108,15 @@ void tst_resource_copy(const char *file, const int lineno,
 		dest = ".";
 
 	const char *ltproot = getenv("LTPROOT");
+	const char *dataroot = tst_dataroot();
+
+	/* look for data files in $LTP_DATAROOT, $LTPROOT/testcases/bin
+	 * and $CWD */
+	if (file_copy(file, lineno, cleanup_fn, dataroot, filename, dest))
+		return;
 
 	if (ltproot != NULL) {
-		/* the data are either in testcases/data or testcases/bin */
 		char buf[strlen(ltproot) + 64];
-
-		snprintf(buf, sizeof(buf), "%s/testcases/data", ltproot);
-
-		if (file_copy(file, lineno, cleanup_fn, buf, filename, dest))
-			return;
 		
 		snprintf(buf, sizeof(buf), "%s/testcases/bin", ltproot);
 		
@@ -72,9 +124,8 @@ void tst_resource_copy(const char *file, const int lineno,
 			return;
 	}
 
+	/* try directory test started in as last resort */
 	const char *startwd = tst_get_startwd();
-
-	/* try directory test started int first */
 	if (file_copy(file, lineno, cleanup_fn, startwd, filename, dest))
 		return;
 
diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index 10282f4..eecbfba 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -144,4 +144,7 @@ export TST_TOTAL="$TST_TOTAL"
 # Setup LTPROOT, default to current directory if not set
 if [ -z "$LTPROOT" ]; then
 	export LTPROOT="$PWD"
+	export LTP_DATAROOT="$LTPROOT/datafiles"
+else
+	export LTP_DATAROOT="$LTPROOT/testcases/data/$TCID"
 fi
-- 
1.7.1


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://p.sf.net/sfu/Zoho
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 2/2 v3] ldd01: remove all -m32/-m64 logic
  2014-10-13 12:10 [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot() Jan Stancek
@ 2014-10-13 12:10 ` Jan Stancek
  2014-10-14 15:47 ` [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot() Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Jan Stancek @ 2014-10-13 12:10 UTC (permalink / raw)
  To: ltp-list

and build all binaries with same CFLAGS as rest of LTP build.
Also treat lddfile*.so and lddfile.out as data files.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/commands/ade/ldd/Makefile             |   13 +------
 testcases/commands/ade/ldd/datafiles/Makefile   |   37 ++++++++++++++++++
 testcases/commands/ade/ldd/datafiles/lddfile1.c |    5 ++
 testcases/commands/ade/ldd/datafiles/lddfile2.c |    5 ++
 testcases/commands/ade/ldd/datafiles/lddfile3.c |    5 ++
 testcases/commands/ade/ldd/datafiles/lddfile4.c |    5 ++
 testcases/commands/ade/ldd/datafiles/lddfile5.c |    5 ++
 testcases/commands/ade/ldd/datafiles/main.c     |   18 +++++++++
 testcases/commands/ade/ldd/ldd01                |   46 ++++-------------------
 testcases/commands/ade/ldd/lddfile1.c           |    5 --
 testcases/commands/ade/ldd/lddfile2.c           |    5 --
 testcases/commands/ade/ldd/lddfile3.c           |    5 --
 testcases/commands/ade/ldd/lddfile4.c           |    5 --
 testcases/commands/ade/ldd/lddfile5.c           |    5 --
 testcases/commands/ade/ldd/main.c               |   18 ---------
 15 files changed, 89 insertions(+), 93 deletions(-)
 create mode 100644 testcases/commands/ade/ldd/datafiles/Makefile
 create mode 100644 testcases/commands/ade/ldd/datafiles/lddfile1.c
 create mode 100644 testcases/commands/ade/ldd/datafiles/lddfile2.c
 create mode 100644 testcases/commands/ade/ldd/datafiles/lddfile3.c
 create mode 100644 testcases/commands/ade/ldd/datafiles/lddfile4.c
 create mode 100644 testcases/commands/ade/ldd/datafiles/lddfile5.c
 create mode 100644 testcases/commands/ade/ldd/datafiles/main.c
 delete mode 100644 testcases/commands/ade/ldd/lddfile1.c
 delete mode 100644 testcases/commands/ade/ldd/lddfile2.c
 delete mode 100644 testcases/commands/ade/ldd/lddfile3.c
 delete mode 100644 testcases/commands/ade/ldd/lddfile4.c
 delete mode 100644 testcases/commands/ade/ldd/lddfile5.c
 delete mode 100644 testcases/commands/ade/ldd/main.c

diff --git a/testcases/commands/ade/ldd/Makefile b/testcases/commands/ade/ldd/Makefile
index eae06cd..f37f21b 100644
--- a/testcases/commands/ade/ldd/Makefile
+++ b/testcases/commands/ade/ldd/Makefile
@@ -13,10 +13,6 @@
 #    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.
-#
 # Garrett Cooper, July 2009
 #
 
@@ -24,13 +20,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-CPPFLAGS		+= -fpic
-
 INSTALL_TARGETS		:= ldd01
 
-MAKE_TARGETS		:= $(patsubst $(abs_srcdir)/%.c,%.obj,$(wildcard $(abs_srcdir)/*.c))
-
-$(MAKE_TARGETS): %.obj: %.o
-	mv $^ $@
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
+include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/commands/ade/ldd/datafiles/Makefile b/testcases/commands/ade/ldd/datafiles/Makefile
new file mode 100644
index 0000000..3d91d28
--- /dev/null
+++ b/testcases/commands/ade/ldd/datafiles/Makefile
@@ -0,0 +1,37 @@
+#
+#    commands/ade/ldd/datafiles testcases Makefile.
+#
+#    Copyright (C) 2014, Linux Test Project.
+#
+#    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.
+
+top_srcdir		?= ../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+CPPFLAGS		+= -fpic
+
+INSTALL_TARGETS		:= ldd*.so lddfile.out
+
+LDD_C_FILES		:= $(wildcard $(abs_srcdir)/lddfile*.c)
+LDD_SO_FILES		:= $(patsubst $(abs_srcdir)/%.c,%.obj.so,$(LDD_C_FILES))
+MAKE_TARGETS		:= lddfile.out
+CLEAN_TARGETS		+= *.obj $(LDD_SO_FILES)
+
+%.obj.so: %.o
+	$(CC) $(CFLAGS) -shared -o $@ $^
+
+lddfile.out: main.o $(LDD_SO_FILES)
+	$(CC) $(CFLAGS) -O -o $@ $?
+
+INSTALL_DIR		:= testcases/data/ldd01
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/commands/ade/ldd/datafiles/lddfile1.c b/testcases/commands/ade/ldd/datafiles/lddfile1.c
new file mode 100644
index 0000000..ccb5786
--- /dev/null
+++ b/testcases/commands/ade/ldd/datafiles/lddfile1.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+void file1(void)
+{
+	printf("Control in function %s\n", __func__);
+}
diff --git a/testcases/commands/ade/ldd/datafiles/lddfile2.c b/testcases/commands/ade/ldd/datafiles/lddfile2.c
new file mode 100644
index 0000000..20aede3
--- /dev/null
+++ b/testcases/commands/ade/ldd/datafiles/lddfile2.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+void file2(void)
+{
+	printf("Control in function %s\n", __func__);
+}
diff --git a/testcases/commands/ade/ldd/datafiles/lddfile3.c b/testcases/commands/ade/ldd/datafiles/lddfile3.c
new file mode 100644
index 0000000..a4529f7
--- /dev/null
+++ b/testcases/commands/ade/ldd/datafiles/lddfile3.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+void file3(void)
+{
+	printf("Control in function %s\n", __func__);
+}
diff --git a/testcases/commands/ade/ldd/datafiles/lddfile4.c b/testcases/commands/ade/ldd/datafiles/lddfile4.c
new file mode 100644
index 0000000..9dc339d
--- /dev/null
+++ b/testcases/commands/ade/ldd/datafiles/lddfile4.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+void file4(void)
+{
+	printf("Control in function %s\n", __func__);
+}
diff --git a/testcases/commands/ade/ldd/datafiles/lddfile5.c b/testcases/commands/ade/ldd/datafiles/lddfile5.c
new file mode 100644
index 0000000..3fbb7f6
--- /dev/null
+++ b/testcases/commands/ade/ldd/datafiles/lddfile5.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+void file5(void)
+{
+	printf("Control in function %s\n", __func__);
+}
diff --git a/testcases/commands/ade/ldd/datafiles/main.c b/testcases/commands/ade/ldd/datafiles/main.c
new file mode 100644
index 0000000..69e278e
--- /dev/null
+++ b/testcases/commands/ade/ldd/datafiles/main.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+void file1(void);
+void file2(void);
+void file3(void);
+void file4(void);
+void file5(void);
+
+int main(void)
+{
+	file1();
+	file2();
+	file3();
+	file4();
+	file5();
+	printf("All Functions Executed\n");
+	return 0;
+}
diff --git a/testcases/commands/ade/ldd/ldd01 b/testcases/commands/ade/ldd/ldd01
index c60d3ac..c0e4d07 100755
--- a/testcases/commands/ade/ldd/ldd01
+++ b/testcases/commands/ade/ldd/ldd01
@@ -32,67 +32,37 @@
 #trace_logic=${trace_logic:-"set -x"}
 $trace_logic
 
-CC=${CC:=gcc}
 LDD=${LDD:=ldd}
-TCdat=${TCdat:-`pwd`}
-TCtmp=${TCtmp:-/tmp/ldd01-$$}
+TCID=ldd01
+TST_TOTAL=1
 
-do_cleanup()
-{
-	rm -rf $TCtmp
-}
+. test.sh
 
-do_setup()
+do_test()
 {
-	mkdir $TCtmp
 
-	# Check for ppc64 architecture or x86_64 architecture
-	if uname -a | grep -iq powerpc; then
-		file lddfile1.obj | grep 64-bit >/dev/null 2>&1
-		if [ $? -eq 0 ]; then
-			CFLAGS="-m64"
-		fi
-	elif uname -a | grep -iq x86_64; then
-		file lddfile1.obj | grep 32-bit >/dev/null 2>&1
-		if [ $? -eq 0 ]; then
-			CFLAGS="-m32"
-		fi
-	fi
-	$CC $CFLAGS -shared -o $TCtmp/lddfile1.obj.so $TCdat/lddfile1.obj
-	$CC $CFLAGS -shared -o $TCtmp/lddfile2.obj.so $TCdat/lddfile2.obj
-	$CC $CFLAGS -shared -o $TCtmp/lddfile3.obj.so $TCdat/lddfile3.obj
-	$CC $CFLAGS -shared -o $TCtmp/lddfile4.obj.so $TCdat/lddfile4.obj
-	$CC $CFLAGS -shared -o $TCtmp/lddfile5.obj.so $TCdat/lddfile5.obj
-	$CC $CFLAGS -O -o $TCtmp/a.out $TCtmp/lddfile*.obj.so $TCdat/main.obj
-}
+	export LD_LIBRARY_PATH="$LTP_DATAROOT:$LD_LIBRARY_PATH"
+	LDDTESTFILE="$LTP_DATAROOT/lddfile.out"
 
-do_test()
-{
 	echo "  ASSERTION 1  "
-
-	$LDD $TCtmp/a.out | grep -E "lddfile1.obj.so|lddfile2.obj.so|lddfile3.obj.so|lddfile4.obj.so|lddfile5.obj.so"
+	$LDD $LDDTESTFILE | grep -E "lddfile1.obj.so|lddfile2.obj.so|lddfile3.obj.so|lddfile4.obj.so|lddfile5.obj.so"
 	if [ $? -eq 0 ]; then
 		echo "ASSERTION #1 PASS"
 	else
 		echo "ASSERTION #1 FAIL"
-		do_cleanup
 		return 1
 	fi
 
 	echo " ASSERTION 2  "
-
-	$LDD -v $TCtmp/a.out | grep -E "GLIBC|lddfile1.obj.so|lddfile2.obj.so|lddfile3.obj.so|lddfile4.obj.so|lddfile5.obj.so"
+	$LDD -v $LDDTESTFILE | grep -E "GLIBC|lddfile1.obj.so|lddfile2.obj.so|lddfile3.obj.so|lddfile4.obj.so|lddfile5.obj.so"
 	if [ $? -eq 0 ]; then
 		echo "ASSERTION #2 PASS"
 	else
 		echo "ASSERTION #2 FAIL"
-		do_cleanup
 		return 1
 	fi
 
 	echo "TEST PASSES"
-	do_cleanup
 	return 0
 }
-do_setup
 do_test
diff --git a/testcases/commands/ade/ldd/lddfile1.c b/testcases/commands/ade/ldd/lddfile1.c
deleted file mode 100644
index 377f7a3..0000000
--- a/testcases/commands/ade/ldd/lddfile1.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdio.h>
-void file1()
-{
-	printf("Control in function %s\n", __func__);
-}
diff --git a/testcases/commands/ade/ldd/lddfile2.c b/testcases/commands/ade/ldd/lddfile2.c
deleted file mode 100644
index 5fd2b4b..0000000
--- a/testcases/commands/ade/ldd/lddfile2.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdio.h>
-void file2()
-{
-	printf("Control in function %s\n", __func__);
-}
diff --git a/testcases/commands/ade/ldd/lddfile3.c b/testcases/commands/ade/ldd/lddfile3.c
deleted file mode 100644
index d6b4cc9..0000000
--- a/testcases/commands/ade/ldd/lddfile3.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdio.h>
-void file3()
-{
-	printf("Control in function %s\n", __func__);
-}
diff --git a/testcases/commands/ade/ldd/lddfile4.c b/testcases/commands/ade/ldd/lddfile4.c
deleted file mode 100644
index 1db89bb..0000000
--- a/testcases/commands/ade/ldd/lddfile4.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdio.h>
-void file4()
-{
-	printf("Control in function %s\n", __func__);
-}
diff --git a/testcases/commands/ade/ldd/lddfile5.c b/testcases/commands/ade/ldd/lddfile5.c
deleted file mode 100644
index 2f46cdb..0000000
--- a/testcases/commands/ade/ldd/lddfile5.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdio.h>
-void file5()
-{
-	printf("Control in function %s\n", __func__);
-}
diff --git a/testcases/commands/ade/ldd/main.c b/testcases/commands/ade/ldd/main.c
deleted file mode 100644
index 0f23b8b..0000000
--- a/testcases/commands/ade/ldd/main.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <stdio.h>
-
-void file1();
-void file2();
-void file3();
-void file4();
-void file5();
-
-int main()
-{
-	file1();
-	file2();
-	file3();
-	file4();
-	file5();
-	printf("All Functions Executed\n");
-	return 0;
-}
-- 
1.7.1


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://p.sf.net/sfu/Zoho
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot()
  2014-10-13 12:10 [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot() Jan Stancek
  2014-10-13 12:10 ` [LTP] [PATCH 2/2 v3] ldd01: remove all -m32/-m64 logic Jan Stancek
@ 2014-10-14 15:47 ` Cyril Hrubis
       [not found]   ` <900297128.9002452.1413303441974.JavaMail.zimbra@redhat.com>
  1 sibling, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2014-10-14 15:47 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> LTP_DATAROOT (test.sh) and tst_dataroot (libltp) define directory
> which holds test data files.
> 
> If LTPROOT is defined, it is $LTPROOT/testcases/data/$TCID
> otherwise it's $CWD/datafiles (where CWD is current working
> directory, before any call to tst_tmdir())

...

>  2.1.3 Subexecutables
>  ^^^^^^^^^^^^^^^^^^^^
> diff --git a/include/tst_resource.h b/include/tst_resource.h
> index a02a313..94c24b7 100644
> --- a/include/tst_resource.h
> +++ b/include/tst_resource.h
> @@ -41,6 +41,9 @@
>  
>  #include "test.h"
>  
> +void tst_dataroot_init(void);

Do we really need to export this function? The only usage for it IMHO
will be the test for the tst_dataroot() function itself. I would rather
see three tests one for each scenario and keep the test library API as
minimal as possible.

> +const char *tst_dataroot(void);
> +

...

> diff --git a/lib/tst_resource.c b/lib/tst_resource.c
> index 54d4795..7c8deee 100644
> --- a/lib/tst_resource.c
> +++ b/lib/tst_resource.c
> @@ -21,9 +21,61 @@
>   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>   */
>  
> +#include <pthread.h>
>  #include "tst_resource.h"
>  #include "ltp_priv.h"
>  
> +#ifndef PATH_MAX
> +#ifdef MAXPATHLEN
> +#define PATH_MAX	MAXPATHLEN
> +#else
> +#define PATH_MAX	1024
> +#endif
> +#endif
> +
> +static pthread_mutex_t tmutex = PTHREAD_MUTEX_INITIALIZER;
> +static char dataroot[PATH_MAX];
> +extern char *TCID;
> +
> +void tst_dataroot_init(void)
> +{
> +	const char *ltproot = getenv("LTPROOT");
> +	char curdir[PATH_MAX];
> +	const char *startdir;
> +	int ret;
> +
> +	/* 1. if LTPROOT is set, use $LTPROOT/testcases/data/$TCID
> +	 * 2. else if startwd is set by tst_tmdir(), use $STARWD/datafiles
> +	 * 3. else use $CWD/datafiles */
> +	if (ltproot) {
> +		ret = snprintf(dataroot, PATH_MAX, "%s/testcases/data/%s",
> +			ltproot, TCID);
> +	} else {
> +		startdir = tst_get_startwd();
> +		if (startdir[0] == 0) {
> +			if (getcwd(curdir, PATH_MAX) == NULL)
> +				tst_brkm(TBROK | TERRNO, NULL,
> +					"tst_dataroot getcwd");
> +			startdir = curdir;
> +		}
> +		ret = snprintf(dataroot, PATH_MAX, "%s/datafiles", startdir);
> +	}
> +
> +	if (ret < 0 || ret >= PATH_MAX)
> +		tst_brkm(TBROK, NULL, "tst_dataroot snprintf: %d", ret);
> +}
> +
> +const char *tst_dataroot(void)
> +{
> +	if (dataroot[0] == 0) {
> +		pthread_mutex_lock(&tmutex);
> +		if (dataroot[0] == 0)
> +			tst_dataroot_init();
> +		pthread_mutex_unlock(&tmutex);
> +	}

That is a bit too preemptive but generally fine, but I would use
pthread_once() here instead.

> +	return dataroot;
> +}
> +
>  static int file_copy(const char *file, const int lineno,
>                       void (*cleanup_fn)(void), const char *path,
>  		     const char *filename, const char *dest)
> @@ -56,15 +108,15 @@ void tst_resource_copy(const char *file, const int lineno,
>  		dest = ".";
>  
>  	const char *ltproot = getenv("LTPROOT");
> +	const char *dataroot = tst_dataroot();
> +
> +	/* look for data files in $LTP_DATAROOT, $LTPROOT/testcases/bin
> +	 * and $CWD */
> +	if (file_copy(file, lineno, cleanup_fn, dataroot, filename, dest))
> +		return;
>  
>  	if (ltproot != NULL) {
> -		/* the data are either in testcases/data or testcases/bin */
>  		char buf[strlen(ltproot) + 64];
> -
> -		snprintf(buf, sizeof(buf), "%s/testcases/data", ltproot);
> -
> -		if (file_copy(file, lineno, cleanup_fn, buf, filename, dest))
> -			return;
>  		
>  		snprintf(buf, sizeof(buf), "%s/testcases/bin", ltproot);

Hmm, maybe we can omit looking into testcases/bin/, since the
directory to store datafiles is well defined now (and there does not
seems to be any testcases that rely on that behavior).

> @@ -72,9 +124,8 @@ void tst_resource_copy(const char *file, const int lineno,
>  			return;
>  	}
>  
> +	/* try directory test started in as last resort */
>  	const char *startwd = tst_get_startwd();
> -
> -	/* try directory test started int first */
>  	if (file_copy(file, lineno, cleanup_fn, startwd, filename, dest))
>  		return;
>  
> diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
> index 10282f4..eecbfba 100644
> --- a/testcases/lib/test.sh
> +++ b/testcases/lib/test.sh
> @@ -144,4 +144,7 @@ export TST_TOTAL="$TST_TOTAL"
>  # Setup LTPROOT, default to current directory if not set
>  if [ -z "$LTPROOT" ]; then
>  	export LTPROOT="$PWD"
> +	export LTP_DATAROOT="$LTPROOT/datafiles"
> +else
> +	export LTP_DATAROOT="$LTPROOT/testcases/data/$TCID"
>  fi


Otherwise it looks very good.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot()
       [not found]   ` <900297128.9002452.1413303441974.JavaMail.zimbra@redhat.com>
@ 2014-10-15  6:30     ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2014-10-15  6:30 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list

Hi!
> > Hmm, maybe we can omit looking into testcases/bin/, since the
> > directory to store datafiles is well defined now (and there does not
> > seems to be any testcases that rely on that behavior).
> 
> At least creat07 needs it. It creates temporary dir and then copies
> creat07_child to it - creat07_child is not treated as datafile.
> I'd keep the fallback to testcases/bin - it doesn't hurt anything.

Ah, the ETXTBSY one that tries to call creat() on currently executed
binary, I've missed this one. Ok, let's keep it there.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2014-10-15  6:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-13 12:10 [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot() Jan Stancek
2014-10-13 12:10 ` [LTP] [PATCH 2/2 v3] ldd01: remove all -m32/-m64 logic Jan Stancek
2014-10-14 15:47 ` [LTP] [PATCH 1/2 v3] add LTP_DATAROOT and tst_dataroot() Cyril Hrubis
     [not found]   ` <900297128.9002452.1413303441974.JavaMail.zimbra@redhat.com>
2014-10-15  6:30     ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.