/* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file src/test_fc.c * \brief Test frame control structures. * \ingroup test */ #include "common/std.h" #include "lib/rnd.h" #include "lib/test.h" #include "mac/pbproc/inc/fc.h" #define NB_ITER 10000 typedef void (*check_f_t) (test_t t, const pbproc_fc_t *fc); #include "obj/inc/generic.h" #include "obj/inc/beacon.h" #include "obj/inc/sof.h" #include "obj/inc/sack.h" #include "obj/inc/rts_cts.h" #include "obj/inc/sound.h" #include "obj/inc/rsof.h" static struct { const char *name; check_f_t f; } checks[] = { { "generic", check_generic }, { "beacon", check_beacon }, { "sof", check_sof }, { "sack", check_sack }, { "rts_cts", check_rts_cts }, { "sound", check_sound }, { "rsof", check_rsof }, { NULL, NULL } }; void fc_test_suite (test_t t) { uint i, j, k; pbproc_fc_t fc; lib_rnd_t rnd[1]; test_suite_begin (t, "fc"); /* Init. */ lib_rnd_init (rnd, 1234); /* Test cases loop. */ for (i = 0; checks[i].name; i++) { test_case_begin (t, checks[i].name); test_begin (t, "word to fields") { for (j = 0; j < NB_ITER; j++) { for (k = 0; k < COUNT (fc.words); k++) fc.words[k] = lib_rnd32 (rnd); checks[i].f (t, &fc); } } test_end; } } static uint fc_ppb_test_decode (u8 ppb) { uint mant = ppb >> 4; uint exp = ppb & 0xf; if (exp < 1) return mant; else if (exp == 1) return (mant + 16) << (exp - 1); else return ((mant + 16) << (exp - 1)) + (1 << (exp - 2)); } static void fc_ppb_test_value (test_t t, uint v) { test_within (t); u8 ppb = pbproc_fc_pbb (v); uint ppb_dec_l, ppb_dec_p; if (ppb == 0) ppb_dec_l = 0; else { u8 ppb_l = ppb >> 4 | ppb << 4; ppb_l--; ppb_l = ppb_l >> 4 | ppb_l << 4; ppb_dec_l = fc_ppb_test_decode (ppb_l); } if (ppb == 255) ppb_dec_p = 0xffffffffu; else { u8 ppb_p = ppb >> 4 | ppb << 4; ppb_p++; ppb_p = ppb_p >> 4 | ppb_p << 4; ppb_dec_p = fc_ppb_test_decode (ppb_p); } test_fail_unless (ppb_dec_l <= v && v < ppb_dec_p, "bad PPB: integer = %u, coded = 0x%02x", v, ppb); } void fc_ppb_test_suite (test_t t) { test_suite_begin (t, "fc ppb"); test_case_begin (t, "basic"); test_begin (t, "enumerate") { uint i; for (i = 0; i < 2 << 19; i++) fc_ppb_test_value (t, i); } test_end; } int main (int argc, char **argv) { test_t t; test_init (t, argc, argv); fc_test_suite (t); fc_ppb_test_suite (t); test_result (t); return test_nb_failed (t) == 0 ? 0 : 1; }