Skip to content

Commit c70baa9

Browse files
Fix kv parsing bug in greentea client.
Mbed greentea sends all KV pairs in the following format: "{{key,value}}\n" Previously the greentea client code was not reading the final '\n' from the UART as part of the HandleKV() call. This did not cause an error when multiple KV pairs were being parsed because any whitespace proceeding a message was ignored. Once the final KV pair was sent, however, HandleKV() would only read up to the "}}" leaving the final '\n' in the UART buffer.
1 parent a6207ca commit c70baa9

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static int CurTok = 0;
523523
*
524524
* tok_eof ::= EOF (end of file)
525525
* tok_open ::= "{{"
526-
* tok_close ::= "}}"
526+
* tok_close ::= "}}\n"
527527
* tok_semicolon ::= ";"
528528
* tok_string ::= [a-zA-Z0-9_-!@#$%^&*()]+ // See isstring() function
529529
*
@@ -597,7 +597,7 @@ extern "C" int greentea_parse_kv(char *out_key,
597597

598598
case tok_open:
599599
if (HandleKV(out_key, out_value, out_key_size, out_value_size)) {
600-
// We've found {{ KEY ; VALUE }} expression
600+
// We've found {{ KEY ; VALUE }}\n expression
601601
return 1;
602602
}
603603
break;
@@ -684,7 +684,7 @@ static int isstring(int c) {
684684
*
685685
* <TOK_EOF> ::= EOF (end of file)
686686
* <TOK_OPEN> ::= "{{"
687-
* <TOK_CLOSE> ::= "}}"
687+
* <TOK_CLOSE> ::= "}}\n"
688688
* <TOK_SEMICOLON> ::= ";"
689689
* <TOK_STRING> ::= [a-zA-Z0-9_-!@#$%^&*()]+ // See isstring() function *
690690
*
@@ -737,13 +737,16 @@ static int gettok(char *out_str, const int str_size) {
737737
}
738738

739739
// close ::= '}'
740-
if (LastChar == '}') {
741-
LastChar = greentea_getc();
742-
if (LastChar == '}') {
743-
LastChar = '!';
744-
return tok_close;
745-
}
746-
}
740+
if (LastChar == '}') {
741+
LastChar = greentea_getc();
742+
if (LastChar == '}') {
743+
LastChar = greentea_getc();
744+
if (LastChar == '\n') {
745+
LastChar = '!';
746+
return tok_close;
747+
}
748+
}
749+
}
747750

748751
if (LastChar == EOF)
749752
return tok_eof;
@@ -762,8 +765,8 @@ static int gettok(char *out_str, const int str_size) {
762765
* <MESSAGE>: <TOK_OPEN> <TOK_STRING> <TOK_SEMICOLON> <TOK_STRING> <TOK_CLOSE>
763766
*
764767
* Examples:
765-
* message: "{{__timeout; 1000}}"
766-
* "{{__sync; 12345678-1234-5678-1234-567812345678}}"
768+
* message: "{{__timeout; 1000}}\n"
769+
* "{{__sync; 12345678-1234-5678-1234-567812345678}}\n"
767770
*
768771
* \param out_key Output buffer to store key string value
769772
* \param out_value Output buffer to store value string value

0 commit comments

Comments
 (0)