Merge pull request #4364 from mazimkhan/mbed-tls-test

Add C API for Greentea client
pull/4592/head
Jimmy Brisson 2017-06-19 11:58:47 -05:00 committed by GitHub
commit 1ffbdfc048
2 changed files with 31 additions and 16 deletions

View File

@ -21,6 +21,7 @@
#ifndef GREENTEA_CLIENT_TEST_ENV_H_ #ifndef GREENTEA_CLIENT_TEST_ENV_H_
#define GREENTEA_CLIENT_TEST_ENV_H_ #define GREENTEA_CLIENT_TEST_ENV_H_
#ifdef __cplusplus
#ifdef YOTTA_GREENTEA_CLIENT_VERSION_STRING #ifdef YOTTA_GREENTEA_CLIENT_VERSION_STRING
#define MBED_GREENTEA_CLIENT_VERSION_STRING YOTTA_GREENTEA_CLIENT_VERSION_STRING #define MBED_GREENTEA_CLIENT_VERSION_STRING YOTTA_GREENTEA_CLIENT_VERSION_STRING
#else #else
@ -81,7 +82,6 @@ extern const char* GREENTEA_TEST_ENV_LCOV_START;
/** /**
* Greentea-client related API for communication with host side * Greentea-client related API for communication with host side
*/ */
void GREENTEA_SETUP(const int, const char *);
void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *buffer, size_t size); void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *buffer, size_t size);
void GREENTEA_TESTSUITE_RESULT(const int); void GREENTEA_TESTSUITE_RESULT(const int);
void GREENTEA_TESTCASE_START(const char *test_case_name); void GREENTEA_TESTCASE_START(const char *test_case_name);
@ -90,12 +90,10 @@ void GREENTEA_TESTCASE_FINISH(const char *test_case_name, const size_t passes, c
/** /**
* Test suite result related notification API * Test suite result related notification API
*/ */
void greentea_send_kv(const char *, const char *);
void greentea_send_kv(const char *, const int); void greentea_send_kv(const char *, const int);
void greentea_send_kv(const char *, const int, const int); void greentea_send_kv(const char *, const int, const int);
void greentea_send_kv(const char *, const char *, const int); void greentea_send_kv(const char *, const char *, const int);
void greentea_send_kv(const char *, const char *, const int, const int); void greentea_send_kv(const char *, const char *, const int, const int);
int greentea_parse_kv(char *, char *, const int, const int);
#ifdef MBED_CFG_DEBUG_OPTIONS_COVERAGE #ifdef MBED_CFG_DEBUG_OPTIONS_COVERAGE
/** /**
@ -105,6 +103,25 @@ void greentea_notify_coverage_start(const char *path);
void greentea_notify_coverage_end(); void greentea_notify_coverage_end();
#endif // MBED_CFG_DEBUG_OPTIONS_COVERAGE #endif // MBED_CFG_DEBUG_OPTIONS_COVERAGE
#endif // __cplusplus
#ifdef __cplusplus
extern "C" {
#endif
/**
* Greentea-client C API
*/
void GREENTEA_SETUP(const int timeout, const char * host_test);
void greentea_send_kv(const char * key, const char * val);
int greentea_parse_kv(char * key, char * val,
const int key_len, const int val_len);
int greentea_getc();
#ifdef __cplusplus
}
#endif
#endif // GREENTEA_CLIENT_TEST_ENV_H_ #endif // GREENTEA_CLIENT_TEST_ENV_H_
/** @}*/ /** @}*/

View File

