Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions tests/test_ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ struct test_ch_data {
pthread_barrier_t *barrier2;
};

char buffer[512];
char expected[512];
/* set by the log callback in the call-home client thread, polled by the test thread */
static ATOMIC_T expected_msg_received;
static ATOMIC_PTR_T expected;

int TEST_PORT = 10050, TEST_PORT_2 = 10051, TEST_PORT_3 = 10052, TEST_PORT_4 = 10053;
const char *TEST_PORT_STR = "10050", *TEST_PORT_2_STR = "10051", *TEST_PORT_3_STR = "10052", *TEST_PORT_4_STR = "10053";

static void
test_msg_callback(const struct nc_session *session, NC_VERB_LEVEL level, const char *msg)
{
const char *exp = ATOMIC_PTR_LOAD_RELAXED(expected);

(void) level;
(void) session;

if (strstr(msg, expected)) {
strncpy(buffer, msg, 511);
if (exp && strstr(msg, exp)) {
ATOMIC_STORE_RELAXED(expected_msg_received, 1);
}

printf("%s\n", msg);
Expand Down Expand Up @@ -97,8 +100,8 @@ server_thread_ssh(void *arg)

/* set print clb so we get access to messages */
nc_set_print_clb_session(test_msg_callback);
buffer[0] = '\0';
strcpy(expected, "reconnecting in");
ATOMIC_STORE_RELAXED(expected_msg_received, 0);
ATOMIC_PTR_STORE_RELAXED(expected, "reconnecting in");

/* prepare data for deleting the call-home client */
ret = nc_server_config_del_ch_client("ch_ssh", &test_data->tree);
Expand All @@ -123,7 +126,7 @@ server_thread_ssh(void *arg)
} else if (ret & (NC_PSPOLL_TIMEOUT | NC_PSPOLL_NOSESSIONS)) {
usleep(500);
}
} while (!strlen(buffer));
} while (!ATOMIC_LOAD_RELAXED(expected_msg_received));

/* delete the call-home client, the thread should end */
ret = nc_server_config_setup_data(test_data->tree);
Expand Down Expand Up @@ -433,8 +436,8 @@ server_thread_delete_while_session(void *arg)
struct test_ch_data *test_data = test_ctx->test_data;

nc_set_print_clb_session(test_msg_callback);
buffer[0] = '\0';
strcpy(expected, "thread exit");
ATOMIC_STORE_RELAXED(expected_msg_received, 0);
ATOMIC_PTR_STORE_RELAXED(expected, "thread exit");

ps = nc_ps_new();
assert_non_null(ps);
Expand Down Expand Up @@ -464,9 +467,9 @@ server_thread_delete_while_session(void *arg)

do {
usleep(5000);
} while (!strlen(buffer));
} while (!ATOMIC_LOAD_RELAXED(expected_msg_received));

assert_true(strlen(buffer) > 0);
assert_true(ATOMIC_LOAD_RELAXED(expected_msg_received));

pthread_barrier_wait(test_data->barrier2);

Expand Down
Loading