All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions
@ 2014-02-11  9:48 Alexey Kodanev
  2014-02-11  9:48 ` [LTP] [PATCH v2 3/4] lib: compile *_r.c to libltp_r library, add testcases_r.mk Alexey Kodanev
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Alexey Kodanev @ 2014-02-11  9:48 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko, Alexey Kodanev

Use thread-safe versions of tst_res's functions if tests linked
with pthread library.

Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
 include/test.h |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/include/test.h b/include/test.h
index 29824d3..e3de278 100644
--- a/include/test.h
+++ b/include/test.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  * Copyright (c) 2009-2013 Cyril Hrubis chrubis@suse.cz
+ * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
  *
  * 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
@@ -114,6 +115,36 @@
 extern int Forker_pids[];
 extern int Forker_npids;
 
+/*
+ * Macro to use for making functions called only once in
+ * multi-threaded tests such as init or cleanup function.
+ * The first call to @name_fn function by any thread shall
+ * call the @exec_fn. Subsequent calls shall not call @exec_fn.
+ * *_fn functions must not take any arguments.
+ */
+#define DECLARE_ONCE_FN(name_fn, exec_fn)			\
+	static pthread_once_t name_fn##_ex = PTHREAD_ONCE_INIT;	\
+	void name_fn(void)					\
+	{							\
+		pthread_once(&name_fn##_ex, exec_fn);		\
+	}
+
+/*
+ * Will be defined if test is compiled with -pthread.
+ * Then we can use thread-safe versions.
+ */
+#ifdef _REENTRANT
+#define tst_res			tst_res_r
+#define tst_resm		tst_resm_r
+#define tst_resm_hexd		tst_resm_hexd_r
+#define tst_brk			tst_brk_r
+#define tst_brkm		tst_brkm_r
+#define tst_require_root	tst_require_root_r
+#define tst_flush		tst_flush_r
+#define tst_exit		tst_exit_r
+#define tst_environ		tst_environ_r
+#endif
+
 /* lib/tst_res.c */
 const char *strttype(int ttype);
 void tst_res(int ttype, char *fname, char *arg_fmt, ...)
-- 
1.7.1


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2 3/4] lib: compile *_r.c to libltp_r library, add testcases_r.mk
  2014-02-11  9:48 [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions Alexey Kodanev
@ 2014-02-11  9:48 ` Alexey Kodanev
  2014-02-11  9:48 ` [LTP] [PATCH 4/4] lib: add tst_res_r.c Alexey Kodanev
  2014-02-12 15:37 ` [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions chrubis
  2 siblings, 0 replies; 14+ messages in thread
From: Alexey Kodanev @ 2014-02-11  9:48 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko, Alexey Kodanev

Add rules to build *_r.c files. All compiled lib/*_r.c files will be
included in libltp_r.a library.
testcases_r.mk can be used in multi-threaded tests.

Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
 include/mk/lib.mk         |   15 ++++++++++++++-
 include/mk/testcases_r.mk |   29 +++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletions(-)
 create mode 100644 include/mk/testcases_r.mk

diff --git a/include/mk/lib.mk b/include/mk/lib.mk
index 456db24..3bec31c 100644
--- a/include/mk/lib.mk
+++ b/include/mk/lib.mk
@@ -20,6 +20,7 @@
 # Garrett Cooper, July 2009
 #
 # Copyright (C) Cyril Hrubis <chrubis@suse.cz> 2012
+# Copyright (C) 2014 Oracle and/or its affiliates. All Rights Reserved.
 #
 
 # Makefile to include for libraries.
@@ -46,7 +47,7 @@ ifneq ($(MAKECMDGOALS),install)
 LIB ?= $(INTERNAL_LIB)
 endif
 
-MAKE_TARGETS	+= $(LIB)
+MAKE_TARGETS	+= $(LIB) $(LIB_R)
 
 LIBSRCS		?= $(wildcard $(abs_srcdir)/*.c)
 
@@ -60,7 +61,11 @@ LIBSRCS		:= $(subst $(abs_srcdir)/,,$(wildcard $(LIBSRCS)))
 
 LIBSRCS		:= $(filter-out $(FILTER_OUT_LIBSRCS),$(LIBSRCS))
 
+LIBSRCS_R	:= $(filter %_r.c,$(LIBSRCS))
+LIBSRCS		:= $(filter-out %_r.c,$(LIBSRCS))
+
 LIBOBJS		:= $(LIBSRCS:.c=.o)
+LIBOBJS_R	:= $(LIBSRCS_R:.c=.o)
 
 $(LIB): $(notdir $(LIBOBJS))
 	if [ -z "$(strip $^)" ] ; then \
@@ -70,4 +75,12 @@ $(LIB): $(notdir $(LIBOBJS))
 	$(if $(AR),$(AR),ar) -rc "$@" $^
 	$(if $(RANLIB),$(RANLIB),ranlib) "$@"
 
+$(LIB_R): $(notdir $(LIBOBJS_R))
+	if [ -z "$(strip $^)" ] ; then \
+		echo "Cowardly refusing to create empty archive"; \
+		exit 1; \
+	fi
+	$(if $(AR),$(AR),ar) -rc "$@" $^
+	$(if $(RANLIB),$(RANLIB),ranlib) "$@"
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/include/mk/testcases_r.mk b/include/mk/testcases_r.mk
new file mode 100644
index 0000000..49db8a5
--- /dev/null
+++ b/include/mk/testcases_r.mk
@@ -0,0 +1,29 @@
+# Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
+#
+# 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 would 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 the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+#
+# For inclusion in multi-threaded test-cases
+#
+
+include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/functions.mk
+
+# Link static libltp_r before libltp because it has unresolved symbols
+# defined in libltp
+LDLIBS		+= -lltp_r -pthread
+
+include $(top_srcdir)/include/mk/testcases.mk
-- 
1.7.1


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-11  9:48 [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions Alexey Kodanev
  2014-02-11  9:48 ` [LTP] [PATCH v2 3/4] lib: compile *_r.c to libltp_r library, add testcases_r.mk Alexey Kodanev
@ 2014-02-11  9:48 ` Alexey Kodanev
  2014-02-12 15:44   ` chrubis
  2014-02-13  8:47   ` Mike Frysinger
  2014-02-12 15:37 ` [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions chrubis
  2 siblings, 2 replies; 14+ messages in thread
From: Alexey Kodanev @ 2014-02-11  9:48 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko, Alexey Kodanev

It contains thread-safe versions of functions defined in tst_res.c.
NOPASS mode not implemented yet.

Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
 lib/tst_res_r.c |  499 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 499 insertions(+), 0 deletions(-)
 create mode 100644 lib/tst_res_r.c

diff --git a/lib/tst_res_r.c b/lib/tst_res_r.c
new file mode 100644
index 0000000..1cf79ad
--- /dev/null
+++ b/lib/tst_res_r.c
@@ -0,0 +1,499 @@
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2009-2013 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
+ *
+ * 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 would 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 the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <pthread.h>
+#include "tst_res.h"
+
+/*
+ * Synchronize access to global vars T_exitval, T_out, tst_count with
+ * mutexes.
+ */
+pthread_mutex_t exitval_mutex = PTHREAD_MUTEX_INITIALIZER,
+                tstcount_mutex =  PTHREAD_MUTEX_INITIALIZER,
+                tout_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static int exitval_or(int ttype_result)
+{
+	int res;
+	pthread_mutex_lock(&exitval_mutex);
+	res = T_exitval |= ttype_result;
+	pthread_mutex_unlock(&exitval_mutex);
+	return res;
+}
+
+static int exitval_and(int ttype_result)
+{
+	int res;
+	pthread_mutex_lock(&exitval_mutex);
+	res = T_exitval &= ttype_result;
+	pthread_mutex_unlock(&exitval_mutex);
+	return res;
+}
+
+static int get_tst_count()
+{
+	int res;
+	pthread_mutex_lock(&tstcount_mutex);
+	res = tst_count;
+	pthread_mutex_unlock(&tstcount_mutex);
+	return res;
+}
+
+static void cat_file_r(char *filename);
+
+/*
+ * tst_print_r() - thread-safe version of tst_print()
+ * Additionally takes filename, because it isn't using global File
+ */
+static void tst_print_r(char *tcid, char *fname, int tnum, int ttype, char *tmesg)
+{
+	/*
+	 * avoid unintended side effects from failures with fprintf when
+	 * calling write(2), et all.
+	 */
+	int err = errno;
+	const char *type;
+	int ttype_result = TTYPE_RESULT(ttype);
+	char message[USERMESG];
+	size_t size;
+
+#if DEBUG
+	printf("IN tst_print_r: tnum = %d, ttype = %d, tmesg = %s\n",
+	       tnum, ttype, tmesg);
+	fflush(stdout);
+#endif
+
+	/*
+	 * Save the test result type by ORing ttype into the current exit value
+	 * (used by tst_exit()).  This is already done in tst_res(), but is
+	 * also done here to catch internal warnings.  For internal warnings,
+	 * tst_print() is called directly with a case of TWARN.
+	 */
+	exitval_or(ttype_result);
+
+	/*
+	 * If output mode is DISCARD, or if the output mode is NOPASS and this
+	 * result is not one of FAIL, BROK, or WARN, just return.  This check
+	 * is necessary even though we check for DISCARD mode inside of
+	 * tst_res(), since occasionally we get to this point without going
+	 * through tst_res() (e.g. internal TWARN messages).
+	 */
+	if (T_mode == DISCARD || (T_mode == NOPASS && ttype_result != TFAIL &&
+				  ttype_result != TBROK
+				  && ttype_result != TWARN))
+		return;
+
+	/*
+	 * Build the result line and print it.
+	 */
+	type = strttype(ttype);
+	if (T_mode == VERBOSE) {
+		size = snprintf(message, sizeof(message),
+				"%-8s %4d  %s  :  %s", tcid, tnum, type, tmesg);
+	} else {
+		size = snprintf(message, sizeof(message),
+				"%-8s %4d       %s  :  %s",
+				tcid, tnum, type, tmesg);
+	}
+
+	if (size >= sizeof(message)) {
+		printf("%s: %i: line too long\n", __func__, __LINE__);
+		abort();
+	}
+
+	if (ttype & TERRNO) {
+		size += snprintf(message + size, sizeof(message) - size,
+				 ": errno=%s(%i): %s", strerrnodef(err),
+				 err, strerror(err));
+	}
+
+	if (size >= sizeof(message)) {
+		printf("%s: %i: line too long\n", __func__, __LINE__);
+		abort();
+	}
+
+	if (ttype & TTERRNO) {
+		size += snprintf(message + size, sizeof(message) - size,
+				 ": TEST_ERRNO=%s(%i): %s",
+				 strerrnodef(TEST_ERRNO), (int)TEST_ERRNO,
+				 strerror(TEST_ERRNO));
+	}
+
+	if (size + 1 >= sizeof(message)) {
+		printf("%s: %i: line too long\n", __func__, __LINE__);
+		abort();
+	}
+
+	message[size] = '\n';
+	message[size + 1] = '\0';
+
+	pthread_mutex_lock(&tout_mutex);
+	fputs(message, T_out);
+	pthread_mutex_unlock(&tout_mutex);
+
+	/*
+	 * If tst_res() was called with a file, append file contents to the
+	 * end of last printed result.
+	 */
+	if (fname != NULL)
+		cat_file_r(fname);
+}
+
+/*
+ * check_env_once() - thread-safe version of check_env()
+ */
+static void check_env_once(void)
+{
+	char *value;
+
+#if DEBUG
+	printf("IN check_env_r\n");
+	fflush(stdout);
+#endif
+
+	/* BTOUTPUT not defined, use default */
+	if ((value = getenv(TOUTPUT)) == NULL) {
+		T_mode = VERBOSE;
+		return;
+	}
+
+	if (strcmp(value, TOUT_NOPASS_S) == 0) {
+		T_mode = NOPASS;
+		return;
+	}
+
+	if (strcmp(value, TOUT_DISCARD_S) == 0) {
+		T_mode = DISCARD;
+		return;
+	}
+
+	/* default */
+	T_mode = VERBOSE;
+	return;
+}
+DECLARE_ONCE_FN(check_env_r, check_env_once)
+
+/*
+ * tst_res_r() - thread-safe version of tst_res()
+ * Note: NOPASS mode not implemented
+ */
+void tst_res_r(int ttype, char *fname, char *arg_fmt, ...)
+{
+	char tmesg[USERMESG];
+	int ttype_result = TTYPE_RESULT(ttype);
+
+#if DEBUG
+	printf("IN tst_res_r; tst_count = %d\n", get_tst_count());
+	fflush(stdout);
+#endif
+
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+	/*
+	 * Save the test result type by ORing ttype into the current exit
+	 * value (used by tst_exit()).
+	 */
+	exitval_or(ttype_result);
+	/*
+	 * Unless T_out has already been set by tst_environ(), make tst_res()
+	 * output go to standard output.
+	 */
+	pthread_mutex_lock(&tout_mutex);
+	if (T_out == NULL)
+		T_out = stdout;
+	pthread_mutex_unlock(&tout_mutex);
+
+	/*
+	 * Check TOUTPUT environment variable (if first time) and set T_mode
+	 * flag.
+	 */
+	check_env_r();
+
+	if (fname != 0 && access(fname, F_OK) != 0)
+		fname = NULL;
+
+	/*
+	 * Set the test case number and print the results, depending on the
+	 * display type.
+	 */
+	if (ttype_result == TWARN || ttype_result == TINFO) {
+		tst_print_r(TCID, fname, 0, ttype, tmesg);
+	} else {
+		if (get_tst_count() < 0)
+			tst_print_r(TCID, NULL, 0, TWARN,
+				  "tst_res(): tst_count < 0 is not valid");
+
+		/*
+		 * Process each display type.
+		 */
+		switch (T_mode) {
+		case DISCARD:
+			break;
+		/* thread-safe NOPASS mode not implemented */
+		default:	/* VERBOSE */
+			tst_print_r(TCID, fname, get_tst_count() + 1,
+				ttype, tmesg);
+			break;
+		}
+
+		pthread_mutex_lock(&tstcount_mutex);
+		++tst_count;
+		pthread_mutex_unlock(&tstcount_mutex);
+	}
+}
+
+/*
+ * tst_flush_r() - thread-safe version of tst_flush()
+ * Note: NOPASS mode not implemented
+ */
+void tst_flush_r(void)
+{
+#if DEBUG
+	printf("IN tst_flush_r\n");
+	fflush(stdout);
+#endif
+
+	pthread_mutex_lock(&tout_mutex);
+	fflush(T_out);
+	pthread_mutex_unlock(&tout_mutex);
+}
+
+/*
+ * cat_file_r() - thread-safe version of cat_file()
+ */
+static void cat_file_r(char *filename)
+{
+	FILE *fp;
+	int b_read = 0, b_written = 0;
+	char buffer[BUFSIZ];
+	char warn_msg[MAXMESG];
+
+#if DEBUG
+	printf("IN cat_file_r\n");
+	fflush(stdout);
+#endif
+
+	if ((fp = fopen(filename, "r")) == NULL) {
+		sprintf(warn_msg,
+			"tst_res(): fopen(%s, \"r\") failed; errno = %d: %s",
+			filename, errno, strerror(errno));
+		tst_print_r(TCID, NULL, 0, TWARN, warn_msg);
+		return;
+	}
+
+	errno = 0;
+
+	pthread_mutex_lock(&tout_mutex);
+	while ((b_read = fread(buffer, 1, BUFSIZ, fp)) != 0) {
+		b_written = fwrite(buffer, 1, b_read, T_out);
+		if (b_written != b_read)
+			break;
+	}
+	pthread_mutex_unlock(&tout_mutex);
+
+	if (b_read && b_written != b_read) {
+		sprintf(warn_msg, "tst_res(): While trying to cat \"%s\", "
+			"fwrite() wrote only %d of %d bytes",
+			filename, b_written, b_read);
+		tst_print_r(TCID, NULL, 0, TWARN, warn_msg);
+	}
+
+	if (!feof(fp)) {
+		sprintf(warn_msg,
+			"tst_res(): While trying to cat \"%s\", fread() "
+			"failed, errno = %d: %s",
+			filename, errno, strerror(errno));
+		tst_print_r(TCID, NULL, 0, TWARN, warn_msg);
+	}
+
+	if (fclose(fp) != 0) {
+		sprintf(warn_msg,
+			"tst_res(): While trying to cat \"%s\", fclose() "
+			"failed, errno = %d: %s",
+			filename, errno, strerror(errno));
+		tst_print_r(TCID, NULL, 0, TWARN, warn_msg);
+	}
+}
+
+
+/*
+ * tst_exit_once() - thread-safe version of tst_exit()
+ */
+static void tst_exit_once(void)
+{
+#if DEBUG
+	printf("IN tst_exit_r\n");
+	fflush(stdout);
+	fflush(stdout);
+#endif
+
+	/* Call tst_flush() flush any output in the buffer. */
+	tst_flush_r();
+
+	/* Mask out TRETR, TINFO, and TCONF results from the exit status. */
+	exit(exitval_and(~(TRETR | TINFO | TCONF)));
+}
+DECLARE_ONCE_FN(tst_exit_r, tst_exit_once)
+
+/*
+ * tst_environ_r() - thread-safe version of tst_environ()
+ */
+int tst_environ_r(void)
+{
+	int res;
+	pthread_mutex_lock(&tout_mutex);
+	T_out = fdopen(dup(fileno(stdout)), "w");
+	res = T_out ? 0 : -1;
+	pthread_mutex_unlock(&tout_mutex);
+	return res;
+}
+
+/*
+ * tst_brk_r() - thread-safe version of tst_brk()
+ */
+void tst_brk_r(int ttype, char *fname, void (*func) (void), char *arg_fmt, ...)
+{
+	char tmesg[USERMESG];
+	int ttype_result = TTYPE_RESULT(ttype);
+	char warn_msg[MAXMESG];
+
+#if DEBUG
+	printf("IN tst_brk_r\n");
+	fflush(stdout);
+	fflush(stdout);
+#endif
+
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+	/*
+	 * Only FAIL, BROK, CONF, and RETR are supported by tst_brk().
+	 */
+	if (ttype_result != TFAIL && ttype_result != TBROK &&
+	    ttype_result != TCONF && ttype_result != TRETR) {
+		sprintf(warn_msg, "%s: Invalid Type: %d. Using TBROK",
+			__func__, ttype_result);
+		tst_print_r(TCID, fname, 0, TWARN, warn_msg);
+		/* Keep TERRNO, TTERRNO, etc. */
+		ttype = (ttype & ~ttype_result) | TBROK;
+	}
+
+	tst_res_r(ttype, fname, "%s", tmesg);
+
+	if (ttype_result == TCONF)
+		tst_res_r(ttype, NULL,
+			"Remaining cases not appropriate for "
+			"configuration");
+	else if (ttype_result == TRETR)
+		tst_res_r(ttype, NULL, "Remaining cases retired");
+	else if (ttype_result == TBROK)
+		tst_res_r(TBROK, NULL, "Remaining cases broken");
+
+	if (func != NULL)
+		(*func) ();
+	tst_exit_r();
+}
+
+/*
+ * tst_resm_r() - thread-safe version of tst_resm()
+ */
+void tst_resm_r(int ttype, char *arg_fmt, ...)
+{
+	char tmesg[USERMESG];
+
+#if DEBUG
+	printf("IN tst_resm_r\n");
+	fflush(stdout);
+	fflush(stdout);
+#endif
+
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+	tst_res_r(ttype, NULL, "%s", tmesg);
+}
+
+/*
+ * tst_resm_hexd_r() - thread-safe version of tst_resm_hexd()
+ */
+void tst_resm_hexd_r(int ttype, const void *buf, size_t size, char *arg_fmt, ...)
+{
+	char tmesg[USERMESG];
+
+#if DEBUG
+	printf("IN tst_resm_hexd_r\n");
+	fflush(stdout);
+#endif
+
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+	static const size_t symb_num	= 2; /* xx */
+	static const size_t size_max	= 16;
+	size_t offset = strlen(tmesg);
+	char *pmesg = tmesg;
+
+	if (size > size_max || size == 0 ||
+		(offset + size * (symb_num + 1)) >= USERMESG)
+		tst_res_r(ttype, NULL, "%s", tmesg);
+	else
+		pmesg += offset;
+
+	size_t i;
+	for (i = 0; i < size; ++i) {
+		/* add space before byte except first one */
+		if (pmesg != tmesg)
+			*(pmesg++) = ' ';
+
+		sprintf(pmesg, "%02x", ((unsigned char *)buf)[i]);
+		pmesg += symb_num;
+		if ((i + 1) % size_max == 0 || i + 1 == size) {
+			tst_res_r(ttype, NULL, "%s", tmesg);
+			pmesg = tmesg;
+		}
+	}
+}
+
+/*
+ * tst_brkm_r() - thread-safe version of tst_brkm()
+ */
+void tst_brkm_r(int ttype, void (*func) (void), char *arg_fmt, ...)
+{
+	char tmesg[USERMESG];
+
+#if DEBUG
+	printf("IN tst_brkm_r\n");
+	fflush(stdout);
+	fflush(stdout);
+#endif
+
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
+
+	tst_brk_r(ttype, NULL, func, "%s", tmesg);
+	/* Shouldn't be reach, but fixes build time warnings about noreturn. */
+	abort();
+}
+
+/*
+ * tst_require_root_r() - thread-safe version of tst_require_root()
+ */
+void tst_require_root_r(void (*func) (void))
+{
+	if (geteuid() != 0)
+		tst_brkm_r(TCONF, func, "Test needs to be run as root");
+}
-- 
1.7.1


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions
  2014-02-11  9:48 [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions Alexey Kodanev
  2014-02-11  9:48 ` [LTP] [PATCH v2 3/4] lib: compile *_r.c to libltp_r library, add testcases_r.mk Alexey Kodanev
  2014-02-11  9:48 ` [LTP] [PATCH 4/4] lib: add tst_res_r.c Alexey Kodanev
@ 2014-02-12 15:37 ` chrubis
  2 siblings, 0 replies; 14+ messages in thread
From: chrubis @ 2014-02-12 15:37 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list

Hi!
> Use thread-safe versions of tst_res's functions if tests linked
> with pthread library.
> 
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
>  include/test.h |   31 +++++++++++++++++++++++++++++++
>  1 files changed, 31 insertions(+), 0 deletions(-)
> 
> diff --git a/include/test.h b/include/test.h
> index 29824d3..e3de278 100644
> --- a/include/test.h
> +++ b/include/test.h
> @@ -1,6 +1,7 @@
>  /*
>   * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
>   * Copyright (c) 2009-2013 Cyril Hrubis chrubis@suse.cz
> + * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
>   *
>   * 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
> @@ -114,6 +115,36 @@
>  extern int Forker_pids[];
>  extern int Forker_npids;
>  
> +/*
> + * Macro to use for making functions called only once in
> + * multi-threaded tests such as init or cleanup function.
> + * The first call to @name_fn function by any thread shall
> + * call the @exec_fn. Subsequent calls shall not call @exec_fn.
> + * *_fn functions must not take any arguments.
> + */
> +#define DECLARE_ONCE_FN(name_fn, exec_fn)			\
> +	static pthread_once_t name_fn##_ex = PTHREAD_ONCE_INIT;	\
> +	void name_fn(void)					\
> +	{							\
> +		pthread_once(&name_fn##_ex, exec_fn);		\
> +	}

We can hide the pthread_once vairable from the global namespace by
putting it to the body of the function (because it's static).

> +/*
> + * Will be defined if test is compiled with -pthread.
> + * Then we can use thread-safe versions.
> + */
> +#ifdef _REENTRANT
> +#define tst_res			tst_res_r
> +#define tst_resm		tst_resm_r
> +#define tst_resm_hexd		tst_resm_hexd_r
> +#define tst_brk			tst_brk_r
> +#define tst_brkm		tst_brkm_r
> +#define tst_require_root	tst_require_root_r
> +#define tst_flush		tst_flush_r
> +#define tst_exit		tst_exit_r
> +#define tst_environ		tst_environ_r
> +#endif
> +

I would rather see this done in less hacky way. I'm thinking how, but
know of anything better for now.


-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-11  9:48 ` [LTP] [PATCH 4/4] lib: add tst_res_r.c Alexey Kodanev
@ 2014-02-12 15:44   ` chrubis
       [not found]     ` <5128140.KmexAZrTeg@vapier>
  2014-02-13  8:47   ` Mike Frysinger
  1 sibling, 1 reply; 14+ messages in thread
From: chrubis @ 2014-02-12 15:44 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list

Hi!
> It contains thread-safe versions of functions defined in tst_res.c.
> NOPASS mode not implemented yet.
> 
> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
> ---
>  lib/tst_res_r.c |  499 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 499 insertions(+), 0 deletions(-)
>  create mode 100644 lib/tst_res_r.c
> 
> diff --git a/lib/tst_res_r.c b/lib/tst_res_r.c
> new file mode 100644
> index 0000000..1cf79ad
> --- /dev/null
> +++ b/lib/tst_res_r.c
> @@ -0,0 +1,499 @@
> +/*
> + * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
> + * Copyright (c) 2009-2013 Cyril Hrubis <chrubis@suse.cz>
> + * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
> + *
> + * 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 would 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 the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + *
> + */
> +
> +#include <pthread.h>
> +#include "tst_res.h"
> +
> +/*
> + * Synchronize access to global vars T_exitval, T_out, tst_count with
> + * mutexes.
> + */
> +pthread_mutex_t exitval_mutex = PTHREAD_MUTEX_INITIALIZER,
> +                tstcount_mutex =  PTHREAD_MUTEX_INITIALIZER,
> +                tout_mutex = PTHREAD_MUTEX_INITIALIZER;

This should be static.

> +static int exitval_or(int ttype_result)
> +{
> +	int res;
> +	pthread_mutex_lock(&exitval_mutex);
> +	res = T_exitval |= ttype_result;
> +	pthread_mutex_unlock(&exitval_mutex);
> +	return res;
> +}
> +
> +static int exitval_and(int ttype_result)
> +{
> +	int res;
> +	pthread_mutex_lock(&exitval_mutex);
> +	res = T_exitval &= ttype_result;
> +	pthread_mutex_unlock(&exitval_mutex);
> +	return res;
> +}
> +
> +static int get_tst_count()
> +{
> +	int res;
> +	pthread_mutex_lock(&tstcount_mutex);
> +	res = tst_count;
> +	pthread_mutex_unlock(&tstcount_mutex);
> +	return res;
> +}
> +
> +static void cat_file_r(char *filename);

This is hardly pefromance critical code so we don't need fine grade
locking as this. What we can do in most of the cases is to take the
mutext and call the function from tst_res.c, which would lead to much
simpler code.

> +/*
> + * tst_print_r() - thread-safe version of tst_print()
> + * Additionally takes filename, because it isn't using global File
> + */
> +static void tst_print_r(char *tcid, char *fname, int tnum, int ttype, char *tmesg)
> +{
> +	/*
> +	 * avoid unintended side effects from failures with fprintf when
> +	 * calling write(2), et all.
> +	 */
> +	int err = errno;
> +	const char *type;
> +	int ttype_result = TTYPE_RESULT(ttype);
> +	char message[USERMESG];
> +	size_t size;
> +
> +#if DEBUG
> +	printf("IN tst_print_r: tnum = %d, ttype = %d, tmesg = %s\n",
> +	       tnum, ttype, tmesg);
> +	fflush(stdout);
> +#endif
> +
> +	/*
> +	 * Save the test result type by ORing ttype into the current exit value
> +	 * (used by tst_exit()).  This is already done in tst_res(), but is
> +	 * also done here to catch internal warnings.  For internal warnings,
> +	 * tst_print() is called directly with a case of TWARN.
> +	 */
> +	exitval_or(ttype_result);
> +
> +	/*
> +	 * If output mode is DISCARD, or if the output mode is NOPASS and this
> +	 * result is not one of FAIL, BROK, or WARN, just return.  This check
> +	 * is necessary even though we check for DISCARD mode inside of
> +	 * tst_res(), since occasionally we get to this point without going
> +	 * through tst_res() (e.g. internal TWARN messages).
> +	 */
> +	if (T_mode == DISCARD || (T_mode == NOPASS && ttype_result != TFAIL &&
> +				  ttype_result != TBROK
> +				  && ttype_result != TWARN))
> +		return;
> +
> +	/*
> +	 * Build the result line and print it.
> +	 */
> +	type = strttype(ttype);
> +	if (T_mode == VERBOSE) {
> +		size = snprintf(message, sizeof(message),
> +				"%-8s %4d  %s  :  %s", tcid, tnum, type, tmesg);
> +	} else {
> +		size = snprintf(message, sizeof(message),
> +				"%-8s %4d       %s  :  %s",
> +				tcid, tnum, type, tmesg);
> +	}
> +
> +	if (size >= sizeof(message)) {
> +		printf("%s: %i: line too long\n", __func__, __LINE__);
> +		abort();
> +	}
> +
> +	if (ttype & TERRNO) {
> +		size += snprintf(message + size, sizeof(message) - size,
> +				 ": errno=%s(%i): %s", strerrnodef(err),
> +				 err, strerror(err));
> +	}
> +
> +	if (size >= sizeof(message)) {
> +		printf("%s: %i: line too long\n", __func__, __LINE__);
> +		abort();
> +	}
> +
> +	if (ttype & TTERRNO) {
> +		size += snprintf(message + size, sizeof(message) - size,
> +				 ": TEST_ERRNO=%s(%i): %s",
> +				 strerrnodef(TEST_ERRNO), (int)TEST_ERRNO,
> +				 strerror(TEST_ERRNO));
> +	}
> +
> +	if (size + 1 >= sizeof(message)) {
> +		printf("%s: %i: line too long\n", __func__, __LINE__);
> +		abort();
> +	}
> +
> +	message[size] = '\n';
> +	message[size + 1] = '\0';
> +
> +	pthread_mutex_lock(&tout_mutex);
> +	fputs(message, T_out);
> +	pthread_mutex_unlock(&tout_mutex);
> +
> +	/*
> +	 * If tst_res() was called with a file, append file contents to the
> +	 * end of last printed result.
> +	 */
> +	if (fname != NULL)
> +		cat_file_r(fname);
> +}

The same here. I don't like that the code is copied, one copy of messy
tst_print_r is more than enough. All that should be needed are mutexes
in the entry points to the ltp library, or do we have real reason not
to do it this way?

Moreover all stdio functions are protected by mutexes anyway (which is
the reason why we fgetc is so horribly slow and why we have
fgetc_unlocked)

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-11  9:48 ` [LTP] [PATCH 4/4] lib: add tst_res_r.c Alexey Kodanev
  2014-02-12 15:44   ` chrubis
@ 2014-02-13  8:47   ` Mike Frysinger
  2014-02-13 10:05     ` Alexey Kodanev
  2014-02-13 10:11     ` chrubis
  1 sibling, 2 replies; 14+ messages in thread
From: Mike Frysinger @ 2014-02-13  8:47 UTC (permalink / raw)
  To: ltp-list; +Cc: Alexey Kodanev, vasily.isaenko


[-- Attachment #1.1: Type: text/plain, Size: 1095 bytes --]

On Tuesday, February 11, 2014 13:48:10 Alexey Kodanev wrote:
> +static int get_tst_count()

random note: never never never use () with functions.  always always always 
use (void).  i'm guessing you're not aware, but what you've written here may 
be called (warning free!) like so:
	get_tst_count(1, 2, 3);

yes, even with -W -Wall -Wextra.  please stamp this horrible habit out of your 
code.

> +	/*
> +	 * Build the result line and print it.
> +	 */
> +	type = strttype(ttype);
> +	if (T_mode == VERBOSE) {
> +		size = snprintf(message, sizeof(message),
> +				"%-8s %4d  %s  :  %s", tcid, tnum, type, tmesg);
> +	} else {
> +		size = snprintf(message, sizeof(message),
> +				"%-8s %4d       %s  :  %s",
> +				tcid, tnum, type, tmesg);
> +	}
> +
> +	if (size >= sizeof(message)) {
> +		printf("%s: %i: line too long\n", __func__, __LINE__);
> +		abort();
> +	}

ugh, the 90's called and they want their staticly defined stack buffers back.  
use asprintf() and throw this historical wart in the trash where it belongs.

i've cleaned up tst_res.c some.
-mike

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 382 bytes --]

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-13  8:47   ` Mike Frysinger
@ 2014-02-13 10:05     ` Alexey Kodanev
  2014-02-13 23:06       ` Mike Frysinger
  2014-02-13 10:11     ` chrubis
  1 sibling, 1 reply; 14+ messages in thread
From: Alexey Kodanev @ 2014-02-13 10:05 UTC (permalink / raw)
  To: Mike Frysinger, ltp-list; +Cc: vasily.isaenko

Hi!
On 02/13/2014 12:47 PM, Mike Frysinger wrote:
> On Tuesday, February 11, 2014 13:48:10 Alexey Kodanev wrote:
>> +static int get_tst_count()
> random note: never never never use () with functions.  always always always
> use (void).  i'm guessing you're not aware, but what you've written here may
> be called (warning free!) like so:
> 	get_tst_count(1, 2, 3);
>
> yes, even with -W -Wall -Wextra.  please stamp this horrible habit out of your
> code.
Thank you for explanation!
There is a trick to try g++ to compile the code, it will throw an error 
on that and stops compilation.

Best regards,
Alexey


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-13  8:47   ` Mike Frysinger
  2014-02-13 10:05     ` Alexey Kodanev
@ 2014-02-13 10:11     ` chrubis
  1 sibling, 0 replies; 14+ messages in thread
From: chrubis @ 2014-02-13 10:11 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: Alexey Kodanev, ltp-list, vasily.isaenko

Hi!
> yes, even with -W -Wall -Wextra.  please stamp this horrible habit out of your

The -W is older name for -Wextra (look at -Wextra in gcc man page).

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
       [not found]     ` <5128140.KmexAZrTeg@vapier>
@ 2014-02-13 10:21       ` chrubis
       [not found]         ` <52FCA8DF.4030503@oracle.com>
  0 siblings, 1 reply; 14+ messages in thread
From: chrubis @ 2014-02-13 10:21 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: Alexey Kodanev, ltp-list, vasily.isaenko

Hi!
> > This is hardly pefromance critical code so we don't need fine grade
> > locking as this. What we can do in most of the cases is to take the
> > mutext and call the function from tst_res.c, which would lead to much
> > simpler code.
> 
> glibc provides pthread mutex lock/unlock stubs, so i wonder if we even need _r 
> variants.  if the program hasn't linked against -lpthread, then the funcs will 
> simply return.  if it has, then you get locking.

That sounds interesting. Do you know if this is implemented in uClibc
(and possibly in other alternative libc libraries) too?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
       [not found]         ` <52FCA8DF.4030503@oracle.com>
@ 2014-02-13 13:04           ` chrubis
  0 siblings, 0 replies; 14+ messages in thread
From: chrubis @ 2014-02-13 13:04 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list, Mike Frysinger

Hi!
> >> glibc provides pthread mutex lock/unlock stubs, so i wonder if we even need _r
> >> variants.  if the program hasn't linked against -lpthread, then the funcs will
> >> simply return.  if it has, then you get locking.
> > That sounds interesting. Do you know if this is implemented in uClibc
> > (and possibly in other alternative libc libraries) too?
> If portability is acceptable we could put mutex initializer in the 
> libltp. Another question should we lock/unlock mutex inside the libltp's 
> functions or set it like in the example I sent previously (use wrapper 
> macros)?

In a case that mutex stubs are common practice among libc
implementations I would be for adding the mutexes directly into the
libltp.a and do the locking inside the original functions. If not we
should go with wrappers.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-13 10:05     ` Alexey Kodanev
@ 2014-02-13 23:06       ` Mike Frysinger
  2014-02-14 13:59         ` Alexey Kodanev
  2014-02-19 15:19         ` chrubis
  0 siblings, 2 replies; 14+ messages in thread
From: Mike Frysinger @ 2014-02-13 23:06 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 1087 bytes --]

On Thursday, February 13, 2014 14:05:32 Alexey Kodanev wrote:
> On 02/13/2014 12:47 PM, Mike Frysinger wrote:
> > On Tuesday, February 11, 2014 13:48:10 Alexey Kodanev wrote:
> >> +static int get_tst_count()
> > 
> > random note: never never never use () with functions.  always always
> > always
> > use (void).  i'm guessing you're not aware, but what you've written here
> > may> 
> > be called (warning free!) like so:
> > 	get_tst_count(1, 2, 3);
> > 
> > yes, even with -W -Wall -Wextra.  please stamp this horrible habit out of
> > your code.
> 
> Thank you for explanation!
> There is a trick to try g++ to compile the code, it will throw an error
> on that and stops compilation.

yeah, C++ fixed this historical wart of C.  sorry for not clarifying.

iiuc (and i could be wrong as i'm not old enough to have lived through it), 
this dates back to when C (ANSI?) didn't have prototypes.  with a lot of code 
out there relying on the behavior, gcc never stopped accepting it.

i wonder if we could argue for like a newer GNU standard to reject it.
-mike

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 382 bytes --]

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-13 23:06       ` Mike Frysinger
@ 2014-02-14 13:59         ` Alexey Kodanev
  2014-02-14 17:16           ` Mike Frysinger
  2014-02-19 15:19         ` chrubis
  1 sibling, 1 reply; 14+ messages in thread
From: Alexey Kodanev @ 2014-02-14 13:59 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: vasily.isaenko, ltp-list

Hi!
On 02/14/2014 03:06 AM, Mike Frysinger wrote:
> On Thursday, February 13, 2014 14:05:32 Alexey Kodanev wrote:
>> On 02/13/2014 12:47 PM, Mike Frysinger wrote:
>>> On Tuesday, February 11, 2014 13:48:10 Alexey Kodanev wrote:
>>>> +static int get_tst_count()
>>> random note: never never never use () with functions.  always always
>>> always
>>> use (void).  i'm guessing you're not aware, but what you've written here
>>> may>
>>> be called (warning free!) like so:
>>> 	get_tst_count(1, 2, 3);
>>>
>>> yes, even with -W -Wall -Wextra.  please stamp this horrible habit out of
>>> your code.
>> Thank you for explanation!
>> There is a trick to try g++ to compile the code, it will throw an error
>> on that and stops compilation.
> yeah, C++ fixed this historical wart of C.  sorry for not clarifying.
>
> iiuc (and i could be wrong as i'm not old enough to have lived through it),
> this dates back to when C (ANSI?) didn't have prototypes.  with a lot of code
> out there relying on the behavior, gcc never stopped accepting it.
>
> i wonder if we could argue for like a newer GNU standard to reject it.
> -mike
True, what about -Wold-style-definition option? It will reveal old-style 
usage, at least would print a warning... Compiled LTP with the option, 
got 2 thousand warnings! There are truly a lot of code which is still 
using it and LTP's code one of them.

Best regards,
Alexey

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-14 13:59         ` Alexey Kodanev
@ 2014-02-14 17:16           ` Mike Frysinger
  0 siblings, 0 replies; 14+ messages in thread
From: Mike Frysinger @ 2014-02-14 17:16 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 1635 bytes --]

On Friday, February 14, 2014 17:59:14 Alexey Kodanev wrote:
> On 02/14/2014 03:06 AM, Mike Frysinger wrote:
> > On Thursday, February 13, 2014 14:05:32 Alexey Kodanev wrote:
> >> On 02/13/2014 12:47 PM, Mike Frysinger wrote:
> >>> On Tuesday, February 11, 2014 13:48:10 Alexey Kodanev wrote:
> >>>> +static int get_tst_count()
> >>> 
> >>> random note: never never never use () with functions.  always always
> >>> always
> >>> use (void).  i'm guessing you're not aware, but what you've written here
> >>> may>
> >>> 
> >>> be called (warning free!) like so:
> >>> 	get_tst_count(1, 2, 3);
> >>> 
> >>> yes, even with -W -Wall -Wextra.  please stamp this horrible habit out
> >>> of
> >>> your code.
> >> 
> >> Thank you for explanation!
> >> There is a trick to try g++ to compile the code, it will throw an error
> >> on that and stops compilation.
> > 
> > yeah, C++ fixed this historical wart of C.  sorry for not clarifying.
> > 
> > iiuc (and i could be wrong as i'm not old enough to have lived through
> > it),
> > this dates back to when C (ANSI?) didn't have prototypes.  with a lot of
> > code out there relying on the behavior, gcc never stopped accepting it.
> > 
> > i wonder if we could argue for like a newer GNU standard to reject it.
> 
> True, what about -Wold-style-definition option? It will reveal old-style
> usage, at least would print a warning... Compiled LTP with the option,
> got 2 thousand warnings! There are truly a lot of code which is still
> using it and LTP's code one of them.

we should look at adding that to our default warning list at configure time
-mike

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 382 bytes --]

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 4/4] lib: add tst_res_r.c
  2014-02-13 23:06       ` Mike Frysinger
  2014-02-14 13:59         ` Alexey Kodanev
