diff --git a/tests/net/trickle/Makefile b/tests/net/trickle/Makefile new file mode 100644 index 00000000000..b80ea39a8e5 --- /dev/null +++ b/tests/net/trickle/Makefile @@ -0,0 +1,6 @@ +BOARD ?= qemu_x86 +MDEF_FILE = prj.mdef +KERNEL_TYPE ?= nano +CONF_FILE = prj.conf + +include $(ZEPHYR_BASE)/Makefile.inc diff --git a/tests/net/trickle/prj.conf b/tests/net/trickle/prj.conf new file mode 100644 index 00000000000..a4b3484c650 --- /dev/null +++ b/tests/net/trickle/prj.conf @@ -0,0 +1,18 @@ +CONFIG_NETWORKING=y +CONFIG_NET_YAIP=y +CONFIG_NET_IPV6=y +CONFIG_NET_UDP=y +CONFIG_NET_TCP=n +CONFIG_NET_IPV4=y +CONFIG_NET_MAX_CONTEXTS=1 +CONFIG_NET_L2_DUMMY=y +CONFIG_NET_LOG=y +CONFIG_SYS_LOG_SHOW_COLOR=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_NET_IPV6_ND=n +CONFIG_NET_IPV6_DAD=n +CONFIG_NET_NBUF_TX_COUNT=1 +CONFIG_NET_NBUF_RX_COUNT=1 +CONFIG_NET_NBUF_DATA_COUNT=2 +CONFIG_NET_TRICKLE=y +#CONFIG_NETWORK_IP_STACK_DEBUG_TRICKLE=y diff --git a/tests/net/trickle/prj.mdef b/tests/net/trickle/prj.mdef new file mode 100644 index 00000000000..791a012181e --- /dev/null +++ b/tests/net/trickle/prj.mdef @@ -0,0 +1,5 @@ +% Application : Unit test + +% TASK NAME PRIO ENTRY STACK GROUPS +% =================================================== + TASK MAIN 7 main 2048 [EXE] diff --git a/tests/net/trickle/src/Makefile b/tests/net/trickle/src/Makefile new file mode 100644 index 00000000000..f284a4d5ca3 --- /dev/null +++ b/tests/net/trickle/src/Makefile @@ -0,0 +1,3 @@ +obj-y = main.o +ccflags-y += -I${ZEPHYR_BASE}/tests/include +ccflags-y += -I${ZEPHYR_BASE}/net/yaip diff --git a/tests/net/trickle/src/main.c b/tests/net/trickle/src/main.c new file mode 100644 index 00000000000..1d34761a223 --- /dev/null +++ b/tests/net/trickle/src/main.c @@ -0,0 +1,306 @@ +/* main.c - Application main entry point */ + +/* + * Copyright (c) 2015 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include "net_private.h" + +#if defined(CONFIG_NETWORK_IP_STACK_DEBUG_CONTEXT) +#define DBG(fmt, ...) printk(fmt, ##__VA_ARGS__) +#else +#define DBG(fmt, ...) +#endif + +static int token1 = 1, token2 = 2; + +static struct nano_sem wait; +static bool cb_called; +static bool test_failed; + +#define WAIT_TIME (sys_clock_ticks_per_sec) + +/* Set CHECK_LONG_TIMEOUT to 1 if you want to check longer timeout. + * Do not do this for automated tests as those need to finish asap. + */ +#define CHECK_LONG_TIMEOUT 0 +#if CHECK_LONG_TIMEOUT > 0 +#define WAIT_TIME_LONG (sys_clock_ticks_per_sec * 10) +#endif + +#define T1_IMIN 3 +#define T1_IMAX 10 +#define T1_K 2 + +#define T2_IMIN 4 +#define T2_IMAX 11 +#define T2_K 2 + +static struct net_trickle t1; +static struct net_trickle t2; + +static void cb(struct net_trickle *trickle, bool do_suppress, void *user_data) +{ + TC_PRINT("Trickle %p callback called\n", trickle); + + nano_sem_give(&wait); + + cb_called = true; +} + +static bool test_trickle_create(void) +{ + int ret; + + ret = net_trickle_create(&t1, T1_IMIN, T1_IMAX, T1_K); + if (ret) { + TC_ERROR("Trickle 1 create failed\n"); + return false; + } + + ret = net_trickle_create(&t2, T2_IMIN, T2_IMAX, T2_K); + if (ret) { + TC_ERROR("Trickle 2 create failed\n"); + return false; + } + + return true; +} + +static bool test_trickle_start(void) +{ + int ret; + + ret = net_trickle_start(&t1, cb, &t1); + if (ret) { + TC_ERROR("Trickle 1 start failed\n"); + return false; + } + + ret = net_trickle_start(&t2, cb, &t2); + if (ret) { + TC_ERROR("Trickle 2 start failed\n"); + return false; + } + + return true; +} + +static bool test_trickle_stop(void) +{ + int ret; + + ret = net_trickle_stop(&t1); + if (ret) { + TC_ERROR("Trickle 1 stop failed\n"); + return false; + } + + ret = net_trickle_stop(&t2); + if (ret) { + TC_ERROR("Trickle 2 stop failed\n"); + return false; + } + + return true; +} + +static bool test_trickle_1_status(void) +{ + if (!net_trickle_is_running(&t1)) { + TC_ERROR("Trickle 1 not running\n"); + return false; + } + + if (token1 != token2) { + net_trickle_inconsistency(&t1); + } else { + net_trickle_consistency(&t1); + } + + return true; +} + +static bool test_trickle_2_status(void) +{ + if (!net_trickle_is_running(&t2)) { + TC_ERROR("Trickle 2 not running\n"); + return false; + } + + if (token1 == token2) { + net_trickle_consistency(&t2); + } else { + net_trickle_inconsistency(&t2); + } + + return true; +} + +static bool test_trickle_1_wait(void) +{ + cb_called = false; + nano_sem_take(&wait, WAIT_TIME); + + if (!cb_called) { + TC_ERROR("Trickle 1 no timeout\n"); + return false; + } + + if (!net_trickle_is_running(&t1)) { + TC_ERROR("Trickle 1 not running\n"); + return false; + } + + return true; +} + +#if CHECK_LONG_TIMEOUT > 0 +static bool test_trickle_1_wait_long(void) +{ + cb_called = false; + nano_sem_take(&wait, WAIT_TIME_LONG); + + if (!cb_called) { + TC_ERROR("Trickle 1 no timeout\n"); + return false; + } + + if (!net_trickle_is_running(&t1)) { + TC_ERROR("Trickle 1 not running\n"); + return false; + } + + return true; +} +#endif + +static bool test_trickle_2_wait(void) +{ + cb_called = false; + nano_sem_take(&wait, WAIT_TIME); + + if (!cb_called) { + TC_ERROR("Trickle 2 no timeout\n"); + return false; + } + + if (!net_trickle_is_running(&t2)) { + TC_ERROR("Trickle 2 not running\n"); + return false; + } + + return true; +} + +static bool test_trickle_1_stopped(void) +{ + if (net_trickle_is_running(&t1)) { + TC_ERROR("Trickle 1 running\n"); + return false; + } + + return true; +} + +static bool test_trickle_2_inc(void) +{ + if (!net_trickle_is_running(&t2)) { + TC_ERROR("Trickle 2 is not running\n"); + return false; + } + + token2++; + + return true; +} + +static bool test_trickle_1_update(void) +{ + if (!net_trickle_is_running(&t1)) { + TC_ERROR("Trickle 1 is not running\n"); + return false; + } + + token1 = token2; + + return true; +} + +static bool test_init(void) +{ + nano_sem_init(&wait); + + return true; +} + +static const struct { + const char *name; + bool (*func)(void); +} tests[] = { + { "trickle test init", test_init }, + { "trickle create", test_trickle_create }, + { "trickle start", test_trickle_start }, + { "trickle 1 check status", test_trickle_1_status }, + { "trickle 2 check status", test_trickle_2_status }, + { "trickle 1 wait timeout", test_trickle_1_wait }, + { "trickle 2 wait timeout", test_trickle_2_wait }, + { "trickle 1 update", test_trickle_1_update }, + { "trickle 1 check status", test_trickle_1_status }, + { "trickle 2 update", test_trickle_2_inc }, + { "trickle 2 check status", test_trickle_2_status }, + { "trickle 1 check status", test_trickle_1_status }, + +#if CHECK_LONG_TIMEOUT > 0 + { "trickle 1 wait long timeout", test_trickle_1_wait_long }, +#endif + { "trickle stop", test_trickle_stop }, + { "trickle 1 check stopped", test_trickle_1_stopped }, +}; + +void main(void) +{ + int count, pass; + + for (count = 0, pass = 0; count < ARRAY_SIZE(tests); count++) { + TC_START(tests[count].name); + test_failed = false; + if (!tests[count].func() || test_failed) { + TC_END(FAIL, "failed\n"); + } else { + TC_END(PASS, "passed\n"); + pass++; + } + } + + TC_END_REPORT(((pass != ARRAY_SIZE(tests)) ? TC_FAIL : TC_PASS)); +} diff --git a/tests/net/trickle/testcase.ini b/tests/net/trickle/testcase.ini new file mode 100644 index 00000000000..01bcacaa493 --- /dev/null +++ b/tests/net/trickle/testcase.ini @@ -0,0 +1,6 @@ +[test] +tags = net-trickle +build_only = true +arch_whitelist = x86 +# Doesn't work for ia32_pci +filter = CONFIG_SOC : "ia32"