libnfc/test/test_access_storm.c
Romuald Conty 2d53208082 Fix unit tests
This commit bring tests to life!

New issue
Summary: test_dep_states test fails
When first device is idle, the second one states  "RF Transmission Error" instead of simply not found any available device.
Full cutter log here:

debug   libnfc.chip.pn53x       InJumpForDEP
debug   libnfc.chip.pn53x       Timeout values: 300
debug   libnfc.bus.uart TX: 00  00  ff  05  fb  d4  56  00  00  00  d6  00
debug   libnfc.bus.uart RX: 00  00  ff  00  ff  00
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.bus.uart Timeout!
debug   libnfc.chip.pn53x       InJumpForDEP
debug   libnfc.chip.pn53x       Timeout values: 300
debug   libnfc.bus.uart TX: 00  00  ff  05  fb  d4  56  00  00  00  d6  00
debug   libnfc.bus.uart RX: 00  00  ff  00  ff  00
debug   libnfc.chip.pn53x       PN53x ACKed
debug   libnfc.bus.uart RX: 00  00  ff  03  fd
debug   libnfc.bus.uart RX: d5  57
debug   libnfc.bus.uart RX: 01
debug   libnfc.bus.uart RX: d3  00
debug   libnfc.chip.pn53x       Chip error: "Timeout" (01), returned error: "RF Transmission Error" (-20))
F
===============================================================================
Failure: test_dep_states
Problem with nfc_idle
<0 == res>
expected: <0>
  actual: <-20>

diff:
? -20

./test_device_modes_as_dep.c:171: initiator_thread(): cut_assert_equal_int(0, res, cut_test_context_set_current_result_user_message( cut_test_context_current_peek(), cut_test_context_take_printf(cut_test_context_current_peek(), "Problem with nfc_idle")))
===============================================================================
2013-01-18 18:28:45 +01:00

56 lines
1.4 KiB
C

#include <cutter.h>
#include <nfc/nfc.h>
#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);
void
test_access_storm(void)
{
int n = NTESTS;
nfc_connstring connstrings[MAX_DEVICE_COUNT];
int res = 0;
nfc_context *context;
nfc_init(&context);
size_t ref_device_count = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
if (!ref_device_count)
cut_omit("No NFC device found");
while (n) {
size_t device_count = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
cut_assert_equal_int(ref_device_count, device_count, cut_message("device count"));
for (size_t i = 0; i < device_count; i++) {
nfc_device *device;
nfc_target ant[MAX_TARGET_COUNT];
device = nfc_open(context, connstrings[i]);
cut_assert_not_null(device, cut_message("nfc_open"));
res = nfc_initiator_init(device);
cut_assert_equal_int(0, res, cut_message("nfc_initiator_init"));
const nfc_modulation nm = {
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
cut_assert_operator_int(res, >= , 0, cut_message("nfc_initiator_list_passive_targets"));
nfc_close(device);
}
n--;
}
nfc_exit(context);
}