@ 2014-02-19 15:19         ` chrubis
  1 sibling, 0 replies; 14+ messages in thread
From: chrubis @ 2014-02-19 15:19 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: Alexey Kodanev, vasily.isaenko, ltp-list

Hi!
> > > random note: never never never use () with functions.  always always
> > > always
> > > use (void).  i'm guessing you're not aware, but what you've written here
> > > may> 
> > > be called (warning free!) like so:
> > > 	get_tst_count(1, 2, 3);
> > > 
> > > yes, even with -W -Wall -Wextra.  please stamp this horrible habit out of
> > > your code.
> > 
> > Thank you for explanation!
> > There is a trick to try g++ to compile the code, it will throw an error
> > on that and stops compilation.
> 
> yeah, C++ fixed this historical wart of C.  sorry for not clarifying.
> 
> iiuc (and i could be wrong as i'm not old enough to have lived through it), 
> this dates back to when C (ANSI?) didn't have prototypes.  with a lot of code 
> out there relying on the behavior, gcc never stopped accepting it.

That would be K&R C that dates back to UNIX days (at least from what
I've read about the history, haven't lived these days either).

> i wonder if we could argue for like a newer GNU standard to reject it.

That would be nice. Although there is a lot of code that dates back to
the old days, quite a lot of test in LTP as well so there is no way to
get this mandatory for existing projects, we simply have no manpower to
rewrite all the sources in a week or so. On the other way it would be
nice to instruct the compiler to abort on any new code that includes
old-style declarations.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2014-02-19 15:19 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-11  9:48 [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions Alexey Kodanev
2014-02-11  9:48 ` [LTP] [PATCH v2 3/4] lib: compile *_r.c to libltp_r library, add testcases_r.mk Alexey Kodanev
2014-02-11  9:48 ` [LTP] [PATCH 4/4] lib: add tst_res_r.c Alexey Kodanev
2014-02-12 15:44   ` chrubis
     [not found]     ` <5128140.KmexAZrTeg@vapier>
2014-02-13 10:21       ` chrubis
     [not found]         ` <52FCA8DF.4030503@oracle.com>
2014-02-13 13:04           ` chrubis
2014-02-13  8:47   ` Mike Frysinger
2014-02-13 10:05     ` Alexey Kodanev
2014-02-13 23:06       ` Mike Frysinger
2014-02-14 13:59         ` Alexey Kodanev
2014-02-14 17:16           ` Mike Frysinger
2014-02-19 15:19         ` chrubis
2014-02-13 10:11     ` chrubis
2014-02-12 15:37 ` [LTP] [PATCH v2 2/4] lib/test.h: create macro to declare init/cleanup functions chrubis

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.