Move the bitfield test to tests/lib/
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 7 Feb 2013 22:30:52 +0000 (17:30 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 7 Feb 2013 22:30:52 +0000 (17:30 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
.gitignore
tests/Makefile.am
tests/lib/Makefile.am
tests/lib/runall.sh
tests/lib/test-bitfield.c [new file with mode: 0644]
tests/runall.sh
tests/test-bitfield.c [deleted file]

index 03443dfca8dc7dc946e019c4179bb5b74fcd5439..752308e7b38a2c732d48688eed2dbfeafd26ba0e 100644 (file)
@@ -1,4 +1,4 @@
-/tests/test-bitfield
+/tests/lib/test-bitfield
 /tests/lib/test-seeks
 *.o
 *.a
index 47891e90af0945d3accf10f7d3cd0fe1351af031..816fa6600c82dac5e6bcd5340fd5c5e2914a7e19 100644 (file)
@@ -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:
index e9e264bbbb17c5756f1243f33f42b8fc0cc691d9..0613bebd916f62d5eaed25cce8c9c2d03af8e926 100644 (file)
@@ -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
 
index 34503bbbcfa7aff71f304aa594b9039b39c965ea..b5522ad0a19c0b515e838b33dc76b69fbe542ee8 100755 (executable)
@@ -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
\ No newline at end of file
+./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396
+
+# run bitfield tests
+./test-bitfield
diff --git a/tests/lib/test-bitfield.c b/tests/lib/test-bitfield.c
new file mode 100644 (file)
index 0000000..3bf7568
--- /dev/null
@@ -0,0 +1,371 @@
+/*
+ * test-bitfield.c
+ *
+ * BabelTrace - bitfield test program
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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;
+}
index b2af65647c8a2418b6737ead0e9a6cc2dc4a840d..9e0bdca5a3ed44f42ecd8bbb82d0dac3860fcd6a 100755 (executable)
@@ -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
diff --git a/tests/test-bitfield.c b/tests/test-bitfield.c
deleted file mode 100644 (file)
index 3bf7568..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * test-bitfield.c
- *
- * BabelTrace - bitfield test program
- *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * 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;
-}
This page took 0.051633 seconds and 4 git commands to generate.