lib: add tst_res_hexd for newlib
PATCH 1/1 lib: add tst_res_hexd for newlib
Locking mutex isn't necessary for oldlib, because
we already lock at tst_res__ level.
--- 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
include/tst_test.h +8 -0
@@ -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. */
lib/newlib_tests/.gitignore +2 -1
@@ -11,5 +11,6 @@ test10 test11 test12 test13 -tst_safe_fileops tst_device +tst_safe_fileops +tst_res_hexd
lib/newlib_tests/tst_res_hexd.c new file +31 -0
@@ -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, +};
lib/tst_res.c +14 -12
@@ -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,
Signature · 1 line
1.8.3.1
PATCH 1/1 lib: add tst_res_hexd for newlib
Hi!
Quoted 2 lines
Locking mutex isn't necessary for oldlib, because
we already lock attst_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.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 lib: add tst_res_hexd for newlib
----- Original Message -----
Quoted 10 lines
From: "Cyril Hrubis" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Thursday, 6 October, 2016 2:35:29 PM
Subject: Re: [PATCH] lib: addtst_res_hexdfor newlibHi!
Quoted 2 lines
Locking mutex isn't necessary for oldlib, because
we already lock attst_res__level.
Quoted 6 lines
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
Quoted 5 lines
--
Cyril Hrubis
[email protected]