Skip to content

Commit 1ffbdfc

Browse files
Merge pull request #4364 from mazimkhan/mbed-tls-test
Add C API for Greentea client
2 parents d806121 + 0b92919 commit 1ffbdfc

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

features/frameworks/greentea-client/greentea-client/test_env.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifndef GREENTEA_CLIENT_TEST_ENV_H_
2222
#define GREENTEA_CLIENT_TEST_ENV_H_
2323

24+
#ifdef __cplusplus
2425
#ifdef YOTTA_GREENTEA_CLIENT_VERSION_STRING
2526
#define MBED_GREENTEA_CLIENT_VERSION_STRING YOTTA_GREENTEA_CLIENT_VERSION_STRING
2627
#else
@@ -81,7 +82,6 @@ extern const char* GREENTEA_TEST_ENV_LCOV_START;
8182
/**
8283
* Greentea-client related API for communication with host side
8384
*/
84-
void GREENTEA_SETUP(const int, const char *);
8585
void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *buffer, size_t size);
8686
void GREENTEA_TESTSUITE_RESULT(const int);
8787
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
9090
/**
9191
* Test suite result related notification API
9292
*/
93-
void greentea_send_kv(const char *, const char *);
9493
void greentea_send_kv(const char *, const int);
9594
void greentea_send_kv(const char *, const int, const int);
9695
void greentea_send_kv(const char *, const char *, const int);
9796
void greentea_send_kv(const char *, const char *, const int, const int);
98-
int greentea_parse_kv(char *, char *, const int, const int);
9997

10098
#ifdef MBED_CFG_DEBUG_OPTIONS_COVERAGE
10199
/**
@@ -105,6 +103,25 @@ void greentea_notify_coverage_start(const char *path);
105103
void greentea_notify_coverage_end();
106104
#endif // MBED_CFG_DEBUG_OPTIONS_COVERAGE
107105

106+
#endif // __cplusplus
107+
108+
#ifdef __cplusplus
109+
extern "C" {
110+
#endif
111+
112+
/**
113+
* Greentea-client C API
114+
*/
115+
void GREENTEA_SETUP(const int timeout, const char * host_test);
116+
void greentea_send_kv(const char * key, const char * val);
117+
int greentea_parse_kv(char * key, char * val,
118+
const int key_len, const int val_len);
119+
int greentea_getc();
120+
121+
#ifdef __cplusplus
122+
}
123+
#endif
124+
108125
#endif // GREENTEA_CLIENT_TEST_ENV_H_
109126

110127
/** @}*/

features/frameworks/greentea-client/source/greentea_test_env.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void _GREENTEA_SETUP_COMMON(const int timeout, const char *host_test_name, char
9494
* and add host test's callback handlers to main event loop
9595
* This function is blocking.
9696
*/
97-
void GREENTEA_SETUP(const int timeout, const char *host_test_name) {
97+
extern "C" void GREENTEA_SETUP(const int timeout, const char *host_test_name) {
9898
char _value[GREENTEA_UUID_LENGTH] = {0};
9999
_GREENTEA_SETUP_COMMON(timeout, host_test_name, _value, GREENTEA_UUID_LENGTH);
100100
}
@@ -293,7 +293,7 @@ inline void greentea_write_int(const int val)
293293
* \param value Message payload, string value
294294
*
295295
*/
296-
void greentea_send_kv(const char *key, const char *val) {
296+
extern "C" void greentea_send_kv(const char *key, const char *val) {
297297
if (key && val) {
298298
greentea_write_preamble();
299299
greentea_write_string(key);
@@ -511,7 +511,6 @@ static int gettok(char *, const int);
511511
static int getNextToken(char *, const int);
512512
static int HandleKV(char *, char *, const int, const int);
513513
static int isstring(int);
514-
static int _get_char();
515514

516515
/**
517516
* \brief Current token of key-value protocol's tokenizer
@@ -555,7 +554,7 @@ enum Token {
555554
* \return Next character from the stream or EOF if stream has ended.
556555
*
557556
*/
558-
static int _get_char() {
557+
extern "C" int greentea_getc() {
559558
return greentea_serial->getc();
560559
}
561560

@@ -574,7 +573,7 @@ static int _get_char() {
574573
* success == 0 when end of the stream was found
575574
*
576575
*/
577-
int greentea_parse_kv(char *out_key,
576+
extern "C" int greentea_parse_kv(char *out_key,
578577
char *out_value,
579578
const int out_key_size,
580579
const int out_value_size) {
@@ -689,7 +688,7 @@ static int gettok(char *out_str, const int str_size) {
689688

690689
// whitespace ::=
691690
while (isspace(LastChar)) {
692-
LastChar = _get_char();
691+
LastChar = greentea_getc();
693692
}
694693

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

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

713712
// semicolon ::= ';'
714713
if (LastChar == ';') {
715-
LastChar = _get_char();
714+
LastChar = greentea_getc();
716715
return tok_semicolon;
717716
}
718717

719718
// open ::= '{{'
720719
if (LastChar == '{') {
721-
LastChar = _get_char();
720+
LastChar = greentea_getc();
722721
if (LastChar == '{') {
723-
LastChar = _get_char();
722+
LastChar = greentea_getc();
724723
return tok_open;
725724
}
726725
}
727726

728727
// close ::= '}'
729728
if (LastChar == '}') {
730-
LastChar = _get_char();
729+
LastChar = greentea_getc();
731730
if (LastChar == '}') {
732-
//LastChar = _get_char();
733731
return tok_close;
734732
}
735733
}
@@ -739,7 +737,7 @@ static int gettok(char *out_str, const int str_size) {
739737

740738
// Otherwise, just return the character as its ascii value.
741739
int ThisChar = LastChar;
742-
LastChar = _get_char();
740+
LastChar = greentea_getc();
743741
return ThisChar;
744742
}
745743

0 commit comments

Comments
 (0)