mirror of https://github.com/ARMmbed/mbed-os.git
CMake: greentea: Fix io issue with greentea-client
The stdio implementation of the standalone greentea-client wasn't streaming "KiVi protocol" messages through the serial IO. Separate out the existing implementation for greentea-client that uses mbed_retarget.h's `read` and `write` functions so greentea tests continue to work with the standalone client. The IO fixture is shared between the "legacy" embedded greentea-client and the newer standalone client.pull/14904/head
parent
8a507e651e
commit
e9747d7bcd
|
@ -11,3 +11,4 @@ add_subdirectory(frameworks/COMPONENT_FPGA_CI_TEST_SHIELD)
|
|||
add_subdirectory(frameworks/mbed-client-cli)
|
||||
add_subdirectory(frameworks/unity)
|
||||
add_subdirectory(frameworks/utest)
|
||||
add_subdirectory(frameworks/mbed-greentea-io)
|
||||
|
|
|
@ -239,22 +239,6 @@ static void greentea_write_postamble()
|
|||
greentea_putc('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Write a string to the serial port
|
||||
*
|
||||
* This function writes a '\0' terminated string from the target
|
||||
* to the host. It writes directly to the serial port using the
|
||||
* the write() method.
|
||||
*
|
||||
* \param str - string value
|
||||
*
|
||||
*/
|
||||
void greentea_write_string(const char *str)
|
||||
{
|
||||
write(STDOUT_FILENO, str, strlen(str));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Write an int to the serial port
|
||||
*
|
||||
|
@ -536,40 +520,6 @@ enum Token {
|
|||
tok_string = -5
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Read character from stream of data
|
||||
*
|
||||
* Closure for default "get character" function.
|
||||
* This function is used to read characters from the stream
|
||||
* (default is serial port RX). Key-value protocol tokenizer
|
||||
* will build stream of tokes used by key-value protocol to
|
||||
* detect valid messages.
|
||||
*
|
||||
* If EOF is received parser finishes parsing and stops. In
|
||||
* situation where we have serial port stream of data parsing
|
||||
* goes forever.
|
||||
*
|
||||
* \return Next character from the stream or EOF if stream has ended.
|
||||
*
|
||||
*/
|
||||
extern "C" int greentea_getc() {
|
||||
uint8_t c;
|
||||
read(STDOUT_FILENO, &c, 1);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Write character from stream of data
|
||||
*
|
||||
* \return The number of bytes written
|
||||
*
|
||||
*/
|
||||
extern "C" void greentea_putc(int c) {
|
||||
uint8_t _c = c;
|
||||
write(STDOUT_FILENO, &_c, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief parse input string for key-value pairs: {{key;value}}
|
||||
* This function should replace scanf() used to
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# Copyright (c) 2021 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_library(mbed-greentea-io INTERFACE)
|
||||
target_sources(mbed-greentea-io INTERFACE mbed_io.cpp)
|
||||
target_link_libraries(mbed-greentea-io INTERFACE mbed-core)
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 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 <cstdint>
|
||||
#include <cstring>
|
||||
#include "platform/mbed_retarget.h"
|
||||
|
||||
extern "C" void greentea_write_string(const char *str)
|
||||
{
|
||||
write(STDOUT_FILENO, str, strlen(str));
|
||||
}
|
||||
|
||||
extern "C" int greentea_getc()
|
||||
{
|
||||
uint8_t c;
|
||||
read(STDOUT_FILENO, &c, 1);
|
||||
return c;
|
||||
}
|
||||
|
||||
extern "C" void greentea_putc(int c)
|
||||
{
|
||||
uint8_t _c = c;
|
||||
write(STDOUT_FILENO, &_c, 1);
|
||||
}
|
|
@ -61,7 +61,7 @@ macro(mbed_greentea_add_test)
|
|||
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os)
|
||||
endif()
|
||||
|
||||
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS greentea::client mbed-unity mbed-utest)
|
||||
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS greentea::client_userio mbed-greentea-io mbed-unity mbed-utest)
|
||||
|
||||
target_link_libraries(${MBED_GREENTEA_TEST_NAME}
|
||||
PRIVATE
|
||||
|
|
Loading…
Reference in New Issue