[posix] enhance reset implementation to support code coverage (#3071)

This commit is contained in:
Yakun Xu
2018-09-14 10:59:07 -10:00
committed by Jonathan Hui
parent a23f778e11
commit ed794337e7
10 changed files with 78 additions and 43 deletions
+4
View File
@@ -129,6 +129,10 @@ ot_cli_mtd_LDFLAGS += -Wl,-Ma
endif
if OPENTHREAD_BUILD_COVERAGE
CPPFLAGS_COMMON += \
-DOPENTHREAD_ENABLE_COVERAGE \
$(NULL)
CLEANFILES = $(wildcard *.gcda *.gcno)
endif # OPENTHREAD_BUILD_COVERAGE
+20
View File
@@ -37,6 +37,15 @@
#include "openthread-system.h"
#if OPENTHREAD_EXAMPLES_POSIX
#include <setjmp.h>
#include <unistd.h>
jmp_buf gResetJump;
void __gcov_flush();
#endif
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
void *otPlatCAlloc(size_t aNum, size_t aSize)
{
@@ -58,6 +67,17 @@ int main(int argc, char *argv[])
{
otInstance *sInstance;
#if OPENTHREAD_EXAMPLES_POSIX
if (setjmp(gResetJump))
{
alarm(0);
#if OPENTHREAD_ENABLE_COVERAGE
__gcov_flush();
#endif
execvp(argv[0], argv);
}
#endif
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
size_t otInstanceBufferLength = 0;
uint8_t *otInstanceBuffer = NULL;
+4
View File
@@ -180,6 +180,10 @@ ot_ncp_radio_LDFLAGS += -Wl,-Ma
endif
if OPENTHREAD_BUILD_COVERAGE
CPPFLAGS_COMMON += \
-DOPENTHREAD_ENABLE_COVERAGE \
$(NULL)
CLEANFILES = $(wildcard *.gcda *.gcno)
endif # OPENTHREAD_BUILD_COVERAGE
+20
View File
@@ -36,6 +36,15 @@
#include "openthread-system.h"
#if OPENTHREAD_EXAMPLES_POSIX
#include <setjmp.h>
#include <unistd.h>
jmp_buf gResetJump;
void __gcov_flush();
#endif
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
void *otPlatCAlloc(size_t aNum, size_t aSize)
{
@@ -57,6 +66,17 @@ int main(int argc, char *argv[])
{
otInstance *sInstance;
#if OPENTHREAD_EXAMPLES_POSIX
if (setjmp(gResetJump))
{
alarm(0);
#if OPENTHREAD_ENABLE_COVERAGE
__gcov_flush();
#endif
execvp(argv[0], argv);
}
#endif
#if OPENTHREAD_ENABLE_MULTIPLE_INSTANCES
size_t otInstanceBufferLength = 0;
uint8_t *otInstanceBuffer = NULL;
+4
View File
@@ -71,6 +71,10 @@ libopenthread_posix_a_LIBADD = \
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o")
if OPENTHREAD_BUILD_COVERAGE
libopenthread_posix_a_CPPFLAGS += \
-DOPENTHREAD_ENABLE_COVERAGE \
$(NULL)
CLEANFILES = $(wildcard *.gcda *.gcno)
endif # OPENTHREAD_BUILD_COVERAGE
+4 -16
View File
@@ -29,6 +29,7 @@
#include "platform-posix.h"
#ifndef _WIN32
#include <setjmp.h>
#include <unistd.h>
#endif
@@ -37,8 +38,7 @@
#include "openthread-system.h"
#ifndef _WIN32
extern int gArgumentsCount;
extern char **gArguments;
extern jmp_buf gResetJump;
#endif
static otPlatResetReason sPlatResetReason = OT_PLAT_RESET_REASON_POWER_ON;
@@ -56,23 +56,11 @@ void otPlatReset(otInstance *aInstance)
#else // elif OPENTHREAD_PLATFORM_USE_PSEUDO_RESET
// Restart the process using execvp.
char *argv[gArgumentsCount + 1];
for (int i = 0; i < gArgumentsCount; ++i)
{
argv[i] = gArguments[i];
}
argv[gArgumentsCount] = NULL;
otSysDeinit();
platformUartRestore();
alarm(0);
execvp(argv[0], argv);
perror("reset failed");
exit(EXIT_FAILURE);
longjmp(gResetJump, 1);
assert(false);
#endif // else OPENTHREAD_PLATFORM_USE_PSEUDO_RESET
-6
View File
@@ -59,9 +59,6 @@ extern bool gPlatformPseudoResetWasRequested;
static volatile bool gTerminate = false;
#ifndef _WIN32
int gArgumentsCount = 0;
char **gArguments = NULL;
static void handleSignal(int aSignal)
{
(void)aSignal;
@@ -90,9 +87,6 @@ void otSysInit(int aArgCount, char *aArgVector[])
openlog(basename(aArgVector[0]), LOG_PID, LOG_USER);
setlogmask(setlogmask(0) & LOG_UPTO(LOG_NOTICE));
gArgumentsCount = aArgCount;
gArguments = aArgVector;
signal(SIGTERM, &handleSignal);
signal(SIGHUP, &handleSignal);
#endif
+4
View File
@@ -145,6 +145,10 @@ ot_cli_LDFLAGS += -Wl,-Ma
endif
if OPENTHREAD_BUILD_COVERAGE
CPPFLAGS_COMMON += \
-DOPENTHREAD_ENABLE_COVERAGE \
$(NULL)
CLEANFILES = $(wildcard *.gcda *.gcno)
endif # OPENTHREAD_BUILD_COVERAGE
+14 -3
View File
@@ -29,6 +29,8 @@
#include <assert.h>
#include <openthread-core-config.h>
#include <setjmp.h>
#include <unistd.h>
#include <openthread/config.h>
#define OPENTHREAD_POSIX_APP_NCP 1
@@ -47,6 +49,10 @@
#include "openthread-system.h"
jmp_buf gResetJump;
void __gcov_flush();
void otTaskletsSignalPending(otInstance *aInstance)
{
(void)aInstance;
@@ -56,7 +62,14 @@ int main(int argc, char *argv[])
{
otInstance *sInstance;
pseudo_reset:
if (setjmp(gResetJump))
{
alarm(0);
#if OPENTHREAD_ENABLE_COVERAGE
__gcov_flush();
#endif
execvp(argv[0], argv);
}
otSysInit(argc, argv);
@@ -81,8 +94,6 @@ pseudo_reset:
otInstanceFinalize(sInstance);
goto pseudo_reset;
return 0;
}
+4 -18
View File
@@ -28,14 +28,14 @@
#include "platform-posix.h"
#include <setjmp.h>
#include <unistd.h>
#include <openthread/platform/misc.h>
#include "openthread-system.h"
extern int gArgumentsCount;
extern char **gArguments;
extern jmp_buf gResetJump;
static otPlatResetReason sPlatResetReason = OT_PLAT_RESET_REASON_POWER_ON;
bool gPlatformPseudoResetWasRequested;
@@ -43,31 +43,17 @@ static otPlatMcuPowerState gPlatMcuPowerState = OT_PLAT_MCU_POWER_STATE_ON;
void otPlatReset(otInstance *aInstance)
{
int i = 0;
// Restart the process using execvp.
char *argv[gArgumentsCount + 1];
#if OPENTHREAD_PLATFORM_USE_PSEUDO_RESET
gPlatformPseudoResetWasRequested = true;
sPlatResetReason = OT_PLAT_RESET_REASON_SOFTWARE;
#else // elif OPENTHREAD_PLATFORM_USE_PSEUDO_RESET
for (i = 0; i < gArgumentsCount; ++i)
{
argv[i] = gArguments[i];
}
argv[gArgumentsCount] = NULL;
otSysDeinit();
platformUartRestore();
alarm(0);
execvp(argv[0], argv);
perror("reset failed");
exit(EXIT_FAILURE);
longjmp(gResetJump, 1);
assert(false);
#endif // else OPENTHREAD_PLATFORM_USE_PSEUDO_RESET