Skip to content

Commit

Permalink
Merge branch 'master' into pd-lstatus-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sidcha authored Oct 11, 2023
2 parents 4fe6c8b + dbff2d1 commit a3bf00d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ list(APPEND LIB_OSDP_PRIVATE_INCLUDE_DIRS

if (OpenSSL_FOUND)
list(APPEND LIB_OSDP_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) # Needed for python library building
list(APPEND LIB_OSDP_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
list(APPEND LIB_OSDP_DEFINITIONS "-DCONFIG_OSDP_USE_OPENSSL")
list(APPEND LIB_OSDP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crypto/openssl.c)
elseif (MbedTLS_FOUND)
Expand Down Expand Up @@ -100,6 +101,7 @@ target_include_directories(${LIB_OSDP_STATIC}
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/libosdp>
PRIVATE
${LIB_OSDP_INCLUDE_DIRS}
${LIB_OSDP_PRIVATE_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/utils/include
)
Expand Down
12 changes: 9 additions & 3 deletions tests/unit-tests/test-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@ static int test_fops_write(void *arg, const void *buf, int size, int offset)
return (int)ret;
}

static void test_fops_close(void *arg)
static int test_fops_close(void *arg)
{
struct test_data *t = arg;

if (t->fd == 0) {
printf(SUB_1 "%s_close: fd:%d\n",
t->is_cp ? "sender" : "receiver", t->fd);
return;
return -1;
}
close(t->fd);
t->fd = 0;
return 0;
}

static int test_create_file()
Expand Down Expand Up @@ -159,7 +160,7 @@ static bool test_check_rec_file()
return false;
}

void run_file_tx_tests(struct test *t)
void run_file_tx_tests(struct test *t, bool line_noise)
{
bool result = false;
int rc, size, offset;
Expand Down Expand Up @@ -237,12 +238,16 @@ void run_file_tx_tests(struct test *t)
}

printf(SUB_1 "monitoring file tx progress\n");
if (line_noise)
enable_line_noise();

while (1) {
usleep(100 * 1000);
rc = osdp_get_file_tx_status(cp_ctx, 0, &size, &offset);
if (rc < 0) {
printf(SUB_1 "status query failed!\n");
if (line_noise)
print_line_noise_stats();
goto error;
}
if (offset == size)
Expand All @@ -253,6 +258,7 @@ void run_file_tx_tests(struct test *t)
printf(SUB_1 "file transfer test %s\n",
result ? "succeeded" : "failed");
error:
disable_line_noise();
async_runner_stop(cp_runner);
async_runner_stop(pd_runner);

Expand Down
45 changes: 44 additions & 1 deletion tests/unit-tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,54 @@ int async_runner_stop(int work_id)
return 0;
}

volatile bool g_introduce_line_noise;
unsigned long g_total_packets;
unsigned long g_corrupted_packets;

void enable_line_noise()
{
g_introduce_line_noise = true;
}

void disable_line_noise()
{
g_introduce_line_noise = false;
}

void print_line_noise_stats()
{
printf(SUB_1 "LN-Stats: Total:%lu Corrupted:%lu",
g_total_packets, g_corrupted_packets);
}

void corrupt_buffer(uint8_t *buf, int len)
{
int p, n = 3;

while (n--) {
p = randint(len);
buf[p] = randint(255);
}
}

void maybe_corrupt_buffer(uint8_t *buf, int len)
{
if (!g_introduce_line_noise)
return;
g_total_packets++;
if (randint(10*1000) < (5*1000))
return;
corrupt_buffer(buf, len);
g_corrupted_packets++;
}

int test_mock_cp_send(void *data, uint8_t *buf, int len)
{
int i;
ARG_UNUSED(data);
assert(len < MOCK_BUF_LEN);

maybe_corrupt_buffer(buf, len);
for (i = 0; i < len; i++) {
if (CIRCBUF_PUSH(cp_to_pd_buf, buf + i))
break;
Expand All @@ -130,6 +172,7 @@ int test_mock_pd_send(void *data, uint8_t *buf, int len)
int i;
ARG_UNUSED(data);

maybe_corrupt_buffer(buf, len);
for (i = 0; i < len; i++) {
if (CIRCBUF_PUSH(pd_to_cp_buf, buf + i))
break;
Expand Down Expand Up @@ -251,7 +294,7 @@ int main(int argc, char *argv[])

run_cp_fsm_tests(&t);

run_file_tx_tests(&t);
run_file_tx_tests(&t, false);

rc = test_end(&t);

Expand Down
5 changes: 4 additions & 1 deletion tests/unit-tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ struct test {
int test_setup_devices(struct test *t, osdp_t **cp, osdp_t **pd);
int async_runner_start(osdp_t *ctx, void (*fn)(osdp_t *));
int async_runner_stop(int runner);
void enable_line_noise();
void disable_line_noise();
void print_line_noise_stats();

void run_cp_fsm_tests(struct test *t);
void run_cp_phy_fsm_tests(struct test *t);
void run_cp_phy_tests(struct test *t);
void run_file_tx_tests(struct test *t);
void run_file_tx_tests(struct test *t, bool line_noise);

#endif

0 comments on commit a3bf00d

Please sign in to comment.