Skip to content

Commit

Permalink
fix: encoding option made fragment test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Apr 3, 2024
1 parent fc49c87 commit 90082b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def check_output(tx_status, tx_output, rx_status, rx_output):
# Expected rx output & status
z_rx_expected_status = 0
z_rx_expected_output = (
"[rx]: Received packet on test/zenoh-pico-fragment, len: 10000, validity: 1, qos {priority: 4, cong_ctrl: 0}")
"[rx]: Received packet on test/zenoh-pico-fragment, len: 10000, validity: 1")

# Check the exit status of tx
if tx_status == z_tx_expected_status:
Expand Down
17 changes: 12 additions & 5 deletions tests/z_test_fragment_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,36 @@ void data_handler(const z_sample_t *sample, void *ctx) {
break;
}
}
printf("[rx]: Received packet on %s, len: %d, validity: %d, qos {priority: %d, cong_ctrl: %d}\n", z_loan(keystr),
(int)sample->payload.len, is_valid, z_qos_get_priority(sample->qos),
z_qos_get_congestion_control(sample->qos));
printf("[rx]: Received packet on %s, len: %d, validity: %d\n", z_loan(keystr), (int)sample->payload.len, is_valid);
z_drop(z_move(keystr));
}

int main(int argc, char **argv) {
const char *keyexpr = "test/zenoh-pico-fragment";
const char *mode = "client";
const char *mode = NULL;
char *llocator = NULL;
char *clocator = NULL;
(void)argv;

// Check if peer mode
if (argc > 1) {
mode = "peer";
llocator = "udp/224.0.0.224:7447#iface=lo";
} else {
mode = "client";
clocator = "tcp/127.0.0.1:7447";
}
// Set config
z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (mode != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
// Open session
z_owned_session_t s = z_open(z_move(config));
if (!z_check(s)) {
Expand Down
38 changes: 25 additions & 13 deletions tests/z_test_fragment_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <zenoh-pico.h>
#include <string.h>

#include "zenoh-pico.h"

#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "test/zenoh-pico-fragment";
const char *mode = "client";
const char *mode = NULL;
char *llocator = NULL;
char *clocator = NULL;
uint8_t *value = NULL;
size_t size = 10000;
(void)argv;

// Check if peer mode
if (argc > 1) {
mode = "peer";
llocator = "udp/224.0.0.224:7447#iface=lo";
}
// Init value
value = malloc(size);
if (value == NULL) {
Expand All @@ -39,12 +37,25 @@ int main(int argc, char **argv) {
for (size_t i = 0; i < size; i++) {
value[i] = (uint8_t)i;
}
// Check if peer or client mode
if (argc > 1) {
mode = "peer";
llocator = "udp/224.0.0.224:7447#iface=lo";
} else {
mode = "client";
clocator = "tcp/127.0.0.1:7447";
}
// Set config
z_owned_config_t config = z_config_default();
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
if (mode != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
}
if (llocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_LISTEN_KEY, z_string_make(llocator));
}
if (clocator != NULL) {
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(clocator));
}
// Open session
z_owned_session_t s = z_open(z_move(config));
if (!z_check(s)) {
Expand All @@ -57,16 +68,17 @@ int main(int argc, char **argv) {
z_close(z_session_move(&s));
return -1;
}
// Wait for joins
if (strcmp(mode, "peer") == 0) {
z_sleep_s(3);
}
// Put data
z_put_options_t options = z_put_options_default();
options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL);
options.priority = Z_PRIORITY_DATA_HIGH;
options.congestion_control = Z_CONGESTION_CONTROL_BLOCK;
for (int i = 0; i < 5; i++) {
printf("[tx]: Sending packet on %s, len: %d\n", keyexpr, (int)size);
if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, size, &options) < 0) {
if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, size, NULL) < 0) {
printf("Oh no! Put has failed...\n");
}
z_sleep_s(1);
}
// Clean up
zp_stop_read_task(z_loan(s));
Expand Down

0 comments on commit 90082b4

Please sign in to comment.