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
|
|
@ -6,15 +6,18 @@
|
|||
#include "nfc/nfc.h"
|
||||
#include "../utils/nfc-utils.h"
|
||||
|
||||
void test_dep_active(void);
|
||||
|
||||
#define INITIATOR 0
|
||||
#define TARGET 1
|
||||
|
||||
pthread_t threads[2];
|
||||
nfc_context *context;
|
||||
nfc_connstring connstrings[2];
|
||||
nfc_device *devices[2];
|
||||
intptr_t result[2];
|
||||
|
||||
void
|
||||
static void
|
||||
abort_test_by_keypress(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
|
|
@ -27,13 +30,13 @@ abort_test_by_keypress(int sig)
|
|||
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) {
|
||||
cut_omit("At least two NFC devices must be plugged-in to run this test");
|
||||
}
|
||||
nfc_init(NULL);
|
||||
devices[TARGET] = nfc_open(NULL, connstrings[TARGET]);
|
||||
devices[INITIATOR] = nfc_open(NULL, connstrings[INITIATOR]);
|
||||
devices[TARGET] = nfc_open(context, connstrings[TARGET]);
|
||||
devices[INITIATOR] = nfc_open(context, connstrings[INITIATOR]);
|
||||
|
||||
signal(SIGINT, abort_test_by_keypress);
|
||||
}
|
||||
|
|
@ -43,7 +46,7 @@ cut_teardown(void)
|
|||
{
|
||||
nfc_close(devices[TARGET]);
|
||||
nfc_close(devices[INITIATOR]);
|
||||
nfc_exit(NULL);
|
||||
nfc_exit(context);
|
||||
}
|
||||
|
||||
struct thread_data {
|
||||
|
|
@ -52,7 +55,7 @@ struct thread_data {
|
|||
nfc_baud_rate nbr;
|
||||
};
|
||||
|
||||
void *
|
||||
static void *
|
||||
target_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
|
|
@ -82,16 +85,14 @@ target_thread(void *arg)
|
|||
};
|
||||
|
||||
uint8_t abtRx[1024];
|
||||
size_t szRx = sizeof(abtRx);
|
||||
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)));
|
||||
if (res < 0) { thread_res = -1; return (void *) thread_res; }
|
||||
|
||||
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)));
|
||||
szRx = (size_t) res;
|
||||
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; }
|
||||
|
||||
const uint8_t abtTx[] = "Hello DEP initiator!";
|
||||
|
|
@ -102,7 +103,7 @@ target_thread(void *arg)
|
|||
return (void *) thread_res;
|
||||
}
|
||||
|
||||
void *
|
||||
static void *
|
||||
initiator_thread(void *arg)
|
||||
{
|
||||
intptr_t thread_res = 0;
|
||||
|
|
@ -134,12 +135,11 @@ initiator_thread(void *arg)
|
|||
|
||||
const uint8_t abtTx[] = "Hello DEP target!";
|
||||
uint8_t abtRx[1024];
|
||||
size_t szRx = sizeof(abtRx);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, &szRx, 5000);
|
||||
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
|
||||
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!";
|
||||
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; }
|
||||
res = nfc_initiator_deselect_target(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
|
||||
test_dep(void)
|
||||
test_dep_active(void)
|
||||
{
|
||||
int res;
|
||||
nfc_baud_rate nbrs[3] = { NBR_106, NBR_212, NBR_424};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue