Use existing functions for Greentea client C API

pull/4364/head
Azim Khan 2017-05-23 12:01:46 +01:00
parent 0edf082c59
commit 088d151507
4 changed files with 18 additions and 64 deletions

View File

@ -28,6 +28,9 @@
#endif
#include <stdio.h>
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
/**

View File

@ -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();

View File

@ -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;
}

View File

@ -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;
}