tests: Move bitfield unit tests into wpa_supplicant module test

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-05-25 22:17:12 +03:00
parent 8860e0f47c
commit 8b0980af50
3 changed files with 86 additions and 95 deletions

View file

@ -9,6 +9,7 @@
#include "utils/includes.h"
#include "utils/common.h"
#include "utils/bitfield.h"
struct printf_test_data {
@ -73,6 +74,89 @@ static int printf_encode_decode_tests(void)
}
static int bitfield_tests(void)
{
struct bitfield *bf;
int i;
int errors = 0;
wpa_printf(MSG_INFO, "bitfield tests");
bf = bitfield_alloc(123);
if (bf == NULL)
return -1;
for (i = 0; i < 123; i++) {
if (bitfield_is_set(bf, i) || bitfield_is_set(bf, i + 1))
errors++;
if (i > 0 && bitfield_is_set(bf, i - 1))
errors++;
bitfield_set(bf, i);
if (!bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_is_set(bf, i))
errors++;
}
for (i = 123; i < 200; i++) {
if (bitfield_is_set(bf, i) || bitfield_is_set(bf, i + 1))
errors++;
if (i > 0 && bitfield_is_set(bf, i - 1))
errors++;
bitfield_set(bf, i);
if (bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_is_set(bf, i))
errors++;
}
for (i = 0; i < 123; i++) {
if (bitfield_is_set(bf, i) || bitfield_is_set(bf, i + 1))
errors++;
bitfield_set(bf, i);
if (!bitfield_is_set(bf, i))
errors++;
}
for (i = 0; i < 123; i++) {
if (!bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_is_set(bf, i))
errors++;
}
for (i = 0; i < 123; i++) {
if (bitfield_get_first_zero(bf) != i)
errors++;
bitfield_set(bf, i);
}
if (bitfield_get_first_zero(bf) != -1)
errors++;
for (i = 0; i < 123; i++) {
if (!bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_get_first_zero(bf) != i)
errors++;
bitfield_set(bf, i);
}
if (bitfield_get_first_zero(bf) != -1)
errors++;
bitfield_free(bf);
if (errors) {
wpa_printf(MSG_ERROR, "%d bitfield test(s) failed", errors);
return -1;
}
return 0;
}
int utils_module_tests(void)
{
int ret = 0;
@ -81,6 +165,8 @@ int utils_module_tests(void)
if (printf_encode_decode_tests() < 0)
ret = -1;
if (bitfield_tests() < 0)
ret = -1;
return ret;
}

View file

@ -1,5 +1,4 @@
TESTS=test-base64 test-md4 test-md5 test-milenage test-ms_funcs \
test-bitfield \
test-rsa-sig-ver \
test-sha1 \
test-sha256 test-aes test-asn1 test-x509 test-x509v3 test-list test-rc4
@ -51,9 +50,6 @@ test-asn1: test-asn1.o $(LIBS)
test-base64: test-base64.o $(LIBS)
$(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
test-bitfield: test-bitfield.o $(LIBS)
$(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
test-https: test-https.o $(LIBS)
$(LDO) $(LDFLAGS) -o $@ $< $(LLIBS)
@ -93,7 +89,6 @@ test-x509v3: test-x509v3.o $(LIBS)
run-tests: $(TESTS)
./test-aes
./test-bitfield
./test-list
./test-md4
./test-md5

View file

@ -1,90 +0,0 @@
/*
* bitfield unit tests
* Copyright (c) 2013, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
#include "utils/includes.h"
#include "utils/bitfield.h"
int main(int argc, char *argv[])
{
struct bitfield *bf;
int i;
int errors = 0;
bf = bitfield_alloc(123);
if (bf == NULL)
return -1;
for (i = 0; i < 123; i++) {
if (bitfield_is_set(bf, i) || bitfield_is_set(bf, i + 1))
errors++;
if (i > 0 && bitfield_is_set(bf, i - 1))
errors++;
bitfield_set(bf, i);
if (!bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_is_set(bf, i))
errors++;
}
for (i = 123; i < 200; i++) {
if (bitfield_is_set(bf, i) || bitfield_is_set(bf, i + 1))
errors++;
if (i > 0 && bitfield_is_set(bf, i - 1))
errors++;
bitfield_set(bf, i);
if (bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_is_set(bf, i))
errors++;
}
for (i = 0; i < 123; i++) {
if (bitfield_is_set(bf, i) || bitfield_is_set(bf, i + 1))
errors++;
bitfield_set(bf, i);
if (!bitfield_is_set(bf, i))
errors++;
}
for (i = 0; i < 123; i++) {
if (!bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_is_set(bf, i))
errors++;
}
for (i = 0; i < 123; i++) {
if (bitfield_get_first_zero(bf) != i)
errors++;
bitfield_set(bf, i);
}
if (bitfield_get_first_zero(bf) != -1)
errors++;
for (i = 0; i < 123; i++) {
if (!bitfield_is_set(bf, i))
errors++;
bitfield_clear(bf, i);
if (bitfield_get_first_zero(bf) != i)
errors++;
bitfield_set(bf, i);
}
if (bitfield_get_first_zero(bf) != -1)
errors++;
bitfield_free(bf);
if (errors) {
printf("%d test(s) failed\n", errors);
return -1;
}
return 0;
}