1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#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 (volatile 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);
}
|