[api] remove UART from in cli/ncp API (#6243)

This commit removes application library CLI/NCP dependency on platform
layer UART APIs. Instead, application layer provides callbacks sending
CLI/NCP data.

With this change, platforms with native support for formatted output
can simply implement the CLI output callback with something like
`vprintf()`.
This commit is contained in:
Yakun Xu
2021-03-18 22:13:05 -07:00
committed by GitHub
parent 3d10c90da4
commit db1b980e57
113 changed files with 1227 additions and 1473 deletions
+10 -10
View File
@@ -47,22 +47,22 @@ set(COMMON_LIBS
ot-config
)
add_executable(cli-uart-received-fuzzer
cli_uart_received.cpp
add_executable(cli-received-fuzzer
cli_received.cpp
${COMMON_SOURCES}
)
target_compile_options(cli-uart-received-fuzzer
target_compile_options(cli-received-fuzzer
PRIVATE
${COMMON_COMPILE_OPTIONS}
)
target_include_directories(cli-uart-received-fuzzer
target_include_directories(cli-received-fuzzer
PRIVATE
${COMMON_INCLUDES}
)
target_link_libraries(cli-uart-received-fuzzer
target_link_libraries(cli-received-fuzzer
PRIVATE
openthread-cli-ftd
${COMMON_LIBS}
@@ -108,22 +108,22 @@ target_link_libraries(radio-receive-done-fuzzer
${COMMON_LIBS}
)
add_executable(ncp-uart-received-fuzzer
ncp_uart_received.cpp
add_executable(ncp-hdlc-received-fuzzer
ncp_hdlc_received.cpp
${COMMON_SOURCES}
)
target_compile_options(ncp-uart-received-fuzzer
target_compile_options(ncp-hdlc-received-fuzzer
PRIVATE
${COMMON_COMPILE_OPTIONS}
)
target_include_directories(ncp-uart-received-fuzzer
target_include_directories(ncp-hdlc-received-fuzzer
PRIVATE
${COMMON_INCLUDES}
)
target_link_libraries(ncp-uart-received-fuzzer
target_link_libraries(ncp-hdlc-received-fuzzer
PRIVATE
openthread-ncp-ftd
${COMMON_LIBS}
+8 -8
View File
@@ -29,10 +29,10 @@
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
bin_PROGRAMS = \
cli-uart-received-fuzzer \
cli-received-fuzzer \
ip6-send-fuzzer \
radio-receive-done-fuzzer \
ncp-uart-received-fuzzer \
ncp-hdlc-received-fuzzer \
$(NULL)
AM_CPPFLAGS = \
@@ -51,14 +51,14 @@ COMMON_SOURCES = \
fuzzer_platform.h \
$(NULL)
cli_uart_received_fuzzer_LDADD = \
cli_received_fuzzer_LDADD = \
$(top_builddir)/src/cli/libopenthread-cli-ftd.a \
$(COMMON_LDADD) \
$(NULL)
cli_uart_received_fuzzer_SOURCES = \
cli_received_fuzzer_SOURCES = \
$(COMMON_SOURCES) \
cli_uart_received.cpp \
cli_received.cpp \
$(NULL)
ip6_send_fuzzer_LDADD = \
@@ -79,14 +79,14 @@ radio_receive_done_fuzzer_SOURCES = \
radio_receive_done.cpp \
$(NULL)
ncp_uart_received_fuzzer_LDADD = \
ncp_hdlc_received_fuzzer_LDADD = \
$(top_builddir)/src/ncp/libopenthread-ncp-ftd.a \
$(COMMON_LDADD) \
$(NULL)
ncp_uart_received_fuzzer_SOURCES = \
ncp_hdlc_received_fuzzer_SOURCES = \
$(COMMON_SOURCES) \
ncp_uart_received.cpp \
ncp_hdlc_received.cpp \
$(NULL)
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
@@ -28,6 +28,8 @@
#define MAX_ITERATIONS 100
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -38,11 +40,19 @@
#include <openthread/tasklet.h>
#include <openthread/thread.h>
#include <openthread/thread_ftd.h>
#include <openthread/platform/uart.h>
#include "fuzzer_platform.h"
#include "common/code_utils.hpp"
static int CliOutput(void *aContext, const char *aFormat, va_list aArguments)
{
OT_UNUSED_VARIABLE(aContext);
OT_UNUSED_VARIABLE(aFormat);
OT_UNUSED_VARIABLE(aArguments);
return vsnprintf(nullptr, 0, aFormat, aArguments);
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
const otPanId panId = 0xdead;
@@ -55,17 +65,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
FuzzerPlatformInit();
instance = otInstanceInitSingle();
otCliUartInit(instance);
otCliInit(instance, CliOutput, nullptr);
IgnoreError(otLinkSetPanId(instance, panId));
IgnoreError(otIp6SetEnabled(instance, true));
IgnoreError(otThreadSetEnabled(instance, true));
IgnoreError(otThreadBecomeLeader(instance));
buf = static_cast<uint8_t *>(malloc(size));
buf = static_cast<uint8_t *>(malloc(size + 1));
memcpy(buf, data, size);
buf[size] = '\0';
otPlatUartReceived(buf, (uint16_t)size);
otCliInputLine(reinterpret_cast<char *>(buf));
VerifyOrExit(!FuzzerPlatformResetWasRequested());
-23
View File
@@ -40,7 +40,6 @@
#include <openthread/platform/misc.h>
#include <openthread/platform/radio.h>
#include <openthread/platform/settings.h>
#include <openthread/platform/uart.h>
#include "mac/mac_frame.hpp"
@@ -493,28 +492,6 @@ void otPlatSettingsWipe(otInstance *aInstance)
OT_UNUSED_VARIABLE(aInstance);
}
otError otPlatUartEnable(void)
{
return OT_ERROR_NONE;
}
otError otPlatUartDisable(void)
{
return OT_ERROR_NONE;
}
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
{
OT_UNUSED_VARIABLE(aBuf);
OT_UNUSED_VARIABLE(aBufLength);
return OT_ERROR_NONE;
}
otError otPlatUartFlush(void)
{
return OT_ERROR_NOT_IMPLEMENTED;
}
otError otPlatDiagProcess(otInstance *aInstance,
uint8_t aArgsLength,
char * aArgs[],
@@ -38,11 +38,18 @@
#include <openthread/tasklet.h>
#include <openthread/thread.h>
#include <openthread/thread_ftd.h>
#include <openthread/platform/uart.h>
#include "fuzzer_platform.h"
#include "common/code_utils.hpp"
static int HdlcSend(const uint8_t *aBuf, uint16_t aBufLength)
{
OT_UNUSED_VARIABLE(aBuf);
OT_UNUSED_VARIABLE(aBufLength);
return aBufLength;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
const otPanId panId = 0xdead;
@@ -55,7 +62,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
FuzzerPlatformInit();
instance = otInstanceInitSingle();
otNcpInit(instance);
otNcpHdlcInit(instance, HdlcSend);
IgnoreError(otLinkSetPanId(instance, panId));
IgnoreError(otIp6SetEnabled(instance, true));
IgnoreError(otThreadSetEnabled(instance, true));
@@ -65,7 +72,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
memcpy(buf, data, size);
otPlatUartReceived(buf, (uint16_t)size);
otNcpHdlcReceive(buf, static_cast<uint16_t>(size));
VerifyOrExit(!FuzzerPlatformResetWasRequested());