Sharing greentea-client's RawSerial with utest and UNITY.

This commit allows the linker to remove the reference to the RawSerial object
if it not used in the application. This way it only is brought in for
tests.
pull/2455/head
Brian Daniels 2016-08-12 15:32:38 -05:00
parent dd8060b798
commit f334bd7602
7 changed files with 40 additions and 57 deletions

View File

@ -0,0 +1,13 @@
#ifndef GREENTEA_SERIAL_H
#define GREENTEA_SERIAL_H
#include "RawSerial.h"
#include "SingletonPtr.h"
class GreenteaSerial : public mbed::RawSerial {
public:
GreenteaSerial();
};
extern SingletonPtr<GreenteaSerial> greentea_serial;
#endif

View File

@ -0,0 +1,5 @@
#include "greentea-client/greentea_serial.h"
SingletonPtr<GreenteaSerial> greentea_serial;
GreenteaSerial::GreenteaSerial() : mbed::RawSerial(USBTX, USBRX) {};

View File

@ -20,6 +20,7 @@
#include <string.h>
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "greentea-client/greentea_serial.h"
/**
@ -57,13 +58,6 @@ static void greentea_notify_hosttest(const char *);
static void greentea_notify_completion(const int);
static void greentea_notify_version();
/**
* Rawserial object used to provide direct, raw serial communications
* between the target and the host.
*/
RawSerial greentea_serial(USBTX, USBRX);
/** \brief Handshake with host and send setup data (timeout and host test name)
* \details This function will send preamble to master.
* After host test name is received master will invoke host test script
@ -193,8 +187,8 @@ void greentea_notify_coverage_end() {
*/
inline void greentea_write_preamble()
{
greentea_serial.putc('{');
greentea_serial.putc('{');
greentea_serial->putc('{');
greentea_serial->putc('{');
}
/**
@ -211,9 +205,9 @@ inline void greentea_write_preamble()
*/
inline void greentea_write_postamble()
{
greentea_serial.putc('}');
greentea_serial.putc('}');
greentea_serial.putc('\n');
greentea_serial->putc('}');
greentea_serial->putc('}');
greentea_serial->putc('\n');
}
/**
@ -229,7 +223,7 @@ inline void greentea_write_postamble()
inline void greentea_write_string(const char *str)
{
while (*str != '\0') {
greentea_serial.putc(*str);
greentea_serial->putc(*str);
str ++;
}
}
@ -255,7 +249,7 @@ inline void greentea_write_int(const int val)
unsigned int i = 0;
sprintf(intval, "%d", val);
while (intval[i] != '\0') {
greentea_serial.putc(intval[i]);
greentea_serial->putc(intval[i]);
i++;
}
}
@ -275,7 +269,7 @@ void greentea_send_kv(const char *key, const char *val) {
if (key && val) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_string(val);
greentea_write_postamble();
}
@ -298,7 +292,7 @@ void greentea_send_kv(const char *key, const int val) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_int(val);
greentea_write_postamble();
}
@ -322,9 +316,9 @@ void greentea_send_kv(const char *key, const char *val, const int result) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_string(val);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_int(result);
greentea_write_postamble();
@ -355,11 +349,11 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_string(val);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_int(passes);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_int(failures);
greentea_write_postamble();
}
@ -388,9 +382,9 @@ void greentea_send_kv(const char *key, const int passes, const int failures) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_int(passes);
greentea_serial.putc(';');
greentea_serial->putc(';');
greentea_write_int(failures);
greentea_write_postamble();
}

View File

@ -19,7 +19,7 @@
#include "utest/utest_harness.h"
#include "utest/utest_stack_trace.h"
#include "utest/unity_handler.h"
#include "utest/utest_serial.h"
#include "greentea-client/greentea_serial.h"
void utest_unity_assert_failure(void)
{
@ -35,7 +35,7 @@ void utest_unity_ignore_failure(void)
void utest_safe_putc(int chr)
{
utest_serial.putc(chr);
greentea_serial->putc(chr);
}

View File

@ -1,28 +0,0 @@
/****************************************************************************
* Copyright (c) 2015, 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 "utest/utest_serial.h"
RawSerial utest_serial(USBTX, USBRX);
void utest_safe_putc(int chr)
{
utest_serial.putc(chr);
}

View File

@ -19,10 +19,8 @@
#ifndef UTEST_SERIAL_H
#define UTEST_SERIAL_H
#include "mbed.h"
#include "greentea-client/greentea_serial.h"
extern RawSerial utest_serial;
#define utest_printf(...) utest_serial.printf(__VA_ARGS__)
#define utest_printf(...) greentea_serial->printf(__VA_ARGS__)
#endif // UTEST_SERIAL_H

View File

@ -23,6 +23,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "utest/utest_shim.h"
#include "SingletonPtr.h"
namespace utest {
namespace v1 {