4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 * \brief Bitarray test
35 * \author Daniele Basile <asterix@develer.com>
38 #include <struct/bitarray.h>
40 #include <cfg/compiler.h>
42 #include <cfg/debug.h>
52 BITARRAY_ALLOC(test1, TEST1_LEN);
53 BITARRAY_ALLOC(test2, TEST2_LEN);
54 BITARRAY_ALLOC(test3, TEST3_LEN);
55 BITARRAY_ALLOC(test4, TEST4_LEN);
56 BITARRAY_ALLOC(test5, TEST5_LEN);
64 int bitarray_testSetup(void)
67 bitarray_init(&bitx1, TEST1_LEN, test1, sizeof(test1));
68 bitarray_init(&bitx2, TEST2_LEN, test2, sizeof(test2));
69 bitarray_init(&bitx3, TEST3_LEN, test3, sizeof(test3));
70 bitarray_init(&bitx4, TEST4_LEN, test4, sizeof(test4));
71 bitarray_init(&bitx5, TEST5_LEN, test5, sizeof(test5));
75 int bitarray_testRun(void)
77 memset(test1, 0xaa, sizeof(test1));
79 bitarray_dump(&bitx1);
80 for (size_t i = 0; i < TEST1_LEN; i++)
82 if (!((bool)(i % 2) == bitarray_test(&bitx1,i)))
86 memset(test1, 0, sizeof(test1));
87 for (size_t i = 0; i < TEST1_LEN; i++)
90 bitarray_clear(&bitx1,i);
92 bitarray_set(&bitx1, i);
95 bitarray_dump(&bitx1);
96 for (size_t i = 0; i < TEST1_LEN; i++)
98 if (!((bool)(i % 2) == bitarray_test(&bitx1, i)))
102 memset(test1, 0, sizeof(test1));
103 bitarray_set(&bitx1, 0);
104 bitarray_dump(&bitx1);
105 if (!bitarray_test(&bitx1, 0))
108 memset(test1, 0, sizeof(test1));
109 bitarray_set(&bitx1, TEST1_LEN);
110 bitarray_dump(&bitx1);
111 if (!bitarray_test(&bitx1, TEST1_LEN))
115 memset(test2, 0xFF, sizeof(test2));
116 bitarray_dump(&bitx2);
117 if (!bitarray_isFull(&bitx2))
120 memset(test2, 0xFF, sizeof(test2));
121 bitarray_clear(&bitx2, 5);
122 bitarray_dump(&bitx2);
123 if (bitarray_isFull(&bitx2))
126 memset(test2, 0xFF, sizeof(test2));
127 bitarray_clear(&bitx2, 13);
128 bitarray_dump(&bitx2);
129 if (bitarray_isFull(&bitx2))
133 bitarray_set(&bitx3, 12);
134 bitarray_dump(&bitx3);
136 pos = bitarray_firstSetBit(&bitx3);
141 bitarray_set(&bitx4, TEST4_LEN);
142 bitarray_dump(&bitx4);
144 pos = bitarray_firstSetBit(&bitx4);
149 bitarray_set(&bitx5, 71);
150 bitarray_dump(&bitx5);
152 pos = bitarray_firstSetBit(&bitx5);
153 kprintf("pos %d\n", pos);
158 bitarray_clear(&bitx5, 71);
159 bitarray_set(&bitx5, 5);
160 bitarray_dump(&bitx5);
162 pos = bitarray_firstSetBit(&bitx5);
173 int bitarray_testTearDown(void)