@ -94,7 +94,7 @@ void _GREENTEA_SETUP_COMMON(const int timeout, const char *host_test_name, char
* and add host test's callback handlers to main event loop * and add host test's callback handlers to main event loop
* This function is blocking. * This function is blocking.
*/ */
void GREENTEA_SETUP(const int timeout, const char *host_test_name) { extern "C" void GREENTEA_SETUP(const int timeout, const char *host_test_name) {
char _value[GREENTEA_UUID_LENGTH] = {0}; char _value[GREENTEA_UUID_LENGTH] = {0};
_GREENTEA_SETUP_COMMON(timeout, host_test_name, _value, GREENTEA_UUID_LENGTH); _GREENTEA_SETUP_COMMON(timeout, host_test_name, _value, GREENTEA_UUID_LENGTH);
} }
@ -293,7 +293,7 @@ inline void greentea_write_int(const int val)
* \param value Message payload, string value * \param value Message payload, string value
* *
*/ */
void greentea_send_kv(const char *key, const char *val) { extern "C" void greentea_send_kv(const char *key, const char *val) {
if (key && val) { if (key && val) {
greentea_write_preamble(); greentea_write_preamble();
greentea_write_string(key); greentea_write_string(key);
@ -511,7 +511,6 @@ static int gettok(char *, const int);
static int getNextToken(char *, const int); static int getNextToken(char *, const int);
static int HandleKV(char *, char *, const int, const int); static int HandleKV(char *, char *, const int, const int);
static int isstring(int); static int isstring(int);
static int _get_char();
/** /**
* \brief Current token of key-value protocol's tokenizer * \brief Current token of key-value protocol's tokenizer
@ -555,7 +554,7 @@ enum Token {
* \return Next character from the stream or EOF if stream has ended. * \return Next character from the stream or EOF if stream has ended.
* *
*/ */
static int _get_char() { extern "C" int greentea_getc() {
return greentea_serial->getc(); return greentea_serial->getc();
} }
@ -574,7 +573,7 @@ static int _get_char() {
* success == 0 when end of the stream was found * success == 0 when end of the stream was found
* *
*/ */
int greentea_parse_kv(char *out_key, extern "C" int greentea_parse_kv(char *out_key,
char *out_value, char *out_value,
const int out_key_size, const int out_key_size,
const int out_value_size) { const int out_value_size) {
@ -689,7 +688,7 @@ static int gettok(char *out_str, const int str_size) {
// whitespace ::= // whitespace ::=
while (isspace(LastChar)) { while (isspace(LastChar)) {
LastChar = _get_char(); LastChar = greentea_getc();
} }
// string ::= [a-zA-Z0-9_-!@#$%^&*()]+ // string ::= [a-zA-Z0-9_-!@#$%^&*()]+
@ -699,7 +698,7 @@ static int gettok(char *out_str, const int str_size) {
out_str[str_idx++] = LastChar; out_str[str_idx++] = LastChar;
} }
while (isstring((LastChar = _get_char()))) while (isstring((LastChar = greentea_getc())))
if (out_str && str_idx < str_size - 1) { if (out_str && str_idx < str_size - 1) {
out_str[str_idx++] = LastChar; out_str[str_idx++] = LastChar;
} }
@ -712,24 +711,23 @@ static int gettok(char *out_str, const int str_size) {
// semicolon ::= ';' // semicolon ::= ';'
if (LastChar == ';') { if (LastChar == ';') {
LastChar = _get_char(); LastChar = greentea_getc();
return tok_semicolon; return tok_semicolon;
} }
// open ::= '{{' // open ::= '{{'
if (LastChar == '{') { if (LastChar == '{') {
LastChar = _get_char(); LastChar = greentea_getc();
if (LastChar == '{') { if (LastChar == '{') {
LastChar = _get_char(); LastChar = greentea_getc();
return tok_open; return tok_open;
} }
} }
// close ::= '}' // close ::= '}'
if (LastChar == '}') { if (LastChar == '}') {
LastChar = _get_char(); LastChar = greentea_getc();
if (LastChar == '}') { if (LastChar == '}') {
//LastChar = _get_char();
return tok_close; return tok_close;
} }
} }
@ -739,7 +737,7 @@ static int gettok(char *out_str, const int str_size) {
// Otherwise, just return the character as its ascii value. // Otherwise, just return the character as its ascii value.
int ThisChar = LastChar; int ThisChar = LastChar;
LastChar = _get_char(); LastChar = greentea_getc();
return ThisChar; return ThisChar;
} }