-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add CLI input mode to test runner #2955
Changes from all commits
22c1771
83be257
4b74a3b
0fabb5f
39e3037
c58fe45
af8b5bb
323bd90
87c592f
954584b
d9ad3cb
1960949
c8fa02c
c42eeaf
c587153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,15 @@ | |
/* Application version info. */ | ||
#include "aws_application_version.h" | ||
|
||
/* Include files for UART based FreeRTOS+CLI support of test runner. | ||
* Note: This adds a dependency on Common IO for UART communication .*/ | ||
#if defined( AWS_TEST_RUNNER_ENABLE_CLI_INPUT ) && ( AWS_TEST_RUNNER_ENABLE_CLI_INPUT == 1 ) | ||
#include <string.h> | ||
#include "FreeRTOS_CLI.h" | ||
#include "FreeRTOS_CLI_UART.h" | ||
#include "iot_uart.h" | ||
#endif | ||
|
||
/** | ||
* Default value of delay period before the execution of tests on device. | ||
*/ | ||
|
@@ -67,7 +76,7 @@ unsigned int xHeapAfter; | |
* do not change the signature of it. You could, however, add or remove | ||
* RUN_TEST_GROUP statements. | ||
*/ | ||
static void RunTests( void ) | ||
static void RunTestSuites( void ) | ||
{ | ||
/* Tests can be disabled in aws_test_runner_config.h */ | ||
|
||
|
@@ -265,25 +274,9 @@ static void RunTests( void ) | |
RUN_TEST_GROUP( deviceShadow_Integration ); | ||
#endif | ||
} | ||
/*-----------------------------------------------------------*/ | ||
|
||
void TEST_RUNNER_RunTests_task( void * pvParameters ) | ||
void RunTestsWrapper() | ||
{ | ||
/* Disable unused parameter warning. */ | ||
( void ) pvParameters; | ||
|
||
/* Initialize unity. */ | ||
UnityFixture.Verbose = 1; | ||
UnityFixture.GroupFilter = 0; | ||
UnityFixture.NameFilter = testrunnerTEST_FILTER; | ||
UnityFixture.RepeatCount = 1; | ||
|
||
/* Add sufficient delay before starting tests on device to allow | ||
* device to be available as serial port connection to the host machine | ||
* OS. | ||
* The serial console is used by host machine to view device logs. */ | ||
vTaskDelay( pdMS_TO_TICKS( AWS_TEST_RUNNER_DELAY_MS ) ); | ||
|
||
UNITY_BEGIN(); | ||
|
||
/* Give the print buffer time to empty */ | ||
|
@@ -293,7 +286,7 @@ void TEST_RUNNER_RunTests_task( void * pvParameters ) | |
xHeapBefore = xPortGetFreeHeapSize(); | ||
#endif | ||
|
||
RunTests(); | ||
RunTestSuites(); | ||
|
||
#if ( testrunnerFULL_MEMORYLEAK_ENABLED == 1 ) | ||
|
||
|
@@ -313,6 +306,132 @@ void TEST_RUNNER_RunTests_task( void * pvParameters ) | |
|
||
/* Currently disabled. Will be enabled after cleanup. */ | ||
UNITY_END(); | ||
} | ||
|
||
/*-----------------------------------------------------------*/ | ||
#if defined( AWS_TEST_RUNNER_ENABLE_CLI_INPUT ) && ( AWS_TEST_RUNNER_ENABLE_CLI_INPUT == 1 ) | ||
|
||
/* Global flag that represents whether a "start" command is received | ||
* on the serial console. */ | ||
static BaseType_t xReceivedCommand = pdFALSE; | ||
|
||
/** | ||
* @brief The command handler for the "start" command recognized by the | ||
* serial console of the FreeRTOS test runner. On receiving the command, | ||
* the test runner begins executing tests on the device. | ||
* | ||
* @return Returns pdFALSE to indicate completion of execution of tests. | ||
*/ | ||
static BaseType_t prvRunTestsCommand( int8_t * pcWriteBuffer, | ||
size_t xWriteBufferLen, | ||
const int8_t * pcCommandString ) | ||
{ | ||
( void ) pcWriteBuffer; | ||
( void ) xWriteBufferLen; | ||
( void ) pcCommandString; | ||
|
||
/* Set flag to indicate reception of command from serial console to start */ | ||
/* executing tests. */ | ||
xReceivedCommand = pdTRUE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An "OK" response back to the peer here will help in debugging a broken CLI connection to the actual test issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the response to acknowledge processing of command. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per offline discussion, removed the response for now as the response would be visible only at the end of the test execution. We can consider adding the response string later if there are architectural changes of running the CLI console in a different task than the test runner. |
||
|
||
RunTestsWrapper(); | ||
|
||
return pdFALSE; | ||
} | ||
|
||
/* Definition of a FreeRTOS+CLI command to instruct the test runner start executing commands. | ||
* The command takes no parameters. */ | ||
static const CLI_Command_Definition_t xStartCommand = | ||
{ | ||
"start", | ||
"start : Instructs test runner to start executing tests on the board.", | ||
prvRunTestsCommand, /* The handler for the command. */ | ||
0 /* Zero number of parameters. */ | ||
}; | ||
|
||
/* Size of the buffer fot storing input command from serial console. */ | ||
#define cmdMAX_INPUT_SIZE 20 | ||
|
||
/* Size of buffer for storing output string for the serial console of test runner. */ | ||
#define cmdMAX_OUTPUT_SIZE 100 | ||
|
||
void prvTestRunnerConsole() | ||
{ | ||
int32_t bytesRead; | ||
int8_t serialInputChar; | ||
|
||
static const char * const pcWelcomeMessage = | ||
"Welcome to the Test Runner console.\r\n[Type the \"start\" command to beging executing tests]\r\n>"; | ||
|
||
/* Register the "start" command that will allow user to signal from the serial console | ||
* about when to start execution of tests by the test runner. */ | ||
FreeRTOS_CLIRegisterCommand( &xStartCommand ); | ||
|
||
/* Print welcome message on serial console to indicate prompt for entering command. */ | ||
uartConsoleIO.write( pcWelcomeMessage, strlen( pcWelcomeMessage ) ); | ||
|
||
/* The input and output buffers are declared static to keep them off the stack. */ | ||
static int8_t pOutputBuffer[ cmdMAX_OUTPUT_SIZE ], pInputBuffer[ cmdMAX_INPUT_SIZE ], pErrorBuffer[ 30 ]; | ||
BaseType_t xErrorEncountered = pdFALSE; | ||
|
||
while( ( xReceivedCommand == pdFALSE ) && ( xErrorEncountered == pdFALSE ) ) | ||
{ | ||
static size_t inputBufferIndex = 0; | ||
|
||
/* Read characters to input buffer. */ | ||
bytesRead = uartConsoleIO.read( &serialInputChar, 1 ); | ||
|
||
if( bytesRead > 0 ) | ||
{ | ||
/* Echo back to the console. */ | ||
uartConsoleIO.write( &serialInputChar, bytesRead ); | ||
|
||
FreeRTOS_CLI_ProcessInputBuffer( uartConsoleIO, | ||
&serialInputChar, | ||
bytesRead, | ||
pInputBuffer, | ||
sizeof( pInputBuffer ), | ||
&inputBufferIndex, | ||
pOutputBuffer, | ||
sizeof( pOutputBuffer ) ); | ||
} | ||
else | ||
{ | ||
snprintf( pErrorBuffer, | ||
sizeof( pErrorBuffer ), | ||
"Read from serial console failed. Error=%d\n", | ||
( int ) bytesRead ); | ||
uartConsoleIO.write( pErrorBuffer, strlen( pErrorBuffer ) ); | ||
|
||
xErrorEncountered = pdTRUE; | ||
} | ||
} | ||
} | ||
#endif /* if defined( AWS_TEST_RUNNER_ENABLE_CLI_INPUT ) && ( AWS_TEST_RUNNER_ENABLE_CLI_INPUT == 1 ) */ | ||
|
||
void TEST_RUNNER_RunTests_task( void * pvParameters ) | ||
{ | ||
/* Disable unused parameter warning. */ | ||
( void ) pvParameters; | ||
|
||
/* Initialize unity. */ | ||
UnityFixture.Verbose = 1; | ||
UnityFixture.GroupFilter = 0; | ||
UnityFixture.NameFilter = testrunnerTEST_FILTER; | ||
UnityFixture.RepeatCount = 1; | ||
|
||
#if defined( AWS_TEST_RUNNER_ENABLE_CLI_INPUT ) && ( AWS_TEST_RUNNER_ENABLE_CLI_INPUT == 1 ) | ||
prvTestRunnerConsole(); | ||
#else | ||
|
||
/* Add sufficient delay before starting tests on device to allow | ||
* device to be available as serial port connection to the host machine | ||
* OS. | ||
* The serial console is used by host machine to view device logs. */ | ||
vTaskDelay( pdMS_TO_TICKS( AWS_TEST_RUNNER_DELAY_MS ) ); | ||
|
||
RunTestsWrapper(); | ||
#endif | ||
|
||
#ifdef CODE_COVERAGE | ||
exit( 0 ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates some code in
FreeRTOS_CLI_ProcessInputBuffer
to handle the exiting the CLI loop. Can we keep code same and instead add a new command such asexit
for the loop to exit gracefully.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed offline and decided that we can add a
exit
command support to theFreeRTOS_CLIEnterConsoleLoop
function to allow the console loop to be terminated in a separate PR.