You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/08/27 20:25:10 UTC
[GitHub] ccollins476ad closed pull request #1331: test/runtest: Move
testbench code into runtest
ccollins476ad closed pull request #1331: test/runtest: Move testbench code into runtest
URL: https://github.com/apache/mynewt-core/pull/1331
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/apps/testbench/src/tbb.c b/apps/testbench/src/tbb.c
index a0633aadef..eb1fc9af4a 100644
--- a/apps/testbench/src/tbb.c
+++ b/apps/testbench/src/tbb.c
@@ -184,10 +184,9 @@ tbb_gap_event(struct ble_gap_event *event, void *arg)
}
MODLOG_DFLT(INFO, "\n");
- if (event->connect.status != 0) {
- /* Connection failed; resume advertising. */
- tbb_advertise();
- }
+ /* Try to advertise again. */
+ tbb_advertise();
+
return 0;
case BLE_GAP_EVENT_DISCONNECT:
diff --git a/apps/testbench/src/testbench.c b/apps/testbench/src/testbench.c
index 895e61fa1a..452bd4e5a8 100644
--- a/apps/testbench/src/testbench.c
+++ b/apps/testbench/src/testbench.c
@@ -44,6 +44,8 @@
#include <id/id.h>
#include <oic/oc_api.h>
#include <oic/oc_gatt.h>
+#include "json_test/json_test.h"
+#include "os_test/os_test.h"
#include "testutil/testutil.h"
@@ -67,17 +69,11 @@
#if MYNEWT_VAL(RUNTEST_CLI)
#include "runtest/runtest.h"
#endif
-
-#include "testbench.h"
#include "tbb.h"
struct os_timeval tv;
struct os_timezone tz;
-/* Init all tasks */
-volatile int tasks_initialized;
-int init_tasks(void);
-
/* Test Task */
#define TESTTASK_PRIO (1)
#define TESTTASK_STACK_SIZE OS_STACK_ALIGN(256)
@@ -86,193 +82,19 @@ static struct os_task testtask;
/* For LED toggling */
int g_led_pin;
-os_stack_t *stack1;
-os_stack_t *stack2;
-os_stack_t *stack3;
-os_stack_t *stack4;
-
-/*
- * Test log cbmem buf
- */
-#define MAX_CBMEM_BUF 2048
-uint32_t *cbmem_buf;
-struct cbmem cbmem;
-
-struct log testlog;
-int total_tests;
-int total_fails;
int blinky_blink;
-int forcefail; /* to optionally force a fail on a tests */
-
#define BLINKY_DUTYCYCLE_SUCCESS 1
#define BLINKY_DUTYCYCLE_FAIL 16
-char buildID[TESTBENCH_BUILDID_SZ];
-
-struct runtest_evq_arg test_event_arg;
-char runtest_token[RUNTEST_REQ_SIZE];
-static int testbench_runtests(struct os_event *ev);
-static void testbench_test_complete(void);
-
-extern uint32_t stack1_size;
-extern uint32_t stack2_size;
-extern uint32_t stack3_size;
-extern uint32_t stack4_size;
-
-struct ts_suite *current_ts;
-
-void
-testbench_ts_result(char *msg, void *arg, bool passed)
-{
- /* Must log valid json with a strlen less than LOG_PRINTF_MAX_ENTRY_LEN */
- char buf[LOG_PRINTF_MAX_ENTRY_LEN];
- char *n;
- int n_len;
- char *s;
- int s_len;
- char *m;
- int m_len;
-
- int len = 35; /* str length of {"k":"","n":"","s":"","m":"","r":1} */
- len += strlen(runtest_token);
-
- /* How much of the test name can we log? */
- n_len = strlen(tu_case_name);
- if (len + n_len >= LOG_PRINTF_MAX_ENTRY_LEN) {
- n_len = LOG_PRINTF_MAX_ENTRY_LEN - len - 1;
- }
- len += n_len;
- n = buf;
- strncpy(n, tu_case_name, n_len + 1);
-
- /* How much of the suite name can we log? */
- s_len = strlen(current_ts->ts_name);
- if (len + s_len >= LOG_PRINTF_MAX_ENTRY_LEN) {
- s_len = LOG_PRINTF_MAX_ENTRY_LEN - len - 1;
- }
- len += s_len;
- s = n + n_len + 2;
- strncpy(s, current_ts->ts_name, s_len + 1);
-
- /* How much of the message can we log? */
- m_len = strlen(msg);
- if (len + m_len >= LOG_PRINTF_MAX_ENTRY_LEN) {
- m_len = LOG_PRINTF_MAX_ENTRY_LEN - len - 1;
- }
- m = s + s_len + 2;
- strncpy(m, msg, m_len + 1);
-
-
- TESTBENCH_UPDATE_TOD;
-
- total_tests++;
- if (!passed) {
- total_fails++;
- }
-
- MODLOG_INFO(
- LOG_MODULE_TEST,
- "{\"k\":\"%s\",\"n\":\"%s\",\"s\":\"%s\",\"m\":\"%s\",\"r\":%d}",
- runtest_token, n, s, m, passed);
-}
-
-void
-testbench_ts_pass(char *msg, void *arg)
-{
- testbench_ts_result(msg, arg, true);
-}
-
-void
-testbench_ts_fail(char *msg, void *arg)
-{
- testbench_ts_result(msg, arg, false);
-}
+OS_TASK_STACK_DEFINE(teststack, TESTTASK_STACK_SIZE);
void
testbench_test_init(void)
{
- total_tests = 0;
- total_fails = 0;
- forcefail = 0;
blinky_blink = BLINKY_DUTYCYCLE_SUCCESS;
}
-static int
-testbench_runtests(struct os_event *ev)
-{
- struct runtest_evq_arg *runtest_arg;
- int run_all = 0;
-
- /*
- * testbench_runtests is normally initiated from newtmanager using the cli
- */
- testbench_test_init();
- if (ev != NULL) {
- runtest_arg = ev->ev_arg;
-
- ts_config.ts_print_results = 0;
- ts_config.ts_system_assert = 0;
-
- /*
- * The specified "token" is appended to the end of every log message
- * that is level INFO and above (i.e. not log_debug log messages)
- */
- strcpy(runtest_token, runtest_arg->run_token);
-
- /*
- * In run_all set, each test suite is executed
- */
- run_all = (strcmp(runtest_arg->run_testname, "all") == 0);
-
- /*
- * If no testname was provided (e.g., in the case where mgmt protocol
- * did not use the newtmgr application), make the default to run all
- * the tests.
- */
- if (runtest_arg->run_testname[0] == '\0') {
- run_all = 1;
- }
-
- /*
- * go through entire list of registered test suites
- */
- SLIST_FOREACH(current_ts, &g_ts_suites, ts_next) {
- if (run_all || !strcmp(runtest_arg->run_testname, current_ts->ts_name)) {
- current_ts->ts_test();
- }
- }
- } else {
- /*
- * run all tests if NULL event is passed as an argument (untested)
- */
- SLIST_FOREACH(current_ts, &g_ts_suites, ts_next) {
- current_ts->ts_test();
- }
- }
- testbench_test_complete();
-
- return tu_any_failed;
-}
-
-/*
- * Print results - ci gateway is checking this message syntax to
- * determine success or failure
- */
-static void
-testbench_test_complete(void)
-{
- MODLOG_INFO(LOG_MODULE_TEST, "%s Done", runtest_token);
- MODLOG_INFO(LOG_MODULE_TEST,
- "%s TESTBENCH TEST %s - Tests run:%d pass:%d fail:%d %s",
- buildID,
- (total_fails ? "FAILED" : "PASSED"),
- total_tests,
- (total_tests-total_fails),
- total_fails,
- runtest_token);
-}
-
/*
* Run the tests
* If any tests fail, blink the LED BLINKY_DUTYCYCLE_FAIL (16) times a second
@@ -290,79 +112,18 @@ testtask_handler(void *arg)
* if any test fails, blinky the LED more rapidly to
* provide visual feedback from physical device.
*/
- if (total_fails) {
+ if (runtest_total_fails_get() > 0) {
blinky_blink = BLINKY_DUTYCYCLE_FAIL;
}
- while (1) {
- /* Wait one second */
- os_time_delay(OS_TICKS_PER_SEC / blinky_blink);
+ /* Wait one second */
+ os_time_delay(OS_TICKS_PER_SEC / blinky_blink);
- /* Toggle the LED */
- hal_gpio_toggle(g_led_pin);
- }
+ /* Toggle the LED */
+ hal_gpio_toggle(g_led_pin);
}
}
-/*
- * init_tasks include test workers
- */
-int
-init_tasks(void)
-{
- os_stack_t *teststack;
-
- /*
- * malloc the stacks for the testworker tasks
- */
- stack1 = malloc(sizeof(os_stack_t) * TASK1_STACK_SIZE);
- assert(stack1);
- stack1_size = TASK1_STACK_SIZE;
-
- stack2 = malloc(sizeof(os_stack_t) * TASK2_STACK_SIZE);
- assert(stack2);
- stack2_size = TASK2_STACK_SIZE;
-
- stack3 = malloc(sizeof(os_stack_t) * TASK3_STACK_SIZE);
- assert(stack3);
- stack3_size = TASK3_STACK_SIZE;
-
- stack4 = malloc(sizeof(os_stack_t) * TASK4_STACK_SIZE);
- assert(stack4);
- stack4_size = TASK4_STACK_SIZE;
-
- teststack = malloc(sizeof(os_stack_t) * TESTTASK_STACK_SIZE);
- assert(teststack);
- os_task_init(&testtask, "testtask", testtask_handler, NULL,
- TESTTASK_PRIO, OS_WAIT_FOREVER, teststack,
- TESTTASK_STACK_SIZE);
-
- tasks_initialized = 1;
- return 0;
-}
-
-/*
- * buildID string is prepended to each log message.
- * BUILD_TARGET and BUILD_ID are assume to be initialized by
- * build infrastructure. testbench.h sets default values if not.
- */
-void
-getBuildID(void)
-{
- sprintf(buildID, "%s Build %s:", BUILD_TARGET, BUILD_ID);
-}
-
-/*
- * Test suites must be declared before being referenced.
- * Note that we're not actually declaring the test suites themselves,
- * but rather their helper functions which initialize the appropriate
- * callbacks before executing on target HW.
- */
-TEST_SUITE_DECL(testbench_mempool);
-TEST_SUITE_DECL(testbench_mutex);
-TEST_SUITE_DECL(testbench_sem);
-TEST_SUITE_DECL(testbench_json);
-
static void
omgr_app_init(void)
{ }
@@ -383,15 +144,6 @@ main(int argc, char **argv)
sysinit();
- getBuildID();
-
- cbmem_buf = malloc(sizeof(uint32_t) * MAX_CBMEM_BUF);
- cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
- log_register("testlog", &testlog, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
-
- rc = modlog_register(LOG_MODULE_TEST, &testlog, LOG_LEVEL_DEBUG, NULL);
- assert(rc == 0);
-
/* Initialize the OIC */
oc_main_init((oc_handler_t *)&omgr_oc_handler);
@@ -406,20 +158,16 @@ main(int argc, char **argv)
* Register the tests that can be run by lookup
* - each test is added to the ts_suites slist
*/
- TEST_SUITE_REGISTER(testbench_mempool);
- TEST_SUITE_REGISTER(testbench_mutex);
- TEST_SUITE_REGISTER(testbench_sem);
- TEST_SUITE_REGISTER(testbench_json);
+ TEST_SUITE_REGISTER(os_mempool_test_suite);
+ TEST_SUITE_REGISTER(os_mutex_test_suite);
+ TEST_SUITE_REGISTER(os_sem_test_suite);
+ TEST_SUITE_REGISTER(test_json_suite);
testbench_test_init(); /* initialize globals include blink duty cycle */
- rc = init_tasks();
-
- /*
- * This sets the callback function for the events that are
- * generated from newtmanager.
- */
- run_evcb_set((os_event_fn*) testbench_runtests);
+ os_task_init(&testtask, "testtask", testtask_handler, NULL,
+ TESTTASK_PRIO, OS_WAIT_FOREVER, teststack,
+ TESTTASK_STACK_SIZE);
MODLOG_INFO(LOG_MODULE_TEST, "testbench app initialized");
diff --git a/apps/testbench/src/testbench.h b/apps/testbench/src/testbench.h
deleted file mode 100644
index 869725230a..0000000000
--- a/apps/testbench/src/testbench.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-#ifndef _H_TESTBENCH
-#define _H_TESTBENCH
-
-#include "os/mynewt.h"
-
-#include <bsp/bsp.h>
-#include <hal/hal_gpio.h>
-#include <hal/hal_flash.h>
-#include <console/console.h>
-#if MYNEWT_VAL(SHELL_TASK)
-#include <shell/shell.h>
-#endif
-#include <log/log.h>
-#include <stats/stats.h>
-#include <config/config.h>
-#include "flash_map/flash_map.h"
-#include <hal/hal_system.h>
-#if MYNEWT_VAL(SPLIT_LOADER)
-#include "split/split.h"
-#endif
-#include <bootutil/image.h>
-#include <bootutil/bootutil.h>
-#include <imgmgr/imgmgr.h>
-#include <assert.h>
-#include <string.h>
-#include <json/json.h>
-#include <reboot/log_reboot.h>
-#include <id/id.h>
-
-#include "testutil/testutil.h"
-
-#if MYNEWT_VAL(CONFIG_NFFS)
-#include <nffs/nffs.h>
-#include "nffs/nffs_test.h"
-#endif
-
-#if MYNEWT_VAL(CONFIG_FCB)
-#include <fcb/fcb.h>
-#endif
-
-#include "bootutil/bootutil_test.h"
-
-#include <stddef.h>
-#include <config/config_file.h>
-#include "mbedtls/mbedtls_test.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef IMGMGR_HASH_LEN
-#define IMGMGR_HASH_LEN 32
-#endif
-
-extern char image_id[IMGMGR_HASH_LEN * 2 + 1];
-
-/* For LED toggling */
-int g_led_pin;
-
-#if MYNEWT_VAL(CONFIG_NFFS)
-/*
- * NFFS
- */
-int testbench_nffs();
-extern struct nffs_area_desc *nffs_current_area_descs;
-#endif
-
-/*
- * Test log cbmem buf
- */
-extern uint32_t *cbmem_buf;
-extern struct cbmem cbmem;
-
-extern struct log testlog;
-
-#define TESTBENCH_BUILDID_SZ 64
-extern char buildID[TESTBENCH_BUILDID_SZ];
-
-/*
- * defaults if not specified
- */
-#ifndef BUILD_ID
-#define BUILD_ID "1.2.3.4"
-#endif
-
-#ifndef BUILD_TARGET
-#define BUILD_TARGET "ARDUINO_ZERO"
-#endif
-
-/*
- * Pool of test worker tasks and matching stacks
- */
-struct os_task task1;
-struct os_task task2;
-struct os_task task3;
-struct os_task task4;
-
-/*
- * stacks are re-used to minimize space on the target
- * Set the size to the biggest we'll need to run tests
- * We assume that no more than 4 test tasks are needed
- */
-#define TESTHANDLER_STACK_SIZE OS_STACK_ALIGN(256)
-
-extern os_stack_t *stack1;
-#define TASK1_STACK_SIZE TESTHANDLER_STACK_SIZE
-
-extern os_stack_t *stack2;
-#define TASK2_STACK_SIZE TESTHANDLER_STACK_SIZE
-
-extern os_stack_t *stack3;
-#define TASK3_STACK_SIZE TESTHANDLER_STACK_SIZE
-
-extern os_stack_t *stack4;
-#define TASK4_STACK_SIZE TESTHANDLER_STACK_SIZE
-
-/*
- * Generic routines for testsuite and testcase callbacks
- */
-void testbench_ts_init(void *arg);
-void testbench_ts_pretest(void* arg);
-void testbench_ts_posttest(void* arg);
-void testbench_ts_pass(char *msg, void *arg);
-void testbench_ts_fail(char *msg, void *arg);
-
-void testbench_tc_pretest(void* arg);
-void testbench_tc_postest(void* arg);
-
-#define TESTBENCH_TOD_DELAY 1
-
-/* XXX hack to allow the idle task to run and update the TOD */
-#define TESTBENCH_UPDATE_TOD os_time_delay(TESTBENCH_TOD_DELAY)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _H_TESTBENCH */
diff --git a/apps/testbench/src/testbench_json.c b/apps/testbench/src/testbench_json.c
deleted file mode 100644
index 58fa7a5c91..0000000000
--- a/apps/testbench/src/testbench_json.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 <stdio.h>
-#include <string.h>
-#include "os/mynewt.h"
-#include "modlog/modlog.h"
-#include "testutil/testutil.h"
-#include "testbench.h"
-
-#ifndef JSON_BIGBUF_SIZE
-#define JSON_BIGBUF_SIZE 192
-#endif
-
-extern char *bigbuf;
-
-void
-testbench_json_init(void *arg)
-{
- MODLOG_DFLT(DEBUG, "%s testbench json_init", buildID);
-
- bigbuf = os_malloc(JSON_BIGBUF_SIZE);
-
- tu_suite_set_pass_cb(testbench_ts_pass, NULL);
- tu_suite_set_fail_cb(testbench_ts_fail, NULL);
-}
-
-void
-testbench_json_complete(void *arg)
-{
- os_free((void*)bigbuf);
-}
-
-TEST_CASE_DECL(test_json_simple_encode);
-TEST_CASE_DECL(test_json_simple_decode);
-
-TEST_SUITE(testbench_json_suite)
-{
- MODLOG_DFLT(DEBUG, "%s testbench_json", buildID);
-
- tu_suite_set_init_cb(testbench_json_init, NULL);
- tu_suite_set_complete_cb(testbench_json_complete, NULL);
-
- test_json_simple_encode();
- test_json_simple_decode();
-}
-
-int
-testbench_json()
-{
- tu_suite_set_init_cb(testbench_json_init, NULL);
- tu_suite_set_complete_cb(testbench_json_complete, NULL);
- MODLOG_DFLT(DEBUG, "%s testbench_json", buildID);
- testbench_json_suite();
-
- return tu_any_failed;
-}
diff --git a/apps/testbench/src/testbench_mempool.c b/apps/testbench/src/testbench_mempool.c
deleted file mode 100644
index d44ecae250..0000000000
--- a/apps/testbench/src/testbench_mempool.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 <stdio.h>
-#include <string.h>
-#include "os/mynewt.h"
-#include "modlog/modlog.h"
-#include "testutil/testutil.h"
-#include "testbench.h"
-
-/* Limit max blocks for testing */
-#define MEMPOOL_TEST_MAX_BLOCKS (128)
-
-/* Create a memory pool for testing */
-#ifndef MEM_BLOCK_SIZE
-#define MEM_BLOCK_SIZE (80)
-#endif
-
-#ifndef MEM_MEM_BLOCKS
-#define NUM_MEM_BLOCKS (10)
-#endif
-
-/* Test memory pool structure */
-struct os_mempool g_TstMempool;
-
-/* Test memory pool buffer */
-os_membuf_t *TstMembuf;
-extern uint32_t TstMembufSz;
-
-/* Array of block pointers. */
-void *block_array[MEMPOOL_TEST_MAX_BLOCKS];
-
-void
-testbench_mempool_init(void *arg)
-{
- MODLOG_DFLT(DEBUG, "%s testbench mempool_init", buildID);
-
- TstMembufSz = (sizeof(os_membuf_t) *
- OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE));
- TstMembuf = os_malloc(TstMembufSz);
-
- tu_suite_set_pass_cb(testbench_ts_pass, NULL);
- tu_suite_set_fail_cb(testbench_ts_fail, NULL);
-}
-
-void
-testbench_mempool_complete(void *arg)
-{
- os_free((void*)TstMembuf);
-}
-
-TEST_CASE_DECL(os_mempool_test_case)
-
-TEST_SUITE(testbench_mempool_suite)
-{
- MODLOG_DFLT(DEBUG, "%s testbench_mempool", buildID);
-
- tu_suite_set_init_cb(testbench_mempool_init, NULL);
- tu_suite_set_complete_cb(testbench_mempool_complete, NULL);
-
- os_mempool_test_case();
-}
-
-int
-testbench_mempool()
-{
- tu_suite_set_init_cb(testbench_mempool_init, NULL);
- tu_suite_set_complete_cb(testbench_mempool_complete, NULL);
- MODLOG_DFLT(DEBUG, "%s testbench_mempool", buildID);
- testbench_mempool_suite();
-
- return tu_any_failed;
-}
diff --git a/apps/testbench/src/testbench_mutex.c b/apps/testbench/src/testbench_mutex.c
deleted file mode 100644
index bbff8e3526..0000000000
--- a/apps/testbench/src/testbench_mutex.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <sys/time.h>
-#include "os/mynewt.h"
-#include "modlog/modlog.h"
-#include "testutil/testutil.h"
-#include "testbench.h"
-
-#ifdef ARCH_sim
-#define MUTEX_TEST_STACK_SIZE 1024
-#else
-#define MUTEX_TEST_STACK_SIZE 256
-#endif
-
-struct os_mutex g_mutex1;
-struct os_mutex g_mutex2;
-
-volatile int g_mutex_test;
-
-void
-testbench_mutex_ts_init(void *arg)
-{
- MODLOG_DFLT(DEBUG, "%s starting %s", buildID, tu_case_name);
-}
-
-/*
- * "Suspend" the test worker tasks after each test completes.
- * These tasks can be re-used for other tests, the stack also can be re-used.
- */
-void
-testbench_mutex_tc_posttest(void* arg)
-{
- os_error_t err;
- int taskcount = (int) arg;
-
- if (taskcount >= 1) {
- err = os_task_remove(&task1);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 2) {
- err = os_task_remove(&task2);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 3) {
- err = os_task_remove(&task3);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 4) {
- err = os_task_remove(&task4);
- TEST_ASSERT(err == OS_OK);
- }
-
- return;
-}
-
-/*
- * "Suspend" the test worker tasks after each test completes.
- * These tasks can be re-used for other tests, the stack also can be re-used.
- */
-void
-testbench_mutex_posttest(void* arg)
-{
- os_error_t err;
- int taskcount = (int) arg;
-
- if (taskcount >= 1) {
- err = os_task_remove(&task1);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 2) {
- err = os_task_remove(&task2);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 3) {
- err = os_task_remove(&task3);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 4) {
- err = os_task_remove(&task4);
- TEST_ASSERT(err == OS_OK);
- }
-
- return;
-}
-
-/*
- * callback run before testbench_mutex_suite starts
- */
-void
-testbench_mutex_init(void *arg)
-{
- tu_case_idx = 0;
- tu_case_failed = 0;
-
- MODLOG_DFLT(DEBUG, "%s testbench test_init", buildID);
-
- tu_suite_set_pass_cb(testbench_ts_pass, NULL);
- tu_suite_set_fail_cb(testbench_ts_fail, NULL);
-}
-
-TEST_CASE_DECL(os_mutex_test_basic)
-TEST_CASE_DECL(os_mutex_test_case_1)
-TEST_CASE_DECL(os_mutex_test_case_2)
-
-TEST_SUITE(testbench_mutex_suite)
-{
- int taskcount;
-
- MODLOG_DFLT(DEBUG, "%s mutex_suite start", buildID);
-
- taskcount = 1;
- tu_case_set_post_cb(testbench_mutex_tc_posttest, (void*)taskcount);
- os_mutex_test_basic();
-
- taskcount = 3;
- tu_case_set_post_cb(testbench_mutex_tc_posttest, (void*)taskcount);
- os_mutex_test_case_1();
-
- taskcount = 4;
- tu_case_set_post_cb(testbench_mutex_tc_posttest, (void*)taskcount);
- os_mutex_test_case_2();
-}
-
-int
-testbench_mutex()
-{
- tu_suite_set_init_cb(testbench_mutex_init, NULL);
-
- testbench_mutex_suite();
-
- return tu_any_failed;
-}
diff --git a/apps/testbench/src/testbench_sem.c b/apps/testbench/src/testbench_sem.c
deleted file mode 100644
index 89b02ff8c6..0000000000
--- a/apps/testbench/src/testbench_sem.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 <stdio.h>
-#include <string.h>
-#include "os/mynewt.h"
-#include "modlog/modlog.h"
-#include "testutil/testutil.h"
-#include "testbench.h"
-
-#define SEM_TEST_STACK_SIZE 256
-
-struct os_sem g_sem1;
-
-void
-testbench_sem_ts_init(void *arg)
-{
- MODLOG_DFLT(DEBUG, "%s starting %s", buildID, tu_case_name);
-}
-
-void sem_test_basic_handler(void* arg);
-
-void
-testbench_sem_posttest(void* arg)
-{
- os_error_t err;
- int taskcount = (int) arg;
-
- if (taskcount >= 1) {
- err = os_task_remove(&task1);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 2) {
- err = os_task_remove(&task2);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 3) {
- err = os_task_remove(&task3);
- TEST_ASSERT(err == OS_OK);
- }
- if (taskcount >= 4) {
- err = os_task_remove(&task4);
- TEST_ASSERT(err == OS_OK);
- }
-
- return;
-}
-
-/*
- * run before testbench_sem starts executing
- */
-void
-testbench_sem_init(void *arg)
-{
- tu_case_idx = 0;
- tu_case_failed = 0;
-
- MODLOG_DFLT(DEBUG, "%s testbench_sem suite init",
- buildID);
-
- tu_suite_set_pass_cb(testbench_ts_pass, NULL);
- tu_suite_set_fail_cb(testbench_ts_fail, NULL);
-}
-
-TEST_CASE(os_sem_test_null)
-{
- return;
-}
-
-TEST_CASE(os_sem_test_fail)
-{
- extern int forcefail;
-
- if (forcefail) {
- TEST_ASSERT(0);
- }
- return;
-}
-
-TEST_CASE_DECL(os_sem_test_null)
-TEST_CASE_DECL(os_sem_test_fail)
-TEST_CASE_DECL(os_sem_test_basic)
-TEST_CASE_DECL(os_sem_test_case_1)
-TEST_CASE_DECL(os_sem_test_case_2)
-TEST_CASE_DECL(os_sem_test_case_3)
-TEST_CASE_DECL(os_sem_test_case_4)
-
-TEST_SUITE(testbench_sem_suite)
-{
- int taskcount;
-
- os_sem_test_null();
-
- taskcount = 1;
- tu_case_set_post_cb(testbench_sem_posttest, (void*)taskcount);
- os_sem_test_basic();
-
- taskcount = 3;
- tu_case_set_post_cb(testbench_sem_posttest, (void*)taskcount);
- os_sem_test_case_1();
-
- taskcount = 4;
- tu_case_set_post_cb(testbench_sem_posttest, (void*)taskcount);
- os_sem_test_case_2();
-
- tu_case_set_post_cb(testbench_sem_posttest, (void*)taskcount);
- os_sem_test_case_3();
-
- tu_case_set_post_cb(testbench_sem_posttest, (void*)taskcount);
- os_sem_test_case_4();
-}
-
-void
-testbench_sem()
-{
- tu_suite_set_init_cb(testbench_sem_init, NULL);
- testbench_sem_suite();
-
- MODLOG_DFLT(DEBUG, "%s testbench_sem suite complete", buildID);
-
- return;
-}
diff --git a/apps/testbench/syscfg.yml b/apps/testbench/syscfg.yml
index a606ac55ea..80e561624d 100644
--- a/apps/testbench/syscfg.yml
+++ b/apps/testbench/syscfg.yml
@@ -54,6 +54,7 @@ syscfg.vals:
LOG_NEWTMGR: 1
CONFIG_NEWTMGR: 1
+ RUNTEST_LOG: 1
RUNTEST_CLI: 1
RUNTEST_NEWTMGR: 1
diff --git a/encoding/json/test/include/json_test/json_test.h b/encoding/json/test/include/json_test/json_test.h
new file mode 100644
index 0000000000..66d8707100
--- /dev/null
+++ b/encoding/json/test/include/json_test/json_test.h
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+#ifndef H_JSON_TEST_
+#define H_JSON_TEST_
+
+#include "os/mynewt.h"
+#include "testutil/testutil.h"
+
+TEST_SUITE_DECL(test_json_suite);
+
+#endif
diff --git a/encoding/json/test/src/test_json.c b/encoding/json/test/src/test_json.c
index faf5fc5855..1057b856da 100644
--- a/encoding/json/test/src/test_json.c
+++ b/encoding/json/test/src/test_json.c
@@ -19,14 +19,20 @@
#include "os/mynewt.h"
#include "testutil/testutil.h"
-#include "test_json.h"
+#include "test_json_priv.h"
TEST_CASE_DECL(test_json_simple_encode);
TEST_CASE_DECL(test_json_simple_decode);
-TEST_SUITE(test_json_suite) {
+TEST_SUITE(test_json_suite)
+{
+ bigbuf = malloc(JSON_BIGBUF_SIZE);
+ TEST_ASSERT_FATAL(bigbuf != NULL);
+
test_json_simple_encode();
test_json_simple_decode();
+
+ free(bigbuf);
}
#if MYNEWT_VAL(SELFTEST)
diff --git a/encoding/json/test/src/test_json.h b/encoding/json/test/src/test_json_priv.h
similarity index 94%
rename from encoding/json/test/src/test_json.h
rename to encoding/json/test/src/test_json_priv.h
index aa1a4b3140..a32c4fbe2e 100644
--- a/encoding/json/test/src/test_json.h
+++ b/encoding/json/test/src/test_json_priv.h
@@ -22,7 +22,6 @@
#include <assert.h>
#include <string.h>
#include "testutil/testutil.h"
-#include "test_json.h"
#include "json/json.h"
#ifdef __cplusplus
@@ -34,12 +33,8 @@ char *output1;
char *outputboolspace;
char *outputboolempty;
-#if MYNEWT_VAL(SELFTEST)
#define JSON_BIGBUF_SIZE 192
-char bigbuf[JSON_BIGBUF_SIZE];
-#else
char *bigbuf;
-#endif
int buf_index;
/* a test structure to hold the json flat buffer and pass bytes
@@ -63,4 +58,3 @@ void test_buf_init(struct test_jbuf *ptjb, char *string);
#endif
#endif /* TEST_JSON_H */
-
diff --git a/encoding/json/test/src/test_json_utils.c b/encoding/json/test/src/test_json_utils.c
index f641afdefe..a8258e5158 100644
--- a/encoding/json/test/src/test_json_utils.c
+++ b/encoding/json/test/src/test_json_utils.c
@@ -19,7 +19,7 @@
#include <assert.h>
#include <string.h>
#include "testutil/testutil.h"
-#include "test_json.h"
+#include "test_json_priv.h"
#include "json/json.h"
char *output = "{\"KeyBool\": true,\"KeyInt\": -1234,\"KeyUint\": 1353214,\"KeyString\": \"foobar\",\"KeyStringN\": \"foobarlong\",\"KeyIntArr\": [153,2532,-322]}";
@@ -28,11 +28,7 @@ char *output1 ="{\"KeyBoolArr\": [true, false], \"KeyUintArr\": [0, 65535, 42949
char *outputboolspace = "{\"KeyBoolArr\": [ true , false,true ]}";
char *outputboolempty = "{\"KeyBoolArr\": , \"KeyBoolArr\": [ ]}";
-#if MYNEWT_VAL(SELFTEST)
-char bigbuf[JSON_BIGBUF_SIZE];
-#else
char *bigbuf;
-#endif
int buf_index;
int
diff --git a/encoding/json/test/src/testcases/json_simple_decode.c b/encoding/json/test/src/testcases/json_simple_decode.c
index cea42de324..27f1cde011 100644
--- a/encoding/json/test/src/testcases/json_simple_decode.c
+++ b/encoding/json/test/src/testcases/json_simple_decode.c
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include "test_json.h"
+#include "test_json_priv.h"
/* now test the decode on a string */
TEST_CASE(test_json_simple_decode)
diff --git a/encoding/json/test/src/testcases/json_simple_encode.c b/encoding/json/test/src/testcases/json_simple_encode.c
index 79a77b4a53..1de6eaeede 100644
--- a/encoding/json/test/src/testcases/json_simple_encode.c
+++ b/encoding/json/test/src/testcases/json_simple_encode.c
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include "test_json.h"
+#include "test_json_priv.h"
TEST_CASE(test_json_simple_encode)
{
diff --git a/kernel/os/include/os/os.h b/kernel/os/include/os/os.h
index 49d546dc8d..40cbf54df6 100644
--- a/kernel/os/include/os/os.h
+++ b/kernel/os/include/os/os.h
@@ -123,7 +123,6 @@ void os_start(void);
#include "os/os_sched.h"
#include "os/os_sem.h"
#include "os/os_task.h"
-#include "os/os_test.h"
#include "os/os_time.h"
#include "os/os_trace_api.h"
#include "os/queue.h"
diff --git a/kernel/os/include/os/os_mempool.h b/kernel/os/include/os/os_mempool.h
index a7fac1ddd5..6624915677 100644
--- a/kernel/os/include/os/os_mempool.h
+++ b/kernel/os/include/os/os_mempool.h
@@ -188,6 +188,17 @@ os_error_t os_mempool_init(struct os_mempool *mp, uint16_t blocks,
os_error_t os_mempool_ext_init(struct os_mempool_ext *mpe, uint16_t blocks,
uint32_t block_size, void *membuf, char *name);
+/**
+ * Removes the specified mempool from the list of initialized mempools.
+ *
+ * @param mp The mempool to unregister.
+ *
+ * @return 0 on success;
+ * OS_INVALID_PARM if the mempool is not
+ * registered.
+ */
+os_error_t os_mempool_unregister(struct os_mempool *mp);
+
/**
* Clears a memory pool.
*
diff --git a/kernel/os/include/os/os_task.h b/kernel/os/include/os/os_task.h
index ccb87d9dc8..503501b262 100644
--- a/kernel/os/include/os/os_task.h
+++ b/kernel/os/include/os/os_task.h
@@ -37,9 +37,12 @@
extern "C" {
#endif
+#define OS_TASK_STACK_DEFINE_NOSTATIC(__name, __size) \
+ os_stack_t __name [OS_STACK_ALIGN(__size)] \
+ __attribute__((aligned(OS_STACK_ALIGNMENT)))
+
#define OS_TASK_STACK_DEFINE(__name, __size) \
- static os_stack_t __name [OS_STACK_ALIGN(__size)] \
- __attribute__((aligned(OS_STACK_ALIGNMENT)));
+ static OS_TASK_STACK_DEFINE_NOSTATIC(__name, __size);
/** Highest priority task */
#define OS_TASK_PRI_HIGHEST (0)
diff --git a/kernel/os/src/os_mempool.c b/kernel/os/src/os_mempool.c
index 5df846dfd3..10a5aa391f 100644
--- a/kernel/os/src/os_mempool.c
+++ b/kernel/os/src/os_mempool.c
@@ -155,6 +155,44 @@ os_mempool_ext_init(struct os_mempool_ext *mpe, uint16_t blocks,
return 0;
}
+os_error_t
+os_mempool_unregister(struct os_mempool *mp)
+{
+ struct os_mempool *prev;
+ struct os_mempool *next;
+ struct os_mempool *cur;
+
+ /* Remove the mempool from the global stailq. This is done manually rather
+ * than with `STAILQ_REMOVE` to allow for a graceful failure if the mempool
+ * isn't found.
+ */
+
+ prev = NULL;
+ STAILQ_FOREACH(cur, &g_os_mempool_list, mp_list) {
+ if (cur == mp) {
+ break;
+ }
+ prev = cur;
+ }
+
+ if (cur == NULL) {
+ return OS_INVALID_PARM;
+ }
+
+ if (prev == NULL) {
+ STAILQ_REMOVE_HEAD(&g_os_mempool_list, mp_list);
+ } else {
+ next = STAILQ_NEXT(cur, mp_list);
+ if (next == NULL) {
+ *g_os_mempool_list.stqh_last = next;
+ }
+
+ STAILQ_NEXT(prev, mp_list) = next;
+ }
+
+ return 0;
+}
+
os_error_t
os_mempool_clear(struct os_mempool *mp)
{
diff --git a/kernel/os/include/os/os_test.h b/kernel/os/test/include/os_test/os_test.h
similarity index 86%
rename from kernel/os/include/os/os_test.h
rename to kernel/os/test/include/os_test/os_test.h
index b71d608897..87fd57d1e0 100644
--- a/kernel/os/include/os/os_test.h
+++ b/kernel/os/test/include/os_test/os_test.h
@@ -20,10 +20,15 @@
#ifndef H_OS_TEST_
#define H_OS_TEST_
+#include "testutil/testutil.h"
+
#ifdef __cplusplus
extern "C" {
#endif
+TEST_SUITE_DECL(os_mutex_test_suite);
+TEST_SUITE_DECL(os_sem_test_suite);
+TEST_SUITE_DECL(os_mempool_test_suite);
int os_test_all(void);
#ifdef __cplusplus
diff --git a/kernel/os/test/pkg.yml b/kernel/os/test/pkg.yml
index 894d88134f..211a2920d5 100644
--- a/kernel/os/test/pkg.yml
+++ b/kernel/os/test/pkg.yml
@@ -24,7 +24,9 @@ pkg.keywords:
pkg.deps:
- "@apache-mynewt-core/kernel/os"
+ - "@apache-mynewt-core/test/runtest"
- "@apache-mynewt-core/test/testutil"
pkg.deps.SELFTEST:
- "@apache-mynewt-core/sys/console/stub"
+ - "@apache-mynewt-core/sys/log/stub"
diff --git a/kernel/os/test/src/mempool_test.c b/kernel/os/test/src/mempool_test.c
index 23be30655e..640ae81ffb 100644
--- a/kernel/os/test/src/mempool_test.c
+++ b/kernel/os/test/src/mempool_test.c
@@ -28,7 +28,6 @@ int alignment = 4;
int alignment = 8;
#endif
-#if MYNEWT_VAL(SELFTEST)
/* Test memory pool structure */
struct os_mempool g_TstMempool;
@@ -37,7 +36,6 @@ void *block_array[MEMPOOL_TEST_MAX_BLOCKS];
/* Test memory pool buffer */
os_membuf_t *TstMembuf;
-#endif
uint32_t TstMembufSz;
@@ -57,37 +55,22 @@ mempool_test_get_pool_size(int num_blocks, int block_size)
return mem_pool_size;
}
-void
-os_mempool_ts_pretest(void* arg)
-{
- os_init(NULL);
- sysinit();
-}
-
-void
-os_mempool_ts_posttest(void* arg)
-{
- return;
-}
-
-void
-os_mempool_test_init(void *arg)
-{
- TstMembufSz = (sizeof(os_membuf_t) *
- OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE));
- TstMembuf = malloc(TstMembufSz);
-
- tu_suite_set_pre_test_cb(os_mempool_ts_pretest, NULL);
- tu_suite_set_post_test_cb(os_mempool_ts_posttest, NULL);
-}
-
TEST_CASE_DECL(os_mempool_test_case)
TEST_CASE_DECL(os_mempool_test_ext_basic)
TEST_CASE_DECL(os_mempool_test_ext_nested)
TEST_SUITE(os_mempool_test_suite)
{
+ TstMembufSz = (sizeof(os_membuf_t) *
+ OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE));
+ TstMembuf = malloc(TstMembufSz);
+ TEST_ASSERT_FATAL(TstMembuf != NULL);
+
os_mempool_test_case();
os_mempool_test_ext_basic();
os_mempool_test_ext_nested();
+
+ free(TstMembuf);
+ TstMembufSz = 0;
+ TstMembuf = NULL;
}
diff --git a/kernel/os/test/src/mutex_test.c b/kernel/os/test/src/mutex_test.c
index 2b75d1749d..5ad7479590 100644
--- a/kernel/os/test/src/mutex_test.c
+++ b/kernel/os/test/src/mutex_test.c
@@ -29,29 +29,22 @@
#ifdef ARCH_sim
#define MUTEX_TEST_STACK_SIZE OS_STACK_ALIGN(1024)
#endif
-
-struct os_task task1;
-os_stack_t *stack1;
-
-struct os_task task2;
-os_stack_t *stack2;
-
-struct os_task task3;
-os_stack_t *stack3;
-
-struct os_task task4;
-os_stack_t *stack4;
+#endif /* MYNEWT_VAL(SELFTEST) */
struct os_mutex g_mutex1;
struct os_mutex g_mutex2;
volatile int g_mutex_test;
-#endif /* MYNEWT_VAL(SELFTEST) */
volatile int g_task1_val;
volatile int g_task2_val;
volatile int g_task3_val;
volatile int g_task4_val;
+static struct os_task *os_test_task1;
+static struct os_task *os_test_task2;
+static struct os_task *os_test_task3;
+static struct os_task *os_test_task4;
+
/*
* Handlers for each of the test threads are implemented here as they
* are shared amongst multiple test cases.
@@ -139,11 +132,10 @@ void
mutex_test1_task1_handler(void *arg)
{
os_error_t err;
- struct os_task *t;
int iters;
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == mutex_test1_task1_handler);
+ os_test_task1 = os_sched_get_current_task();
+ TEST_ASSERT(os_test_task1->t_func == mutex_test1_task1_handler);
for (iters = 0; iters < 3; iters++) {
os_time_delay(OS_TICKS_PER_SEC / 10);
@@ -164,11 +156,10 @@ void
mutex_test2_task1_handler(void *arg)
{
os_error_t err;
- struct os_task *t;
int iters;
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == mutex_test2_task1_handler);
+ os_test_task1 = os_sched_get_current_task();
+ TEST_ASSERT(os_test_task1->t_func == mutex_test2_task1_handler);
for (iters = 0; iters < 3; iters++) {
err = os_mutex_pend(&g_mutex1, 0);
@@ -182,7 +173,7 @@ mutex_test2_task1_handler(void *arg)
* through!
*/
if (iters == 0) {
- TEST_ASSERT(task4.t_flags & OS_TASK_FLAG_MUTEX_WAIT);
+ TEST_ASSERT(os_test_task4->t_flags & OS_TASK_FLAG_MUTEX_WAIT);
}
if (g_mutex_test == 4) {
@@ -200,13 +191,12 @@ void
mutex_task2_handler(void *arg)
{
os_error_t err;
- struct os_task *t;
+
+ os_test_task2 = os_sched_get_current_task();
+ TEST_ASSERT(os_test_task2->t_func == mutex_task2_handler);
if (g_mutex_test == 1) {
while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == mutex_task2_handler);
-
os_time_delay(OS_TICKS_PER_SEC / 20);
while (1) {
/* Wait here forever */
@@ -222,9 +212,6 @@ mutex_task2_handler(void *arg)
}
while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == mutex_task2_handler);
-
err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
if (g_mutex_test == 4) {
TEST_ASSERT(err == OS_TIMEOUT);
@@ -241,13 +228,12 @@ void
mutex_task3_handler(void *arg)
{
os_error_t err;
- struct os_task *t;
+
+ os_test_task3 = os_sched_get_current_task();
+ TEST_ASSERT(os_test_task3->t_func == mutex_task3_handler);
if (g_mutex_test == 1) {
while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == mutex_task3_handler);
-
/* Get mutex 1 */
err = os_mutex_pend(&g_mutex1, OS_TIMEOUT_NEVER);
TEST_ASSERT(err == OS_OK);
@@ -264,18 +250,13 @@ mutex_task3_handler(void *arg)
} else {
if (g_mutex_test == 2) {
/* Sleep for 3 seconds */
- t = os_sched_get_current_task();
os_time_delay(OS_TICKS_PER_SEC / 33);
} else if (g_mutex_test == 3) {
/* Sleep for 3 seconds */
- t = os_sched_get_current_task();
os_time_delay(OS_TICKS_PER_SEC / 20);
}
while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == mutex_task3_handler);
-
err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
if (g_mutex_test == 4) {
TEST_ASSERT(err == OS_TIMEOUT);
@@ -297,17 +278,17 @@ void
mutex_task4_handler(void *arg)
{
os_error_t err;
- struct os_task *t;
- while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == mutex_task4_handler);
+ os_test_task4 = os_sched_get_current_task();
+ TEST_ASSERT(os_test_task4->t_func == mutex_task4_handler);
+ while (1) {
if (g_mutex_test == 5) {
err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC / 10);
} else {
err = os_mutex_pend(&g_mutex1, OS_TICKS_PER_SEC * 10);
- TEST_ASSERT((t->t_flags & OS_TASK_FLAG_MUTEX_WAIT) == 0);
+ TEST_ASSERT(
+ (os_test_task4->t_flags & OS_TASK_FLAG_MUTEX_WAIT) == 0);
}
if (g_mutex_test == 4 || g_mutex_test == 5) {
@@ -325,69 +306,13 @@ mutex_task4_handler(void *arg)
}
}
-void
-os_mutex_tc_pretest(void* arg)
-{
-#if MYNEWT_VAL(SELFTEST)
- /*
- * Only call if running in "native" simulated environment
- */
- os_init(NULL);
- sysinit();
-#endif
- return;
-}
-
-void
-os_mutex_tc_posttest(void* arg)
-{
-#if MYNEWT_VAL(SELFTEST)
- /*
- * Only call if running in "native" simulated environment
- */
- os_start();
-#endif
- return;
-}
-
-void
-os_mutex_test_init(void *arg)
-{
-
- /*
- * Stack should be allocated in target environemnt
- * so they are sized correctly.
- */
-#if MYNEWT_VAL(SELFTEST)
- stack1 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
- assert(stack1);
- stack1_size = MUTEX_TEST_STACK_SIZE;
- stack2 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
- assert(stack2);
- stack2_size = MUTEX_TEST_STACK_SIZE;
- stack3 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
- assert(stack3);
- stack3_size = MUTEX_TEST_STACK_SIZE;
- stack4 = malloc(sizeof(os_stack_t) * MUTEX_TEST_STACK_SIZE);
- assert(stack4);
- stack4_size = MUTEX_TEST_STACK_SIZE;
-#endif
-}
-
TEST_CASE_DECL(os_mutex_test_basic)
TEST_CASE_DECL(os_mutex_test_case_1)
TEST_CASE_DECL(os_mutex_test_case_2)
TEST_SUITE(os_mutex_test_suite)
{
- tu_case_set_post_cb(os_mutex_tc_posttest, NULL);
os_mutex_test_basic();
-
- tu_case_set_pre_cb(os_mutex_tc_pretest, NULL);
- tu_case_set_post_cb(os_mutex_tc_posttest, NULL);
os_mutex_test_case_1();
-
- tu_case_set_pre_cb(os_mutex_tc_pretest, NULL);
- tu_case_set_post_cb(os_mutex_tc_posttest, NULL);
os_mutex_test_case_2();
}
diff --git a/kernel/os/test/src/os_test.c b/kernel/os/test/src/os_test.c
index 3afcb49eaa..46bb288f01 100644
--- a/kernel/os/test/src/os_test.c
+++ b/kernel/os/test/src/os_test.c
@@ -26,14 +26,10 @@
#include <sys/time.h>
#include "os/mynewt.h"
+#include "os_test/os_test.h"
#include "testutil/testutil.h"
#include "os_test_priv.h"
-uint32_t stack1_size;
-uint32_t stack2_size;
-uint32_t stack3_size;
-uint32_t stack4_size;
-
/*
* Most of this file is the driver for the kernel selftest running in sim
* In the sim environment, we can initialize and restart mynewt at will
@@ -65,44 +61,14 @@ os_test_restart(void)
tu_restart();
}
-/*
- * sysinit and os_start are only called if running in a sim environment
- * (ie MYNEWT_VAL(SELFTEST) is set)
- */
-void
-os_selftest_pretest_cb(void* arg)
-{
- os_init(NULL);
- sysinit();
-}
-
-void
-os_selftest_posttest_cb(void *arg)
-{
- os_start();
-}
-
-extern void os_mempool_test_init(void *arg);
-extern void os_sem_test_init(void *arg);
-extern void os_mutex_test_init(void *arg);
-
int
os_test_all(void)
{
-
- tu_suite_set_init_cb(os_mempool_test_init, NULL);
os_mempool_test_suite();
-#if 1
- tu_suite_set_init_cb(os_mutex_test_init, NULL);
os_mutex_test_suite();
-#endif
- tu_suite_set_init_cb(os_sem_test_init, NULL);
os_sem_test_suite();
-
os_mbuf_test_suite();
-
os_eventq_test_suite();
-
os_callout_test_suite();
return tu_case_failed;
diff --git a/kernel/os/test/src/os_test_priv.h b/kernel/os/test/src/os_test_priv.h
index e8a701b8e8..99630af523 100644
--- a/kernel/os/test/src/os_test_priv.h
+++ b/kernel/os/test/src/os_test_priv.h
@@ -47,27 +47,9 @@ extern "C" {
#define TASK3_PRIO (TASK2_PRIO + 1)
#define TASK4_PRIO (TASK3_PRIO + 1)
-extern struct os_task task1;
-extern os_stack_t *stack1;
-extern uint32_t stack1_size;
-
-extern struct os_task task2;
-extern os_stack_t *stack2;
-extern uint32_t stack2_size;
-
-extern struct os_task task3;
-extern os_stack_t *stack3;
-extern uint32_t stack3_size;
-
-extern struct os_task task4;
-extern os_stack_t *stack4;
-extern uint32_t stack4_size;
-
void os_test_restart(void);
-int os_mempool_test_suite(void);
int os_mbuf_test_suite(void);
-int os_mutex_test_suite(void);
int os_sem_test_suite(void);
int os_eventq_test_suite(void);
int os_callout_test_suite(void);
diff --git a/kernel/os/test/src/sem_test.c b/kernel/os/test/src/sem_test.c
index 90cac09642..99cb272044 100644
--- a/kernel/os/test/src/sem_test.c
+++ b/kernel/os/test/src/sem_test.c
@@ -23,26 +23,7 @@
#include "testutil/testutil.h"
#include "os_test_priv.h"
-#if MYNEWT_VAL(SELFTEST)
-
-#ifdef ARCH_sim
-#define SEM_TEST_STACK_SIZE OS_STACK_ALIGN(1024)
-#endif
-
-struct os_task task1;
-os_stack_t *stack1;
-
-struct os_task task2;
-os_stack_t *stack2;
-
-struct os_task task3;
-os_stack_t *stack3;
-
-struct os_task task4;
-os_stack_t *stack4;
-
struct os_sem g_sem1;
-#endif /* MYNEWT_VAL(SELFTEST) */
/*
* TEST NUMBERS:
@@ -280,48 +261,6 @@ sem_test_4_task4_handler(void *arg)
sem_test_pend_release_loop(0, 2000, 2000);
}
-void
-os_sem_tc_pretest(void* arg)
-{
-#if MYNEWT_VAL(SELFTEST)
- os_init(NULL);
- sysinit();
-#endif
- return;
-}
-
-void
-os_sem_tc_posttest(void* arg)
-{
-#if MYNEWT_VAL(SELFTEST)
- os_start();
-#endif
- return;
-}
-
-void
-os_sem_test_init(void *arg)
-{
- /*
- * Only allocate stacks here for selftest running in sim environment.
- * Testing apps should allocate stacks for BSP environments
- */
-#if MYNEWT_VAL(SELFTEST)
- stack1 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
- assert(stack1);
- stack1_size = SEM_TEST_STACK_SIZE;
- stack2 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
- assert(stack2);
- stack2_size = SEM_TEST_STACK_SIZE;
- stack3 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
- assert(stack3);
- stack3_size = SEM_TEST_STACK_SIZE;
- stack4 = malloc(sizeof(os_stack_t) * SEM_TEST_STACK_SIZE);
- assert(stack4);
- stack4_size = SEM_TEST_STACK_SIZE;
-#endif
-}
-
TEST_CASE_DECL(os_sem_test_basic)
TEST_CASE_DECL(os_sem_test_case_1)
TEST_CASE_DECL(os_sem_test_case_2)
@@ -330,23 +269,9 @@ TEST_CASE_DECL(os_sem_test_case_4)
TEST_SUITE(os_sem_test_suite)
{
- tu_case_set_pre_cb(os_sem_tc_pretest, NULL);
- tu_case_set_post_cb(os_sem_tc_posttest, NULL);
os_sem_test_basic();
-
- tu_case_set_pre_cb(os_sem_tc_pretest, NULL);
- tu_case_set_post_cb(os_sem_tc_posttest, NULL);
os_sem_test_case_1();
-
- tu_case_set_pre_cb(os_sem_tc_pretest, NULL);
- tu_case_set_post_cb(os_sem_tc_posttest, NULL);
os_sem_test_case_2();
-
- tu_case_set_pre_cb(os_sem_tc_pretest, NULL);
- tu_case_set_post_cb(os_sem_tc_posttest, NULL);
os_sem_test_case_3();
-
- tu_case_set_pre_cb(os_sem_tc_pretest, NULL);
- tu_case_set_post_cb(os_sem_tc_posttest, NULL);
os_sem_test_case_4();
}
diff --git a/kernel/os/test/src/testcases/os_mempool_test_case.c b/kernel/os/test/src/testcases/os_mempool_test_case.c
index 9bd2f783f5..044c458c59 100644
--- a/kernel/os/test/src/testcases/os_mempool_test_case.c
+++ b/kernel/os/test/src/testcases/os_mempool_test_case.c
@@ -36,6 +36,8 @@ mempool_test(int num_blocks, int block_size, bool clear)
void *block;
os_error_t rc;
+ os_mempool_unregister(&g_TstMempool);
+
/* Check for too many blocks */
TEST_ASSERT(num_blocks <= MEMPOOL_TEST_MAX_BLOCKS);
diff --git a/kernel/os/test/src/testcases/os_mutex_test_basic.c b/kernel/os/test/src/testcases/os_mutex_test_basic.c
index a0c63e4a91..0c7e03ff9c 100644
--- a/kernel/os/test/src/testcases/os_mutex_test_basic.c
+++ b/kernel/os/test/src/testcases/os_mutex_test_basic.c
@@ -16,12 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "runtest/runtest.h"
#include "os_test_priv.h"
TEST_CASE(os_mutex_test_basic)
{
- os_mutex_init(&g_mutex1);
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
- os_task_init(&task1, "task1", mutex_test_basic_handler, NULL,
- TASK1_PRIO, OS_WAIT_FOREVER, stack1, stack1_size);
+ os_mutex_init(&g_mutex1);
+ runtest_init_task(mutex_test_basic_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
}
diff --git a/kernel/os/test/src/testcases/os_mutex_test_case_1.c b/kernel/os/test/src/testcases/os_mutex_test_case_1.c
index a84549dc61..f2fae74278 100644
--- a/kernel/os/test/src/testcases/os_mutex_test_case_1.c
+++ b/kernel/os/test/src/testcases/os_mutex_test_case_1.c
@@ -16,12 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "os/mynewt.h"
+#include "runtest/runtest.h"
#include "os_test_priv.h"
TEST_CASE(os_mutex_test_case_1)
{
int rc;
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
+
g_mutex_test = 1;
g_task1_val = 0;
g_task2_val = 0;
@@ -32,12 +39,10 @@ TEST_CASE(os_mutex_test_case_1)
rc = os_mutex_init(&g_mutex2);
TEST_ASSERT(rc == 0);
- os_task_init(&task1, "task1", mutex_test1_task1_handler, NULL,
- TASK1_PRIO, OS_WAIT_FOREVER, stack1, stack1_size);
-
- os_task_init(&task2, "task2", mutex_task2_handler, NULL,
- TASK2_PRIO, OS_WAIT_FOREVER, stack2, stack2_size);
-
- os_task_init(&task3, "task3", mutex_task3_handler, NULL,
- TASK3_PRIO, OS_WAIT_FOREVER, stack3, stack3_size);
+ runtest_init_task(mutex_test1_task1_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
+ runtest_init_task(mutex_task2_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 2);
+ runtest_init_task(mutex_task3_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 3);
}
diff --git a/kernel/os/test/src/testcases/os_mutex_test_case_2.c b/kernel/os/test/src/testcases/os_mutex_test_case_2.c
index eb806ddd6b..e7c8e3d131 100644
--- a/kernel/os/test/src/testcases/os_mutex_test_case_2.c
+++ b/kernel/os/test/src/testcases/os_mutex_test_case_2.c
@@ -16,10 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "os/mynewt.h"
+#include "runtest/runtest.h"
#include "os_test_priv.h"
TEST_CASE(os_mutex_test_case_2)
{
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
+
g_mutex_test = 2;
g_task1_val = 0;
g_task2_val = 0;
@@ -27,15 +34,12 @@ TEST_CASE(os_mutex_test_case_2)
os_mutex_init(&g_mutex1);
os_mutex_init(&g_mutex2);
- os_task_init(&task1, "task1", mutex_test2_task1_handler, NULL, TASK1_PRIO,
- OS_WAIT_FOREVER, stack1, stack1_size);
-
- os_task_init(&task2, "task2", mutex_task2_handler, NULL, TASK2_PRIO,
- OS_WAIT_FOREVER, stack2, stack2_size);
-
- os_task_init(&task3, "task3", mutex_task3_handler, NULL, TASK3_PRIO,
- OS_WAIT_FOREVER, stack3, stack3_size);
-
- os_task_init(&task4, "task4", mutex_task4_handler, NULL, TASK4_PRIO,
- OS_WAIT_FOREVER, stack4, stack4_size);
+ runtest_init_task(mutex_test2_task1_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
+ runtest_init_task(mutex_task2_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 2);
+ runtest_init_task(mutex_task3_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 3);
+ runtest_init_task(mutex_task4_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 4);
}
diff --git a/kernel/os/test/src/testcases/os_sem_test_basic.c b/kernel/os/test/src/testcases/os_sem_test_basic.c
index bee6675214..59f8027e50 100644
--- a/kernel/os/test/src/testcases/os_sem_test_basic.c
+++ b/kernel/os/test/src/testcases/os_sem_test_basic.c
@@ -16,15 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "os/mynewt.h"
+#include "runtest/runtest.h"
#include "os_test_priv.h"
+#include "sem_test.h"
TEST_CASE(os_sem_test_basic)
{
os_error_t err;
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
+
err = os_sem_init(&g_sem1, 1);
TEST_ASSERT(err == OS_OK);
- os_task_init(&task1, "task1", sem_test_basic_handler, NULL,
- TASK1_PRIO, OS_WAIT_FOREVER, stack1, stack1_size);
+ runtest_init_task(sem_test_basic_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
}
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_1.c b/kernel/os/test/src/testcases/os_sem_test_case_1.c
index 2417365f2a..f94d66a7a3 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_1.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_1.c
@@ -16,21 +16,26 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "os/mynewt.h"
+#include "runtest/runtest.h"
#include "os_test_priv.h"
TEST_CASE(os_sem_test_case_1)
{
os_error_t err;
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
+
err = os_sem_init(&g_sem1, 1);
TEST_ASSERT(err == OS_OK);
- os_task_init(&task1, "task1", sem_test_1_task1_handler, NULL,
- TASK1_PRIO, OS_WAIT_FOREVER, stack1, stack1_size);
-
- os_task_init(&task2, "task2", sem_test_1_task2_handler, NULL,
- TASK2_PRIO, OS_WAIT_FOREVER, stack2, stack2_size);
-
- os_task_init(&task3, "task3", sem_test_1_task3_handler, NULL,
- TASK3_PRIO, OS_WAIT_FOREVER, stack3, stack3_size);
+ runtest_init_task(sem_test_1_task1_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
+ runtest_init_task(sem_test_1_task2_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 2);
+ runtest_init_task(sem_test_1_task3_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 3);
}
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_2.c b/kernel/os/test/src/testcases/os_sem_test_case_2.c
index 47b838eea3..f4df1306f2 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_2.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_2.c
@@ -16,24 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "os/mynewt.h"
+#include "runtest/runtest.h"
#include "os_test_priv.h"
TEST_CASE(os_sem_test_case_2)
{
os_error_t err;
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
+
err = os_sem_init(&g_sem1, 1);
TEST_ASSERT(err == OS_OK);
- os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL,
- TASK1_PRIO, OS_WAIT_FOREVER, stack1, stack1_size);
-
- os_task_init(&task2, "task2", sem_test_2_task2_handler, NULL,
- TASK2_PRIO, OS_WAIT_FOREVER, stack2, stack2_size);
-
- os_task_init(&task3, "task3", sem_test_2_task3_handler, NULL,
- TASK3_PRIO, OS_WAIT_FOREVER, stack3, stack3_size);
-
- os_task_init(&task4, "task4", sem_test_2_task4_handler, NULL,
- TASK4_PRIO, OS_WAIT_FOREVER, stack4, stack4_size);
+ runtest_init_task(sem_test_sleep_task_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
+ runtest_init_task(sem_test_2_task2_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 2);
+ runtest_init_task(sem_test_2_task3_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 3);
+ runtest_init_task(sem_test_2_task4_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 4);
}
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_3.c b/kernel/os/test/src/testcases/os_sem_test_case_3.c
index 21084913ca..3e8c38baaf 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_3.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_3.c
@@ -16,24 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "os/mynewt.h"
+#include "runtest/runtest.h"
#include "os_test_priv.h"
TEST_CASE(os_sem_test_case_3)
{
os_error_t err;
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
+
err = os_sem_init(&g_sem1, 1);
TEST_ASSERT(err == OS_OK);
- os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL,
- TASK1_PRIO, OS_WAIT_FOREVER, stack1, stack1_size);
-
- os_task_init(&task2, "task2", sem_test_3_task2_handler, NULL,
- TASK2_PRIO, OS_WAIT_FOREVER, stack2, stack2_size);
-
- os_task_init(&task3, "task3", sem_test_3_task3_handler, NULL,
- TASK3_PRIO, OS_WAIT_FOREVER, stack3, stack3_size);
-
- os_task_init(&task4, "task4", sem_test_3_task4_handler, NULL,
- TASK4_PRIO, OS_WAIT_FOREVER, stack4, stack4_size);
+ runtest_init_task(sem_test_sleep_task_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
+ runtest_init_task(sem_test_3_task2_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 2);
+ runtest_init_task(sem_test_3_task3_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 3);
+ runtest_init_task(sem_test_3_task4_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 4);
}
diff --git a/kernel/os/test/src/testcases/os_sem_test_case_4.c b/kernel/os/test/src/testcases/os_sem_test_case_4.c
index 0ddd9b7ff6..65bf18518b 100644
--- a/kernel/os/test/src/testcases/os_sem_test_case_4.c
+++ b/kernel/os/test/src/testcases/os_sem_test_case_4.c
@@ -16,24 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+#include "os/mynewt.h"
+#include "runtest/runtest.h"
#include "os_test_priv.h"
TEST_CASE(os_sem_test_case_4)
{
os_error_t err;
+#if MYNEWT_VAL(SELFTEST)
+ sysinit();
+#endif
+
err = os_sem_init(&g_sem1, 1);
TEST_ASSERT(err == OS_OK);
- os_task_init(&task1, "task1", sem_test_sleep_task_handler, NULL,
- TASK1_PRIO, OS_WAIT_FOREVER, stack1, stack1_size);
-
- os_task_init(&task2, "task2", sem_test_4_task2_handler, NULL,
- TASK2_PRIO, OS_WAIT_FOREVER, stack2, stack2_size);
-
- os_task_init(&task3, "task3", sem_test_4_task3_handler, NULL,
- TASK3_PRIO, OS_WAIT_FOREVER, stack3, stack3_size);
-
- os_task_init(&task4, "task4", sem_test_4_task4_handler, NULL,
- TASK4_PRIO, OS_WAIT_FOREVER, stack4, stack4_size);
+ runtest_init_task(sem_test_sleep_task_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 1);
+ runtest_init_task(sem_test_4_task2_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 2);
+ runtest_init_task(sem_test_4_task4_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 3);
+ runtest_init_task(sem_test_4_task4_handler,
+ MYNEWT_VAL(OS_MAIN_TASK_PRIO) + 4);
}
diff --git a/test/runtest/include/runtest/runtest.h b/test/runtest/include/runtest/runtest.h
index 65688aef98..2240999545 100644
--- a/test/runtest/include/runtest/runtest.h
+++ b/test/runtest/include/runtest/runtest.h
@@ -19,39 +19,68 @@
#ifndef __RUNTEST_H__
#define __RUNTEST_H__
+#include "os/mynewt.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-/*
- * Adds the run test commands to your shell/newtmgr.
+#define RUNTEST_NMGR_OP_TEST 0
+#define RUNTEST_NMGR_OP_LIST 1
+
+/* Define the prefix to to add to all test log messages. If the user's syscfg
+ * specifies the `RUNTEST_PREFIX` setting, use that value. Otherwise, generate
+ * the prefix from some legacy cflags (`BUILD_TARGET` and `BUILD_ID`).
*/
-void runtest_init(void);
-/*
+#if MYNEWT_VAL(RUNTEST_PREFIX)
+
+#define RUNTEST_PREFIX MYNEWT_VAL(RUNTEST_PREFIX)
+
+#else
+
+#ifndef BUILD_ID
+#define BUILD_ID "UNKNOWN_ID"
+#endif
+
+#ifndef BUILD_TARGET
+#define BUILD_TARGET "UNKNOWN_TARGET"
+#endif
+
+#define RUNTEST_PREFIX BUILD_TARGET " Build " BUILD_ID
+
+#endif
+
+/**
* Retrieves the event queue used by the runtest package.
*/
-struct os_eventq *run_evq_get(void);
+struct os_eventq *runtest_evq_get(void);
-/*
- * Callback for runtest events - newtmgr uses this to add
- * run test requests to default queue for test application (e.g., mynewtsanity)
+/**
+ * Designates the event queue that runtest should use.
*/
-void run_evcb_set(os_event_fn *cb);
+void runtest_evq_set(struct os_eventq *evq);
-/*
- * Token is append to log messages - for use by ci gateway
+/**
+ * Initializes a new task from the runtest task pool.
*/
-#define RUNTEST_REQ_SIZE 32
-extern char runtest_test_token[RUNTEST_REQ_SIZE];
+struct os_task *runtest_init_task(os_task_func_t task_handler, uint8_t prio);
-/*
- * Argument struct passed in from "run" requests via newtmgr
+/**
+ * Enqueues a single test for immediate execution.
+ *
+ * @param test_name The name of the test to run.
+ * @param token Optional string to include in test results.
+ *
+ * @return 0 on success;
+ * SYS_EAGAIN if a test is already in progress.
+ */
+int runtest_run(const char *test_name, const char *token);
+
+/**
+ * Retrieves the total number of test failures.
*/
-struct runtest_evq_arg {
- char* run_testname;
- char* run_token;
-};
+int runtest_total_fails_get(void);
#ifdef __cplusplus
}
diff --git a/test/runtest/pkg.yml b/test/runtest/pkg.yml
index 49be8420d5..f51d3b32a3 100644
--- a/test/runtest/pkg.yml
+++ b/test/runtest/pkg.yml
@@ -22,14 +22,19 @@ pkg.description: Allow control over launching test suites
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
+pkg.deps:
+ - "@apache-mynewt-core/encoding/cborattr"
pkg.deps.RUNTEST_CLI:
- "@apache-mynewt-core/sys/shell"
-pkg.req_apis.RUNTEST_CLI:
- - console
pkg.deps.RUNTEST_NEWTMGR:
- "@apache-mynewt-core/mgmt/mgmt"
- "@apache-mynewt-core/encoding/json"
- "@apache-mynewt-core/test/testutil"
+pkg.deps.RUNTEST_LOG:
+ - "@apache-mynewt-core/sys/log/modlog"
+ - "@apache-mynewt-core/util/cbmem"
+pkg.req_apis.RUNTEST_CLI:
+ - console
pkg.init:
runtest_init: 500
diff --git a/test/runtest/src/runtest.c b/test/runtest/src/runtest.c
index 634b7f7aec..a5b57e8f4e 100644
--- a/test/runtest/src/runtest.c
+++ b/test/runtest/src/runtest.c
@@ -23,6 +23,7 @@
#include "os/mynewt.h"
#include "console/console.h"
+#include "testutil/testutil.h"
#include "runtest/runtest.h"
#include "runtest_priv.h"
@@ -32,28 +33,292 @@
struct shell_cmd runtest_cmd_struct;
#endif
-#if MYNEWT_VAL(RUNTEST_NEWTMGR)
-#include "mgmt/mgmt.h"
-struct mgmt_group runtest_nmgr_group;
+#if MYNEWT_VAL(RUNTEST_LOG)
+#include "cbmem/cbmem.h"
+#include "modlog/modlog.h"
+static uint8_t runtest_cbmem_buf[MYNEWT_VAL(RUNTEST_LOG_SIZE)];
+static struct cbmem runtest_cbmem;
+static struct log runtest_log;
#endif
-static struct os_eventq *run_evq;
+static void runtest_evt_fn(struct os_event *ev);
+
+static int runtest_total_tests;
+static int runtest_total_fails;
+static struct ts_suite *runtest_current_ts;
+static char runtest_token[MYNEWT_VAL(RUNTEST_MAX_TOKEN_LEN)];
+static char runtest_test_name[MYNEWT_VAL(RUNTEST_MAX_TEST_NAME_LEN)];
+static bool runtest_busy;
+
+static struct os_eventq *runtest_evq;
+static struct os_mutex runtest_mtx;
+static struct os_event run_test_event = {
+ .ev_cb = runtest_evt_fn,
+};
+
+struct runtest_task {
+ struct os_task task;
+ char name[sizeof "taskX"];
+ OS_TASK_STACK_DEFINE_NOSTATIC(stack, MYNEWT_VAL(RUNTEST_STACK_SIZE));
+};
+
+static struct runtest_task runtest_tasks[MYNEWT_VAL(RUNTEST_NUM_TASKS)];
+
+#define RUNTEST_BUILD_ID
-extern int run_nmgr_register_group();
+static int runtest_next_task_idx;
/**
* Retrieves the event queue used by the runtest package.
*/
struct os_eventq *
-run_evq_get(void)
+runtest_evq_get(void)
{
- return run_evq;
+ return runtest_evq;
}
void
-run_evq_set(struct os_eventq *evq)
+runtest_evq_set(struct os_eventq *evq)
+{
+ runtest_evq = evq;
+}
+
+static void
+runtest_lock(void)
+{
+ int rc;
+
+ rc = os_mutex_pend(&runtest_mtx, OS_TIMEOUT_NEVER);
+ assert(rc == 0);
+}
+
+static void
+runtest_unlock(void)
+{
+ int rc;
+
+ rc = os_mutex_release(&runtest_mtx);
+ assert(rc == 0);
+}
+
+int
+runtest_total_fails_get(void)
+{
+ return runtest_total_fails;
+}
+
+struct os_task *
+runtest_init_task(os_task_func_t task_handler, uint8_t prio)
+{
+ struct os_task *task;
+ os_stack_t *stack;
+ char *name;
+ int rc;
+
+ if (runtest_next_task_idx >= MYNEWT_VAL(RUNTEST_NUM_TASKS)) {
+ TEST_ASSERT_FATAL(0, "No more test tasks");
+ return NULL;
+ }
+
+ task = &runtest_tasks[runtest_next_task_idx].task;
+ stack = runtest_tasks[runtest_next_task_idx].stack;
+ name = runtest_tasks[runtest_next_task_idx].name;
+
+ strcpy(name, "task");
+ name[4] = '0' + runtest_next_task_idx;
+ name[5] = '\0';
+
+ rc = os_task_init(task, name, task_handler, NULL,
+ prio, OS_WAIT_FOREVER, stack,
+ MYNEWT_VAL(RUNTEST_STACK_SIZE));
+ TEST_ASSERT_FATAL(rc == 0);
+
+ runtest_next_task_idx++;
+
+ return task;
+}
+
+static void
+runtest_reset(void)
+{
+ int rc;
+
+ while (runtest_next_task_idx > 0) {
+ runtest_next_task_idx--;
+
+ rc = os_task_remove(&runtest_tasks[runtest_next_task_idx].task);
+ assert(rc == OS_OK);
+ }
+}
+
+static void
+runtest_log_result(const char *msg, bool passed)
+{
+#if MYNEWT_VAL(RUNTEST_LOG)
+ /* Must log valid json with a strlen less than LOG_PRINTF_MAX_ENTRY_LEN */
+ char buf[LOG_PRINTF_MAX_ENTRY_LEN];
+ char *n;
+ int n_len;
+ char *s;
+ int s_len;
+ char *m;
+ int m_len;
+ int len;
+
+ /* str length of {"k":"","n":"","s":"","m":"","r":1}<token> */
+ len = 35 + strlen(runtest_token);
+
+ /* How much of the test name can we log? */
+ n_len = strlen(tu_case_name);
+ if (len + n_len >= LOG_PRINTF_MAX_ENTRY_LEN) {
+ n_len = LOG_PRINTF_MAX_ENTRY_LEN - len - 1;
+ }
+ len += n_len;
+ n = buf;
+ strncpy(n, tu_case_name, n_len + 1);
+
+ /* How much of the suite name can we log? */
+ s_len = strlen(runtest_current_ts->ts_name);
+ if (len + s_len >= LOG_PRINTF_MAX_ENTRY_LEN) {
+ s_len = LOG_PRINTF_MAX_ENTRY_LEN - len - 1;
+ }
+ len += s_len;
+ s = n + n_len + 2;
+ strncpy(s, runtest_current_ts->ts_name, s_len + 1);
+
+ /* How much of the message can we log? */
+ m_len = strlen(msg);
+ if (len + m_len >= LOG_PRINTF_MAX_ENTRY_LEN) {
+ m_len = LOG_PRINTF_MAX_ENTRY_LEN - len - 1;
+ }
+ m = s + s_len + 2;
+ strncpy(m, msg, m_len + 1);
+
+ /* XXX Hack to allow the idle task to run and update the timestamp. */
+ os_time_delay(1);
+
+ runtest_total_tests++;
+ if (!passed) {
+ runtest_total_fails++;
+ }
+
+ MODLOG_INFO(
+ LOG_MODULE_TEST,
+ "{\"k\":\"%s\",\"n\":\"%s\",\"s\":\"%s\",\"m\":\"%s\",\"r\":%d}",
+ runtest_token, n, s, m, passed);
+#endif
+}
+
+static void
+runtest_pass(char *msg, void *arg)
+{
+ runtest_reset();
+ runtest_log_result(msg, true);
+}
+
+static void
+runtest_fail(char *msg, void *arg)
+{
+ runtest_reset();
+ runtest_log_result(msg, false);
+}
+
+static struct ts_suite *
+runtest_find_test(const char *suite_name)
+{
+ struct ts_suite *cur;
+
+ SLIST_FOREACH(cur, &g_ts_suites, ts_next) {
+ if (strcmp(cur->ts_name, suite_name) == 0) {
+ return cur;
+ }
+ }
+
+ return NULL;
+}
+
+static void
+runtest_test_complete(void)
+{
+#if MYNEWT_VAL(RUNTEST_LOG)
+ if (runtest_total_tests > 0) {
+ MODLOG_INFO(LOG_MODULE_TEST, "%s Done", runtest_token);
+ MODLOG_INFO(LOG_MODULE_TEST,
+ "%s TESTBENCH TEST %s - Tests run:%d pass:%d fail:%d %s",
+ RUNTEST_PREFIX,
+ runtest_total_fails ? "FAILED" : "PASSED",
+ runtest_total_tests,
+ runtest_total_tests - runtest_total_fails,
+ runtest_total_fails,
+ runtest_token);
+ }
+#endif
+ runtest_busy = false;
+}
+
+static void
+runtest_evt_fn(struct os_event *ev)
+{
+ int runtest_all;
+
+ runtest_total_tests = 0;
+ runtest_total_fails = 0;
+
+ tu_suite_set_pass_cb(runtest_pass, NULL);
+ tu_suite_set_fail_cb(runtest_fail, NULL);
+
+ if (ev != NULL) {
+ ts_config.ts_print_results = 0;
+ ts_config.ts_system_assert = 0;
+
+ /* The specified "token" is appended to the end of every log message
+ * that is level INFO and above (i.e. not log_debug log messages)
+ */
+ strcpy(runtest_token, runtest_token);
+
+ runtest_all = runtest_test_name[0] == '\0' ||
+ strcmp(runtest_test_name, "all") == 0;
+
+ if (runtest_all) {
+ SLIST_FOREACH(runtest_current_ts, &g_ts_suites, ts_next) {
+ runtest_current_ts->ts_test();
+ }
+ } else {
+ runtest_current_ts = runtest_find_test(runtest_test_name);
+ if (runtest_current_ts != NULL) {
+ runtest_current_ts->ts_test();
+ }
+ }
+ }
+ runtest_test_complete();
+}
+
+int
+runtest_run(const char *test_name, const char *token)
{
- run_evq = evq;
+ int rc;
+
+ /* Only allow one test at a time. */
+ runtest_lock();
+
+ if (runtest_busy) {
+ rc = SYS_EAGAIN;
+ } else if (test_name[0] != '\0' &&
+ strcmp(test_name, "all") != 0 &&
+ runtest_find_test(test_name) == NULL) {
+ rc = SYS_ENOENT;
+ } else {
+ strncpy(runtest_test_name, test_name, sizeof runtest_test_name);
+ strncpy(runtest_token, token, sizeof runtest_token);
+
+ runtest_busy = true;
+ os_eventq_put(runtest_evq_get(), &run_test_event);
+ rc = 0;
+ }
+
+ runtest_unlock();
+
+ return rc;
}
/*
@@ -67,14 +332,34 @@ runtest_init(void)
/* Ensure this function only gets called by sysinit. */
SYSINIT_ASSERT_ACTIVE();
+ runtest_next_task_idx = 0;
+
+#if MYNEWT_VAL(RUNTEST_LOG)
+ rc = cbmem_init(&runtest_cbmem, runtest_cbmem_buf,
+ MYNEWT_VAL(RUNTEST_LOG_SIZE));
+ SYSINIT_PANIC_ASSERT(rc == 0);
+
+ /* Create a cbmem log and map the "test" module to it. */
+ rc = log_register("testlog", &runtest_log, &log_cbmem_handler,
+ &runtest_cbmem, LOG_SYSLEVEL);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+
+ rc = modlog_register(LOG_MODULE_TEST, &runtest_log, LOG_LEVEL_DEBUG, NULL);
+ assert(rc == 0);
+#endif
+
#if MYNEWT_VAL(RUNTEST_CLI)
shell_cmd_register(&runtest_cmd_struct);
#endif
#if MYNEWT_VAL(RUNTEST_NEWTMGR)
- rc = run_nmgr_register_group();
+ rc = runtest_nmgr_register_group();
SYSINIT_PANIC_ASSERT(rc == 0);
#endif
- run_evq_set(os_eventq_dflt_get());
+ rc = os_mutex_init(&runtest_mtx);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+
+ /* Use the main event queue by default. */
+ runtest_evq_set(os_eventq_dflt_get());
}
diff --git a/test/runtest/src/runtest_nmgr.c b/test/runtest/src/runtest_nmgr.c
index 956c14f028..28801376c2 100644
--- a/test/runtest/src/runtest_nmgr.c
+++ b/test/runtest/src/runtest_nmgr.c
@@ -31,56 +31,40 @@
#include "runtest/runtest.h"
#include "runtest_priv.h"
-static int run_nmgr_test(struct mgmt_cbuf *);
-static int run_nmgr_list(struct mgmt_cbuf *);
+static int runtest_nmgr_test(struct mgmt_cbuf *);
+static int runtest_nmgr_list(struct mgmt_cbuf *);
-struct mgmt_group run_nmgr_group;
+static struct mgmt_group runtest_nmgr_group;
-#define RUN_NMGR_OP_TEST 0
-#define RUN_NMGR_OP_LIST 1
-
-const struct mgmt_handler run_nmgr_handlers[] = {
- [RUN_NMGR_OP_TEST] = {NULL, run_nmgr_test},
- [RUN_NMGR_OP_LIST] = {run_nmgr_list, NULL}
+static const struct mgmt_handler runtest_nmgr_handlers[] = {
+ [RUNTEST_NMGR_OP_TEST] = { NULL, runtest_nmgr_test },
+ [RUNTEST_NMGR_OP_LIST] = { runtest_nmgr_list, NULL }
};
-extern void sanity_start_test();
-struct os_event run_test_event;
-
-char run_testname[RUNTEST_REQ_SIZE];
-char run_token[RUNTEST_REQ_SIZE];
-
-struct runtest_evq_arg runtest_arg;
-os_event_fn *run_callback;
-
-void
-run_evcb_set(os_event_fn *cb)
-{
- run_callback = cb;
-}
-
/*
* package "run test" request from newtmgr and enqueue on default queue
* of the application which is actually running the tests (e.g., mynewtsanity).
* Application callback was initialized by call to run_evb_set() above.
*/
static int
-run_nmgr_test(struct mgmt_cbuf *cb)
+runtest_nmgr_test(struct mgmt_cbuf *cb)
{
+ char testname[MYNEWT_VAL(RUNTEST_MAX_TEST_NAME_LEN)] = "";
+ char token[MYNEWT_VAL(RUNTEST_MAX_TOKEN_LEN)];
int rc;
- const struct cbor_attr_t attr[3] = {
+ const struct cbor_attr_t attr[] = {
[0] = {
.attribute = "testname",
.type = CborAttrTextStringType,
- .addr.string = run_testname,
- .len = sizeof(run_testname)
+ .addr.string = testname,
+ .len = sizeof(testname)
},
[1] = {
.attribute = "token",
.type = CborAttrTextStringType,
- .addr.string = run_token,
- .len = sizeof(run_token)
+ .addr.string = token,
+ .len = sizeof(token)
},
[2] = {
.attribute = NULL
@@ -88,30 +72,39 @@ run_nmgr_test(struct mgmt_cbuf *cb)
};
rc = cbor_read_object(&cb->it, attr);
- if (rc) {
- return rc;
+ if (rc != 0) {
+ return MGMT_ERR_EINVAL;
}
/*
- * testname is either a specific test or newtmgr passed "all".
- * token is appened to log messages.
+ * testname is one of:
+ * a) a specific test suite name
+ * b) "all".
+ * c) "" (empty string); equivalent to "all".
+ *
+ * token is appended to log messages.
*/
- runtest_arg.run_testname = run_testname;
- runtest_arg.run_token = run_token;
+ rc = runtest_run(testname, token);
+ switch (rc) {
+ case 0:
+ return 0;
+
+ case SYS_EAGAIN:
+ return MGMT_ERR_EBADSTATE;
- run_test_event.ev_arg = &runtest_arg;
- run_test_event.ev_cb = run_callback;
+ case SYS_ENOENT:
+ return MGMT_ERR_ENOENT;
- os_eventq_put(run_evq_get(), &run_test_event);
-
- return 0;
+ default:
+ return MGMT_ERR_EUNKNOWN;
+ }
}
/*
* List all register tests
*/
static int
-run_nmgr_list(struct mgmt_cbuf *cb)
+runtest_nmgr_list(struct mgmt_cbuf *cb)
{
CborError g_err = CborNoError;
CborEncoder run_list;
@@ -140,20 +133,12 @@ run_nmgr_list(struct mgmt_cbuf *cb)
* Register nmgr group handlers
*/
int
-run_nmgr_register_group(void)
+runtest_nmgr_register_group(void)
{
- int rc;
-
- MGMT_GROUP_SET_HANDLERS(&run_nmgr_group, run_nmgr_handlers);
- run_nmgr_group.mg_group_id = MGMT_GROUP_ID_RUN;
-
- rc = mgmt_group_register(&run_nmgr_group);
- if (rc != 0) {
- goto err;
- }
- return (0);
+ MGMT_GROUP_SET_HANDLERS(&runtest_nmgr_group, runtest_nmgr_handlers);
+ runtest_nmgr_group.mg_group_id = MGMT_GROUP_ID_RUN;
-err:
- return (rc);
+ return mgmt_group_register(&runtest_nmgr_group);
}
-#endif /* MYNEWT_VAL(RUN_NEWTMGR) */
+
+#endif /* MYNEWT_VAL(RUNTEST_NEWTMGR) */
diff --git a/test/runtest/src/runtest_priv.h b/test/runtest/src/runtest_priv.h
index af43895560..45b85aca18 100644
--- a/test/runtest/src/runtest_priv.h
+++ b/test/runtest/src/runtest_priv.h
@@ -26,11 +26,8 @@ extern "C" {
#if MYNEWT_VAL(RUNTEST_CLI)
extern struct shell_cmd runtest_cmd_struct;
#endif
-#if MYNEWT_VAL(RUNTEST_NEWTMGR)
-extern struct mgmt_group runtest_nmgr_group;
-#endif
-int runtest();
+int runtest_nmgr_register_group(void);
#ifdef __cplusplus
}
diff --git a/test/runtest/syscfg.yml b/test/runtest/syscfg.yml
index c085f7d645..2d5be4027a 100644
--- a/test/runtest/syscfg.yml
+++ b/test/runtest/syscfg.yml
@@ -19,11 +19,42 @@
# Package: test/runtest
syscfg.defs:
+ RUNTEST_LOG:
+ description: >
+ Causes test results to be written to a cbmem-backed log.
+ value: 0
+ RUNTEST_LOG_SIZE:
+ description: >
+ The size of the test log cbmem (bytes).
+ value: 2048
+ restrictions:
+ - 'RUNTEST_LOG_SIZE > 0 || !RUNTEST_LOG'
RUNTEST_CLI:
description: 'CLI commands for accessing tests'
- value: 1
+ value: 0
restrictions:
- SHELL_TASK
RUNTEST_NEWTMGR:
- description: 'Newtmgr command to execute tests'
+ description: 'Enable newtmgr command to execute tests'
value: 1
+ RUNTEST_PREFIX:
+ description: >
+ String to preface all log messages with. If this is undefined, the
+ prefix is constructed from the legacy C macros `BUILD_TARGET` and
+ `BUILD_TEST`.
+ value:
+ RUNTEST_NUM_TASKS:
+ description: 'The number of generic tasks available to unit tests.'
+ value: 4
+ RUNTEST_STACK_SIZE:
+ description: 'The stack size, in words, of each generic test task.'
+ value: 256
+ RUNTEST_MAX_TEST_NAME_LEN:
+ description: 'The maximum length, in characters, of each test name.'
+ value: 32
+ RUNTEST_MAX_TOKEN_LEN:
+ description: >
+ The maximum length, in characters, of the test token name. The
+ test token is specified by the runtest client and is included in
+ test result log entries.
+ value: 32
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services