From d7e0b926acee5d847169d15e21fac7dea6007b4c Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Fri, 13 Aug 2010 18:34:30 +0000 Subject: [PATCH] Rename the only test of the regression test suite to a more explicit name. - While here, add assertions, enhance slightly the code and decrease the number of loop turns. --- test/Makefile.am | 6 ++-- test/test_access.c | 56 --------------------------------- test/test_access_storm.c | 67 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 59 deletions(-) delete mode 100644 test/test_access.c create mode 100644 test/test_access_storm.c diff --git a/test/Makefile.am b/test/Makefile.am index 9c8fafd..a55e5cf 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -8,12 +8,12 @@ TESTS = run-test.sh TESTS_ENVIRONMENT = NO_MAKE=yes CUTTER="$(CUTTER)" noinst_LTLIBRARIES = \ - test_access.la + test_access_storm.la AM_LDFLAGS = -module -rpath $(libdir) -avoid-version -no-undefined -test_access_la_SOURCES = test_access.c -test_access_la_LIBADD = $(top_builddir)/libnfc/libnfc.la +test_access_storm_la_SOURCES = test_access_storm.c +test_access_storm_la_LIBADD = $(top_builddir)/libnfc/libnfc.la echo-cutter: @echo $(CUTTER) diff --git a/test/test_access.c b/test/test_access.c deleted file mode 100644 index df96156..0000000 --- a/test/test_access.c +++ /dev/null @@ -1,56 +0,0 @@ -#include - -#include - -#define NTESTS 42 -#define MAX_TARGET_COUNT 8 - -void -test_access (void) -{ - int n = NTESTS; - nfc_device_desc_t devices[8]; - size_t device_count, ref_device_count, target_count; - bool res; - - nfc_list_devices (devices, 8, &ref_device_count); - if (!ref_device_count) - cut_omit ("No NFC device found"); - - while (n) { - size_t i; - - nfc_list_devices (devices, 8, &device_count); - cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); - - for (i = 0; i < device_count; i++) { - nfc_device_t *device; - nfc_target_info_t anti[MAX_TARGET_COUNT]; - - device = nfc_connect (&(devices[i])); - cut_assert_not_null (device, cut_message ("nfc_connect")); - - nfc_initiator_init(device); - - // Drop the field for a while - nfc_configure(device,NDO_ACTIVATE_FIELD,false); - - // Let the reader only try once to find a tag - nfc_configure(device,NDO_INFINITE_SELECT,false); - - // Configure the CRC and Parity settings - nfc_configure(device,NDO_HANDLE_CRC,true); - nfc_configure(device,NDO_HANDLE_PARITY,true); - - // Enable field so more power consuming cards can power themselves - nfc_configure(device,NDO_ACTIVATE_FIELD,true); - - res = nfc_initiator_list_passive_targets(device, NM_ISO14443A_106, anti, MAX_TARGET_COUNT, &target_count); - cut_assert_true (res, cut_message ("nfc_initiator_list_passive_targets")); - - nfc_disconnect (device); - } - - n--; - } -} diff --git a/test/test_access_storm.c b/test/test_access_storm.c new file mode 100644 index 0000000..de1e715 --- /dev/null +++ b/test/test_access_storm.c @@ -0,0 +1,67 @@ +#include + +#include + +#define NTESTS 10 +#define MAX_DEVICE_COUNT 8 +#define MAX_TARGET_COUNT 8 + +/* + * This is basically a stress-test to ensure we don't left a device in an + * inconsistent state after use. + */ +void +test_access_storm (void) +{ + int n = NTESTS; + nfc_device_desc_t devices[MAX_DEVICE_COUNT]; + size_t device_count, ref_device_count, target_count; + bool res; + + nfc_list_devices (devices, MAX_DEVICE_COUNT, &ref_device_count); + if (!ref_device_count) + cut_omit ("No NFC device found"); + + while (n) { + size_t i; + + nfc_list_devices (devices, MAX_DEVICE_COUNT, &device_count); + cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); + + for (i = 0; i < device_count; i++) { + nfc_device_t *device; + nfc_target_info_t anti[MAX_TARGET_COUNT]; + + device = nfc_connect (&(devices[i])); + cut_assert_not_null (device, cut_message ("nfc_connect")); + + res = nfc_initiator_init(device); + cut_assert_true (res, cut_message ("nfc_initiator_init")); + + // Drop the field for a while + res = nfc_configure(device,NDO_ACTIVATE_FIELD,false); + cut_assert_true (res, cut_message ("nfc_configure")); + + // Let the reader only try once to find a tag + res = nfc_configure(device,NDO_INFINITE_SELECT,false); + cut_assert_true (res, cut_message ("nfc_configure")); + + // Configure the CRC and Parity settings + res = nfc_configure(device,NDO_HANDLE_CRC,true); + cut_assert_true (res, cut_message ("nfc_configure")); + res = nfc_configure(device,NDO_HANDLE_PARITY,true); + cut_assert_true (res, cut_message ("nfc_configure")); + + // Enable field so more power consuming cards can power themselves + res = nfc_configure(device,NDO_ACTIVATE_FIELD,true); + cut_assert_true (res, cut_message ("nfc_configure")); + + res = nfc_initiator_list_passive_targets(device, NM_ISO14443A_106, anti, MAX_TARGET_COUNT, &target_count); + cut_assert_true (res, cut_message ("nfc_initiator_list_passive_targets")); + + nfc_disconnect (device); + } + + n--; + } +}