You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/09/13 03:42:22 UTC
[29/41] incubator-mynewt-core git commit: syscfg / sysinit
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/mbedtls/test/src/mbedtls_test.c
----------------------------------------------------------------------
diff --git a/libs/mbedtls/test/src/mbedtls_test.c b/libs/mbedtls/test/src/mbedtls_test.c
new file mode 100644
index 0000000..85038f8
--- /dev/null
+++ b/libs/mbedtls/test/src/mbedtls_test.c
@@ -0,0 +1,228 @@
+/**
+ * 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 "syscfg/syscfg.h"
+#include "testutil/testutil.h"
+
+#include "mbedtls/mbedtls_test.h"
+#include "mbedtls/sha1.h"
+#include "mbedtls/sha256.h"
+#include "mbedtls/sha512.h"
+#include "mbedtls/aes.h"
+#include "mbedtls/arc4.h"
+#include "mbedtls/bignum.h"
+#include "mbedtls/ccm.h"
+#include "mbedtls/dhm.h"
+#include "mbedtls/ecjpake.h"
+#include "mbedtls/ecp.h"
+#include "mbedtls/entropy.h"
+#include "mbedtls/gcm.h"
+#include "mbedtls/hmac_drbg.h"
+#include "mbedtls/md5.h"
+#include "mbedtls/pkcs5.h"
+#include "mbedtls/ripemd160.h"
+#include "mbedtls/rsa.h"
+#include "mbedtls/x509.h"
+#include "mbedtls/xtea.h"
+
+TEST_CASE(sha1_test)
+{
+ int rc;
+
+ rc = mbedtls_sha1_self_test(0);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(sha256_test)
+{
+ int rc;
+
+ rc = mbedtls_sha256_self_test(0);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(sha512_test)
+{
+ int rc;
+
+ rc = mbedtls_sha512_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(aes_test)
+{
+ int rc;
+
+ rc = mbedtls_aes_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(arc4_test)
+{
+ int rc;
+
+ rc = mbedtls_arc4_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(bignum_test)
+{
+ int rc;
+
+ rc = mbedtls_mpi_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ccm_test)
+{
+ int rc;
+
+ rc = mbedtls_ccm_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(dhm_test)
+{
+ int rc;
+
+ rc = mbedtls_dhm_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ecp_test)
+{
+ int rc;
+
+ rc = mbedtls_ecp_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(entropy_test)
+{
+#if 0 /* XXX fix this later, no strong entropy source atm */
+ int rc;
+
+ rc = mbedtls_entropy_self_test(1);
+ TEST_ASSERT(rc == 0);
+#endif
+}
+
+TEST_CASE(gcm_test)
+{
+ int rc;
+
+ rc = mbedtls_gcm_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(hmac_drbg_test)
+{
+ int rc;
+
+ rc = mbedtls_hmac_drbg_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(md5_test)
+{
+ int rc;
+
+ rc = mbedtls_md5_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(pkcs5_test)
+{
+ int rc;
+
+ rc = mbedtls_pkcs5_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(ripemd160_test)
+{
+ int rc;
+
+ rc = mbedtls_ripemd160_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(rsa_test)
+{
+ int rc;
+
+ rc = mbedtls_rsa_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(x509_test)
+{
+ int rc;
+
+ rc = mbedtls_x509_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+TEST_CASE(xtea_test)
+{
+ int rc;
+
+ rc = mbedtls_xtea_self_test(1);
+ TEST_ASSERT(rc == 0);
+}
+
+
+TEST_SUITE(mbedtls_test_all)
+{
+ sha1_test();
+ sha256_test();
+ sha512_test();
+ aes_test();
+ arc4_test();
+ bignum_test();
+ ccm_test();
+ dhm_test();
+ ecp_test();
+ entropy_test();
+ gcm_test();
+ hmac_drbg_test();
+ md5_test();
+ pkcs5_test();
+ ripemd160_test();
+ rsa_test();
+ x509_test();
+ xtea_test();
+}
+
+#if MYNEWT_VAL(SELFTEST)
+int
+main(int argc, char **argv)
+{
+ tu_config.tc_print_results = 1;
+ tu_init();
+
+ mbedtls_test_all();
+
+ return tu_any_failed;
+}
+
+#endif
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/libs/newtmgr/include/newtmgr/newtmgr.h b/libs/newtmgr/include/newtmgr/newtmgr.h
index 0e5637b..00d1b00 100644
--- a/libs/newtmgr/include/newtmgr/newtmgr.h
+++ b/libs/newtmgr/include/newtmgr/newtmgr.h
@@ -127,7 +127,7 @@ struct nmgr_transport {
};
-int nmgr_task_init(uint8_t, os_stack_t *, uint16_t);
+int nmgr_task_init(void);
int nmgr_transport_init(struct nmgr_transport *nt,
nmgr_transport_out_func_t output_func);
int nmgr_rx_req(struct nmgr_transport *nt, struct os_mbuf *req);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/newtmgr/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/newtmgr/pkg.yml b/libs/newtmgr/pkg.yml
index a0e75a2..2dbdb71 100644
--- a/libs/newtmgr/pkg.yml
+++ b/libs/newtmgr/pkg.yml
@@ -28,12 +28,23 @@ pkg.deps:
- libs/os
- libs/json
- libs/util
- - libs/testutil
- libs/shell
- sys/reboot
pkg.deps.BLE_HOST:
- libs/newtmgr/transport/ble
-pkg.features:
- - NEWTMGR
+pkg.init_function: nmgr_pkg_init
+pkg.init_stage: 5
+
+pkg.syscfg_defs:
+ NEWTMGR_TASK_PRIO:
+ description: 'TBD'
+ type: 'task_priority'
+ value: 'any'
+ NEWTMGR_STACK_SIZE:
+ description: 'TBD'
+ value: 512
+ NEWTMGR_BLE_HOST:
+ description: 'TBD'
+ value: 'MYNEWT_PKG_NET_NIMBLE_HOST'
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/libs/newtmgr/src/newtmgr.c b/libs/newtmgr/src/newtmgr.c
index c3bc614..9b0d696 100644
--- a/libs/newtmgr/src/newtmgr.c
+++ b/libs/newtmgr/src/newtmgr.c
@@ -17,18 +17,22 @@
* under the License.
*/
-#include <os/os.h>
-#include <os/endian.h>
-
#include <assert.h>
#include <string.h>
-#include <shell/shell.h>
-#include <console/console.h>
-#include <newtmgr/newtmgr.h>
+#include "syscfg/syscfg.h"
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "os/endian.h"
+
+#include "shell/shell.h"
+#include "console/console.h"
+#include "newtmgr/newtmgr.h"
#include "newtmgr_priv.h"
+os_stack_t newtmgr_stack[OS_STACK_ALIGN(MYNEWT_VAL(NEWTMGR_STACK_SIZE))];
+
struct nmgr_transport g_nmgr_shell_transport;
struct os_mutex g_nmgr_group_list_lock;
@@ -624,7 +628,7 @@ err:
}
int
-nmgr_task_init(uint8_t prio, os_stack_t *stack_ptr, uint16_t stack_len)
+nmgr_task_init(void)
{
int rc;
@@ -641,8 +645,9 @@ nmgr_task_init(uint8_t prio, os_stack_t *stack_ptr, uint16_t stack_len)
goto err;
}
- rc = os_task_init(&g_nmgr_task, "newtmgr", nmgr_task, NULL, prio,
- OS_WAIT_FOREVER, stack_ptr, stack_len);
+ rc = os_task_init(&g_nmgr_task, "newtmgr", nmgr_task, NULL,
+ MYNEWT_VAL(NEWTMGR_TASK_PRIO), OS_WAIT_FOREVER,
+ newtmgr_stack, MYNEWT_VAL(NEWTMGR_STACK_SIZE));
if (rc != 0) {
goto err;
}
@@ -656,3 +661,12 @@ nmgr_task_init(uint8_t prio, os_stack_t *stack_ptr, uint16_t stack_len)
err:
return (rc);
}
+
+void
+nmgr_pkg_init(void)
+{
+ int rc;
+
+ rc = nmgr_task_init();
+ SYSINIT_PANIC_ASSERT(rc == 0);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
----------------------------------------------------------------------
diff --git a/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h b/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
index a320eaa..315a6e8 100644
--- a/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
+++ b/libs/newtmgr/transport/ble/include/nmgrble/newtmgr_ble.h
@@ -23,6 +23,6 @@
int
nmgr_ble_proc_mq_evt(struct os_event *ev);
int
-nmgr_ble_gatt_svr_init(struct os_eventq *evq, struct ble_hs_cfg *cfg);
+nmgr_ble_gatt_svr_init(void);
#endif /* _NETMGR_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/newtmgr/transport/ble/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/newtmgr/transport/ble/pkg.yml b/libs/newtmgr/transport/ble/pkg.yml
index 9ab9d4e..8c444fe 100644
--- a/libs/newtmgr/transport/ble/pkg.yml
+++ b/libs/newtmgr/transport/ble/pkg.yml
@@ -28,3 +28,6 @@ pkg.keywords:
pkg.deps:
- libs/os
- net/nimble
+
+pkg.init_function: newtmgr_ble_pkg_init
+pkg.init_stage: 5
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/newtmgr/transport/ble/src/newtmgr_ble.c
----------------------------------------------------------------------
diff --git a/libs/newtmgr/transport/ble/src/newtmgr_ble.c b/libs/newtmgr/transport/ble/src/newtmgr_ble.c
index 716a974..5ddbe95 100644
--- a/libs/newtmgr/transport/ble/src/newtmgr_ble.c
+++ b/libs/newtmgr/transport/ble/src/newtmgr_ble.c
@@ -20,9 +20,10 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
+#include "sysinit/sysinit.h"
#include "host/ble_hs.h"
-#include <newtmgr/newtmgr.h>
-#include <os/endian.h>
+#include "newtmgr/newtmgr.h"
+#include "os/endian.h"
/* nmgr ble mqueue */
struct os_mqueue ble_nmgr_mq;
@@ -33,7 +34,6 @@ struct nmgr_transport ble_nt;
/* ble nmgr attr handle */
uint16_t g_ble_nmgr_attr_handle;
-struct os_eventq *app_evq;
/**
* The vendor specific "newtmgr" service consists of one write no-rsp
* characteristic for newtmgr requests: a single-byte characteristic that can
@@ -193,7 +193,7 @@ nmgr_ble_out(struct nmgr_transport *nt, struct os_mbuf *m)
{
int rc;
- rc = os_mqueue_put(&ble_nmgr_mq, app_evq, m);
+ rc = os_mqueue_put(&ble_nmgr_mq, ble_hs_cfg.parent_evq, m);
if (rc != 0) {
goto err;
}
@@ -210,13 +210,11 @@ err:
* @return 0 on success; non-zero on failure
*/
int
-nmgr_ble_gatt_svr_init(struct os_eventq *evq, struct ble_hs_cfg *cfg)
+nmgr_ble_gatt_svr_init(void)
{
int rc;
- assert(evq != NULL);
-
- rc = ble_gatts_count_cfg(gatt_svr_svcs, cfg);
+ rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
goto err;
}
@@ -226,8 +224,6 @@ nmgr_ble_gatt_svr_init(struct os_eventq *evq, struct ble_hs_cfg *cfg)
return rc;
}
- app_evq = evq;
-
os_mqueue_init(&ble_nmgr_mq, &ble_nmgr_mq);
rc = nmgr_transport_init(&ble_nt, &nmgr_ble_out);
@@ -235,3 +231,12 @@ nmgr_ble_gatt_svr_init(struct os_eventq *evq, struct ble_hs_cfg *cfg)
err:
return rc;
}
+
+void
+newtmgr_ble_pkg_init(void)
+{
+ int rc;
+
+ rc = nmgr_ble_gatt_svr_init();
+ SYSINIT_PANIC_ASSERT(rc == 0);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mbuf.h b/libs/os/include/os/os_mbuf.h
index f3c48ae..e0733fd 100644
--- a/libs/os/include/os/os_mbuf.h
+++ b/libs/os/include/os/os_mbuf.h
@@ -245,6 +245,9 @@ void os_msys_reset(void);
/* Return a packet header mbuf from the system pool */
struct os_mbuf *os_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len);
+int os_msys_count(void);
+int os_msys_num_free(void);
+
/* Initialize a mbuf pool */
int os_mbuf_pool_init(struct os_mbuf_pool *, struct os_mempool *mp,
uint16_t, uint16_t);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/os/pkg.yml b/libs/os/pkg.yml
index 85133e1..d302374 100644
--- a/libs/os/pkg.yml
+++ b/libs/os/pkg.yml
@@ -24,18 +24,56 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.deps:
- - libs/testutil
+ - sys/sysinit
- libs/util
+
pkg.req_apis:
- console
-pkg.deps.SHELL:
+pkg.deps.OS_CLI:
- libs/shell
-pkg.cflags.SHELL: -DSHELL_PRESENT
-pkg.deps.COREDUMP:
+pkg.deps.OS_COREDUMP:
- sys/coredump
-pkg.cflags.COREDUMP: -DCOREDUMP_PRESENT
-# Satisfy capability dependencies for the self-contained test executable.
-pkg.deps.SELFTEST: libs/console/stub
+pkg.init_function: os_pkg_init
+pkg.init_stage: 0
+
+pkg.syscfg_defs:
+ OS_CLI:
+ description: 'TBD'
+ value: 'MYNEWT_PKG_LIBS_SHELL'
+ OS_COREDUMP:
+ description: 'TBD'
+ value: 'MYNEWT_PKG_SYS_COREDUMP'
+
+ MSYS_1_BLOCK_COUNT:
+ description: 'TBD'
+ value: 12
+ MSYS_1_BLOCK_SIZE:
+ description: 'TBD'
+ value: 260
+ MSYS_2_BLOCK_COUNT:
+ description: 'TBD'
+ value: 0
+ MSYS_2_BLOCK_SIZE:
+ description: 'TBD'
+ value: 0
+ MSYS_3_BLOCK_COUNT:
+ description: 'TBD'
+ value: 0
+ MSYS_3_BLOCK_SIZE:
+ description: 'TBD'
+ value: 0
+ MSYS_4_BLOCK_COUNT:
+ description: 'TBD'
+ value: 0
+ MSYS_4_BLOCK_SIZE:
+ description: 'TBD'
+ value: 0
+ MSYS_5_BLOCK_COUNT:
+ description: 'TBD'
+ value: 0
+ MSYS_5_BLOCK_SIZE:
+ description: 'TBD'
+ value: 0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/arch/cortex_m0/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_fault.c b/libs/os/src/arch/cortex_m0/os_fault.c
index 563f91a..4167682 100644
--- a/libs/os/src/arch/cortex_m0/os_fault.c
+++ b/libs/os/src/arch/cortex_m0/os_fault.c
@@ -17,15 +17,17 @@
* under the License.
*/
-#include <console/console.h>
-#include <hal/hal_system.h>
-#ifdef COREDUMP_PRESENT
-#include <coredump/coredump.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "syscfg/syscfg.h"
+#include "console/console.h"
+#include "hal/hal_system.h"
+#if MYNEWT_VAL(OS_COREDUMP)
+#include "coredump/coredump.h"
#endif
#include "os/os.h"
-#include <stdint.h>
-#include <unistd.h>
struct exception_frame {
uint32_t r0;
@@ -73,7 +75,7 @@ struct coredump_regs {
void __assert_func(const char *file, int line, const char *func, const char *e);
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(OS_COREDUMP)
static void
trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs)
{
@@ -131,7 +133,7 @@ __assert_func(const char *file, int line, const char *func, const char *e)
void
os_default_irq(struct trap_frame *tf)
{
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(OS_COREDUMP)
struct coredump_regs regs;
#endif
@@ -147,7 +149,7 @@ os_default_irq(struct trap_frame *tf)
console_printf("r12:0x%08lx lr:0x%08lx pc:0x%08lx psr:0x%08lx\n",
tf->ef->r12, tf->ef->lr, tf->ef->pc, tf->ef->psr);
console_printf("ICSR:0x%08lx\n", SCB->ICSR);
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(OS_COREDUMP)
trap_to_coredump(tf, ®s);
coredump_dump(®s, sizeof(regs));
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index 48f6976..cef11f9 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -210,9 +210,6 @@ os_arch_os_init(void)
NVIC_SetVector(i, (uint32_t)os_default_irq_asm);
}
- /* Call bsp related OS initializations */
- bsp_init();
-
/* Set the PendSV interrupt exception priority to the lowest priority */
NVIC_SetPriority(PendSV_IRQn, PEND_SV_PRIO);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/arch/cortex_m4/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_fault.c b/libs/os/src/arch/cortex_m4/os_fault.c
index a6c2b7c..d7806db 100644
--- a/libs/os/src/arch/cortex_m4/os_fault.c
+++ b/libs/os/src/arch/cortex_m4/os_fault.c
@@ -17,12 +17,13 @@
* under the License.
*/
-#include <console/console.h>
-#include <hal/hal_system.h>
+#include "syscfg/syscfg.h"
+#include "console/console.h"
+#include "hal/hal_system.h"
#include "os/os.h"
-#ifdef COREDUMP_PRESENT
-#include <coredump/coredump.h>
+#if MYNEWT_VAL(OS_COREDUMP)
+#include "coredump/coredump.h"
#endif
#include <stdint.h>
@@ -74,7 +75,7 @@ struct coredump_regs {
void __assert_func(const char *file, int line, const char *func, const char *e);
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(OS_COREDUMP)
static void
trap_to_coredump(struct trap_frame *tf, struct coredump_regs *regs)
{
@@ -132,7 +133,7 @@ __assert_func(const char *file, int line, const char *func, const char *e)
void
os_default_irq(struct trap_frame *tf)
{
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(OS_COREDUMP)
struct coredump_regs regs;
#endif
@@ -151,7 +152,7 @@ os_default_irq(struct trap_frame *tf)
SCB->ICSR, SCB->HFSR, SCB->CFSR);
console_printf("BFAR:0x%08lx MMFAR:0x%08lx\n", SCB->BFAR, SCB->MMFAR);
-#ifdef COREDUMP_PRESENT
+#if MYNEWT_VAL(OS_COREDUMP)
trap_to_coredump(tf, ®s);
coredump_dump(®s, sizeof(regs));
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index 961d7a0..6f47789 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -17,12 +17,14 @@
* under the License.
*/
+#include "sysinit/sysinit.h"
#include "os/os.h"
#include "os/queue.h"
#include "os/os_dev.h"
#include "os_priv.h"
#include "hal/hal_os_tick.h"
+#include "hal/hal_bsp.h"
#include <assert.h>
@@ -113,11 +115,17 @@ os_init(void)
err = os_arch_os_init();
assert(err == OS_OK);
+ /* Call bsp related OS initializations */
+ bsp_init();
+
err = (os_error_t) os_dev_initialize_all(OS_DEV_INIT_PRIMARY);
assert(err == OS_OK);
err = (os_error_t) os_dev_initialize_all(OS_DEV_INIT_SECONDARY);
assert(err == OS_OK);
+
+ /* Initialize target-specific packages. */
+ sysinit();
}
/**
@@ -135,3 +143,9 @@ os_start(void)
err = os_arch_os_start();
assert(err == OS_OK);
}
+
+void
+os_pkg_init(void)
+{
+ os_msys_init();
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index a2302df..c7183f9 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -261,6 +261,33 @@ err:
return (NULL);
}
+int
+os_msys_count(void)
+{
+ struct os_mbuf_pool *omp;
+ int total;
+
+ total = 0;
+ STAILQ_FOREACH(omp, &g_msys_pool_list, omp_next) {
+ total += omp->omp_pool->mp_num_blocks;
+ }
+
+ return total;
+}
+
+int
+os_msys_num_free(void)
+{
+ struct os_mbuf_pool *omp;
+ int total;
+
+ total = 0;
+ STAILQ_FOREACH(omp, &g_msys_pool_list, omp_next) {
+ total += omp->omp_pool->mp_num_free;
+ }
+
+ return total;
+}
/**
* Initialize a pool of mbufs.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/os_msys_init.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_msys_init.c b/libs/os/src/os_msys_init.c
new file mode 100644
index 0000000..fe0d569
--- /dev/null
+++ b/libs/os/src/os_msys_init.c
@@ -0,0 +1,147 @@
+/**
+ * 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 <assert.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "os/os_mempool.h"
+#include "util/mem.h"
+#include "os_priv.h"
+
+#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
+#define SYSINIT_MSYS_1_MEMBLOCK_SIZE \
+ OS_ALIGN(MYNEWT_VAL(MSYS_1_BLOCK_SIZE), 4)
+#define SYSINIT_MSYS_1_MEMPOOL_SIZE \
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_1_BLOCK_COUNT), \
+ SYSINIT_MSYS_1_MEMBLOCK_SIZE)
+static os_membuf_t os_msys_init_1_data[SYSINIT_MSYS_1_MEMPOOL_SIZE];
+static struct os_mbuf_pool os_msys_init_1_mbuf_pool;
+static struct os_mempool os_msys_init_1_mempool;
+#endif
+
+#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
+#define SYSINIT_MSYS_2_MEMBLOCK_SIZE \
+ OS_ALIGN(MYNEWT_VAL(MSYS_2_BLOCK_SIZE), 4)
+#define SYSINIT_MSYS_2_MEMPOOL_SIZE \
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_2_BLOCK_COUNT), \
+ SYSINIT_MSYS_2_MEMBLOCK_SIZE)
+static os_membuf_t os_msys_init_2_data[SYSINIT_MSYS_2_MEMPOOL_SIZE];
+static struct os_mbuf_pool os_msys_init_2_mbuf_pool;
+static struct os_mempool os_msys_init_2_mempool;
+#endif
+
+#if MYNEWT_VAL(MSYS_3_BLOCK_COUNT) > 0
+#define SYSINIT_MSYS_3_MEMBLOCK_SIZE \
+ OS_ALIGN(MYNEWT_VAL(MSYS_3_BLOCK_SIZE), 4)
+#define SYSINIT_MSYS_3_MEMPOOL_SIZE \
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_3_BLOCK_COUNT), \
+ SYSINIT_MSYS_3_MEMBLOCK_SIZE)
+static os_membuf_t os_msys_init_3_data[SYSINIT_MSYS_3_MEMPOOL_SIZE];
+static struct os_mbuf_pool os_msys_init_3_mbuf_pool;
+static struct os_mempool os_msys_init_3_mempool;
+#endif
+
+#if MYNEWT_VAL(MSYS_4_BLOCK_COUNT) > 0
+#define SYSINIT_MSYS_4_MEMBLOCK_SIZE \
+ OS_ALIGN(MYNEWT_VAL(MSYS_4_BLOCK_SIZE), 4)
+#define SYSINIT_MSYS_4_MEMPOOL_SIZE \
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_4_BLOCK_COUNT), \
+ SYSINIT_MSYS_4_MEMBLOCK_SIZE)
+static os_membuf_t os_msys_init_4_data[SYSINIT_MSYS_4_MEMPOOL_SIZE];
+static struct os_mbuf_pool os_msys_init_4_mbuf_pool;
+static struct os_mempool os_msys_init_4_mempool;
+#endif
+
+#if MYNEWT_VAL(MSYS_5_BLOCK_COUNT) > 0
+#define SYSINIT_MSYS_5_MEMBLOCK_SIZE \
+ OS_ALIGN(MYNEWT_VAL(MSYS_5_BLOCK_SIZE), 4)
+#define SYSINIT_MSYS_5_MEMPOOL_SIZE \
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_5_BLOCK_COUNT), \
+ SYSINIT_MSYS_5_MEMBLOCK_SIZE)
+
+static os_membuf_t os_msys_init_5_data[SYSINIT_MSYS_5_MEMPOOL_SIZE];
+static struct os_mbuf_pool os_msys_init_5_mbuf_pool;
+static struct os_mempool os_msys_init_5_mempool;
+#endif
+
+static void
+os_msys_init_once(void *data, struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool,
+ int block_count, int block_size, char *name)
+{
+ int rc;
+
+ rc = mem_init_mbuf_pool(data, mempool, mbuf_pool, block_count, block_size,
+ name);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+
+ rc = os_msys_register(mbuf_pool);
+ SYSINIT_PANIC_ASSERT(rc == 0);
+}
+
+void
+os_msys_init(void)
+{
+ os_msys_reset();
+
+#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
+ os_msys_init_once(os_msys_init_1_data,
+ &os_msys_init_1_mempool,
+ &os_msys_init_1_mbuf_pool,
+ MYNEWT_VAL(MSYS_1_BLOCK_COUNT),
+ SYSINIT_MSYS_1_MEMBLOCK_SIZE,
+ "msys_1");
+#endif
+
+#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
+ os_msys_init_once(os_msys_init_2_data,
+ &os_msys_init_2_mempool,
+ &os_msys_init_2_mbuf_pool,
+ MYNEWT_VAL(MSYS_2_BLOCK_COUNT),
+ SYSINIT_MSYS_2_MEMBLOCK_SIZE,
+ "msys_2");
+#endif
+
+#if MYNEWT_VAL(MSYS_3_BLOCK_COUNT) > 0
+ os_msys_init_once(os_msys_init_3_data,
+ &os_msys_init_3_mempool,
+ &os_msys_init_3_mbuf_pool,
+ MYNEWT_VAL(MSYS_3_BLOCK_COUNT),
+ SYSINIT_MSYS_3_MEMBLOCK_SIZE,
+ "msys_3");
+#endif
+
+#if MYNEWT_VAL(MSYS_4_BLOCK_COUNT) > 0
+ os_msys_init_once(os_msys_init_4_data,
+ &os_msys_init_4_mempool,
+ &os_msys_init_4_mbuf_pool,
+ MYNEWT_VAL(MSYS_4_BLOCK_COUNT),
+ SYSINIT_MSYS_4_MEMBLOCK_SIZE,
+ "msys_4");
+#endif
+
+#if MYNEWT_VAL(MSYS_5_BLOCK_COUNT) > 0
+ os_msys_init_once(os_msys_init_5_data,
+ &os_msys_init_5_mempool,
+ &os_msys_init_5_mbuf_pool,
+ MYNEWT_VAL(MSYS_5_BLOCK_COUNT),
+ SYSINIT_MSYS_5_MEMBLOCK_SIZE,
+ "msys_5");
+#endif
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/os_priv.h
----------------------------------------------------------------------
diff --git a/libs/os/src/os_priv.h b/libs/os/src/os_priv.h
index b5c8f65..7745a0a 100644
--- a/libs/os/src/os_priv.h
+++ b/libs/os/src/os_priv.h
@@ -33,4 +33,6 @@ extern struct os_task_stailq g_os_task_list;
extern struct os_task *g_current_task;
extern struct os_callout_list g_callout_list;
+void os_msys_init(void);
+
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/arch/cortex_m4/os_test_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/arch/cortex_m4/os_test_arch_arm.c b/libs/os/src/test/arch/cortex_m4/os_test_arch_arm.c
deleted file mode 100644
index 35134f7..0000000
--- a/libs/os/src/test/arch/cortex_m4/os_test_arch_arm.c
+++ /dev/null
@@ -1,27 +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 "testutil/testutil.h"
-#include "os_test_priv.h"
-
-void
-os_test_restart(void)
-{
- tu_restart();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/arch/sim/os_test_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/arch/sim/os_test_arch_sim.c b/libs/os/src/test/arch/sim/os_test_arch_sim.c
deleted file mode 100644
index 3b6cfbf..0000000
--- a/libs/os/src/test/arch/sim/os_test_arch_sim.c
+++ /dev/null
@@ -1,52 +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 <setjmp.h>
-#include <signal.h>
-#include <string.h>
-#include <sys/time.h>
-#include "testutil/testutil.h"
-#include "os/os.h"
-#include "os_test_priv.h"
-
-void
-os_test_restart(void)
-{
- struct sigaction sa;
- struct itimerval it;
- int rc;
-
- g_os_started = 0;
-
- memset(&sa, 0, sizeof sa);
- sa.sa_handler = SIG_IGN;
-
- sigaction(SIGALRM, &sa, NULL);
- sigaction(SIGVTALRM, &sa, NULL);
-
- memset(&it, 0, sizeof(it));
- rc = setitimer(ITIMER_VIRTUAL, &it, NULL);
- if (rc != 0) {
- perror("Cannot set itimer");
- abort();
- }
-
- tu_restart();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/eventq_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/eventq_test.c b/libs/os/src/test/eventq_test.c
deleted file mode 100644
index cb1ed94..0000000
--- a/libs/os/src/test/eventq_test.c
+++ /dev/null
@@ -1,416 +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 <string.h>
-#include "testutil/testutil.h"
-#include "os/os.h"
-#include "os_test_priv.h"
-#include "os/os_eventq.h"
-
-#define MY_STACK_SIZE (5120)
-#define POLL_STACK_SIZE (4096)
-/* Task 1 sending task */
-/* Define task stack and task object */
-#define SEND_TASK_PRIO (1)
-struct os_task eventq_task_s;
-os_stack_t eventq_task_stack_s[MY_STACK_SIZE];
-
-/* Task 2 receiving task */
-#define RECEIVE_TASK_PRIO (2)
-struct os_task eventq_task_r;
-os_stack_t eventq_task_stack_r[MY_STACK_SIZE];
-
-struct os_eventq my_eventq;
-
-#define SIZE_MULTI_EVENT (4)
-struct os_eventq multi_eventq[SIZE_MULTI_EVENT];
-
-/* This is to set the events we will use below */
-struct os_event g_event;
-struct os_event m_event[SIZE_MULTI_EVENT];
-
-/* Setting the event to send and receive multiple data */
-uint8_t my_event_type = 1;
-
-/* Setting up data for the poll */
-/* Define the task stack for the eventq_task_poll_send */
-#define SEND_TASK_POLL_PRIO (3)
-struct os_task eventq_task_poll_s;
-os_stack_t eventq_task_stack_poll_s[POLL_STACK_SIZE];
-
-/* Define the task stack for the eventq_task_poll_receive */
-#define RECEIVE_TASK_POLL_PRIO (4)
-struct os_task eventq_task_poll_r;
-os_stack_t eventq_task_stack_poll_r[POLL_STACK_SIZE ];
-
-/* Setting the data for the poll timeout */
-/* Define the task stack for the eventq_task_poll_timeout_send */
-#define SEND_TASK_POLL_TIMEOUT_PRIO (5)
-struct os_task eventq_task_poll_timeout_s;
-os_stack_t eventq_task_stack_poll_timeout_s[POLL_STACK_SIZE];
-
-/* Define the task stack for the eventq_task_poll_receive */
-#define RECEIVE_TASK_POLL_TIMEOUT_PRIO (6)
-struct os_task eventq_task_poll_timeout_r;
-os_stack_t eventq_task_stack_poll_timeout_r[POLL_STACK_SIZE];
-
-/* Setting the data for the poll single */
-/* Define the task stack for the eventq_task_poll_single_send */
-#define SEND_TASK_POLL_SINGLE_PRIO (7)
-struct os_task eventq_task_poll_single_s;
-os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE];
-
-/* Define the task stack for the eventq_task_poll_single_receive */
-#define RECEIVE_TASK_POLL_SINGLE_PRIO (8)
-struct os_task eventq_task_poll_single_r;
-os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE];
-
-/* This is the task function to send data */
-void
-eventq_task_send(void *arg)
-{
- int i;
-
- g_event.ev_queued = 0;
- g_event.ev_type = my_event_type;
- g_event.ev_arg = NULL;
-
- os_eventq_put(&my_eventq, &g_event);
-
- os_time_delay(OS_TICKS_PER_SEC / 2);
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- m_event[i].ev_type = i + 2;
- m_event[i].ev_arg = NULL;
-
- /* Put and send */
- os_eventq_put(&multi_eventq[i], &m_event[i]);
- os_time_delay(OS_TICKS_PER_SEC / 2);
- }
-
- /* This task sleeps until the receive task completes the test. */
- os_time_delay(1000000);
-}
-
-/* This is the task function is the receiving function */
-void
-eventq_task_receive(void *arg)
-{
- struct os_event *event;
- int i;
-
- event = os_eventq_get(&my_eventq);
- TEST_ASSERT(event->ev_type == my_event_type);
-
- /* Receiving multi event from the send task */
- for (i = 0; i < SIZE_MULTI_EVENT; i++) {
- event = os_eventq_get(&multi_eventq[i]);
- TEST_ASSERT(event->ev_type == i + 2);
- }
-
- /* Finishes the test when OS has been started */
- os_test_restart();
-}
-
-void
-eventq_task_poll_send(void *arg)
-{
- struct os_eventq *eventqs[SIZE_MULTI_EVENT];
- int i;
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- eventqs[i] = &multi_eventq[i];
- }
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- m_event[i].ev_type = i + 10;
- m_event[i].ev_arg = NULL;
-
- /* Put and send */
- os_eventq_put(eventqs[i], &m_event[i]);
- os_time_delay(OS_TICKS_PER_SEC / 2);
- }
-
- /* This task sleeps until the receive task completes the test. */
- os_time_delay(1000000);
-}
-
-void
-eventq_task_poll_receive(void *arg)
-{
- struct os_eventq *eventqs[SIZE_MULTI_EVENT];
- struct os_event *event;
- int i;
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- eventqs[i] = &multi_eventq[i];
- }
-
- /* Recieving using the os_eventq_poll*/
- for (i = 0; i < SIZE_MULTI_EVENT; i++) {
- event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
- TEST_ASSERT(event->ev_type == i +10);
- }
-
- /* Finishes the test when OS has been started */
- os_test_restart();
-
-}
-
-/* Sending with a time failure */
-void
-eventq_task_poll_timeout_send(void *arg)
-{
- struct os_eventq *eventqs[SIZE_MULTI_EVENT];
- int i;
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- eventqs[i] = &multi_eventq[i];
- }
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_time_delay(1000);
-
- /* Put and send */
- os_eventq_put(eventqs[i], &m_event[i]);
- os_time_delay(OS_TICKS_PER_SEC / 2);
- }
-
- /* This task sleeps until the receive task completes the test. */
- os_time_delay(1000000);
-
-}
-
-/* Receiving multiple event queues with a time failure */
-void
-eventq_task_poll_timeout_receive(void *arg)
-{
- struct os_eventq *eventqs[SIZE_MULTI_EVENT];
- struct os_event *event;
- int i;
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- eventqs[i] = &multi_eventq[i];
- }
-
- /* Recieving using the os_eventq_poll_timeout*/
- for (i = 0; i < SIZE_MULTI_EVENT; i++) {
- event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 200);
- TEST_ASSERT(event == NULL);
- }
-
- /* Finishes the test when OS has been started */
- os_test_restart();
-
-}
-
-/* Sending a single event to poll */
-void
-eventq_task_poll_single_send(void *arg)
-{
- struct os_eventq *eventqs[SIZE_MULTI_EVENT];
- int i;
- int position = 2;
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- eventqs[i] = &multi_eventq[i];
- }
-
- /* Put and send */
- os_eventq_put(eventqs[position], &m_event[position]);
- os_time_delay(OS_TICKS_PER_SEC / 2);
-
- /* This task sleeps until the receive task completes the test. */
- os_time_delay(1000000);
-}
-
-/* Recieving the single event */
-void
-eventq_task_poll_single_receive(void *arg)
-{
- struct os_eventq *eventqs[SIZE_MULTI_EVENT];
- struct os_event *event;
- int i;
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- eventqs[i] = &multi_eventq[i];
- }
-
- /* Recieving using the os_eventq_poll*/
- event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
- TEST_ASSERT(event->ev_type == 20);
-
- /* Finishes the test when OS has been started */
- os_test_restart();
-}
-
-TEST_CASE(event_test_sr)
-{
- int i;
-
- /* Initializing the OS */
- os_init();
- /* Initialize the task */
- os_task_init(&eventq_task_s, "eventq_task_s", eventq_task_send, NULL,
- SEND_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_s, MY_STACK_SIZE);
-
- /* Receive events and check whether the eevnts are correctly received */
- os_task_init(&eventq_task_r, "eventq_task_r", eventq_task_receive, NULL,
- RECEIVE_TASK_PRIO, OS_WAIT_FOREVER, eventq_task_stack_r,
- MY_STACK_SIZE);
-
- os_eventq_init(&my_eventq);
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(&multi_eventq[i]);
- }
-
- /* Does not return until OS_restart is called */
- os_start();
-
-}
-
-/* To test for the basic function of os_eventq_poll() */
-TEST_CASE(event_test_poll_sr)
-{
- int i;
-
- /* Initializing the OS */
- os_init();
- /* Initialize the task */
- os_task_init(&eventq_task_poll_s, "eventq_task_poll_s", eventq_task_poll_send,
- NULL, SEND_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_s,
- POLL_STACK_SIZE);
-
- /* Receive events and check whether the eevnts are correctly received */
- os_task_init(&eventq_task_poll_r, "eventq_task_r", eventq_task_poll_receive,
- NULL, RECEIVE_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_r,
- POLL_STACK_SIZE);
-
- /* Initializing the eventqs. */
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(&multi_eventq[i]);
- }
-
- /* Does not return until OS_restart is called */
- os_start();
-
-}
-
-/* Test case for poll timeout */
-TEST_CASE(event_test_poll_timeout_sr)
-{
- int i;
-
- /* Initializing the OS */
- os_init();
- /* Initialize the task */
- os_task_init(&eventq_task_poll_timeout_s, "eventq_task_poll_timeout_s",
- eventq_task_poll_timeout_send, NULL, SEND_TASK_POLL_TIMEOUT_PRIO,
- OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_s, POLL_STACK_SIZE);
-
- /* Receive events and check whether the eevnts are correctly received */
- os_task_init(&eventq_task_poll_timeout_r, "eventq_task_timeout_r",
- eventq_task_poll_timeout_receive, NULL, RECEIVE_TASK_POLL_TIMEOUT_PRIO,
- OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_r, POLL_STACK_SIZE);
-
- /* Initializing the eventqs. */
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(&multi_eventq[i]);
-
- m_event[i].ev_type = i + 10;
- m_event[i].ev_arg = NULL;
- }
-
- /* Does not return until OS_restart is called */
- os_start();
-
-}
-
-/* The case for poll single */
-/* Test case for poll timeout */
-TEST_CASE(event_test_poll_single_sr)
-{
- int i;
-
- /* Initializing the OS */
- os_init();
- /* Initialize the task */
- os_task_init(&eventq_task_poll_single_s, "eventq_task_poll_single_s",
- eventq_task_poll_single_send, NULL, SEND_TASK_POLL_SINGLE_PRIO,
- OS_WAIT_FOREVER, eventq_task_stack_poll_single_s, POLL_STACK_SIZE);
-
- /* Receive events and check whether the eevnts are correctly received */
- os_task_init(&eventq_task_poll_single_r, "eventq_task_single_r",
- eventq_task_poll_single_receive, NULL, RECEIVE_TASK_POLL_SINGLE_PRIO,
- OS_WAIT_FOREVER, eventq_task_stack_poll_single_r, POLL_STACK_SIZE);
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(&multi_eventq[i]);
-
- m_event[i].ev_type = 10 * i;
- m_event[i].ev_arg = NULL;
- }
-
- /* Does not return until OS_restart is called */
- os_start();
-
-}
-
-/**
- * Tests eventq_poll() with a timeout of 0. This should not involve the
- * scheduler at all, so it should work without starting the OS.
- */
-TEST_CASE(event_test_poll_0timo)
-{
- struct os_eventq *eventqs[SIZE_MULTI_EVENT];
- struct os_event *evp;
- struct os_event ev;
- int i;
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(&multi_eventq[i]);
- eventqs[i] = &multi_eventq[i];
- }
-
- evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
- TEST_ASSERT(evp == NULL);
-
- /* Ensure no eventq thinks a task is waiting on it. */
- for (i = 0; i < SIZE_MULTI_EVENT; i++) {
- TEST_ASSERT(eventqs[i]->evq_task == NULL);
- }
-
- /* Put an event on one of the queues. */
- memset(&ev, 0, sizeof ev);
- ev.ev_type = 1;
- os_eventq_put(eventqs[3], &ev);
-
- evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
- TEST_ASSERT(evp == &ev);
-}
-
-TEST_SUITE(os_eventq_test_suite)
-{
- event_test_sr();
- event_test_poll_sr();
- event_test_poll_timeout_sr();
- event_test_poll_single_sr();
- event_test_poll_0timo();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/mbuf_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/mbuf_test.c b/libs/os/src/test/mbuf_test.c
deleted file mode 100644
index dd4121d..0000000
--- a/libs/os/src/test/mbuf_test.c
+++ /dev/null
@@ -1,420 +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 "testutil/testutil.h"
-#include "os/os.h"
-#include "os_test_priv.h"
-
-#include <string.h>
-
-/*
- * NOTE: currently, the buffer size cannot be changed as some tests are
- * hard-coded for this size.
- */
-#define MBUF_TEST_POOL_BUF_SIZE (256)
-#define MBUF_TEST_POOL_BUF_COUNT (10)
-
-#define MBUF_TEST_DATA_LEN (1024)
-
-static os_membuf_t os_mbuf_membuf[OS_MEMPOOL_SIZE(MBUF_TEST_POOL_BUF_SIZE,
- MBUF_TEST_POOL_BUF_COUNT)];
-
-static struct os_mbuf_pool os_mbuf_pool;
-static struct os_mempool os_mbuf_mempool;
-static uint8_t os_mbuf_test_data[MBUF_TEST_DATA_LEN];
-
-static void
-os_mbuf_test_setup(void)
-{
- int rc;
- int i;
-
- rc = os_mempool_init(&os_mbuf_mempool, MBUF_TEST_POOL_BUF_COUNT,
- MBUF_TEST_POOL_BUF_SIZE, &os_mbuf_membuf[0], "mbuf_pool");
- TEST_ASSERT_FATAL(rc == 0, "Error creating memory pool %d", rc);
-
- rc = os_mbuf_pool_init(&os_mbuf_pool, &os_mbuf_mempool,
- MBUF_TEST_POOL_BUF_SIZE, MBUF_TEST_POOL_BUF_COUNT);
- TEST_ASSERT_FATAL(rc == 0, "Error creating mbuf pool %d", rc);
-
- for (i = 0; i < sizeof os_mbuf_test_data; i++) {
- os_mbuf_test_data[i] = i;
- }
-}
-
-static void
-os_mbuf_test_misc_assert_sane(struct os_mbuf *om, void *data,
- int buflen, int pktlen, int pkthdr_len)
-{
- uint8_t *data_min;
- uint8_t *data_max;
- int totlen;
- int i;
-
- TEST_ASSERT_FATAL(om != NULL);
-
- if (OS_MBUF_IS_PKTHDR(om)) {
- TEST_ASSERT(OS_MBUF_PKTLEN(om) == pktlen);
- }
-
- totlen = 0;
- for (i = 0; om != NULL; i++) {
- if (i == 0) {
- TEST_ASSERT(om->om_len == buflen);
- TEST_ASSERT(om->om_pkthdr_len == pkthdr_len);
- }
-
- data_min = om->om_databuf + om->om_pkthdr_len;
- data_max = om->om_databuf + om->om_omp->omp_databuf_len - om->om_len;
- TEST_ASSERT(om->om_data >= data_min && om->om_data <= data_max);
-
- if (data != NULL) {
- TEST_ASSERT(memcmp(om->om_data, data + totlen, om->om_len) == 0);
- }
-
- totlen += om->om_len;
- om = SLIST_NEXT(om, om_next);
- }
-
- TEST_ASSERT(totlen == pktlen);
-}
-
-
-TEST_CASE(os_mbuf_test_alloc)
-{
- struct os_mbuf *m;
- int rc;
-
- os_mbuf_test_setup();
-
- m = os_mbuf_get(&os_mbuf_pool, 0);
- TEST_ASSERT_FATAL(m != NULL, "Error allocating mbuf");
-
- rc = os_mbuf_free(m);
- TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf %d", rc);
-}
-
-TEST_CASE(os_mbuf_test_get_pkthdr)
-{
- struct os_mbuf *m;
-
- os_mbuf_test_setup();
-
-#if (MBUF_TEST_POOL_BUF_SIZE <= 256)
- m = os_mbuf_get_pkthdr(&os_mbuf_pool, MBUF_TEST_POOL_BUF_SIZE - 1);
- TEST_ASSERT_FATAL(m == NULL, "Error: should not have returned mbuf");
-#endif
-
- m = os_mbuf_get(&os_mbuf_pool, MBUF_TEST_POOL_BUF_SIZE);
- TEST_ASSERT_FATAL(m == NULL, "Error: should not have returned mbuf");
-}
-
-
-TEST_CASE(os_mbuf_test_dup)
-{
- struct os_mbuf *om;
- struct os_mbuf *om2;
- struct os_mbuf *dup;
- int rc;
-
- os_mbuf_test_setup();
-
- /* Test first allocating and duplicating a single mbuf */
- om = os_mbuf_get(&os_mbuf_pool, 0);
- TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf");
-
- rc = os_mbuf_append(om, os_mbuf_test_data, 200);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 0);
-
- dup = os_mbuf_dup(om);
- TEST_ASSERT_FATAL(dup != NULL, "NULL mbuf returned from dup");
- TEST_ASSERT_FATAL(dup != om, "duplicate matches original.");
- os_mbuf_test_misc_assert_sane(dup, os_mbuf_test_data, 200, 200, 0);
-
- rc = os_mbuf_free(om);
- TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf om %d", rc);
-
- rc = os_mbuf_free(dup);
- TEST_ASSERT_FATAL(rc == 0, "Error free'ing mbuf dup %d", rc);
-
- om = os_mbuf_get(&os_mbuf_pool, 0);
- TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf");
- rc = os_mbuf_append(om, os_mbuf_test_data, 200);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 0);
-
- om2 = os_mbuf_get(&os_mbuf_pool, 0);
- TEST_ASSERT_FATAL(om2 != NULL, "Error allocating mbuf");
- rc = os_mbuf_append(om2, os_mbuf_test_data + 200, 200);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_test_misc_assert_sane(om2, os_mbuf_test_data + 200, 200, 200, 0);
-
- os_mbuf_concat(om, om2);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 400, 0);
-
- dup = os_mbuf_dup(om);
- TEST_ASSERT_FATAL(dup != NULL, "NULL mbuf returned from dup");
- TEST_ASSERT_FATAL(dup != om, "Duplicate matches original");
- TEST_ASSERT_FATAL(SLIST_NEXT(dup, om_next) != NULL,
- "NULL chained element, duplicate should match original");
-
- os_mbuf_test_misc_assert_sane(dup, os_mbuf_test_data, 200, 400, 0);
-
- rc = os_mbuf_free_chain(om);
- TEST_ASSERT_FATAL(rc == 0, "Cannot free mbuf chain %d", rc);
-
- rc = os_mbuf_free_chain(dup);
- TEST_ASSERT_FATAL(rc == 0, "Cannot free mbuf chain %d", rc);
-}
-
-TEST_CASE(os_mbuf_test_append)
-{
- struct os_mbuf *om;
- int rc;
- uint8_t databuf[] = {0xa, 0xb, 0xc, 0xd};
- uint8_t cmpbuf[] = {0xff, 0xff, 0xff, 0xff};
-
- os_mbuf_test_setup();
-
- om = os_mbuf_get(&os_mbuf_pool, 0);
- TEST_ASSERT_FATAL(om != NULL, "Error allocating mbuf");
- os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 0);
-
- rc = os_mbuf_append(om, databuf, sizeof(databuf));
- TEST_ASSERT_FATAL(rc == 0, "Cannot add %d bytes to mbuf",
- sizeof(databuf));
- os_mbuf_test_misc_assert_sane(om, databuf, sizeof databuf, sizeof databuf,
- 0);
-
- memcpy(cmpbuf, OS_MBUF_DATA(om, uint8_t *), om->om_len);
- TEST_ASSERT_FATAL(memcmp(cmpbuf, databuf, sizeof(databuf)) == 0,
- "Databuf doesn't match cmpbuf");
-}
-
-TEST_CASE(os_mbuf_test_extend)
-{
- struct os_mbuf *om;
- void *v;
-
- os_mbuf_test_setup();
-
- /*** Series of successful extensions. */
- om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om != NULL);
-
- TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 222);
- TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
- os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18);
-
- v = os_mbuf_extend(om, 20);
- TEST_ASSERT(v != NULL);
- TEST_ASSERT(v == om->om_data);
- TEST_ASSERT(om->om_len == 20);
-
- TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 202);
- TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
- os_mbuf_test_misc_assert_sane(om, NULL, 20, 20, 18);
-
- v = os_mbuf_extend(om, 100);
- TEST_ASSERT(v != NULL);
- TEST_ASSERT(v == om->om_data + 20);
- TEST_ASSERT(om->om_len == 120);
-
- TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 102);
- TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
- os_mbuf_test_misc_assert_sane(om, NULL, 120, 120, 18);
-
- v = os_mbuf_extend(om, 101);
- TEST_ASSERT(v != NULL);
- TEST_ASSERT(v == om->om_data + 120);
- TEST_ASSERT(om->om_len == 221);
-
- TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 1);
- TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
- os_mbuf_test_misc_assert_sane(om, NULL, 221, 221, 18);
-
- v = os_mbuf_extend(om, 1);
- TEST_ASSERT(v != NULL);
- TEST_ASSERT(v == om->om_data + 221);
- TEST_ASSERT(om->om_len == 222);
-
- TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
- TEST_ASSERT(SLIST_NEXT(om, om_next) == NULL);
- os_mbuf_test_misc_assert_sane(om, NULL, 222, 222, 18);
-
- /* Overflow into next buffer. */
- v = os_mbuf_extend(om, 1);
- TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
- TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL);
-
- TEST_ASSERT(v == SLIST_NEXT(om, om_next)->om_data);
- TEST_ASSERT(om->om_len == 222);
- TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1);
- os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18);
-
- /*** Attempt to extend by an amount larger than max buf size fails. */
- v = os_mbuf_extend(om, 257);
- TEST_ASSERT(v == NULL);
- TEST_ASSERT(OS_MBUF_TRAILINGSPACE(om) == 0);
- TEST_ASSERT(SLIST_NEXT(om, om_next) != NULL);
-
- TEST_ASSERT(om->om_len == 222);
- TEST_ASSERT(SLIST_NEXT(om, om_next)->om_len == 1);
- os_mbuf_test_misc_assert_sane(om, NULL, 222, 223, 18);
-}
-
-TEST_CASE(os_mbuf_test_pullup)
-{
- struct os_mbuf *om;
- struct os_mbuf *om2;
- int rc;
-
- os_mbuf_test_setup();
-
- /*** Free when too much os_mbuf_test_data is requested. */
- om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om != NULL);
-
- om = os_mbuf_pullup(om, 1);
- TEST_ASSERT(om == NULL);
-
- /*** No effect when all os_mbuf_test_data is already at the start. */
- om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om != NULL);
-
- rc = os_mbuf_append(om, os_mbuf_test_data, 1);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18);
-
- om = os_mbuf_pullup(om, 1);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 1, 1, 18);
-
- /*** Spread os_mbuf_test_data across four mbufs. */
- om2 = os_mbuf_get(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om2 != NULL);
- rc = os_mbuf_append(om2, os_mbuf_test_data + 1, 1);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_concat(om, om2);
-
- om2 = os_mbuf_get(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om2 != NULL);
- rc = os_mbuf_append(om2, os_mbuf_test_data + 2, 1);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_concat(om, om2);
-
- om2 = os_mbuf_get(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om2 != NULL);
- rc = os_mbuf_append(om2, os_mbuf_test_data + 3, 1);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_concat(om, om2);
-
- TEST_ASSERT_FATAL(OS_MBUF_PKTLEN(om) == 4);
-
- om = os_mbuf_pullup(om, 4);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 4, 4, 18);
-
- os_mbuf_free_chain(om);
-
- /*** Require an allocation. */
- om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om != NULL);
-
- om->om_data += 100;
- rc = os_mbuf_append(om, os_mbuf_test_data, 100);
- TEST_ASSERT_FATAL(rc == 0);
-
- om2 = os_mbuf_get(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om2 != NULL);
- rc = os_mbuf_append(om2, os_mbuf_test_data + 100, 100);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_concat(om, om2);
-
- om = os_mbuf_pullup(om, 200);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 200, 200, 18);
-
- /*** Partial pullup. */
- om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om != NULL);
-
- om->om_data += 100;
- rc = os_mbuf_append(om, os_mbuf_test_data, 100);
- TEST_ASSERT_FATAL(rc == 0);
-
- om2 = os_mbuf_get(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om2 != NULL);
- rc = os_mbuf_append(om2, os_mbuf_test_data + 100, 100);
- TEST_ASSERT_FATAL(rc == 0);
- os_mbuf_concat(om, om2);
-
- om = os_mbuf_pullup(om, 150);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 150, 200, 18);
-}
-
-TEST_CASE(os_mbuf_test_adj)
-{
- struct os_mbuf *om;
- int rc;
-
- os_mbuf_test_setup();
-
- om = os_mbuf_get_pkthdr(&os_mbuf_pool, 10);
- TEST_ASSERT_FATAL(om != NULL);
-
- rc = os_mbuf_append(om, os_mbuf_test_data, sizeof os_mbuf_test_data);
- TEST_ASSERT_FATAL(rc == 0);
-
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data, 222,
- sizeof os_mbuf_test_data, 18);
-
- /* Remove from the front. */
- os_mbuf_adj(om, 10);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212,
- sizeof os_mbuf_test_data - 10, 18);
-
- /* Remove from the back. */
- os_mbuf_adj(om, -10);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 10, 212,
- sizeof os_mbuf_test_data - 20, 18);
-
- /* Remove entire first buffer. */
- os_mbuf_adj(om, 212);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 222, 0,
- sizeof os_mbuf_test_data - 232, 18);
-
- /* Remove next buffer. */
- os_mbuf_adj(om, 256);
- os_mbuf_test_misc_assert_sane(om, os_mbuf_test_data + 478, 0,
- sizeof os_mbuf_test_data - 488, 18);
-
- /* Remove more data than is present. */
- os_mbuf_adj(om, 1000);
- os_mbuf_test_misc_assert_sane(om, NULL, 0, 0, 18);
-}
-
-TEST_SUITE(os_mbuf_test_suite)
-{
- os_mbuf_test_alloc();
- os_mbuf_test_dup();
- os_mbuf_test_append();
- os_mbuf_test_pullup();
- os_mbuf_test_extend();
- os_mbuf_test_adj();
- os_mbuf_test_get_pkthdr();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/mempool_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/mempool_test.c b/libs/os/src/test/mempool_test.c
deleted file mode 100644
index cd17c90..0000000
--- a/libs/os/src/test/mempool_test.c
+++ /dev/null
@@ -1,227 +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 "testutil/testutil.h"
-#include "os/os.h"
-#include "os_test_priv.h"
-
-/* Create a memory pool for testing */
-#define NUM_MEM_BLOCKS (10)
-#define MEM_BLOCK_SIZE (80)
-
-/* Limit max blocks for testing */
-#define MEMPOOL_TEST_MAX_BLOCKS (128)
-
-#if OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4
-int alignment = 4;
-#else
-int alignment = 8;
-#endif
-
-/* Test memory pool structure */
-struct os_mempool g_TstMempool;
-
-/* Test memory pool buffer */
-os_membuf_t TstMembuf[OS_MEMPOOL_SIZE(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE)];
-
-/* Array of block pointers. */
-void *block_array[MEMPOOL_TEST_MAX_BLOCKS];
-
-int verbose = 0;
-
-static int
-mempool_test_get_pool_size(int num_blocks, int block_size)
-{
- int mem_pool_size;
-
-#if OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4
- mem_pool_size = (num_blocks * ((block_size + 3)/4) * sizeof(os_membuf_t));
-#else
- mem_pool_size = (num_blocks * ((block_size + 7)/8) * sizeof(os_membuf_t));
-#endif
-
- return mem_pool_size;
-}
-
-static void
-mempool_test(int num_blocks, int block_size)
-{
- int cnt;
- int true_block_size;
- int mem_pool_size;
- uint32_t test_block;
- uint8_t *tstptr;
- void **free_ptr;
- void *block;
- os_error_t rc;
-
- /* Check for too many blocks */
- TEST_ASSERT(num_blocks <= MEMPOOL_TEST_MAX_BLOCKS);
-
- rc = os_mempool_init(&g_TstMempool, num_blocks, MEM_BLOCK_SIZE,
- &TstMembuf[0], "TestMemPool");
- TEST_ASSERT_FATAL(rc == 0, "Error creating memory pool %d", rc);
-
- TEST_ASSERT(g_TstMempool.mp_num_free == num_blocks,
- "Number of free blocks not equal to total blocks!");
-
- TEST_ASSERT(SLIST_FIRST(&g_TstMempool) == (void *)&TstMembuf[0],
- "Free list pointer does not point to first block!");
-
- mem_pool_size = mempool_test_get_pool_size(num_blocks, block_size);
- TEST_ASSERT(mem_pool_size == sizeof(TstMembuf),
- "Total memory pool size not correct! (%d vs %lu)",
- mem_pool_size, (unsigned long)sizeof(TstMembuf));
-
- /* Get the real block size */
-#if (OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4)
- true_block_size = (g_TstMempool.mp_block_size + 3) & ~3;
-#else
- true_block_size = (g_TstMempool.mp_block_size + 7) & ~7;
-#endif
-
- /* Traverse free list. Better add up to number of blocks! */
- cnt = 0;
- free_ptr = (void **)&TstMembuf;
- tstptr = (uint8_t *)&TstMembuf;
- while (1) {
- /* Increment # of elements by 1 */
- ++cnt;
-
- /* If the free list is NULL, leave */
- if (*free_ptr == NULL) {
- break;
- }
-
- TEST_ASSERT(((uint8_t *)*free_ptr - (uint8_t *)free_ptr) ==
- true_block_size,
- "Free pointers are more than one block apart!");
-
- /* Move to next memory block */
- tstptr += true_block_size;
-
- TEST_ASSERT(*free_ptr == (void *)tstptr,
- "Error: free_ptr=%p testptr=%p\n", *free_ptr, tstptr);
-
- free_ptr = *free_ptr;
- }
-
- /* Last one in list better be NULL */
- TEST_ASSERT(cnt == g_TstMempool.mp_num_blocks,
- "Free list contains too many elements (%u)", cnt);
-
- /* Get a block */
- block = os_memblock_get(&g_TstMempool);
- TEST_ASSERT(block != NULL,
- "Error: get block fails when pool should have elements");
-
- TEST_ASSERT(g_TstMempool.mp_num_free == (num_blocks-1),
- "Number of free blocks incorrect (%u vs %u)",
- g_TstMempool.mp_num_free, (num_blocks-1));
-
- /* Put back the block */
- rc = os_memblock_put(&g_TstMempool, block);
- TEST_ASSERT(rc == 0, "Put block fails with error code=%d\n", rc);
-
- TEST_ASSERT(g_TstMempool.mp_num_free == num_blocks,
- "Number of free blocks incorrect (%u vs %u)",
- g_TstMempool.mp_num_free, num_blocks);
-
- /* remove all the blocks. Make sure we get count. */
- memset(block_array, 0, sizeof(block_array));
- cnt = 0;
- while (1) {
- block = os_memblock_get(&g_TstMempool);
- if (block == NULL) {
- break;
- }
- block_array[cnt] = block;
- ++cnt;
- if (cnt == MEMPOOL_TEST_MAX_BLOCKS) {
- break;
- }
- }
-
- TEST_ASSERT((cnt == g_TstMempool.mp_num_blocks) &&
- (cnt != MEMPOOL_TEST_MAX_BLOCKS),
- "Got more blocks than mempool contains (%d vs %d)",
- cnt, g_TstMempool.mp_num_blocks);
-
- /* Better be no free blocks left! */
- TEST_ASSERT(g_TstMempool.mp_num_free == 0,
- "Got all blocks but number free not zero! (%d)",
- g_TstMempool.mp_num_free);
-
- /* Now put them all back */
- for (cnt = 0; cnt < g_TstMempool.mp_num_blocks; ++cnt) {
- rc = os_memblock_put(&g_TstMempool, block_array[cnt]);
- TEST_ASSERT(rc == 0,
- "Error putting back block %p (cnt=%d err=%d)",
- block_array[cnt], cnt, rc);
- }
-
- /* Better be no free blocks left! */
- TEST_ASSERT(g_TstMempool.mp_num_free == g_TstMempool.mp_num_blocks,
- "Put all blocks but number free not equal to total!");
-
- /* Better get error when we try these things! */
- rc = os_memblock_put(NULL, block_array[0]);
- TEST_ASSERT(rc != 0,
- "Should have got an error trying to put to null pool");
-
- rc = os_memblock_put(&g_TstMempool, NULL);
- TEST_ASSERT(rc != 0, "No error trying to put to NULL block");
-
- TEST_ASSERT(os_memblock_get(NULL) == NULL,
- "No error trying to get a block from NULL pool");
-
- /* Attempt to free a block outside the range of the membuf */
- test_block = g_TstMempool.mp_membuf_addr;
- test_block -= 4;
- rc = os_memblock_put(&g_TstMempool, (void *)test_block);
- TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
-
- test_block += (true_block_size * g_TstMempool.mp_num_blocks) + 100;
- rc = os_memblock_put(&g_TstMempool, (void *)test_block);
- TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
-
- /* Attempt to free on bad boundary */
- test_block = g_TstMempool.mp_membuf_addr;
- test_block += (true_block_size / 2);
- rc = os_memblock_put(&g_TstMempool, (void *)test_block);
- TEST_ASSERT(rc == OS_INVALID_PARM, "No error freeing bad block address");
-}
-
-/**
- * os mempool test
- *
- * Main test loop for memory pool testing.
- *
- * @return int
- */
-TEST_CASE(os_mempool_test_case)
-{
- mempool_test(NUM_MEM_BLOCKS, MEM_BLOCK_SIZE);
-}
-
-TEST_SUITE(os_mempool_test_suite)
-{
- os_mempool_test_case();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/mutex_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/mutex_test.c b/libs/os/src/test/mutex_test.c
deleted file mode 100644
index ef6a08d..0000000
--- a/libs/os/src/test/mutex_test.c
+++ /dev/null
@@ -1,407 +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 "testutil/testutil.h"
-#include "os/os.h"
-#include "os/os_test.h"
-#include "os/os_cfg.h"
-#include "os/os_mutex.h"
-#include "os_test_priv.h"
-
-#ifdef ARCH_sim
-#define MUTEX_TEST_STACK_SIZE 1024
-#else
-#define MUTEX_TEST_STACK_SIZE 256
-#endif
-
-struct os_task task14;
-os_stack_t stack14[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-struct os_task task15;
-os_stack_t stack15[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-struct os_task task16;
-os_stack_t stack16[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-struct os_task task17;
-os_stack_t stack17[OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE)];
-
-#define TASK14_PRIO (4)
-#define TASK15_PRIO (5)
-#define TASK16_PRIO (6)
-#define TASK17_PRIO (7)
-
-volatile int g_task14_val;
-volatile int g_task15_val;
-volatile int g_task16_val;
-volatile int g_task17_val;
-struct os_mutex g_mutex1;
-struct os_mutex g_mutex2;
-
-static volatile int g_mutex_test;
-
-/**
- * mutex test basic
- *
- * Basic mutex tests
- *
- * @return int
- */
-static void
-mutex_test_basic_handler(void *arg)
-{
- struct os_mutex *mu;
- struct os_task *t;
- os_error_t err;
-
- mu = &g_mutex1;
- t = os_sched_get_current_task();
-
- /* Test some error cases */
- TEST_ASSERT(os_mutex_init(NULL) == OS_INVALID_PARM);
- TEST_ASSERT(os_mutex_release(NULL) == OS_INVALID_PARM);
- TEST_ASSERT(os_mutex_pend(NULL, 0) == OS_INVALID_PARM);
-
- /* Get the mutex */
- err = os_mutex_pend(mu, 0);
- TEST_ASSERT(err == 0,
- "Did not get free mutex immediately (err=%d)", err);
-
- /* Check mutex internals */
- TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 1 &&
- mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
- "Mutex internals not correct after getting mutex\n"
- "Mutex: owner=%p prio=%u level=%u head=%p\n"
- "Task: task=%p prio=%u",
- mu->mu_owner, mu->mu_prio, mu->mu_level,
- SLIST_FIRST(&mu->mu_head),
- t, t->t_prio);
-
- /* Get the mutex again; should be level 2 */
- err = os_mutex_pend(mu, 0);
- TEST_ASSERT(err == 0, "Did not get my mutex immediately (err=%d)", err);
-
- /* Check mutex internals */
- TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 2 &&
- mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
- "Mutex internals not correct after getting mutex\n"
- "Mutex: owner=%p prio=%u level=%u head=%p\n"
- "Task: task=%p prio=%u",
- mu->mu_owner, mu->mu_prio, mu->mu_level,
- SLIST_FIRST(&mu->mu_head), t, t->t_prio);
-
- /* Release mutex */
- err = os_mutex_release(mu);
- TEST_ASSERT(err == 0, "Could not release mutex I own (err=%d)", err);
-
- /* Check mutex internals */
- TEST_ASSERT(mu->mu_owner == t && mu->mu_level == 1 &&
- mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
- "Error: mutex internals not correct after getting mutex\n"
- "Mutex: owner=%p prio=%u level=%u head=%p\n"
- "Task: task=%p prio=%u",
- mu->mu_owner, mu->mu_prio, mu->mu_level,
- SLIST_FIRST(&mu->mu_head), t, t->t_prio);
-
- /* Release it again */
- err = os_mutex_release(mu);
- TEST_ASSERT(err == 0, "Could not release mutex I own (err=%d)", err);
-
- /* Check mutex internals */
- TEST_ASSERT(mu->mu_owner == NULL && mu->mu_level == 0 &&
- mu->mu_prio == t->t_prio && SLIST_EMPTY(&mu->mu_head),
- "Mutex internals not correct after getting mutex\n"
- "Mutex: owner=%p prio=%u level=%u head=%p\n"
- "Task: task=%p prio=%u",
- mu->mu_owner, mu->mu_prio, mu->mu_level,
- SLIST_FIRST(&mu->mu_head), t, t->t_prio);
-
- os_test_restart();
-}
-
-static void
-mutex_test1_task14_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_task14_handler);
-
- for (iters = 0; iters < 3; iters++) {
- os_time_delay(100);
-
- g_task14_val = 1;
-
- err = os_mutex_pend(&g_mutex1, 100);
- TEST_ASSERT(err == OS_OK);
- TEST_ASSERT(g_task16_val == 1);
-
- os_time_delay(100);
- }
-
- os_test_restart();
-}
-
-static void
-mutex_test2_task14_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_task14_handler);
-
- for (iters = 0; iters < 3; iters++) {
- err = os_mutex_pend(&g_mutex1, 0);
- TEST_ASSERT(err == OS_OK, "err=%d", err);
-
- g_task14_val = 1;
- os_time_delay(100);
-
- /*
- * Task17 should have its mutex wait flag set; at least the first time
- * through!
- */
- if (iters == 0) {
- TEST_ASSERT(task17.t_flags & OS_TASK_FLAG_MUTEX_WAIT);
- }
-
- if (g_mutex_test == 4) {
- os_time_delay(150);
- }
-
- os_mutex_release(&g_mutex1);
- os_time_delay(100);
- }
-
- os_test_restart();
-}
-
-static void
-task15_handler(void *arg)
-{
- os_error_t err;
- struct os_task *t;
-
- if (g_mutex_test == 1) {
- while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == task15_handler);
-
- os_time_delay(50);
- while (1) {
- /* Wait here forever */
- }
- }
- } else {
- if (g_mutex_test == 2) {
- /* Sleep for 3 seconds */
- t = os_sched_get_current_task();
- os_time_delay(500);
- } else if (g_mutex_test == 3) {
- /* Sleep for 3 seconds */
- t = os_sched_get_current_task();
- os_time_delay(30);
- }
-
- while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == task15_handler);
-
- err = os_mutex_pend(&g_mutex1, 10000);
- if (g_mutex_test == 4) {
- TEST_ASSERT(err == OS_TIMEOUT);
- } else {
- TEST_ASSERT(err == OS_OK);
- }
-
- os_time_delay(100);
- }
- }
-}
-
-static void
-task16_handler(void *arg)
-{
- os_error_t err;
- struct os_task *t;
-
- if (g_mutex_test == 1) {
- while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == task16_handler);
-
- /* Get mutex 1 */
- err = os_mutex_pend(&g_mutex1, 0xFFFFFFFF);
- TEST_ASSERT(err == OS_OK);
-
- while (g_task14_val != 1) {
- /* Wait till task 1 wakes up and sets val. */
- }
-
- g_task16_val = 1;
-
- err = os_mutex_release(&g_mutex1);
- TEST_ASSERT(err == OS_OK);
- }
- } else {
- if (g_mutex_test == 2) {
- /* Sleep for 3 seconds */
- t = os_sched_get_current_task();
- os_time_delay(30);
- } else if (g_mutex_test == 3) {
- /* Sleep for 3 seconds */
- t = os_sched_get_current_task();
- os_time_delay(50);
- }
-
- while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == task16_handler);
-
- err = os_mutex_pend(&g_mutex1, 10000);
- if (g_mutex_test == 4) {
- TEST_ASSERT(err == OS_TIMEOUT);
- } else {
- TEST_ASSERT(err == OS_OK);
- }
-
- if (err == OS_OK) {
- err = os_mutex_release(&g_mutex1);
- TEST_ASSERT(err == OS_OK);
- }
-
- os_time_delay(10000);
- }
- }
-}
-
-static void
-task17_handler(void *arg)
-{
- os_error_t err;
- struct os_task *t;
-
- while (1) {
- t = os_sched_get_current_task();
- TEST_ASSERT(t->t_func == task17_handler);
-
- if (g_mutex_test == 5) {
- err = os_mutex_pend(&g_mutex1, 10);
- } else {
- err = os_mutex_pend(&g_mutex1, 10000);
- TEST_ASSERT((t->t_flags & OS_TASK_FLAG_MUTEX_WAIT) == 0);
- }
-
- if (g_mutex_test == 4 || g_mutex_test == 5) {
- TEST_ASSERT(err == OS_TIMEOUT);
- } else {
- TEST_ASSERT(err == OS_OK);
- }
-
- if (err == OS_OK) {
- err = os_mutex_release(&g_mutex1);
- TEST_ASSERT(err == OS_OK);
- }
-
- os_time_delay(10000);
- }
-}
-
-TEST_CASE(os_mutex_test_basic)
-{
- os_init();
-
- os_mutex_init(&g_mutex1);
-
- os_task_init(&task14, "task14", mutex_test_basic_handler, NULL,
- TASK14_PRIO, OS_WAIT_FOREVER, stack14,
- OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_start();
-}
-
-TEST_CASE(os_mutex_test_case_1)
-{
- int rc;
-
- os_init();
-
- g_mutex_test = 1;
- g_task14_val = 0;
- g_task15_val = 0;
- g_task16_val = 0;
-
- rc = os_mutex_init(&g_mutex1);
- TEST_ASSERT(rc == 0);
- rc = os_mutex_init(&g_mutex2);
- TEST_ASSERT(rc == 0);
-
- os_task_init(&task14, "task14", mutex_test1_task14_handler, NULL,
- TASK14_PRIO, OS_WAIT_FOREVER, stack14,
- OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO,
- OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO,
- OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_start();
-}
-
-TEST_CASE(os_mutex_test_case_2)
-{
- os_init();
-
- g_mutex_test = 2;
- g_task14_val = 0;
- g_task15_val = 0;
- g_task16_val = 0;
- os_mutex_init(&g_mutex1);
- os_mutex_init(&g_mutex2);
-
- os_task_init(&task14, "task14", mutex_test2_task14_handler, NULL,
- TASK14_PRIO, OS_WAIT_FOREVER, stack14,
- OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_task_init(&task15, "task15", task15_handler, NULL, TASK15_PRIO,
- OS_WAIT_FOREVER, stack15, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_task_init(&task16, "task16", task16_handler, NULL, TASK16_PRIO,
- OS_WAIT_FOREVER, stack16, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_task_init(&task17, "task17", task17_handler, NULL, TASK17_PRIO,
- OS_WAIT_FOREVER, stack17, OS_STACK_ALIGN(MUTEX_TEST_STACK_SIZE));
-
- os_start();
-}
-
-TEST_SUITE(os_mutex_test_suite)
-{
- os_mutex_test_basic();
- os_mutex_test_case_1();
- os_mutex_test_case_2();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/os_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/os_test.c b/libs/os/src/test/os_test.c
deleted file mode 100644
index 1b3af1a..0000000
--- a/libs/os/src/test/os_test.c
+++ /dev/null
@@ -1,52 +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 <assert.h>
-#include <stddef.h>
-#include "testutil/testutil.h"
-#include "os/os_test.h"
-#include "os_test_priv.h"
-
-int
-os_test_all(void)
-{
- os_mempool_test_suite();
- os_mutex_test_suite();
- os_sem_test_suite();
- os_mbuf_test_suite();
- os_eventq_test_suite();
-
-
- return tu_case_failed;
-}
-
-#ifdef MYNEWT_SELFTEST
-
-int
-main(int argc, char **argv)
-{
- tu_config.tc_print_results = 1;
- tu_init();
-
- os_test_all();
-
- return tu_any_failed;
-}
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/libs/os/src/test/os_test_priv.h
----------------------------------------------------------------------
diff --git a/libs/os/src/test/os_test_priv.h b/libs/os/src/test/os_test_priv.h
deleted file mode 100644
index 5193c33..0000000
--- a/libs/os/src/test/os_test_priv.h
+++ /dev/null
@@ -1,32 +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_OS_TEST_PRIV_
-#define H_OS_TEST_PRIV_
-
-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);
-
-
-#endif