public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] lib: add tst_res_hexd for newlib
@ 2016-10-06 11:46 Jan Stancek
  2016-10-06 12:35 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Stancek @ 2016-10-06 11:46 UTC (permalink / raw)
  To: ltp

Locking mutex isn't necessary for oldlib, because
we already lock at tst_res__ level.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 include/tst_test.h              |  8 ++++++++
 lib/newlib_tests/.gitignore     |  3 ++-
 lib/newlib_tests/tst_res_hexd.c | 31 +++++++++++++++++++++++++++++++
 lib/tst_res.c                   | 26 ++++++++++++++------------
 4 files changed, 55 insertions(+), 13 deletions(-)
 create mode 100644 lib/newlib_tests/tst_res_hexd.c

diff --git a/include/tst_test.h b/include/tst_test.h
index 3f7123e3f633..1492ff5c41e8 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -44,6 +44,14 @@ void tst_res_(const char *file, const int lineno, int ttype,
 #define tst_res(ttype, arg_fmt, ...) \
 	tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__)
 
+void tst_resm_hexd_(const char *file, const int lineno, int ttype,
+	const void *buf, size_t size, const char *arg_fmt, ...)
+	__attribute__ ((format (printf, 6, 7)));
+
+#define tst_res_hexd(ttype, buf, size, arg_fmt, ...) \
+	tst_resm_hexd_(__FILE__, __LINE__, (ttype), (buf), (size), \
+			(arg_fmt), ##__VA_ARGS__)
+
 /*
  * Reports result and exits a test.
  */
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index 1b83738fb8b9..bc2409c97ce7 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -11,5 +11,6 @@ test10
 test11
 test12
 test13
-tst_safe_fileops
 tst_device
+tst_safe_fileops
+tst_res_hexd
diff --git a/lib/newlib_tests/tst_res_hexd.c b/lib/newlib_tests/tst_res_hexd.c
new file mode 100644
index 000000000000..333ea56a93ad
--- /dev/null
+++ b/lib/newlib_tests/tst_res_hexd.c
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	char tmp[] = "Hello from tst_res_hexd";
+
+	tst_res_hexd(TPASS, tmp, sizeof(tmp), "%s%d", "dump", 1);
+}
+
+static struct tst_test test = {
+	.tid = "tst_res_hexd",
+	.test_all = do_test,
+};
diff --git a/lib/tst_res.c b/lib/tst_res.c
index b388d0d2e516..261dec0fbba8 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -500,29 +500,33 @@ void tst_resm_(const char *file, const int lineno, int ttype,
 		tst_res__(file, lineno, ttype, "%s", tmesg);
 }
 
+typedef void (*tst_res_func_t)(const char *file, const int lineno,
+		int ttype, const char *fmt, ...);
+
 void tst_resm_hexd_(const char *file, const int lineno, int ttype,
 	const void *buf, size_t size, const char *arg_fmt, ...)
 {
-	NO_NEWLIB_ASSERT(file, lineno);
-
-	pthread_mutex_lock(&tmutex);
-
 	char tmesg[USERMESG];
-
-	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);
+	size_t i;
 	char *pmesg = tmesg;
+	tst_res_func_t res_func;
+
+	if (tst_test)
+		res_func = tst_res_;
+	else
+		res_func = tst_res__;
+
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
 
 	if (size > size_max || size == 0 ||
 		(offset + size * (symb_num + 1)) >= USERMESG)
-		tst_res__(file, lineno, ttype, "%s", tmesg);
+		res_func(file, lineno, ttype, "%s", tmesg);
 	else
 		pmesg += offset;
 
-	size_t i;
 	for (i = 0; i < size; ++i) {
 		/* add space before byte except first one */
 		if (pmesg != tmesg)
@@ -531,12 +535,10 @@ void tst_resm_hexd_(const char *file, const int lineno, int ttype,
 		sprintf(pmesg, "%02x", ((unsigned char *)buf)[i]);
 		pmesg += symb_num;
 		if ((i + 1) % size_max == 0 || i + 1 == size) {
-			tst_res__(file, lineno, ttype, "%s", tmesg);
+			res_func(file, lineno, ttype, "%s", tmesg);
 			pmesg = tmesg;
 		}
 	}
-
-	pthread_mutex_unlock(&tmutex);
 }
 
 void tst_brkm_(const char *file, const int lineno, int ttype,
-- 
1.8.3.1


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

* [LTP] [PATCH] lib: add tst_res_hexd for newlib
  2016-10-06 11:46 [LTP] [PATCH] lib: add tst_res_hexd for newlib Jan Stancek
@ 2016-10-06 12:35 ` Cyril Hrubis
  2016-10-06 14:08   ` Jan Stancek
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2016-10-06 12:35 UTC (permalink / raw)
  To: ltp

Hi!
> Locking mutex isn't necessary for oldlib, because
> we already lock at tst_res__ level.

Well, technically that would mean that the lines from hexdump may be
interleaved with other messages but in reality I doubt that this would
ever happen.

We should propably add a note to test-writing-guidelines, apart from
that this looks OK. Acked.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH] lib: add tst_res_hexd for newlib
  2016-10-06 12:35 ` Cyril Hrubis
@ 2016-10-06 14:08   ` Jan Stancek
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Stancek @ 2016-10-06 14:08 UTC (permalink / raw)
  To: ltp



----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: ltp@lists.linux.it
> Sent: Thursday, 6 October, 2016 2:35:29 PM
> Subject: Re: [PATCH] lib: add tst_res_hexd for newlib
> 
> Hi!
> > Locking mutex isn't necessary for oldlib, because
> > we already lock at tst_res__ level.
> 
> Well, technically that would mean that the lines from hexdump may be
> interleaved with other messages but in reality I doubt that this would
> ever happen.
> 
> We should propably add a note to test-writing-guidelines, apart from
> that this looks OK. Acked.

Pushed.

Regards,
Jan

> 
> --
> Cyril Hrubis
> chrubis@suse.cz
> 

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

end of thread, other threads:[~2016-10-06 14:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-06 11:46 [LTP] [PATCH] lib: add tst_res_hexd for newlib Jan Stancek
2016-10-06 12:35 ` Cyril Hrubis
2016-10-06 14:08   ` Jan Stancek

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