From f334bd7602c2a4aad982ffdca36ebefa72a0dbd5 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Fri, 12 Aug 2016 15:32:38 -0500 Subject: [PATCH] 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. --- .../greentea-client/greentea_serial.h | 13 ++++++ .../source/greentea_serial.cpp | 5 +++ .../greentea-client/source/test_env.cpp | 40 ++++++++----------- .../frameworks/utest/source/unity_handler.cpp | 4 +- .../frameworks/utest/source/utest_serial.cpp | 28 ------------- .../frameworks/utest/utest/utest_serial.h | 6 +-- features/frameworks/utest/utest/utest_types.h | 1 + 7 files changed, 40 insertions(+), 57 deletions(-) create mode 100644 features/frameworks/greentea-client/greentea-client/greentea_serial.h create mode 100644 features/frameworks/greentea-client/source/greentea_serial.cpp delete mode 100644 features/frameworks/utest/source/utest_serial.cpp diff --git a/features/frameworks/greentea-client/greentea-client/greentea_serial.h b/features/frameworks/greentea-client/greentea-client/greentea_serial.h new file mode 100644 index 0000000000..9adba96e5c --- /dev/null +++ b/features/frameworks/greentea-client/greentea-client/greentea_serial.h @@ -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 greentea_serial; +#endif \ No newline at end of file diff --git a/features/frameworks/greentea-client/source/greentea_serial.cpp b/features/frameworks/greentea-client/source/greentea_serial.cpp new file mode 100644 index 0000000000..ee9f31b58f --- /dev/null +++ b/features/frameworks/greentea-client/source/greentea_serial.cpp @@ -0,0 +1,5 @@ +#include "greentea-client/greentea_serial.h" + +SingletonPtr greentea_serial; + +GreenteaSerial::GreenteaSerial() : mbed::RawSerial(USBTX, USBRX) {}; \ No newline at end of file diff --git a/features/frameworks/greentea-client/source/test_env.cpp b/features/frameworks/greentea-client/source/test_env.cpp index 775d691480..bf994fbfb9 100644 --- a/features/frameworks/greentea-client/source/test_env.cpp +++ b/features/frameworks/greentea-client/source/test_env.cpp @@ -20,6 +20,7 @@ #include #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(); } diff --git a/features/frameworks/utest/source/unity_handler.cpp b/features/frameworks/utest/source/unity_handler.cpp index b6dddb95ed..b11454acd3 100644 --- a/features/frameworks/utest/source/unity_handler.cpp +++ b/features/frameworks/utest/source/unity_handler.cpp @@ -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); } diff --git a/features/frameworks/utest/source/utest_serial.cpp b/features/frameworks/utest/source/utest_serial.cpp deleted file mode 100644 index ffc036ee5f..0000000000 --- a/features/frameworks/utest/source/utest_serial.cpp +++ /dev/null @@ -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); -} - - diff --git a/features/frameworks/utest/utest/utest_serial.h b/features/frameworks/utest/utest/utest_serial.h index 111ef90f0a..de0b04d961 100644 --- a/features/frameworks/utest/utest/utest_serial.h +++ b/features/frameworks/utest/utest/utest_serial.h @@ -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 diff --git a/features/frameworks/utest/utest/utest_types.h b/features/frameworks/utest/utest/utest_types.h index 5d07e10782..e2ac004c51 100644 --- a/features/frameworks/utest/utest/utest_types.h +++ b/features/frameworks/utest/utest/utest_types.h @@ -23,6 +23,7 @@ #include #include #include "utest/utest_shim.h" +#include "SingletonPtr.h" namespace utest { namespace v1 {