Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/netgraph/basic.c
/* | /*- | ||||
* SPDX-License-Identifier: BSD-3-Clause | * SPDX-License-Identifier: BSD-3-Clause | ||||
* | * | ||||
* Copyright 2021 Lutz Donnerhacke | * Copyright 2021 Lutz Donnerhacke | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* | * | ||||
Show All 22 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <atf-c.h> | #include <atf-c.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include "util.h" | #include "util.h" | ||||
static void get_data(void *data, size_t len, void *ctx); | static void get_data(void *data, size_t len, void *ctx); | ||||
ATF_TC(send_recv); | ATF_TC(send_recv); | ||||
ATF_TC_HEAD(send_recv, conf) | ATF_TC_HEAD(send_recv, conf) | ||||
{ | { | ||||
atf_tc_set_md_var(conf, "require.user", "root"); | atf_tc_set_md_var(conf, "require.user", "root"); | ||||
} | } | ||||
ATF_TC_BODY(send_recv, dummy) | ATF_TC_BODY(send_recv, dummy) | ||||
{ | { | ||||
char msg[] = "test"; | char msg[] = "test"; | ||||
int received; | int received; | ||||
ng_init(); | ng_init(); | ||||
ng_connect(".", "a", ".", "b"); | ng_connect(".", "a", ".", "b"); | ||||
ng_register_data("b", get_data); | ng_register_data("b", get_data); | ||||
ng_send_data("a", msg, sizeof(msg)); | ng_send_data("a", msg, sizeof(msg)); | ||||
received = 0; | received = 0; | ||||
ng_handle_events(50, &received); | ng_handle_events(50, &received); | ||||
ATF_CHECK(received == 1); | ATF_CHECK(received == 1); | ||||
} | } | ||||
ATF_TC(node); | ATF_TC(node); | ||||
ATF_TC_HEAD(node, conf) | ATF_TC_HEAD(node, conf) | ||||
{ | { | ||||
atf_tc_set_md_var(conf, "require.user", "root"); | atf_tc_set_md_var(conf, "require.user", "root"); | ||||
} | } | ||||
ATF_TC_BODY(node, dummy) | ATF_TC_BODY(node, dummy) | ||||
{ | { | ||||
char msg[] = "test"; | char msg[] = "test"; | ||||
int received; | int received; | ||||
ng_init(); | ng_init(); | ||||
ng_mkpeer(".", "a", "hub", "a"); | ng_mkpeer(".", "a", "hub", "a"); | ||||
ng_name("a", "test hub"); | ng_name("a", "test hub"); | ||||
ng_connect(".", "b", "test hub:", "b"); | ng_connect(".", "b", "test hub:", "b"); | ||||
ng_connect(".", "c", "test hub:", "c"); | ng_connect(".", "c", "test hub:", "c"); | ||||
Show All 15 Lines | ATF_TC_BODY(node, dummy) | ||||
ng_shutdown("test hub:"); | ng_shutdown("test hub:"); | ||||
} | } | ||||
ATF_TC(message); | ATF_TC(message); | ||||
ATF_TC_HEAD(message, conf) | ATF_TC_HEAD(message, conf) | ||||
{ | { | ||||
atf_tc_set_md_var(conf, "require.user", "root"); | atf_tc_set_md_var(conf, "require.user", "root"); | ||||
} | } | ||||
ATF_TC_BODY(message, dummy) | ATF_TC_BODY(message, dummy) | ||||
{ | { | ||||
ng_init(); | ng_init(); | ||||
ng_mkpeer(".", "a", "hub", "a"); | ng_mkpeer(".", "a", "hub", "a"); | ||||
ng_name("a", "test hub"); | ng_name("a", "test hub"); | ||||
ng_send_msg("test hub:", "setpersistent"); | ng_send_msg("test hub:", "setpersistent"); | ||||
ng_rmhook(".", "a"); | ng_rmhook(".", "a"); | ||||
ng_shutdown("test hub:"); | ng_shutdown("test hub:"); | ||||
} | } | ||||
ATF_TC(same_name); | ATF_TC(same_name); | ||||
ATF_TC_HEAD(same_name, conf) | ATF_TC_HEAD(same_name, conf) | ||||
{ | { | ||||
atf_tc_set_md_var(conf, "require.user", "root"); | atf_tc_set_md_var(conf, "require.user", "root"); | ||||
} | } | ||||
ATF_TC_BODY(same_name, dummy) | ATF_TC_BODY(same_name, dummy) | ||||
{ | { | ||||
ng_init(); | ng_init(); | ||||
ng_mkpeer(".", "a", "hub", "a"); | ng_mkpeer(".", "a", "hub", "a"); | ||||
ng_name("a", "test"); | ng_name("a", "test"); | ||||
ng_errors(PASS); | ng_errors(PASS); | ||||
ng_connect(".", "a", ".", "b"); | ng_connect(".", "a", ".", "b"); | ||||
ATF_CHECK_ERRNO(EEXIST, 1); | ATF_CHECK_ERRNO(EEXIST, 1); | ||||
ng_connect(".", "b", ".", "b"); | ng_connect(".", "b", ".", "b"); | ||||
ATF_CHECK_ERRNO(EEXIST, 1); | ATF_CHECK_ERRNO(EEXIST, 1); | ||||
ng_name(".", "test"); | ng_name(".", "test"); | ||||
ATF_CHECK_ERRNO(EADDRINUSE, 1); | ATF_CHECK_ERRNO(EADDRINUSE, 1); | ||||
ng_errors(FAIL); | ng_errors(FAIL); | ||||
ng_shutdown("test:"); | ng_shutdown("test:"); | ||||
} | } | ||||
ATF_TC(queuelimit); | ATF_TC(queuelimit); | ||||
ATF_TC_HEAD(queuelimit, conf) | ATF_TC_HEAD(queuelimit, conf) | ||||
{ | { | ||||
atf_tc_set_md_var(conf, "require.user", "root"); | atf_tc_set_md_var(conf, "require.user", "root"); | ||||
} | } | ||||
ATF_TC_BODY(queuelimit, dummy) | ATF_TC_BODY(queuelimit, dummy) | ||||
{ | { | ||||
int received, i; | int received, i; | ||||
char msg[] = "test"; | char msg[] = "test"; | ||||
const int MAX = 1000; | const int MAX = 1000; | ||||
ng_init(); | ng_init(); | ||||
ng_connect(".", "a", ".", "b"); | ng_connect(".", "a", ".", "b"); | ||||
ng_register_data("b", get_data); | ng_register_data("b", get_data); | ||||
ng_errors(PASS); | ng_errors(PASS); | ||||
for (i = 0; i < MAX; i++) { | for (i = 0; i < MAX; i++) | ||||
{ | |||||
ng_send_data("a", msg, sizeof(msg)); | ng_send_data("a", msg, sizeof(msg)); | ||||
if (errno != 0) | if (errno != 0) | ||||
break; | break; | ||||
/* no ng_handle_events -> messages stall */ | /* no ng_handle_events -> messages stall */ | ||||
} | } | ||||
ng_errors(FAIL); | ng_errors(FAIL); | ||||
printf("queued %d\n", i); | printf("queued %d\n", i); | ||||
sleep(3); | sleep(3); | ||||
Show All 16 Lines | ATF_TP_ADD_TCS(basic) | ||||
ATF_TP_ADD_TC(basic, queuelimit); | ATF_TP_ADD_TC(basic, queuelimit); | ||||
return atf_no_error(); | return atf_no_error(); | ||||
} | } | ||||
static void | static void | ||||
get_data(void *data, size_t len, void *ctx) | get_data(void *data, size_t len, void *ctx) | ||||
{ | { | ||||
int *cnt = ctx; | int *cnt = ctx; | ||||
(void)data; | (void)data; | ||||
printf("Got %zu bytes of data.\n", len); | printf("Got %zu bytes of data.\n", len); | ||||
(*cnt)++; | (*cnt)++; | ||||
} | } |