From c4b098f0d33704a7d26695cb09654d947529b0b4 Mon Sep 17 00:00:00 2001 From: kangping Date: Fri, 1 May 2020 03:27:42 +0800 Subject: [PATCH] [instance] fix multiple instance compilation (#4915) --- .github/workflows/simulation.yml | 22 ++++++++++++++++++++++ etc/cmake/options.cmake | 5 +++++ examples/common-switches.mk | 5 +++++ src/core/common/instance.cpp | 4 ++-- src/core/common/instance.hpp | 6 ++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/simulation.yml b/.github/workflows/simulation.yml index c2f1b5e29..de332acc7 100644 --- a/.github/workflows/simulation.yml +++ b/.github/workflows/simulation.yml @@ -153,6 +153,28 @@ jobs: - name: Codecov uses: codecov/codecov-action@v1 + multiple-instance: + runs-on: ubuntu-18.04 + env: + COVERAGE: 1 + MULTIPLE_INSTANCE: 1 + REFERENCE_DEVICE: 1 + VIRTUAL_TIME: 1 + steps: + - uses: actions/checkout@v2 + - name: Bootstrap + run: | + python3 -m pip install -r tests/scripts/thread-cert/requirements.txt + - name: Build + run: | + ./bootstrap + make -f examples/Makefile-simulation + - name: Run + run: | + VERBOSE=1 make -f examples/Makefile-simulation check + - name: Codecov + uses: codecov/codecov-action@v1 + ncp: runs-on: ubuntu-18.04 env: diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 9cf507fa6..129386781 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -161,6 +161,11 @@ if(OT_MTD_NETDIAG) list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE=1") endif() +option(OT_MULTIPLE_INSTANCE "enable multiple instances") +if(OT_MULTIPLE_INSTANCE) + list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE=1") +endif() + option(OT_PLATFORM_NETIF "enable platform netif support") if(OT_PLATFORM_NETIF) list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE=1") diff --git a/examples/common-switches.mk b/examples/common-switches.mk index fd87ea005..aecc85cfa 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -61,6 +61,7 @@ endif LINK_RAW ?= 0 MAC_FILTER ?= 0 MTD_NETDIAG ?= 0 +MULTIPLE_INSTANCE ?= 0 OTNS ?= 0 PLATFORM_UDP ?= 0 REFERENCE_DEVICE ?= 0 @@ -198,6 +199,10 @@ ifeq ($(MTD_NETDIAG),1) COMMONCFLAGS += -DOPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE=1 endif +ifeq ($(MULTIPLE_INSTANCE),1) +COMMONCFLAGS += -DOPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE=1 +endif + ifeq ($(PLATFORM_UDP),1) COMMONCFLAGS += -DOPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE=1 endif diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index 80a964907..9fca329be 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -143,12 +143,12 @@ Instance *Instance::Init(void *aBuffer, size_t *aBufferSize) { Instance *instance = NULL; - VerifyOrExit(aBufferSize != NULL); + VerifyOrExit(aBufferSize != NULL, OT_NOOP); // Make sure the input buffer is big enough VerifyOrExit(sizeof(Instance) <= *aBufferSize, *aBufferSize = sizeof(Instance)); - VerifyOrExit(aBuffer != NULL); + VerifyOrExit(aBuffer != NULL, OT_NOOP); instance = new (aBuffer) Instance(); diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index d80dc8b36..124964c9d 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -42,6 +42,9 @@ #include #include #include +#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE +#include +#endif #include "common/random_manager.hpp" #include "common/tasklet.hpp" @@ -261,6 +264,9 @@ public: * */ Utils::Heap &GetHeap(void) { return mHeap; } +#else + void HeapFree(void *aPointer) { otPlatFree(aPointer); } + void *HeapCAlloc(size_t aCount, size_t aSize) { return otPlatCAlloc(aCount, aSize); } #endif // OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE #if OPENTHREAD_CONFIG_COAP_API_ENABLE