Skip to content

Add C API for Greentea client #4364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions features/frameworks/greentea-client/greentea-client/test_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef GREENTEA_CLIENT_TEST_ENV_H_
#define GREENTEA_CLIENT_TEST_ENV_H_

#ifdef __cplusplus
#ifdef YOTTA_GREENTEA_CLIENT_VERSION_STRING
#define MBED_GREENTEA_CLIENT_VERSION_STRING YOTTA_GREENTEA_CLIENT_VERSION_STRING
#else
Expand Down Expand Up @@ -81,7 +82,6 @@ extern const char* GREENTEA_TEST_ENV_LCOV_START;
/**
* 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_TESTSUITE_RESULT(const int);
void GREENTEA_TESTCASE_START(const char *test_case_name);
Expand All @@ -90,12 +90,10 @@ void GREENTEA_TESTCASE_FINISH(const char *test_case_name, const size_t passes, c
/**
* 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, const int);
void greentea_send_kv(const char *, const char *, 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
/**
Expand All @@ -105,6 +103,25 @@ void greentea_notify_coverage_start(const char *path);
void greentea_notify_coverage_end();
#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_

/** @}*/
24 changes: 11 additions & 13 deletions features/frameworks/greentea-client/source/greentea_test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 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};
_GREENTEA_SETUP_COMMON(timeout, host_test_name, _value, GREENTEA_UUID_LENGTH);
}
Expand Down Expand Up @@ -293,7 +293,7 @@ inline void greentea_write_int(const int val)
* \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) {
greentea_write_preamble();
greentea_write_string(key);
Expand Down Expand Up @@ -511,7 +511,6 @@ static int gettok(char *, const int);
static int getNextToken(char *, const int);
static int HandleKV(char *, char *, const int, const int);
static int isstring(int);
static int _get_char();

/**
* \brief Current token of key-value protocol's tokenizer
Expand Down Expand Up @@ -555,7 +554,7 @@ enum Token {
* \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();
}

Expand All @@ -574,7 +573,7 @@ static int _get_char() {
* 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,
const int out_key_size,
const int out_value_size) {
Expand Down Expand Up @@ -689,7 +688,7 @@ static int gettok(char *out_str, const int str_size) {

// whitespace ::=
while (isspace(LastChar)) {
LastChar = _get_char();
LastChar = greentea_getc();
}

// string ::= [a-zA-Z0-9_-!@#$%^&*()]+
Expand All @@ -699,7 +698,7 @@ static int gettok(char *out_str, const int str_size) {
out_str[str_idx++] = LastChar;
}

while (isstring((LastChar = _get_char())))
while (isstring((LastChar = greentea_getc())))
if (out_str && str_idx < str_size - 1) {
out_str[str_idx++] = LastChar;
}
Expand All @@ -712,24 +711,23 @@ static int gettok(char *out_str, const int str_size) {

// semicolon ::= ';'
if (LastChar == ';') {
LastChar = _get_char();
LastChar = greentea_getc();
return tok_semicolon;
}

// open ::= '{{'
if (LastChar == '{') {
LastChar = _get_char();
LastChar = greentea_getc();
if (LastChar == '{') {
LastChar = _get_char();
LastChar = greentea_getc();
return tok_open;
}
}

// close ::= '}'
if (LastChar == '}') {
LastChar = _get_char();
LastChar = greentea_getc();
if (LastChar == '}') {
//LastChar = _get_char();
return tok_close;
}
}
Expand All @@ -739,7 +737,7 @@ static int gettok(char *out_str, const int str_size) {

// Otherwise, just return the character as its ascii value.
int ThisChar = LastChar;
LastChar = _get_char();
LastChar = greentea_getc();
return ThisChar;
}

Expand Down