Move the bitfield test to tests/lib/
A message that is not in the archive (sent off-list or not yet received): 20130207174526.GA6632@Krystal
PATCH 1/2 Move the bitfield test to tests/lib/
--- .gitignore | 2 +- tests/Makefile.am | 4 - tests/lib/Makefile.am | 3 +- tests/lib/runall.sh | 5 +- tests/lib/test-bitfield.c | 371 ++++++++++++++++++++++++++++++++++++++++++++++ tests/runall.sh | 7 - tests/test-bitfield.c | 371 ---------------------------------------------- 7 files changed, 378 insertions(+), 385 deletions(-) create mode 100644 tests/lib/test-bitfield.c delete mode 100644 tests/test-bitfield.c
.gitignore +1 -1
@@ -1,4 +1,4 @@ -/tests/test-bitfield +/tests/lib/test-bitfield /tests/lib/test-seeks *.o *.a
tests/Makefile.am +0 -4
@@ -2,10 +2,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include SUBDIRS = lib -noinst_PROGRAMS = test-bitfield - -test_bitfield_SOURCES = test-bitfield.c - EXTRA_DIST = runall.sh ctf-traces/** check-am:
tests/lib/Makefile.am +2 -1
@@ -8,9 +8,10 @@ test_seeks_LDADD = libtestcommon.a \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la -noinst_PROGRAMS = test-seeks +noinst_PROGRAMS = test-seeks test-bitfield test_seeks_SOURCES = test-seeks.c +test_bitfield_SOURCES = test-bitfield.c EXTRA_DIST = README.tap runall.sh
tests/lib/runall.sh +4 -1
@@ -3,4 +3,7 @@ # With a trace than contains empty packets ./test-seeks ../ctf-traces/succeed/wk-heartbeat-u/ 1351532897586558519 1351532897591331194 # With a bigger trace -./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396 +./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396 + +# run bitfield tests +./test-bitfield
tests/lib/test-bitfield.c new file +371 -0
371 lines not on this page · raw message
tests/runall.sh +0 -7
@@ -53,13 +53,6 @@ function run_babeltrace () return $? } -echo -e "Running test-bitfield..." -./test-bitfield -test_check -if [ $? -ne 0 ]; then - exit 1 -fi - #run babeltrace expects success echo -e "Running babeltrace without argument..." run_babeltrace
tests/test-bitfield.c deleted +0 -371
371 lines not on this page · raw message
Signature · 7 lines
1.8.1.1 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/2 Convert the unit tests to the TAP format
--- tests/lib/Makefile.am | 2 + tests/lib/test-bitfield.c | 242 +++++++++++++++++++--------------------------- tests/runall.sh | 88 +++++++---------- 3 files changed, 139 insertions(+), 193 deletions(-)
tests/lib/Makefile.am +2 -0
@@ -8,6 +8,8 @@ test_seeks_LDADD = libtestcommon.a \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la +test_bitfield_LDADD = libtestcommon.a + noinst_PROGRAMS = test-seeks test-bitfield test_seeks_SOURCES = test-seeks.c
tests/lib/test-bitfield.c +100 -142
335 lines not on this page · raw message
tests/runall.sh +37 -51
119 lines not on this page · raw message
Signature · 7 lines
1.8.1.1 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Mathieu Desnoyers
AppliedQuoted 2 lines · * Jérémie Galarneau ([email protected]) wrote:
Signed-off-by Jérémie Galarneau <[email protected]>
merged, thanks!
Mathieu
Quoted 847 lines
--- .gitignore | 2 +- tests/Makefile.am | 4 - tests/lib/Makefile.am | 3 +- tests/lib/runall.sh | 5 +- tests/lib/test-bitfield.c | 371 ++++++++++++++++++++++++++++++++++++++++++++++ tests/runall.sh | 7 - tests/test-bitfield.c | 371 ---------------------------------------------- 7 files changed, 378 insertions(+), 385 deletions(-) create mode 100644 tests/lib/test-bitfield.c delete mode 100644 tests/test-bitfield.c.gitignore +1
-1@@ -1,4 +1,4 @@ -/tests/test-bitfield +/tests/lib/test-bitfield /tests/lib/test-seeks *.o *.atests/Makefile.am +0
-4@@ -2,10 +2,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include SUBDIRS = lib -noinst_PROGRAMS = test-bitfield - -test_bitfield_SOURCES = test-bitfield.c - EXTRA_DIST = runall.sh ctf-traces/** check-am:tests/lib/Makefile.am +2
-1@@ -8,9 +8,10 @@ test_seeks_LDADD = libtestcommon.a \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la -noinst_PROGRAMS = test-seeks +noinst_PROGRAMS = test-seeks test-bitfield test_seeks_SOURCES = test-seeks.c +test_bitfield_SOURCES = test-bitfield.c EXTRA_DIST = README.tap runall.shtests/lib/runall.sh +4
-1@@ -3,4 +3,7 @@ # With a trace than contains empty packets ./test-seeks ../ctf-traces/succeed/wk-heartbeat-u/ 1351532897586558519 1351532897591331194 # With a bigger trace -./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396 +./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396 + +# run bitfield tests +./test-bitfieldtests/lib/test-bitfield.c new file +371
-0@@ -0,0 +1,371 @@ +/* +* test-bitfield.c +* +* BabelTrace - bitfield test program +* +* Copyright 2010 - Mathieu Desnoyers <[email protected]> +* +* 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; under version 2 of the License. +* +* 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, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#define _GNU_SOURCE +#include <babeltrace/bitfield.h> +#include <time.h> +#include <stdlib.h> +#include <stdio.h> + +unsigned int glob; + +/* +* This function is only declared to show the size of a bitfield write in +* objdump. +*/ +void fct (void ) +{ + bt_bitfield_write(&glob, unsigned int, 12, 15, 0x12345678); +} + +/* Test array size, in bytes */ +#define TEST_LEN 128 +#define NR_TESTS 10 + +unsigned int srcrand; + +#if defined(__i386) || defined(__x86_64) + +static inline int fls (int x) +{ +int r; + asm("bsrl %1,%0\n\t" +"cmovzl %2,%0" + :"=&r" (r) :"rm" (x),"rm" (-1 )); +return r +1 ; +} + +#elif defined(__PPC__) + +static __inline__int fls (unsigned int x) +{ +int lz; + + asm ("cntlzw %0,%1" :"=r" (lz) :"r" (x)); +return 32 - lz; +} + +#else + +static int fls (unsigned int x) +{ +int r =32 ; + +if (!x) +return 0 ; +if (!(x &0xFFFF0000U )) { + x <<=16 ; + r -=16 ; + } +if (!(x &0xFF000000U )) { + x <<=8 ; + r -=8 ; + } +if (!(x &0xF0000000U )) { + x <<=4 ; + r -=4 ; + } +if (!(x &0xC0000000U )) { + x <<=2 ; + r -=2 ; + } +if (!(x &0x80000000U )) { + x <<=1 ; + r -=1 ; + } +return r; +} + +#endif + +#define print_byte_array (c, len) \ +do { \ + unsigned long i; \ + \ + for (i = 0; i < (len); i++) { \ + printf("0x%X", (c)[i]); \ + if (i != (len) - 1) \ + printf(" "); \ + } \ + printf("\n"); \ +} while (0) + +#define init_byte_array (c, len, val) \ +do { \ + unsigned long i; \ + \ + for (i = 0; i < (len); i++) \ + (c)[i] = (val); \ +} while (0) + +int run_test_unsigned (void ) +{ +unsigned int src, nrbits; +union { +unsigned char c[TEST_LEN ]; +unsigned short s[TEST_LEN /sizeof (unsigned short )]; +unsigned int i[TEST_LEN /sizeof (unsigned int )]; +unsigned long l[TEST_LEN /sizeof (unsigned long )]; +unsigned long long ll[TEST_LEN /sizeof (unsigned long long )]; + } target; +unsigned long long readval; +unsigned int s, l; +int err =0 ; + +printf ("Running unsigned test with 0x%X\n" , srcrand); + + src = srcrand; + nrbits =fls (src); + +for (s =0 ; s <CHAR_BIT *TEST_LEN ; s++) { +for (l = nrbits; l < (CHAR_BIT *TEST_LEN ) - s; l++) { +init_byte_array (target.c,TEST_LEN ,0xFF ); + bt_bitfield_write(target.c, unsigned char, s, l, src); + bt_bitfield_read(target.c, unsigned char, s, l, &readval); +if (readval != src) { +printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0xFF ); + bt_bitfield_write(target.s, unsigned short, s, l, src); + bt_bitfield_read(target.c, unsigned char, s, l, &readval); +if (readval != src) { +printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0xFF ); + bt_bitfield_write(target.i, unsigned int, s, l, src); + bt_bitfield_read(target.c, unsigned char, s, l, &readval); +if (readval != src) { +printf ("Error (intwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0xFF ); + bt_bitfield_write(target.l, unsigned long, s, l, src); + bt_bitfield_read(target.c, unsigned char, s, l, &readval); +if (readval != src) { +printf ("Error (longwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0xFF ); + bt_bitfield_write(target.ll, unsigned long long, s, l, src); + bt_bitfield_read(target.c, unsigned char, s, l, &readval); +if (readval != src) { +printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + } + } +if (!err) +printf ("Success!\n" ); +else +printf ("Failed!\n" ); +return err; +} + +int run_test_signed (void ) +{ +int src, nrbits; +union { +signed char c[TEST_LEN ]; +short s[TEST_LEN /sizeof (short )]; +int i[TEST_LEN /sizeof (int )]; +long l[TEST_LEN /sizeof (long )]; +long long ll[TEST_LEN /sizeof (long long )]; + } target; +long long readval; +unsigned int s, l; +int err =0 ; + +printf ("Running signed test with 0x%X\n" , srcrand); + + src = srcrand; +if (src &0x80000000U ) + nrbits =fls (~src) +1 ;/* Find least significant bit conveying sign */ +else + nrbits =fls (src) +1 ;/* Keep sign at 0 */ + +for (s =0 ; s <8 *TEST_LEN ; s++) { +for (l = nrbits; l < (8 *TEST_LEN ) - s; l++) { +init_byte_array (target.c,TEST_LEN ,0x0 ); + bt_bitfield_write(target.c, signed char, s, l, src); + bt_bitfield_read(target.c, signed char, s, l, &readval); +if (readval != src) { +printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0x0 ); +bt_bitfield_write (target.s, short, s, l, src); + bt_bitfield_read(target.c, signed char, s, l, &readval); +if (readval != src) { +printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0x0 ); +bt_bitfield_write (target.i, int, s, l, src); + bt_bitfield_read(target.c, signed char, s, l, &readval); +if (readval != src) { +printf ("Error (intwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0x0 ); +bt_bitfield_write (target.l, long, s, l, src); + bt_bitfield_read(target.c, signed char, s, l, &readval); +if (readval != src) { +printf ("Error (longwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + +init_byte_array (target.c,TEST_LEN ,0x0 ); + bt_bitfield_write(target.ll, long long, s, l, src); + bt_bitfield_read(target.c, signed char, s, l, &readval); +if (readval != src) { +printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , + src, readval, s, l); +print_byte_array (target.c,TEST_LEN ); + err =1 ; + } + } + } +if (!err) +printf ("Success!\n" ); +else +printf ("Failed!\n" ); +return err; +} + +int run_test (void ) +{ +int err =0 ; +int i; + +srand (time (NULL )); + + srcrand =0 ; + err |=run_test_unsigned (); + srcrand =0 ; + err |=run_test_signed (); + srcrand =1 ; + err |=run_test_unsigned (); + srcrand = ~0U ; + err |=run_test_unsigned (); + srcrand =-1 ; + err |=run_test_signed (); + srcrand = (int )0x80000000U ; + err |=run_test_signed (); + +for (i =0 ; i <NR_TESTS ; i++) { + srcrand =rand (); + err |=run_test_unsigned (); + err |=run_test_signed (); + } +return err; +} + +int main (int argc,char **argv) +{ +unsigned long src; +unsigned int shift, len; +int ret; +union { +unsigned char c[8 ]; +unsigned short s[4 ]; +unsigned int i[2 ]; +unsigned long l[2 ]; +unsigned long long ll[1 ]; + } target; +unsigned long long readval; + +if (argc >1 ) + src =atoi (argv[1 ]); +else + src =0x12345678 ; +if (argc >2 ) + shift =atoi (argv[2 ]); +else + shift =12 ; +if (argc >3 ) + len =atoi (argv[3 ]); +else + len =40 ; + + target.i[0 ] =0xFFFFFFFF ; + target.i[1 ] =0xFFFFFFFF ; + bt_bitfield_write(target.c, unsigned char, shift, len, src); +printf ("bytewise\n" ); +print_byte_array (target.c,8 ); + + target.i[0 ] =0xFFFFFFFF ; + target.i[1 ] =0xFFFFFFFF ; + bt_bitfield_write(target.s, unsigned short, shift, len, src); +printf ("shortwise\n" ); +print_byte_array (target.c,8 ); + + target.i[0 ] =0xFFFFFFFF ; + target.i[1 ] =0xFFFFFFFF ; + bt_bitfield_write(target.i, unsigned int, shift, len, src); +printf ("intwise\n" ); +print_byte_array (target.c,8 ); + + target.i[0 ] =0xFFFFFFFF ; + target.i[1 ] =0xFFFFFFFF ; + bt_bitfield_write(target.l, unsigned long, shift, len, src); +printf ("longwise\n" ); +print_byte_array (target.c,8 ); + + target.i[0 ] =0xFFFFFFFF ; + target.i[1 ] =0xFFFFFFFF ; + bt_bitfield_write(target.ll, unsigned long long, shift, len, src); +printf ("lluwise\n" ); +print_byte_array (target.c,8 ); + + bt_bitfield_read(target.c, unsigned char, shift, len, &readval); +printf ("read: %llX\n" , readval); + + ret =run_test (); + +return ret; +}tests/runall.sh +0
-7@@ -53,13 +53,6 @@ function run_babeltrace () return $? } -echo -e "Running test-bitfield..." -./test-bitfield -test_check -if [ $? -ne 0 ]; then - exit 1 -fi - #run babeltrace expects success echo -e "Running babeltrace without argument..." run_babeltracetests/test-bitfield.c deleted +0
-371@@ -1,371 +0,0 @@ -/* -* test-bitfield.c -* -* BabelTrace - bitfield test program -* -* Copyright 2010 - Mathieu Desnoyers <[email protected]> -* -* 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; under version 2 of the License. -* -* 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, write to the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#define _GNU_SOURCE -#include <babeltrace/bitfield.h> -#include <time.h> -#include <stdlib.h> -#include <stdio.h> - -unsigned int glob; - -/* -* This function is only declared to show the size of a bitfield write in -* objdump. -*/ -void fct (void ) -{ - bt_bitfield_write(&glob, unsigned int, 12, 15, 0x12345678); -} - -/* Test array size, in bytes */ -#define TEST_LEN 128 -#define NR_TESTS 10 - -unsigned int srcrand; - -#if defined(__i386) || defined(__x86_64) - -static inline int fls (int x) -{ -int r; - asm("bsrl %1,%0\n\t" -"cmovzl %2,%0" - :"=&r" (r) :"rm" (x),"rm" (-1 )); -return r +1 ; -} - -#elif defined(__PPC__) - -static __inline__int fls (unsigned int x) -{ -int lz; - - asm ("cntlzw %0,%1" :"=r" (lz) :"r" (x)); -return 32 - lz; -} - -#else - -static int fls (unsigned int x) -{ -int r =32 ; - -if (!x) -return 0 ; -if (!(x &0xFFFF0000U )) { - x <<=16 ; - r -=16 ; - } -if (!(x &0xFF000000U )) { - x <<=8 ; - r -=8 ; - } -if (!(x &0xF0000000U )) { - x <<=4 ; - r -=4 ; - } -if (!(x &0xC0000000U )) { - x <<=2 ; - r -=2 ; - } -if (!(x &0x80000000U )) { - x <<=1 ; - r -=1 ; - } -return r; -} - -#endif - -#define print_byte_array (c, len) \ -do { \ - unsigned long i; \ - \ - for (i = 0; i < (len); i++) { \ - printf("0x%X", (c)[i]); \ - if (i != (len) - 1) \ - printf(" "); \ - } \ - printf("\n"); \ -} while (0) - -#define init_byte_array (c, len, val) \ -do { \ - unsigned long i; \ - \ - for (i = 0; i < (len); i++) \ - (c)[i] = (val); \ -} while (0) - -int run_test_unsigned (void ) -{ -unsigned int src, nrbits; -union { -unsigned char c[TEST_LEN ]; -unsigned short s[TEST_LEN /sizeof (unsigned short )]; -unsigned int i[TEST_LEN /sizeof (unsigned int )]; -unsigned long l[TEST_LEN /sizeof (unsigned long )]; -unsigned long long ll[TEST_LEN /sizeof (unsigned long long )]; - } target; -unsigned long long readval; -unsigned int s, l; -int err =0 ; - -printf ("Running unsigned test with 0x%X\n" , srcrand); - - src = srcrand; - nrbits =fls (src); - -for (s =0 ; s <CHAR_BIT *TEST_LEN ; s++) { -for (l = nrbits; l < (CHAR_BIT *TEST_LEN ) - s; l++) { -init_byte_array (target.c,TEST_LEN ,0xFF ); - bt_bitfield_write(target.c, unsigned char, s, l, src); - bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0xFF ); - bt_bitfield_write(target.s, unsigned short, s, l, src); - bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0xFF ); - bt_bitfield_write(target.i, unsigned int, s, l, src); - bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0xFF ); - bt_bitfield_write(target.l, unsigned long, s, l, src); - bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0xFF ); - bt_bitfield_write(target.ll, unsigned long long, s, l, src); - bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - } - } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); -return err; -} - -int run_test_signed (void ) -{ -int src, nrbits; -union { -signed char c[TEST_LEN ]; -short s[TEST_LEN /sizeof (short )]; -int i[TEST_LEN /sizeof (int )]; -long l[TEST_LEN /sizeof (long )]; -long long ll[TEST_LEN /sizeof (long long )]; - } target; -long long readval; -unsigned int s, l; -int err =0 ; - -printf ("Running signed test with 0x%X\n" , srcrand); - - src = srcrand; -if (src &0x80000000U ) - nrbits =fls (~src) +1 ;/* Find least significant bit conveying sign */ -else - nrbits =fls (src) +1 ;/* Keep sign at 0 */ - -for (s =0 ; s <8 *TEST_LEN ; s++) { -for (l = nrbits; l < (8 *TEST_LEN ) - s; l++) { -init_byte_array (target.c,TEST_LEN ,0x0 ); - bt_bitfield_write(target.c, signed char, s, l, src); - bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0x0 ); -bt_bitfield_write (target.s, short, s, l, src); - bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0x0 ); -bt_bitfield_write (target.i, int, s, l, src); - bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0x0 ); -bt_bitfield_write (target.l, long, s, l, src); - bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - -init_byte_array (target.c,TEST_LEN ,0x0 ); - bt_bitfield_write(target.ll, long long, s, l, src); - bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } - } - } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); -return err; -} - -int run_test (void ) -{ -int err =0 ; -int i; - -srand (time (NULL )); - - srcrand =0 ; - err |=run_test_unsigned (); - srcrand =0 ; - err |=run_test_signed (); - srcrand =1 ; - err |=run_test_unsigned (); - srcrand = ~0U ; - err |=run_test_unsigned (); - srcrand =-1 ; - err |=run_test_signed (); - srcrand = (int )0x80000000U ; - err |=run_test_signed (); - -for (i =0 ; i <NR_TESTS ; i++) { - srcrand =rand (); - err |=run_test_unsigned (); - err |=run_test_signed (); - } -return err; -} - -int main (int argc,char **argv) -{ -unsigned long src; -unsigned int shift, len; -int ret; -union { -unsigned char c[8 ]; -unsigned short s[4 ]; -unsigned int i[2 ]; -unsigned long l[2 ]; -unsigned long long ll[1 ]; - } target; -unsigned long long readval; - -if (argc >1 ) - src =atoi (argv[1 ]); -else - src =0x12345678 ; -if (argc >2 ) - shift =atoi (argv[2 ]); -else - shift =12 ; -if (argc >3 ) - len =atoi (argv[3 ]); -else - len =40 ; - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.c, unsigned char, shift, len, src); -printf ("bytewise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.s, unsigned short, shift, len, src); -printf ("shortwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.i, unsigned int, shift, len, src); -printf ("intwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.l, unsigned long, shift, len, src); -printf ("longwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.ll, unsigned long long, shift, len, src); -printf ("lluwise\n" ); -print_byte_array (target.c,8 ); - - bt_bitfield_read(target.c, unsigned char, shift, len, &readval); -printf ("read: %llX\n" , readval); - - ret =run_test (); - -return ret; -}Signature · 7 lines
1.8.1.1 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH babeltrace 2/2] Convert the unit tests to the TAP format
Quoted 44 lines · * Jérémie Galarneau ([email protected]) wrote:
Signed-off-by Jérémie Galarneau <[email protected]>--- tests/lib/Makefile.am | 2 + tests/lib/test-bitfield.c | 242 +++++++++++++++++++--------------------------- tests/runall.sh | 88 +++++++---------- 3 files changed, 139 insertions(+), 193 deletions(-)tests/lib/Makefile.am +2
-0@@ -8,6 +8,8 @@ test_seeks_LDADD = libtestcommon.a \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la +test_bitfield_LDADD = libtestcommon.a + noinst_PROGRAMS = test-seeks test-bitfield test_seeks_SOURCES = test-seeks.ctests/lib/test-bitfield.c +2
-2@@ -25,6 +25,8 @@#include <stdlib.h> #include <stdio.h> +#include "tap.h" +unsigned int glob;/* @@ -130,8 +132,6 @@ int run_test_unsigned(void)unsigned int s, l;int err =0 ; -printf ("Running unsigned test with 0x%X\n" , srcrand); - src = srcrand; nrbits =fls (src);
tests/lib/test-bitfield.c int run_test_unsigned(void) · line 146
Quoted 7 lines
tests/lib/test-bitfield.c +0
-4@@ -140,58 +140,38 @@ int run_test_unsigned(void)init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.c, unsigned char, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN );
we seem to be losing a lot of information with this change. Is it possible to keep this info with the transition to TAP when an error is detected ?
Thanks,
Mathieu
Quoted 446 lines
tests/lib/test-bitfield.c +98
-136- err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.s, unsigned short, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.i, unsigned int, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.l, unsigned long, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.ll, unsigned long long, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + err = readval != src ?1 : err; + +if (err) { + goto end; } } } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); +end: +ok (err ==0 ,"Writing and reading back 0x%X, unsigned" , src); +if (err) { +printf ("# Failed with start=%i and length=%i\n" , s, l); + }return err; }@@ -209,163 +189,141 @@ int run_test_signed(void)unsigned int s, l;int err =0 ; -printf ("Running signed test with 0x%X\n" , srcrand); - src = srcrand;if (src &0x80000000U ) nrbits =fls (~src) +1 ;/* Find least significant bit conveying sign */ else nrbits =fls (src) +1 ;/* Keep sign at 0 */ -for (s =0 ; s <8 *TEST_LEN ; s++) { -for (l = nrbits; l < (8 *TEST_LEN ) - s; l++) { +for (s =0 ; s <CHAR_BIT *TEST_LEN ; s++) { +for (l = nrbits; l < (CHAR_BIT *TEST_LEN ) - s; l++) {init_byte_array (target.c,TEST_LEN ,0x0 ); bt_bitfield_write(target.c, signed char, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.s, short, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.i, int, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.l, long, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 ); bt_bitfield_write(target.ll, long long, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + err = readval != src ?1 : err; + +if (err) { + goto end; } } } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); +end: +ok (err ==0 ,"Writing and reading back 0x%X, signed" , src); +if (err) { +printf ("#Failed with start=%i and length=%i\n" , s, l); + }return err; } -int run_test (void ) +void run_test (void ) { -int err =0 ;int i; +plan_tests (NR_TESTS *2 +6 );srand (time (NULL )); srcrand =0 ; - err |=run_test_unsigned (); +run_test_unsigned (); srcrand =0 ; - err |=run_test_signed (); +run_test_signed (); + srcrand =1 ; - err |=run_test_unsigned (); +run_test_unsigned (); + srcrand = ~0U ; - err |=run_test_unsigned (); +run_test_unsigned (); + srcrand =-1 ; - err |=run_test_signed (); +run_test_signed (); + srcrand = (int )0x80000000U ; - err |=run_test_signed (); +run_test_signed ();for (i =0 ; i <NR_TESTS ; i++) { srcrand =rand (); - err |=run_test_unsigned (); - err |=run_test_signed (); +run_test_unsigned (); +run_test_signed (); } -return err; }int main (int argc,char **argv) { -unsigned long src; -unsigned int shift, len; -int ret; -union { -unsigned char c[8 ]; -unsigned short s[4 ]; -unsigned int i[2 ]; -unsigned long l[2 ]; -unsigned long long ll[1 ]; - } target; -unsigned long long readval; +if (argc >1 ) { +/* Run interactive tests */ +unsigned long src; +unsigned int shift, len; +union { +unsigned char c[8 ]; +unsigned short s[4 ]; +unsigned int i[2 ]; +unsigned long l[2 ]; +unsigned long long ll[1 ]; + } target; +unsigned long long readval; -if (argc >1 ) src =atoi (argv[1 ]); -else - src =0x12345678 ; -if (argc >2 ) - shift =atoi (argv[2 ]); -else - shift =12 ; -if (argc >3 ) - len =atoi (argv[3 ]); -else - len =40 ; - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.c, unsigned char, shift, len, src); -printf ("bytewise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.s, unsigned short, shift, len, src); -printf ("shortwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.i, unsigned int, shift, len, src); -printf ("intwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.l, unsigned long, shift, len, src); -printf ("longwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.ll, unsigned long long, shift, len, src); -printf ("lluwise\n" ); -print_byte_array (target.c,8 ); - - bt_bitfield_read(target.c, unsigned char, shift, len, &readval); -printf ("read: %llX\n" , readval); - - ret =run_test (); - -return ret; +if (argc >2 ) + shift =atoi (argv[2 ]); +else + shift =12 ; +if (argc >3 ) + len =atoi (argv[3 ]); +else + len =40 ; + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.c, unsigned char, shift, len, src); +printf ("bytewise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.s, unsigned short, shift, len, src); +printf ("shortwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.i, unsigned int, shift, len, src); +printf ("intwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.l, unsigned long, shift, len, src); +printf ("longwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.ll, unsigned long long, shift, len, src); +printf ("lluwise\n" ); +print_byte_array (target.c,8 ); + + bt_bitfield_read(target.c, unsigned char, shift, len, &readval); +printf ("read: %llX\n" , readval); +print_byte_array (target.c,8 ); + +return 0 ; + } + +/* Run tap-formated tests */ +run_test (); +return exit_status (); }tests/runall.sh +37
-51@@ -5,44 +5,20 @@ DIR=$(readlink -f ${TESTDIR}) BABELTRACE_BIN=${DIR}/../converter/babeltrace CTF_TRACES=${DIR}/ctf-traces -function print_ok () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;32mOK\e[0m" - else - echo -e "OK" - fi -} - -function print_fail () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;31mFAIL\e[0m" - else - echo -e "FAIL" - fi -} - -function test_check () +function test_check_success () { if [ $? -ne 0 ] ; then - print_fail return 1 else - print_ok return 0 fi } function test_check_fail () { - if [ $? -ne 1 ] ; then - print_fail + if [ $? -eq 0 ] ; then return 1 else - print_ok return 0 fi }@@ -53,38 +29,48 @@ function run_babeltrace () return $? } -#run babeltrace expects success -echo -e "Running babeltrace without argument..." -run_babeltrace -test_check -if [ $? -ne 0 ]; then - exit 1 -fi - -for a in ${CTF_TRACES}/succeed/*; do - echo -e "Running babeltrace for trace ${a}..." - run_babeltrace ${a} - test_check - if [ $? -ne 0 ]; then +function print_test_result () +{ + if [ $# -ne 3 ] ; then + echo "Invalid arguments provided" exit 1 fi -done -#run babeltrace expects failure -echo -e "Running babeltrace with bogus argument..." + if [ ${2} -eq 0 ] ; then + echo -n "ok" + else + echo -n "not ok" + fi + echo -e " "${1}" - "${3} +} + +successTraces=(${CTF_TRACES}/succeed/*) +failTraces=(${CTF_TRACES}/fail/*) +testCount=$((2 + ${#successTraces[@]} + ${#failTraces[@]})) + +currentTestIndex=1 +echo -e 1..${testCount} + +#run babeltrace, expects success +run_babeltrace +test_check_success +print_test_result $((currentTestIndex++)) $? "Running babeltrace without arguments" + +#run babeltrace with a bogus argument, expects failure run_babeltrace --bogusarg test_check_fail -if [ $? -ne 0 ]; then - exit 1 -fi +print_test_result $((currentTestIndex++)) $? "Running babeltrace with a bogus argument" + +for tracePath in ${successTraces[@]}; do + run_babeltrace ${tracePath} + test_check_success + print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}" +done -for a in ${CTF_TRACES}/fail/*; do - echo -e "Running babeltrace for trace ${a}..." - run_babeltrace ${a} +for tracePath in ${failTraces[@]}; do + run_babeltrace ${tracePath} test_check_fail - if [ $? -ne 0 ]; then - exit 1 - fi + print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}" done exit 0Signature · 7 lines
1.8.1.1 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
A message that is not in the archive (sent off-list or not yet received): 20130207223409.GB10074@Krystal
Re: [PATCH babeltrace 2/2] Convert the unit tests to the TAP format
Yes, I'll change the test to print more diagnostic info when an error occurs.
Quoted 512 lines · Mathieu Desnoyers
Quoted 44 lines · * Jérémie Galarneau ([email protected]) wrote:
Signed-off-by Jérémie Galarneau <[email protected]>--- tests/lib/Makefile.am | 2 + tests/lib/test-bitfield.c | 242 +++++++++++++++++++--------------------------- tests/runall.sh | 88 +++++++---------- 3 files changed, 139 insertions(+), 193 deletions(-)tests/lib/Makefile.am +2
-0@@ -8,6 +8,8 @@ test_seeks_LDADD = libtestcommon.a \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la +test_bitfield_LDADD = libtestcommon.a + noinst_PROGRAMS = test-seeks test-bitfield test_seeks_SOURCES = test-seeks.ctests/lib/test-bitfield.c +2
-2@@ -25,6 +25,8 @@#include <stdlib.h> #include <stdio.h> +#include "tap.h" +unsigned int glob;/* @@ -130,8 +132,6 @@ int run_test_unsigned(void)unsigned int s, l;int err =0 ; -printf ("Running unsigned test with 0x%X\n" , srcrand); - src = srcrand; nrbits =fls (src);tests/lib/test-bitfield.c int run_test_unsigned(void) · line 146
Quoted 7 lines
tests/lib/test-bitfield.c +0
-4@@ -140,58 +140,38 @@ int run_test_unsigned(void)init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.c, unsigned char, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN );we seem to be losing a lot of information with this change. Is it possible to keep this info with the transition to TAP when an error is detected ?
Thanks,
Mathieu
Quoted 442 lines
tests/lib/test-bitfield.c +98
-136- err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.s, unsigned short, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.i, unsigned int, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.l, unsigned long, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.ll, unsigned long long, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + err = readval != src ?1 : err; + +if (err) { + goto end; } } } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); +end: +ok (err ==0 ,"Writing and reading back 0x%X, unsigned" , src); +if (err) { +printf ("# Failed with start=%i and length=%i\n" , s, l); + }return err; }@@ -209,163 +189,141 @@ int run_test_signed(void)unsigned int s, l;int err =0 ; -printf ("Running signed test with 0x%X\n" , srcrand); - src = srcrand;if (src &0x80000000U ) nrbits =fls (~src) +1 ;/* Find least significant bit conveying sign */ else nrbits =fls (src) +1 ;/* Keep sign at 0 */ -for (s =0 ; s <8 *TEST_LEN ; s++) { -for (l = nrbits; l < (8 *TEST_LEN ) - s; l++) { +for (s =0 ; s <CHAR_BIT *TEST_LEN ; s++) { +for (l = nrbits; l < (CHAR_BIT *TEST_LEN ) - s; l++) {init_byte_array (target.c,TEST_LEN ,0x0 ); bt_bitfield_write(target.c, signed char, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.s, short, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.i, int, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.l, long, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; - } + err = readval != src ?1 : err;init_byte_array (target.c,TEST_LEN ,0x0 ); bt_bitfield_write(target.ll, long long, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + err = readval != src ?1 : err; + +if (err) { + goto end; } } } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); +end: +ok (err ==0 ,"Writing and reading back 0x%X, signed" , src); +if (err) { +printf ("#Failed with start=%i and length=%i\n" , s, l); + }return err; } -int run_test (void ) +void run_test (void ) { -int err =0 ;int i; +plan_tests (NR_TESTS *2 +6 );srand (time (NULL )); srcrand =0 ; - err |=run_test_unsigned (); +run_test_unsigned (); srcrand =0 ; - err |=run_test_signed (); +run_test_signed (); + srcrand =1 ; - err |=run_test_unsigned (); +run_test_unsigned (); + srcrand = ~0U ; - err |=run_test_unsigned (); +run_test_unsigned (); + srcrand =-1 ; - err |=run_test_signed (); +run_test_signed (); + srcrand = (int )0x80000000U ; - err |=run_test_signed (); +run_test_signed ();for (i =0 ; i <NR_TESTS ; i++) { srcrand =rand (); - err |=run_test_unsigned (); - err |=run_test_signed (); +run_test_unsigned (); +run_test_signed (); } -return err; }int main (int argc,char **argv) { -unsigned long src; -unsigned int shift, len; -int ret; -union { -unsigned char c[8 ]; -unsigned short s[4 ]; -unsigned int i[2 ]; -unsigned long l[2 ]; -unsigned long long ll[1 ]; - } target; -unsigned long long readval; +if (argc >1 ) { +/* Run interactive tests */ +unsigned long src; +unsigned int shift, len; +union { +unsigned char c[8 ]; +unsigned short s[4 ]; +unsigned int i[2 ]; +unsigned long l[2 ]; +unsigned long long ll[1 ]; + } target; +unsigned long long readval; -if (argc >1 ) src =atoi (argv[1 ]); -else - src =0x12345678 ; -if (argc >2 ) - shift =atoi (argv[2 ]); -else - shift =12 ; -if (argc >3 ) - len =atoi (argv[3 ]); -else - len =40 ; - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.c, unsigned char, shift, len, src); -printf ("bytewise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.s, unsigned short, shift, len, src); -printf ("shortwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.i, unsigned int, shift, len, src); -printf ("intwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.l, unsigned long, shift, len, src); -printf ("longwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.ll, unsigned long long, shift, len, src); -printf ("lluwise\n" ); -print_byte_array (target.c,8 ); - - bt_bitfield_read(target.c, unsigned char, shift, len, &readval); -printf ("read: %llX\n" , readval); - - ret =run_test (); - -return ret; +if (argc >2 ) + shift =atoi (argv[2 ]); +else + shift =12 ; +if (argc >3 ) + len =atoi (argv[3 ]); +else + len =40 ; + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.c, unsigned char, shift, len, src); +printf ("bytewise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.s, unsigned short, shift, len, src); +printf ("shortwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.i, unsigned int, shift, len, src); +printf ("intwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.l, unsigned long, shift, len, src); +printf ("longwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.ll, unsigned long long, shift, len, src); +printf ("lluwise\n" ); +print_byte_array (target.c,8 ); + + bt_bitfield_read(target.c, unsigned char, shift, len, &readval); +printf ("read: %llX\n" , readval); +print_byte_array (target.c,8 ); + +return 0 ; + } + +/* Run tap-formated tests */ +run_test (); +return exit_status (); }tests/runall.sh +37
-52@@ -5,44 +5,20 @@ DIR=$(readlink -f ${TESTDIR}) BABELTRACE_BIN=${DIR}/../converter/babeltrace CTF_TRACES=${DIR}/ctf-traces -function print_ok () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;32mOK\e[0m" - else - echo -e "OK" - fi -} - -function print_fail () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;31mFAIL\e[0m" - else - echo -e "FAIL" - fi -} - -function test_check () +function test_check_success () { if [ $? -ne 0 ] ; then - print_fail return 1 else - print_ok return 0 fi } function test_check_fail () { - if [ $? -ne 1 ] ; then - print_fail + if [ $? -eq 0 ] ; then return 1 else - print_ok return 0 fi }@@ -53,38 +29,48 @@ function run_babeltrace () return $? } -#run babeltrace expects success -echo -e "Running babeltrace without argument..." -run_babeltrace -test_check -if [ $? -ne 0 ]; then - exit 1 -fi - -for a in ${CTF_TRACES}/succeed/*; do - echo -e "Running babeltrace for trace ${a}..." - run_babeltrace ${a} - test_check - if [ $? -ne 0 ]; then +function print_test_result () +{ + if [ $# -ne 3 ] ; then + echo "Invalid arguments provided" exit 1 fi -done -#run babeltrace expects failure -echo -e "Running babeltrace with bogus argument..." + if [ ${2} -eq 0 ] ; then + echo -n "ok" + else + echo -n "not ok" + fi + echo -e " "${1}" - "${3} +} + +successTraces=(${CTF_TRACES}/succeed/*) +failTraces=(${CTF_TRACES}/fail/*) +testCount=$((2 + ${#successTraces[@]} + ${#failTraces[@]})) + +currentTestIndex=1 +echo -e 1..${testCount} + +#run babeltrace, expects success +run_babeltrace +test_check_success +print_test_result $((currentTestIndex++)) $? "Running babeltrace without arguments" + +#run babeltrace with a bogus argument, expects failure run_babeltrace --bogusarg test_check_fail -if [ $? -ne 0 ]; then - exit 1 -fi +print_test_result $((currentTestIndex++)) $? "Running babeltrace with a bogus argument" + +for tracePath in ${successTraces[@]}; do + run_babeltrace ${tracePath} + test_check_success + print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}" +done -for a in ${CTF_TRACES}/fail/*; do - echo -e "Running babeltrace for trace ${a}..." - run_babeltrace ${a} +for tracePath in ${failTraces[@]}; do + run_babeltrace ${tracePath} test_check_fail - if [ $? -ne 0 ]; then - exit 1 - fi + print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}" done exit 0 --1.8.1.1
Quoted 4 lines
_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
PATCH 1/1 Convert the unit tests to the TAP format
In reply to a message not in the archive--- tests/lib/Makefile.am | 2 + tests/lib/test-bitfield.c | 266 ++++++++++++++++++++++------------------------ tests/runall.sh | 88 +++++++-------- 3 files changed, 165 insertions(+), 191 deletions(-)
tests/lib/Makefile.am +2 -0
@@ -8,6 +8,8 @@ test_seeks_LDADD = libtestcommon.a \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la +test_bitfield_LDADD = libtestcommon.a + noinst_PROGRAMS = test-seeks test-bitfield test_seeks_SOURCES = test-seeks.c
tests/lib/test-bitfield.c +126 -140
380 lines not on this page · raw message
tests/runall.sh +37 -51
119 lines not on this page · raw message
Signature · 7 lines
1.8.1.1 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH babeltrace] Convert the unit tests to the TAP format
Quoted 2 lines · * Jérémie Galarneau ([email protected]) wrote:
Signed-off-by Jérémie Galarneau <[email protected]>
merged with minor style edits.
Some suggestions for improvements:
# TAP mode:
./test-bitfield -t
1..26
......
# TAP mode for N random attempts:
./test-bitfield -t 100
1..1xx
# Print "value", shifted from "shift" bits, in "len" bits type ./test-bitfield -p value shift len
# Print help:
./test-bitfield
./test-bitfield -h (or --help)
I look forward to see the patch!
Thanks,
Mathieu
Quoted 543 lines
--- tests/lib/Makefile.am | 2 + tests/lib/test-bitfield.c | 266 ++++++++++++++++++++++------------------------ tests/runall.sh | 88 +++++++-------- 3 files changed, 165 insertions(+), 191 deletions(-)tests/lib/Makefile.am +2
-0@@ -8,6 +8,8 @@ test_seeks_LDADD = libtestcommon.a \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la +test_bitfield_LDADD = libtestcommon.a + noinst_PROGRAMS = test-seeks test-bitfield test_seeks_SOURCES = test-seeks.ctests/lib/test-bitfield.c +126
-140@@ -25,6 +25,8 @@#include <stdlib.h> #include <stdio.h> +#include "tap.h" +unsigned int glob;/* @@ -39,6 +41,10 @@ void fct(void)/* Test array size, in bytes */ #define TEST_LEN 128#define NR_TESTS 10 +#define SIGNED_TEST_DESC_FMT_STR "Writing and reading back 0x%X, signed" +#define UNSIGNED_TEST_DESC_FMT_STR "Writing and reading back 0x%X, unsigned" +#define DIAG_FMT_STR "Failed reading value written \"%s\"-wise, with start=%i" \ + " and length=%i. Read %llX"unsigned int srcrand;@@ -116,7 +122,19 @@ do { \ (c)[i] = (val); \ } while (0) -int run_test_unsigned(void) +#define check_result (ref, val, buffer, typename, start, len, \ + desc_fmt_str) \ + ({ \ + if (val != ref) { \ + fail(desc_fmt_str, ref); \ + diag(DIAG_FMT_STR, #typename, start, len, val); \ + printf("# "); \ + print_byte_array(buffer, TEST_LEN); \ + } \ + val != ref; \ +}) + +void run_test_unsigned (void ) {unsigned int src, nrbits;union {@@ -128,9 +146,6 @@ int run_test_unsigned(void) } target;unsigned long long readval;unsigned int s, l; -int err =0 ; - -printf ("Running unsigned test with 0x%X\n" , srcrand); src = srcrand; nrbits =fls (src);@@ -140,62 +155,49 @@ int run_test_unsigned(void)init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.c, unsigned char, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + if (check_result(src, readval, target.c, unsigned char, + s, l,UNSIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.s, unsigned short, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + if (check_result(src, readval, target.c, unsigned short, + s, l,UNSIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.i, unsigned int, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + if (check_result(src, readval, target.c, unsigned int, + s, l,UNSIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.l, unsigned long, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + if (check_result(src, readval, target.c, unsigned long, + s, l,UNSIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0xFF ); bt_bitfield_write(target.ll, unsigned long long, s, l, src); bt_bitfield_read(target.c, unsigned char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + if (check_result(src, readval, target.c, unsigned long long, + s, l,UNSIGNED_TEST_DESC_FMT_STR )) { +return ; } } } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); -return err; + +pass (UNSIGNED_TEST_DESC_FMT_STR , src); } -int run_test_signed (void ) +void run_test_signed (void ) {int src, nrbits;union {@@ -207,9 +209,6 @@ int run_test_signed(void) } target;long long readval;unsigned int s, l; -int err =0 ; - -printf ("Running signed test with 0x%X\n" , srcrand); src = srcrand;if (src &0x80000000U )@@ -217,155 +216,142 @@ int run_test_signed(void)else nrbits =fls (src) +1 ;/* Keep sign at 0 */ -for (s =0 ; s <8 *TEST_LEN ; s++) { -for (l = nrbits; l < (8 *TEST_LEN ) - s; l++) { +for (s =0 ; s <CHAR_BIT *TEST_LEN ; s++) { +for (l = nrbits; l < (CHAR_BIT *TEST_LEN ) - s; l++) {init_byte_array (target.c,TEST_LEN ,0x0 ); bt_bitfield_write(target.c, signed char, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (bytewise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + if (check_result(src, readval, target.c, signed char, + s, l,SIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.s, short, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (shortwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; +if (check_result (src, readval, target.c, short, + s, l,SIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.i, int, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (intwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; +if (check_result (src, readval, target.c, int, + s, l,SIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0x0 );bt_bitfield_write (target.l, long, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; +if (check_result (src, readval, target.c, long, + s, l,SIGNED_TEST_DESC_FMT_STR )) { +return ; }init_byte_array (target.c,TEST_LEN ,0x0 ); bt_bitfield_write(target.ll, long long, s, l, src); bt_bitfield_read(target.c, signed char, s, l, &readval); -if (readval != src) { -printf ("Error (longlongwise) src %X read %llX shift %d len %d\n" , - src, readval, s, l); -print_byte_array (target.c,TEST_LEN ); - err =1 ; + if (check_result(src, readval, target.c, long long, + s, l,SIGNED_TEST_DESC_FMT_STR )) { +return ; } } } -if (!err) -printf ("Success!\n" ); -else -printf ("Failed!\n" ); -return err; + +pass (SIGNED_TEST_DESC_FMT_STR , src); } -int run_test (void ) +void run_test (void ) { -int err =0 ;int i; +plan_tests (NR_TESTS *2 +6 );srand (time (NULL )); srcrand =0 ; - err |=run_test_unsigned (); +run_test_unsigned (); srcrand =0 ; - err |=run_test_signed (); +run_test_signed (); + srcrand =1 ; - err |=run_test_unsigned (); +run_test_unsigned (); + srcrand = ~0U ; - err |=run_test_unsigned (); +run_test_unsigned (); + srcrand =-1 ; - err |=run_test_signed (); +run_test_signed (); + srcrand = (int )0x80000000U ; - err |=run_test_signed (); +run_test_signed ();for (i =0 ; i <NR_TESTS ; i++) { srcrand =rand (); - err |=run_test_unsigned (); - err |=run_test_signed (); +run_test_unsigned (); +run_test_signed (); } -return err; }int main (int argc,char **argv) { -unsigned long src; -unsigned int shift, len; -int ret; -union { -unsigned char c[8 ]; -unsigned short s[4 ]; -unsigned int i[2 ]; -unsigned long l[2 ]; -unsigned long long ll[1 ]; - } target; -unsigned long long readval; +if (argc >1 ) { +/* Run interactive tests */ +unsigned long src; +unsigned int shift, len; +union { +unsigned char c[8 ]; +unsigned short s[4 ]; +unsigned int i[2 ]; +unsigned long l[2 ]; +unsigned long long ll[1 ]; + } target; +unsigned long long readval; -if (argc >1 ) src =atoi (argv[1 ]); -else - src =0x12345678 ; -if (argc >2 ) - shift =atoi (argv[2 ]); -else - shift =12 ; -if (argc >3 ) - len =atoi (argv[3 ]); -else - len =40 ; - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.c, unsigned char, shift, len, src); -printf ("bytewise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.s, unsigned short, shift, len, src); -printf ("shortwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.i, unsigned int, shift, len, src); -printf ("intwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.l, unsigned long, shift, len, src); -printf ("longwise\n" ); -print_byte_array (target.c,8 ); - - target.i[0 ] =0xFFFFFFFF ; - target.i[1 ] =0xFFFFFFFF ; - bt_bitfield_write(target.ll, unsigned long long, shift, len, src); -printf ("lluwise\n" ); -print_byte_array (target.c,8 ); - - bt_bitfield_read(target.c, unsigned char, shift, len, &readval); -printf ("read: %llX\n" , readval); - - ret =run_test (); - -return ret; +if (argc >2 ) + shift =atoi (argv[2 ]); +else + shift =12 ; +if (argc >3 ) + len =atoi (argv[3 ]); +else + len =40 ; + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.c, unsigned char, shift, len, src); +printf ("bytewise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.s, unsigned short, shift, len, src); +printf ("shortwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.i, unsigned int, shift, len, src); +printf ("intwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.l, unsigned long, shift, len, src); +printf ("longwise\n" ); +print_byte_array (target.c,8 ); + +init_byte_array (target.c,8 ,0xFF ); + bt_bitfield_write(target.ll, unsigned long long, shift, len, src); +printf ("lluwise\n" ); +print_byte_array (target.c,8 ); + + bt_bitfield_read(target.c, unsigned char, shift, len, &readval); +printf ("read: %llX\n" , readval); +print_byte_array (target.c,8 ); + +return 0 ; + } + +/* Run tap-formated tests */ +run_test (); +return exit_status (); }tests/runall.sh +37
-51@@ -5,44 +5,20 @@ DIR=$(readlink -f ${TESTDIR}) BABELTRACE_BIN=${DIR}/../converter/babeltrace CTF_TRACES=${DIR}/ctf-traces -function print_ok () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;32mOK\e[0m" - else - echo -e "OK" - fi -} - -function print_fail () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;31mFAIL\e[0m" - else - echo -e "FAIL" - fi -} - -function test_check () +function test_check_success () { if [ $? -ne 0 ] ; then - print_fail return 1 else - print_ok return 0 fi } function test_check_fail () { - if [ $? -ne 1 ] ; then - print_fail + if [ $? -eq 0 ] ; then return 1 else - print_ok return 0 fi }@@ -53,38 +29,48 @@ function run_babeltrace () return $? } -#run babeltrace expects success -echo -e "Running babeltrace without argument..." -run_babeltrace -test_check -if [ $? -ne 0 ]; then - exit 1 -fi - -for a in ${CTF_TRACES}/succeed/*; do - echo -e "Running babeltrace for trace ${a}..." - run_babeltrace ${a} - test_check - if [ $? -ne 0 ]; then +function print_test_result () +{ + if [ $# -ne 3 ] ; then + echo "Invalid arguments provided" exit 1 fi -done -#run babeltrace expects failure -echo -e "Running babeltrace with bogus argument..." + if [ ${2} -eq 0 ] ; then + echo -n "ok" + else + echo -n "not ok" + fi + echo -e " "${1}" - "${3} +} + +successTraces=(${CTF_TRACES}/succeed/*) +failTraces=(${CTF_TRACES}/fail/*) +testCount=$((2 + ${#successTraces[@]} + ${#failTraces[@]})) + +currentTestIndex=1 +echo -e 1..${testCount} + +#run babeltrace, expects success +run_babeltrace +test_check_success +print_test_result $((currentTestIndex++)) $? "Running babeltrace without arguments" + +#run babeltrace with a bogus argument, expects failure run_babeltrace --bogusarg test_check_fail -if [ $? -ne 0 ]; then - exit 1 -fi +print_test_result $((currentTestIndex++)) $? "Running babeltrace with a bogus argument" + +for tracePath in ${successTraces[@]}; do + run_babeltrace ${tracePath} + test_check_success + print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}" +done -for a in ${CTF_TRACES}/fail/*; do - echo -e "Running babeltrace for trace ${a}..." - run_babeltrace ${a} +for tracePath in ${failTraces[@]}; do + run_babeltrace ${tracePath} test_check_fail - if [ $? -ne 0 ]; then - exit 1 - fi + print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}" done exit 0Signature · 7 lines
1.8.1.1 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com