From bd5820f77ca4bf8502c6dd11777201db3191b9ff Mon Sep 17 00:00:00 2001 From: Mohammad Azim Khan Date: Wed, 29 Mar 2017 14:42:08 +0100 Subject: [PATCH 1/6] C API for greentea client --- .../greentea-client/test_env_c.h | 33 ++++++++++++++++ .../source/greentea_test_env_c.cpp | 39 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 features/frameworks/greentea-client/greentea-client/test_env_c.h create mode 100644 features/frameworks/greentea-client/source/greentea_test_env_c.cpp diff --git a/features/frameworks/greentea-client/greentea-client/test_env_c.h b/features/frameworks/greentea-client/greentea-client/test_env_c.h new file mode 100644 index 0000000000..fd9754c65e --- /dev/null +++ b/features/frameworks/greentea-client/greentea-client/test_env_c.h @@ -0,0 +1,33 @@ +/** \addtogroup frameworks */ +/** @{*/ +/* + * Copyright (c) 2013-2017, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_ENV_C_H +#define TEST_ENV_C_H + + +/** + * Greentea-client C API for communication with host side + */ +void GREENTEA_SETUP_C(const int timeout, const char * host_test); +void greentea_send_kv_c(const char * key, const char * val); +int greentea_parse_kv_c(char * key, char * val, + const int key_len, const int val_len); + +#endif /* TEST_ENV_C_H */ + diff --git a/features/frameworks/greentea-client/source/greentea_test_env_c.cpp b/features/frameworks/greentea-client/source/greentea_test_env_c.cpp new file mode 100644 index 0000000000..3bf9f873c3 --- /dev/null +++ b/features/frameworks/greentea-client/source/greentea_test_env_c.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013-2017, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "greentea-client/test_env.h" + + +/** + * C extensions of greentea client API. + * + * NOTE: Added to support mbed-tls tests generated in C. Please enable more API if needed. + */ + +extern "C" void GREENTEA_SETUP_C(const int timeout, const char * host_test){ + GREENTEA_SETUP(timeout, host_test); +}; + +extern "C" void greentea_send_kv_c(const char * key, const char * val){ + greentea_send_kv(key, val); +}; + +extern "C" int greentea_parse_kv_c(char * key, char * val, + const int key_len, const int val_len){ + return greentea_parse_kv(key, val, key_len, val_len); +}; + From 0edf082c597a80f35f1594f30cec07fba0f65f59 Mon Sep 17 00:00:00 2001 From: Azim Khan Date: Fri, 19 May 2017 17:27:22 +0100 Subject: [PATCH 2/6] Add getc in C API --- .../frameworks/greentea-client/greentea-client/test_env_c.h | 1 + .../greentea-client/source/greentea_test_env_c.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/features/frameworks/greentea-client/greentea-client/test_env_c.h b/features/frameworks/greentea-client/greentea-client/test_env_c.h index fd9754c65e..94b67a4a2f 100644 --- a/features/frameworks/greentea-client/greentea-client/test_env_c.h +++ b/features/frameworks/greentea-client/greentea-client/test_env_c.h @@ -28,6 +28,7 @@ void GREENTEA_SETUP_C(const int timeout, const char * host_test); void greentea_send_kv_c(const char * key, const char * val); int greentea_parse_kv_c(char * key, char * val, const int key_len, const int val_len); +char greentea_getc(); #endif /* TEST_ENV_C_H */ diff --git a/features/frameworks/greentea-client/source/greentea_test_env_c.cpp b/features/frameworks/greentea-client/source/greentea_test_env_c.cpp index 3bf9f873c3..5c881f977c 100644 --- a/features/frameworks/greentea-client/source/greentea_test_env_c.cpp +++ b/features/frameworks/greentea-client/source/greentea_test_env_c.cpp @@ -16,6 +16,7 @@ */ #include "greentea-client/test_env.h" +#include "greentea-client/greentea_serial.h" /** @@ -37,3 +38,8 @@ extern "C" int greentea_parse_kv_c(char * key, char * val, return greentea_parse_kv(key, val, key_len, val_len); }; +extern "C" char greentea_getc() { + char c = greentea_serial->getc(); + return c; +} + From 088d151507568799ed7597b6951ed89c78c6b8f7 Mon Sep 17 00:00:00 2001 From: Azim Khan Date: Tue, 23 May 2017 12:01:46 +0100 Subject: [PATCH 3/6] Use existing functions for Greentea client C API --- .../greentea-client/test_env.h | 5 ++- .../greentea-client/test_env_c.h | 6 +-- .../source/greentea_test_env.cpp | 26 +++++------ .../source/greentea_test_env_c.cpp | 45 ------------------- 4 files changed, 18 insertions(+), 64 deletions(-) delete mode 100644 features/frameworks/greentea-client/source/greentea_test_env_c.cpp diff --git a/features/frameworks/greentea-client/greentea-client/test_env.h b/features/frameworks/greentea-client/greentea-client/test_env.h index 0f7ffeaffd..bde8aad785 100644 --- a/features/frameworks/greentea-client/greentea-client/test_env.h +++ b/features/frameworks/greentea-client/greentea-client/test_env.h @@ -28,6 +28,9 @@ #endif #include +extern "C" { +#include "test_env_c.h" +} /** * Auxilary macros @@ -90,12 +93,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 /** diff --git a/features/frameworks/greentea-client/greentea-client/test_env_c.h b/features/frameworks/greentea-client/greentea-client/test_env_c.h index 94b67a4a2f..67beceb6c7 100644 --- a/features/frameworks/greentea-client/greentea-client/test_env_c.h +++ b/features/frameworks/greentea-client/greentea-client/test_env_c.h @@ -24,9 +24,9 @@ /** * Greentea-client C API for communication with host side */ -void GREENTEA_SETUP_C(const int timeout, const char * host_test); -void greentea_send_kv_c(const char * key, const char * val); -int greentea_parse_kv_c(char * key, char * val, +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); char greentea_getc(); diff --git a/features/frameworks/greentea-client/source/greentea_test_env.cpp b/features/frameworks/greentea-client/source/greentea_test_env.cpp index 75d5677d74..f2c4298474 100644 --- a/features/frameworks/greentea-client/source/greentea_test_env.cpp +++ b/features/frameworks/greentea-client/source/greentea_test_env.cpp @@ -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); } @@ -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); @@ -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 @@ -555,7 +554,7 @@ enum Token { * \return Next character from the stream or EOF if stream has ended. * */ -static int _get_char() { +extern "C" char greentea_getc() { return greentea_serial->getc(); } @@ -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) { @@ -684,12 +683,12 @@ static int isstring(int c) { * */ static int gettok(char *out_str, const int str_size) { - static int LastChar = '!'; + static char LastChar = '!'; static int str_idx = 0; // whitespace ::= while (isspace(LastChar)) { - LastChar = _get_char(); + LastChar = greentea_getc(); } // string ::= [a-zA-Z0-9_-!@#$%^&*()]+ @@ -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; } @@ -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; } } @@ -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; } diff --git a/features/frameworks/greentea-client/source/greentea_test_env_c.cpp b/features/frameworks/greentea-client/source/greentea_test_env_c.cpp deleted file mode 100644 index 5c881f977c..0000000000 --- a/features/frameworks/greentea-client/source/greentea_test_env_c.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2013-2017, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "greentea-client/test_env.h" -#include "greentea-client/greentea_serial.h" - - -/** - * C extensions of greentea client API. - * - * NOTE: Added to support mbed-tls tests generated in C. Please enable more API if needed. - */ - -extern "C" void GREENTEA_SETUP_C(const int timeout, const char * host_test){ - GREENTEA_SETUP(timeout, host_test); -}; - -extern "C" void greentea_send_kv_c(const char * key, const char * val){ - greentea_send_kv(key, val); -}; - -extern "C" int greentea_parse_kv_c(char * key, char * val, - const int key_len, const int val_len){ - return greentea_parse_kv(key, val, key_len, val_len); -}; - -extern "C" char greentea_getc() { - char c = greentea_serial->getc(); - return c; -} - From 82d948de6b73d4013fcbf25b28532f6d40973bf0 Mon Sep 17 00:00:00 2001 From: Azim Khan Date: Tue, 23 May 2017 15:20:43 +0100 Subject: [PATCH 4/6] Revert greentea_getc() to return 'int' --- .../frameworks/greentea-client/greentea-client/test_env_c.h | 2 +- .../frameworks/greentea-client/source/greentea_test_env.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/frameworks/greentea-client/greentea-client/test_env_c.h b/features/frameworks/greentea-client/greentea-client/test_env_c.h index 67beceb6c7..352b749b66 100644 --- a/features/frameworks/greentea-client/greentea-client/test_env_c.h +++ b/features/frameworks/greentea-client/greentea-client/test_env_c.h @@ -28,7 +28,7 @@ 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); -char greentea_getc(); +int greentea_getc(); #endif /* TEST_ENV_C_H */ diff --git a/features/frameworks/greentea-client/source/greentea_test_env.cpp b/features/frameworks/greentea-client/source/greentea_test_env.cpp index f2c4298474..8b4ee14193 100644 --- a/features/frameworks/greentea-client/source/greentea_test_env.cpp +++ b/features/frameworks/greentea-client/source/greentea_test_env.cpp @@ -554,7 +554,7 @@ enum Token { * \return Next character from the stream or EOF if stream has ended. * */ -extern "C" char greentea_getc() { +extern "C" int greentea_getc() { return greentea_serial->getc(); } @@ -683,7 +683,7 @@ static int isstring(int c) { * */ static int gettok(char *out_str, const int str_size) { - static char LastChar = '!'; + static int LastChar = '!'; static int str_idx = 0; // whitespace ::= From b3cbb07566a54504bfbd2e77ae340665614509ac Mon Sep 17 00:00:00 2001 From: Azim Khan Date: Mon, 5 Jun 2017 13:21:19 +0100 Subject: [PATCH 5/6] Merge greentea-client/test_env_c.h into greentea-client/test_env.h --- .../greentea-client/test_env.h | 23 +++++++++++-- .../greentea-client/test_env_c.h | 34 ------------------- 2 files changed, 20 insertions(+), 37 deletions(-) delete mode 100644 features/frameworks/greentea-client/greentea-client/test_env_c.h diff --git a/features/frameworks/greentea-client/greentea-client/test_env.h b/features/frameworks/greentea-client/greentea-client/test_env.h index bde8aad785..293878ffae 100644 --- a/features/frameworks/greentea-client/greentea-client/test_env.h +++ b/features/frameworks/greentea-client/greentea-client/test_env.h @@ -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 @@ -28,9 +29,6 @@ #endif #include -extern "C" { -#include "test_env_c.h" -} /** * Auxilary macros @@ -106,6 +104,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_ /** @}*/ diff --git a/features/frameworks/greentea-client/greentea-client/test_env_c.h b/features/frameworks/greentea-client/greentea-client/test_env_c.h deleted file mode 100644 index 352b749b66..0000000000 --- a/features/frameworks/greentea-client/greentea-client/test_env_c.h +++ /dev/null @@ -1,34 +0,0 @@ -/** \addtogroup frameworks */ -/** @{*/ -/* - * Copyright (c) 2013-2017, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef TEST_ENV_C_H -#define TEST_ENV_C_H - - -/** - * Greentea-client C API for communication with host side - */ -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(); - -#endif /* TEST_ENV_C_H */ - From 0b929199e462710e039e25c2241546a3a36355d4 Mon Sep 17 00:00:00 2001 From: Azim Khan Date: Tue, 13 Jun 2017 10:02:55 +0100 Subject: [PATCH 6/6] Remove multiple definition of GREENTEA_SETUP added due to rebase --- features/frameworks/greentea-client/greentea-client/test_env.h | 1 - 1 file changed, 1 deletion(-) diff --git a/features/frameworks/greentea-client/greentea-client/test_env.h b/features/frameworks/greentea-client/greentea-client/test_env.h index 293878ffae..6aa2617c57 100644 --- a/features/frameworks/greentea-client/greentea-client/test_env.h +++ b/features/frameworks/greentea-client/greentea-client/test_env.h @@ -82,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);