From 50f1c178e95d6f6685f581a7f30dbae0ec7ba047 Mon Sep 17 00:00:00 2001 From: Anna Bridge Date: Wed, 8 Jun 2016 18:01:27 +0100 Subject: [PATCH] Review comments: Re-implemented utest_printf to use RawSerial. Re-implemented utest_safe_putc() to use Rawserial. Minor cosmetic changes. --- frameworks/utest/source/case.cpp | 1 + frameworks/utest/source/default_handlers.cpp | 2 +- frameworks/utest/source/greentea_handlers.cpp | 3 +- frameworks/utest/source/harness.cpp | 1 + frameworks/utest/source/shim.cpp | 14 ---------- frameworks/utest/source/stack_trace.cpp | 3 +- frameworks/utest/source/unity_handler.cpp | 14 ++++------ frameworks/utest/source/utest_serial.cpp | 28 +++++++++++++++++++ frameworks/utest/utest/shim.h | 1 - frameworks/utest/utest/unity_handler.h | 2 -- frameworks/utest/utest/utest.h | 2 +- frameworks/utest/utest/utest_serial.h | 28 +++++++++++++++++++ 12 files changed, 68 insertions(+), 31 deletions(-) create mode 100644 frameworks/utest/source/utest_serial.cpp create mode 100644 frameworks/utest/utest/utest_serial.h diff --git a/frameworks/utest/source/case.cpp b/frameworks/utest/source/case.cpp index 57395abd4a..71055ece76 100644 --- a/frameworks/utest/source/case.cpp +++ b/frameworks/utest/source/case.cpp @@ -17,6 +17,7 @@ */ #include "utest/case.h" + #include "utest/utest_serial.h" using namespace utest::v1; diff --git a/frameworks/utest/source/default_handlers.cpp b/frameworks/utest/source/default_handlers.cpp index 3ec5636f08..c5d8aa6cca 100644 --- a/frameworks/utest/source/default_handlers.cpp +++ b/frameworks/utest/source/default_handlers.cpp @@ -19,7 +19,7 @@ #include "utest/default_handlers.h" #include "utest/case.h" #include "utest/stack_trace.h" - +#include "utest/utest_serial.h" using namespace utest::v1; diff --git a/frameworks/utest/source/greentea_handlers.cpp b/frameworks/utest/source/greentea_handlers.cpp index 45d544c1de..1dc415aa46 100644 --- a/frameworks/utest/source/greentea_handlers.cpp +++ b/frameworks/utest/source/greentea_handlers.cpp @@ -20,6 +20,7 @@ #include "utest/case.h" #include "greentea-client/test_env.h" #include "utest/stack_trace.h" +#include "utest/utest_serial.h" using namespace utest::v1; @@ -56,7 +57,7 @@ const handlers_t utest::v1::selftest_handlers = { }; -// --- SPECIAL HANDLERS --- +// --- SPECIAL HANDLERS --- static utest::v1::status_t unknown_test_setup_handler(const size_t) { UTEST_LOG_FUNCTION(); utest_printf(">>> I do not know how to tell greentea that the test started, since\n"); diff --git a/frameworks/utest/source/harness.cpp b/frameworks/utest/source/harness.cpp index 31c38835f4..aa689174d8 100644 --- a/frameworks/utest/source/harness.cpp +++ b/frameworks/utest/source/harness.cpp @@ -18,6 +18,7 @@ #include "utest/harness.h" #include "utest/stack_trace.h" +#include "utest/utest_serial.h" #include diff --git a/frameworks/utest/source/shim.cpp b/frameworks/utest/source/shim.cpp index 656023558c..40fac380ed 100644 --- a/frameworks/utest/source/shim.cpp +++ b/frameworks/utest/source/shim.cpp @@ -124,20 +124,6 @@ static int32_t utest_us_ticker_run() return 0; } -int utest_printf(char *str, ...) -{ - volatile uint32_t primask = __get_PRIMASK();\ - if ( (primask & 0x1) == 0){ \ - va_list vargs; - - va_start(vargs, str); - vprintf(str, vargs); - va_end(vargs); - } - - return 0; -} - extern "C" { static const utest_v1_scheduler_t utest_v1_scheduler = diff --git a/frameworks/utest/source/stack_trace.cpp b/frameworks/utest/source/stack_trace.cpp index ba0200af03..ac4bb671cd 100644 --- a/frameworks/utest/source/stack_trace.cpp +++ b/frameworks/utest/source/stack_trace.cpp @@ -21,8 +21,7 @@ #include "utest.h" #include "unity.h" #include "utest/stack_trace.h" - -#include +#include "utest/utest_serial.h" using namespace utest::v1; diff --git a/frameworks/utest/source/unity_handler.cpp b/frameworks/utest/source/unity_handler.cpp index 2b486a5a6b..8a6a53fae4 100644 --- a/frameworks/utest/source/unity_handler.cpp +++ b/frameworks/utest/source/unity_handler.cpp @@ -16,10 +16,10 @@ **************************************************************************** */ - #include "utest/harness.h" - #include "utest/stack_trace.h" - #include "utest/unity_handler.h" - +#include "utest/harness.h" +#include "utest/stack_trace.h" +#include "utest/unity_handler.h" +#include "utest/utest_serial.h" void utest_unity_assert_failure(void) { @@ -35,11 +35,7 @@ void utest_unity_ignore_failure(void) void utest_safe_putc(int chr) { - volatile uint32_t primask = __get_PRIMASK(); - if ( (primask & 0x1) == 0){ - (void)putchar(chr); - } - + utest_serial.putc(chr); } diff --git a/frameworks/utest/source/utest_serial.cpp b/frameworks/utest/source/utest_serial.cpp new file mode 100644 index 0000000000..ffc036ee5f --- /dev/null +++ b/frameworks/utest/source/utest_serial.cpp @@ -0,0 +1,28 @@ +/**************************************************************************** + * 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/frameworks/utest/utest/shim.h b/frameworks/utest/utest/shim.h index 1e0b0c94c8..f9505d5f73 100644 --- a/frameworks/utest/utest/shim.h +++ b/frameworks/utest/utest/shim.h @@ -76,7 +76,6 @@ extern "C" { /// must be implemented by the port void utest_v1_enter_critical_section(void); void utest_v1_leave_critical_section(void); -int utest_printf(char *str, ...); /// This is the default scheduler implementation used by the harness. utest_v1_scheduler_t utest_v1_get_scheduler(void); diff --git a/frameworks/utest/utest/unity_handler.h b/frameworks/utest/utest/unity_handler.h index 5112bcd11f..fc451ec36a 100644 --- a/frameworks/utest/utest/unity_handler.h +++ b/frameworks/utest/utest/unity_handler.h @@ -20,8 +20,6 @@ #define UTEST_UNITY_ASSERT_FAILURE_H #include -#include -#include "cmsis.h" #ifdef __cplusplus extern "C" { diff --git a/frameworks/utest/utest/utest.h b/frameworks/utest/utest/utest.h index 98e20055aa..34c978b445 100644 --- a/frameworks/utest/utest/utest.h +++ b/frameworks/utest/utest/utest.h @@ -23,6 +23,6 @@ #include "case.h" #include "default_handlers.h" #include "harness.h" - +#include "utest/utest_serial.h" #endif // UTEST_H diff --git a/frameworks/utest/utest/utest_serial.h b/frameworks/utest/utest/utest_serial.h new file mode 100644 index 0000000000..111ef90f0a --- /dev/null +++ b/frameworks/utest/utest/utest_serial.h @@ -0,0 +1,28 @@ +/**************************************************************************** + * Copyright (c) 2016, 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. + **************************************************************************** + */ + +#ifndef UTEST_SERIAL_H +#define UTEST_SERIAL_H + +#include "mbed.h" + +extern RawSerial utest_serial; + +#define utest_printf(...) utest_serial.printf(__VA_ARGS__) + +#endif // UTEST_SERIAL_H