Skip to content

Commit 150951f

Browse files
committed
Adding ability to preserve Greentea UUID in test.
The Greentea UUID can be used as a source of entropy/randomness during the test. This is useful for uniquely identifying a test run.
1 parent e4ff16e commit 150951f

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extern const char* GREENTEA_TEST_ENV_LCOV_START;
7777
* Greentea-client related API for communication with host side
7878
*/
7979
void GREENTEA_SETUP(const int, const char *);
80+
void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *buffer, size_t size);
8081
void GREENTEA_TESTSUITE_RESULT(const int);
8182
void GREENTEA_TESTCASE_START(const char *test_case_name);
8283
void GREENTEA_TESTCASE_FINISH(const char *test_case_name, const size_t passes, const size_t failed);

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

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,21 @@ static void greentea_notify_completion(const int);
6060
static void greentea_notify_version();
6161
static void greentea_write_string(const char *str);
6262

63-
/** \brief Handshake with host and send setup data (timeout and host test name)
64-
* \details This function will send preamble to master.
65-
* After host test name is received master will invoke host test script
66-
* and add hos test's callback handlers to main event loop
67-
* This function is blocking.
68-
*/
69-
void GREENTEA_SETUP(const int timeout, const char *host_test_name) {
63+
64+
void _GREENTEA_SETUP_COMMON(const int timeout, const char *host_test_name, char *buffer, size_t size) {
7065
greentea_metrics_setup();
7166
// Key-value protocol handshake function. Waits for {{__sync;...}} message
7267
// Sync preamble: "{{__sync;0dad4a9d-59a3-4aec-810d-d5fb09d852c1}}"
7368
// Example value of sync_uuid == "0dad4a9d-59a3-4aec-810d-d5fb09d852c1"
74-
char _key[8] = {0};
75-
char _value[48] = {0};
76-
while (1) {
77-
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
69+
70+
char _key[8] = {0};
71+
72+
while (1) {
73+
greentea_parse_kv(_key, buffer, sizeof(_key), size);
7874
greentea_write_string("mbedmbedmbedmbedmbedmbedmbedmbed\r\n");
7975
if (strcmp(_key, GREENTEA_TEST_ENV_SYNC) == 0) {
8076
// Found correct __sunc message
81-
greentea_send_kv(_key, _value);
77+
greentea_send_kv(_key, buffer);
8278
break;
8379
}
8480
}
@@ -88,6 +84,27 @@ void GREENTEA_SETUP(const int timeout, const char *host_test_name) {
8884
greentea_notify_hosttest(host_test_name);
8985
}
9086

87+
/** \brief Handshake with host and send setup data (timeout and host test name)
88+
* \details This function will send preamble to master.
89+
* After host test name is received master will invoke host test script
90+
* and add hos test's callback handlers to main event loop
91+
* This function is blocking.
92+
*/
93+
void GREENTEA_SETUP(const int timeout, const char *host_test_name) {
94+
char _value[48] = {0};
95+
_GREENTEA_SETUP_COMMON(timeout, host_test_name, _value, 48);
96+
}
97+
98+
/** \brief Handshake with host and send setup data (timeout and host test name)
99+
* \details This function will send preamble to master.
100+
* After host test name is received master will invoke host test script
101+
* and add hos test's callback handlers to main event loop
102+
* This function is blocking.
103+
*/
104+
void GREENTEA_SETUP_UUID(const int timeout, const char *host_test_name, char *buffer, size_t size) {
105+
_GREENTEA_SETUP_COMMON(timeout, host_test_name, buffer, size);
106+
}
107+
91108
/** \brief Notify host (__exit message) side that test suite execution was complete
92109
* \result Test suite result
93110
* \details If __exit is not received by host side we will assume TIMEOUT
@@ -194,15 +211,15 @@ inline void greentea_write_preamble()
194211
greentea_serial->putc('{');
195212
greentea_serial->putc('{');
196213
}
197-
214+
198215
/**
199216
* \brief Write the postamble characters to the serial port
200217
*
201218
* This function writes the postamble "{{\n" which is required
202219
* for key-value comunication between the target and the host.
203220
* This uses a Rawserial object, greentea_serial, which provides
204221
* a direct interface to the USBTX and USBRX serial pins and allows
205-
* the direct writing of characters using the putc() method.
222+
* the direct writing of characters using the putc() method.
206223
* This suite of functions are provided to allow for serial communication
207224
* to the host from within a thread/ISR.
208225
*
@@ -238,8 +255,8 @@ inline void greentea_write_string(const char *str)
238255
* \brief Write an int to the serial port
239256
*
240257
* This function writes an integer value from the target
241-
* to the host. The integer value is converted to a string and
242-
* and then written character by character directly to the serial
258+
* to the host. The integer value is converted to a string and
259+
* and then written character by character directly to the serial
243260
* port using the greentea_serial, Rawserial object.
244261
* sprintf() is used to convert the int to a string. Sprintf if
245262
* inherently thread safe so can be used.
@@ -302,7 +319,7 @@ void greentea_send_kv(const char *key, const int val) {
302319
greentea_write_postamble();
303320
}
304321
}
305-
322+
306323
/**
307324
* \brief Encapsulate and send key-value-value message from DUT to host
308325
*
@@ -367,10 +384,10 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
367384
/**
368385
* \brief Encapsulate and send key-value-value message from DUT to host
369386
*
370-
* This function uses underlying functions to write directly
371-
* to the serial port, (USBTX). This allows key-value-value to be used
387+
* This function uses underlying functions to write directly
388+
* to the serial port, (USBTX). This allows key-value-value to be used
372389
* from within interrupt context.
373-
* Both values are integers to avoid integer to string conversion
390+
* Both values are integers to avoid integer to string conversion
374391
* made by the user.
375392
*
376393
* Names of the parameters: this function is used to send number

0 commit comments

Comments
 (0)