Add sam3n bechmark into nightly test.
[bertos.git] / bertos / struct / bitarray_test.c
index fa65c44a0791f625f47c3a0b40b26d043c0a99ab..0dad3a270ef9796c87bb8b92f305beb9591120fd 100644 (file)
 #include <cfg/test.h>
 #include <cfg/debug.h>
 
-ALLOC_BITARRAY(test1, 128);
-BitArray ctx;
+#include <string.h>
+
+#define TEST1_LEN   31
+#define TEST2_LEN   17
+#define TEST3_LEN   16
+#define TEST4_LEN   23
+#define TEST5_LEN   72
+
+BITARRAY_ALLOC(test1, TEST1_LEN);
+BITARRAY_ALLOC(test2, TEST2_LEN);
+BITARRAY_ALLOC(test3, TEST3_LEN);
+BITARRAY_ALLOC(test4, TEST4_LEN);
+BITARRAY_ALLOC(test5, TEST5_LEN);
+
+BitArray bitx1;
+BitArray bitx2;
+BitArray bitx3;
+BitArray bitx4;
+BitArray bitx5;
 
 int bitarray_testSetup(void)
 {
        kdbg_init();
-       init_bitarray(&ctx, test1, sizeof(test1));
+       bitarray_init(&bitx1, TEST1_LEN, test1, sizeof(test1));
+       bitarray_init(&bitx2, TEST2_LEN, test2, sizeof(test2));
+       bitarray_init(&bitx3, TEST3_LEN, test3, sizeof(test3));
+       bitarray_init(&bitx4, TEST4_LEN, test4, sizeof(test4));
+       bitarray_init(&bitx5, TEST5_LEN, test5, sizeof(test5));
        return 0;
 }
 
 int bitarray_testRun(void)
 {
+       memset(test1, 0xaa, sizeof(test1));
+
+       bitarray_dump(&bitx1);
+       for (size_t i = 0; i < TEST1_LEN; i++)
+       {
+               if (!((bool)(i % 2) == bitarray_test(&bitx1,i)))
+                       goto error;
+       }
+
+       memset(test1, 0, sizeof(test1));
+       for (size_t i = 0; i < TEST1_LEN; i++)
+       {
+               if ((i % 2) == 0)
+                       bitarray_clear(&bitx1,i);
+               else
+                       bitarray_set(&bitx1, i);
+       }
+
+       bitarray_dump(&bitx1);
+       for (size_t i = 0; i < TEST1_LEN; i++)
+       {
+               if (!((bool)(i % 2) == bitarray_test(&bitx1, i)))
+               goto error;
+       }
+
+       memset(test1, 0, sizeof(test1));
+       bitarray_set(&bitx1, 0);
+       bitarray_dump(&bitx1);
+       if (!bitarray_test(&bitx1, 0))
+               goto error;
+
+       memset(test1, 0, sizeof(test1));
+       bitarray_set(&bitx1, TEST1_LEN);
+       bitarray_dump(&bitx1);
+       if (!bitarray_test(&bitx1, TEST1_LEN))
+               goto error;
+
+       kprintf("Test 2\n");
+       memset(test2, 0xFF, sizeof(test2));
+       bitarray_dump(&bitx2);
+       if (!bitarray_isFull(&bitx2))
+               goto error;
+
+       memset(test2, 0xFF, sizeof(test2));
+       bitarray_clear(&bitx2, 5);
+       bitarray_dump(&bitx2);
+       if (bitarray_isFull(&bitx2))
+               goto error;
+
+       memset(test2, 0xFF, sizeof(test2));
+       bitarray_clear(&bitx2, 13);
+       bitarray_dump(&bitx2);
+       if (bitarray_isFull(&bitx2))
+               goto error;
+
+       kprintf("Test 3\n");
+       bitarray_set(&bitx3, 12);
+       bitarray_dump(&bitx3);
+       int pos = 0;
+       pos = bitarray_firstSetBit(&bitx3);
+       if (pos != 12)
+               goto error;
+
+       kprintf("Test 4\n");
+       bitarray_set(&bitx4, TEST4_LEN);
+       bitarray_dump(&bitx4);
+       pos = 0;
+       pos = bitarray_firstSetBit(&bitx4);
+       if (pos != 23)
+               goto error;
+
+       kprintf("Test 5\n");
+       bitarray_set(&bitx5, 71);
+       bitarray_dump(&bitx5);
+       pos = 0;
+       pos = bitarray_firstSetBit(&bitx5);
+       kprintf("pos %d\n", pos);
+       if (pos != 71)
+               goto error;
+
+       kprintf("Test 6\n");
+       bitarray_clear(&bitx5, 71);
+       bitarray_set(&bitx5, 5);
+       bitarray_dump(&bitx5);
+       pos = 0;
+       pos = bitarray_firstSetBit(&bitx5);
+       if (pos != 5)
+               goto error;
+
        return 0;
+
+error:
+       kprintf("Error!\n");
+       return -1;
 }
 
 int bitarray_testTearDown(void)