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"))) ===============================================================================
This commit is contained in:
parent
443f70dd65
commit
2d53208082
8 changed files with 87 additions and 76 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
TBD - 1.7.0-rc2 (release candidate)
|
||||||
|
--------------------------------------------
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
- Fix tests
|
||||||
|
|
||||||
Dec 09, 2012 - 1.7.0-rc1 (release candidate)
|
Dec 09, 2012 - 1.7.0-rc1 (release candidate)
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ libnfc_la_SOURCES = \
|
||||||
nfc-internal.c \
|
nfc-internal.c \
|
||||||
target-subr.c
|
target-subr.c
|
||||||
|
|
||||||
libnfc_la_LDFLAGS = -no-undefined -version-info 4:0:0 -export-symbols-regex '^nfc_|^iso14443a_|^str_nfc_|pn53x_transceive|pn532_SAMConfiguration'
|
libnfc_la_LDFLAGS = -no-undefined -version-info 4:0:0 -export-symbols-regex '^nfc_|^iso14443a_|^str_nfc_|pn53x_transceive|pn532_SAMConfiguration|pn53x_read_register|pn53x_write_register'
|
||||||
libnfc_la_CFLAGS = @DRIVERS_CFLAGS@
|
libnfc_la_CFLAGS = @DRIVERS_CFLAGS@
|
||||||
libnfc_la_LIBADD = \
|
libnfc_la_LIBADD = \
|
||||||
$(top_builddir)/libnfc/chips/libnfcchips.la \
|
$(top_builddir)/libnfc/chips/libnfcchips.la \
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
* This is basically a stress-test to ensure we don't left a device in an
|
* This is basically a stress-test to ensure we don't left a device in an
|
||||||
* inconsistent state after use.
|
* inconsistent state after use.
|
||||||
*/
|
*/
|
||||||
|
void test_access_storm(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
test_access_storm(void)
|
test_access_storm(void)
|
||||||
{
|
{
|
||||||
|
@ -17,23 +19,22 @@ test_access_storm(void)
|
||||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
nfc_init(NULL);
|
nfc_context *context;
|
||||||
|
nfc_init(&context);
|
||||||
|
|
||||||
size_t ref_device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t ref_device_count = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
|
||||||
if (!ref_device_count)
|
if (!ref_device_count)
|
||||||
cut_omit("No NFC device found");
|
cut_omit("No NFC device found");
|
||||||
|
|
||||||
while (n) {
|
while (n) {
|
||||||
size_t i;
|
size_t device_count = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
|
||||||
|
|
||||||
size_t device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
|
||||||
cut_assert_equal_int(ref_device_count, device_count, cut_message("device count"));
|
cut_assert_equal_int(ref_device_count, device_count, cut_message("device count"));
|
||||||
|
|
||||||
for (i = 0; i < device_count; i++) {
|
for (size_t i = 0; i < device_count; i++) {
|
||||||
nfc_device *device;
|
nfc_device *device;
|
||||||
nfc_target ant[MAX_TARGET_COUNT];
|
nfc_target ant[MAX_TARGET_COUNT];
|
||||||
|
|
||||||
device = nfc_open(NULL, connstrings[i]);
|
device = nfc_open(context, connstrings[i]);
|
||||||
cut_assert_not_null(device, cut_message("nfc_open"));
|
cut_assert_not_null(device, cut_message("nfc_open"));
|
||||||
|
|
||||||
res = nfc_initiator_init(device);
|
res = nfc_initiator_init(device);
|
||||||
|
@ -51,5 +52,5 @@ test_access_storm(void)
|
||||||
|
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
nfc_exit(NULL);
|
nfc_exit(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,18 @@
|
||||||
#include "nfc/nfc.h"
|
#include "nfc/nfc.h"
|
||||||
#include "../utils/nfc-utils.h"
|
#include "../utils/nfc-utils.h"
|
||||||
|
|
||||||
|
void test_dep_active(void);
|
||||||
|
|
||||||
#define INITIATOR 0
|
#define INITIATOR 0
|
||||||
#define TARGET 1
|
#define TARGET 1
|
||||||
|
|
||||||
pthread_t threads[2];
|
pthread_t threads[2];
|
||||||
|
nfc_context *context;
|
||||||
nfc_connstring connstrings[2];
|
nfc_connstring connstrings[2];
|
||||||
nfc_device *devices[2];
|
nfc_device *devices[2];
|
||||||
intptr_t result[2];
|
intptr_t result[2];
|
||||||
|
|
||||||
void
|
static void
|
||||||
abort_test_by_keypress(int sig)
|
abort_test_by_keypress(int sig)
|
||||||
{
|
{
|
||||||
(void) sig;
|
(void) sig;
|
||||||
|
@ -27,13 +30,13 @@ abort_test_by_keypress(int sig)
|
||||||
void
|
void
|
||||||
cut_setup(void)
|
cut_setup(void)
|
||||||
{
|
{
|
||||||
size_t n = nfc_list_devices(NULL, connstrings, 2);
|
nfc_init(&context);
|
||||||
|
size_t n = nfc_list_devices(context, connstrings, 2);
|
||||||
if (n < 2) {
|
if (n < 2) {
|
||||||
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
||||||
}
|
}
|
||||||
nfc_init(NULL);
|
devices[TARGET] = nfc_open(context, connstrings[TARGET]);
|
||||||
devices[TARGET] = nfc_open(NULL, connstrings[TARGET]);
|
devices[INITIATOR] = nfc_open(context, connstrings[INITIATOR]);
|
||||||
devices[INITIATOR] = nfc_open(NULL, connstrings[INITIATOR]);
|
|
||||||
|
|
||||||
signal(SIGINT, abort_test_by_keypress);
|
signal(SIGINT, abort_test_by_keypress);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +46,7 @@ cut_teardown(void)
|
||||||
{
|
{
|
||||||
nfc_close(devices[TARGET]);
|
nfc_close(devices[TARGET]);
|
||||||
nfc_close(devices[INITIATOR]);
|
nfc_close(devices[INITIATOR]);
|
||||||
nfc_exit(NULL);
|
nfc_exit(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct thread_data {
|
struct thread_data {
|
||||||
|
@ -52,7 +55,7 @@ struct thread_data {
|
||||||
nfc_baud_rate nbr;
|
nfc_baud_rate nbr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
static void *
|
||||||
target_thread(void *arg)
|
target_thread(void *arg)
|
||||||
{
|
{
|
||||||
intptr_t thread_res = 0;
|
intptr_t thread_res = 0;
|
||||||
|
@ -82,16 +85,14 @@ target_thread(void *arg)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof(abtRx);
|
|
||||||
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0);
|
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
szRx = (size_t) res;
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
|
@ -102,7 +103,7 @@ target_thread(void *arg)
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
static void *
|
||||||
initiator_thread(void *arg)
|
initiator_thread(void *arg)
|
||||||
{
|
{
|
||||||
intptr_t thread_res = 0;
|
intptr_t thread_res = 0;
|
||||||
|
@ -134,12 +135,11 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof(abtRx);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data (as initiator)"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
|
||||||
|
@ -149,7 +149,7 @@ initiator_thread(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_dep(void)
|
test_dep_active(void)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
nfc_baud_rate nbrs[3] = { NBR_106, NBR_212, NBR_424};
|
nfc_baud_rate nbrs[3] = { NBR_106, NBR_212, NBR_424};
|
||||||
|
|
|
@ -5,15 +5,18 @@
|
||||||
|
|
||||||
#include "nfc/nfc.h"
|
#include "nfc/nfc.h"
|
||||||
|
|
||||||
|
void test_dep_passive(void);
|
||||||
|
|
||||||
#define INITIATOR 0
|
#define INITIATOR 0
|
||||||
#define TARGET 1
|
#define TARGET 1
|
||||||
|
|
||||||
pthread_t threads[2];
|
pthread_t threads[2];
|
||||||
|
nfc_context *context;
|
||||||
nfc_connstring connstrings[2];
|
nfc_connstring connstrings[2];
|
||||||
nfc_device *devices[2];
|
nfc_device *devices[2];
|
||||||
intptr_t result[2];
|
intptr_t result[2];
|
||||||
|
|
||||||
void
|
static void
|
||||||
abort_test_by_keypress(int sig)
|
abort_test_by_keypress(int sig)
|
||||||
{
|
{
|
||||||
(void) sig;
|
(void) sig;
|
||||||
|
@ -26,14 +29,14 @@ abort_test_by_keypress(int sig)
|
||||||
void
|
void
|
||||||
cut_setup(void)
|
cut_setup(void)
|
||||||
{
|
{
|
||||||
size_t n = nfc_list_devices(NULL, connstrings, 2);
|
nfc_init(&context);
|
||||||
|
size_t n = nfc_list_devices(context, connstrings, 2);
|
||||||
if (n < 2) {
|
if (n < 2) {
|
||||||
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
||||||
}
|
}
|
||||||
|
|
||||||
nfc_init(NULL);
|
devices[TARGET] = nfc_open(context, connstrings[TARGET]);
|
||||||
devices[TARGET] = nfc_open(NULL, connstrings[TARGET]);
|
devices[INITIATOR] = nfc_open(context, connstrings[INITIATOR]);
|
||||||
devices[INITIATOR] = nfc_open(NULL, connstrings[INITIATOR]);
|
|
||||||
|
|
||||||
signal(SIGINT, abort_test_by_keypress);
|
signal(SIGINT, abort_test_by_keypress);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +46,7 @@ cut_teardown(void)
|
||||||
{
|
{
|
||||||
nfc_close(devices[TARGET]);
|
nfc_close(devices[TARGET]);
|
||||||
nfc_close(devices[INITIATOR]);
|
nfc_close(devices[INITIATOR]);
|
||||||
nfc_exit(NULL);
|
nfc_exit(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct thread_data {
|
struct thread_data {
|
||||||
|
@ -51,7 +54,7 @@ struct thread_data {
|
||||||
void *cut_test_context;
|
void *cut_test_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
static void *
|
||||||
target_thread(void *arg)
|
target_thread(void *arg)
|
||||||
{
|
{
|
||||||
intptr_t thread_res = 0;
|
intptr_t thread_res = 0;
|
||||||
|
@ -89,10 +92,9 @@ target_thread(void *arg)
|
||||||
// First pass
|
// First pass
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
szRx = (size_t) res;
|
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
|
@ -105,7 +107,7 @@ target_thread(void *arg)
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
|
@ -117,7 +119,7 @@ target_thread(void *arg)
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
|
@ -129,7 +131,7 @@ target_thread(void *arg)
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
szRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
|
||||||
|
@ -139,7 +141,7 @@ target_thread(void *arg)
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
static void *
|
||||||
initiator_thread(void *arg)
|
initiator_thread(void *arg)
|
||||||
{
|
{
|
||||||
intptr_t thread_res = 0;
|
intptr_t thread_res = 0;
|
||||||
|
@ -171,12 +173,11 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof(abtRx);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 500);
|
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
|
@ -194,11 +195,10 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof(abtRx);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 1000);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 1000);
|
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
|
@ -216,11 +216,10 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof(abtRx);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
|
@ -238,11 +237,10 @@ initiator_thread(void *arg)
|
||||||
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
cut_assert_equal_memory("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message("Invalid target general bytes"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof(abtRx);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
|
@ -253,7 +251,7 @@ initiator_thread(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_dep(void)
|
test_dep_passive(void)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,15 @@
|
||||||
#include "nfc/nfc.h"
|
#include "nfc/nfc.h"
|
||||||
#include "../utils/nfc-utils.h"
|
#include "../utils/nfc-utils.h"
|
||||||
|
|
||||||
|
void test_dep_states(void);
|
||||||
|
|
||||||
pthread_t threads[2];
|
pthread_t threads[2];
|
||||||
|
nfc_context *context;
|
||||||
nfc_connstring connstrings[2];
|
nfc_connstring connstrings[2];
|
||||||
nfc_device *first_device, *second_device;
|
nfc_device *first_device, *second_device;
|
||||||
intptr_t result[2];
|
intptr_t result[2];
|
||||||
|
|
||||||
void
|
static void
|
||||||
abort_test_by_keypress(int sig)
|
abort_test_by_keypress(int sig)
|
||||||
{
|
{
|
||||||
(void) sig;
|
(void) sig;
|
||||||
|
@ -24,14 +27,14 @@ abort_test_by_keypress(int sig)
|
||||||
void
|
void
|
||||||
cut_setup(void)
|
cut_setup(void)
|
||||||
{
|
{
|
||||||
size_t n = nfc_list_devices(NULL, connstrings, 2);
|
nfc_init(&context);
|
||||||
|
size_t n = nfc_list_devices(context, connstrings, 2);
|
||||||
if (n < 2) {
|
if (n < 2) {
|
||||||
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
||||||
}
|
}
|
||||||
|
|
||||||
nfc_init(NULL);
|
second_device = nfc_open(context, connstrings[0]);
|
||||||
second_device = nfc_open(NULL, connstrings[0]);
|
first_device = nfc_open(context, connstrings[1]);
|
||||||
first_device = nfc_open(NULL, connstrings[1]);
|
|
||||||
|
|
||||||
signal(SIGINT, abort_test_by_keypress);
|
signal(SIGINT, abort_test_by_keypress);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +44,7 @@ cut_teardown(void)
|
||||||
{
|
{
|
||||||
nfc_close(second_device);
|
nfc_close(second_device);
|
||||||
nfc_close(first_device);
|
nfc_close(first_device);
|
||||||
nfc_exit(NULL);
|
nfc_exit(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct thread_data {
|
struct thread_data {
|
||||||
|
@ -49,7 +52,7 @@ struct thread_data {
|
||||||
void *cut_test_context;
|
void *cut_test_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
static void *
|
||||||
target_thread(void *arg)
|
target_thread(void *arg)
|
||||||
{
|
{
|
||||||
intptr_t thread_res = 0;
|
intptr_t thread_res = 0;
|
||||||
|
@ -60,10 +63,9 @@ target_thread(void *arg)
|
||||||
nfc_target nt;
|
nfc_target nt;
|
||||||
|
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof(abtRx);
|
|
||||||
|
|
||||||
// 1) nfc_target_init should take target in idle mode
|
// 1) nfc_target_init should take target in idle mode
|
||||||
int res = nfc_target_init(device, &nt, abtRx, szRx, 500);
|
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
|
@ -89,16 +91,15 @@ target_thread(void *arg)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
sleep(6);
|
sleep(6);
|
||||||
res = nfc_target_init(device, &nt1, abtRx, szRx, 0);
|
res = nfc_target_init(device, &nt1, abtRx, sizeof(abtRx), 0);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
|
||||||
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
|
||||||
szRx = (size_t) res;
|
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
if (res <= 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||||
|
@ -113,7 +114,7 @@ target_thread(void *arg)
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
static void *
|
||||||
initiator_thread(void *arg)
|
initiator_thread(void *arg)
|
||||||
{
|
{
|
||||||
intptr_t thread_res = 0;
|
intptr_t thread_res = 0;
|
||||||
|
@ -153,12 +154,11 @@ initiator_thread(void *arg)
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof(abtRx);
|
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
|
||||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 500);
|
|
||||||
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, szRx, cut_message("Invalid received data"));
|
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
|
||||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target(device);
|
res = nfc_initiator_deselect_target(device);
|
||||||
|
|
|
@ -6,21 +6,24 @@
|
||||||
#define MAX_DEVICE_COUNT 1
|
#define MAX_DEVICE_COUNT 1
|
||||||
#define MAX_TARGET_COUNT 1
|
#define MAX_TARGET_COUNT 1
|
||||||
|
|
||||||
|
void test_register_access(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
test_register_endianness(void)
|
test_register_access(void)
|
||||||
{
|
{
|
||||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
nfc_init(NULL);
|
nfc_context *context;
|
||||||
|
nfc_init(&context);
|
||||||
|
|
||||||
size_t device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t device_count = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
|
||||||
if (!device_count)
|
if (!device_count)
|
||||||
cut_omit("No NFC device found");
|
cut_omit("No NFC device found");
|
||||||
|
|
||||||
nfc_device *device;
|
nfc_device *device;
|
||||||
|
|
||||||
device = nfc_open(NULL, connstrings[0]);
|
device = nfc_open(context, connstrings[0]);
|
||||||
cut_assert_not_null(device, cut_message("nfc_open"));
|
cut_assert_not_null(device, cut_message("nfc_open"));
|
||||||
|
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
@ -44,5 +47,5 @@ test_register_endianness(void)
|
||||||
cut_assert_equal_uint(0x55, value, cut_message("check register value"));
|
cut_assert_equal_uint(0x55, value, cut_message("check register value"));
|
||||||
|
|
||||||
nfc_close(device);
|
nfc_close(device);
|
||||||
nfc_exit(NULL);
|
nfc_exit(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#define MAX_DEVICE_COUNT 1
|
#define MAX_DEVICE_COUNT 1
|
||||||
#define MAX_TARGET_COUNT 1
|
#define MAX_TARGET_COUNT 1
|
||||||
|
|
||||||
|
void test_register_endianness(void);
|
||||||
|
|
||||||
#include "chips/pn53x.h"
|
#include "chips/pn53x.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -13,15 +15,16 @@ test_register_endianness(void)
|
||||||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
nfc_init(NULL);
|
nfc_context *context;
|
||||||
|
nfc_init(&context);
|
||||||
|
|
||||||
size_t device_count = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
|
size_t device_count = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
|
||||||
if (!device_count)
|
if (!device_count)
|
||||||
cut_omit("No NFC device found");
|
cut_omit("No NFC device found");
|
||||||
|
|
||||||
nfc_device *device;
|
nfc_device *device;
|
||||||
|
|
||||||
device = nfc_open(NULL, connstrings[0]);
|
device = nfc_open(context, connstrings[0]);
|
||||||
cut_assert_not_null(device, cut_message("nfc_open"));
|
cut_assert_not_null(device, cut_message("nfc_open"));
|
||||||
|
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
@ -32,8 +35,8 @@ test_register_endianness(void)
|
||||||
|
|
||||||
/* Read invalid SFR register */
|
/* Read invalid SFR register */
|
||||||
res = pn53x_read_register(device, 0xFFF0, &value);
|
res = pn53x_read_register(device, 0xFFF0, &value);
|
||||||
cut_assert_equal_int(0, res, cut_message("read register 0xFFF0"));
|
cut_assert_equal_int(-1, res, cut_message("read register 0xFFF0"));
|
||||||
|
|
||||||
nfc_close(device);
|
nfc_close(device);
|
||||||
nfc_exit(NULL);
|
nfc_exit(context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue