Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
utest_default_handlers.cpp
00001 /**************************************************************************** 00002 * Copyright (c) 2015, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 **************************************************************************** 00017 */ 00018 00019 #if DEVICE_SERIAL 00020 00021 #include "utest/utest_default_handlers.h" 00022 #include "utest/utest_case.h" 00023 #include "utest/utest_stack_trace.h" 00024 #include "utest/utest_serial.h" 00025 00026 using namespace utest::v1; 00027 00028 static void test_failure_handler(const failure_t failure); 00029 00030 const handlers_t utest::v1::verbose_continue_handlers = { 00031 verbose_test_setup_handler, 00032 verbose_test_teardown_handler, 00033 test_failure_handler, 00034 verbose_case_setup_handler, 00035 verbose_case_teardown_handler, 00036 verbose_case_failure_handler 00037 }; 00038 00039 const handlers_t& utest::v1::default_handlers = greentea_abort_handlers; 00040 00041 // --- SPECIAL HANDLERS --- 00042 static void test_failure_handler(const failure_t failure) { 00043 UTEST_LOG_FUNCTION(); 00044 if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) { 00045 verbose_test_failure_handler(failure); 00046 utest_printf("{{failure}}\n{{end}}\n"); 00047 while(1) ; 00048 } 00049 } 00050 00051 // --- VERBOSE TEST HANDLERS --- 00052 utest::v1::status_t utest::v1::verbose_test_setup_handler(const size_t number_of_cases) 00053 { 00054 UTEST_LOG_FUNCTION(); 00055 utest_printf(">>> Running %u test cases...\n", number_of_cases); 00056 return STATUS_CONTINUE; 00057 } 00058 00059 void utest::v1::verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure) 00060 { 00061 UTEST_LOG_FUNCTION(); 00062 utest_printf("\n>>> Test cases: %u passed, %u failed", passed, failed); 00063 if (failure.reason == REASON_NONE) { 00064 utest_printf("\n"); 00065 } else { 00066 utest_printf(" with reason '%s'\n", stringify(failure.reason)); 00067 } 00068 if (failed) utest_printf(">>> TESTS FAILED!\n"); 00069 } 00070 00071 void utest::v1::verbose_test_failure_handler(const failure_t failure) 00072 { 00073 utest_printf(">>> failure with reason '%s' during '%s'\n", stringify(failure.reason), stringify(failure.location)); 00074 00075 } 00076 00077 // --- VERBOSE CASE HANDLERS --- 00078 utest::v1::status_t utest::v1::verbose_case_setup_handler(const Case *const source, const size_t index_of_case) 00079 { 00080 UTEST_LOG_FUNCTION(); 00081 utest_printf("\n>>> Running case #%u: '%s'...\n", index_of_case + 1, source->get_description ()); 00082 return STATUS_CONTINUE; 00083 } 00084 00085 utest::v1::status_t utest::v1::verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure) 00086 { 00087 UTEST_LOG_FUNCTION(); 00088 utest_printf(">>> '%s': %u passed, %u failed", source->get_description (), passed, failed); 00089 if (failure.reason == REASON_NONE) { 00090 utest_printf("\n"); 00091 } else { 00092 utest_printf(" with reason '%s'\n", stringify(failure.reason)); 00093 } 00094 return STATUS_CONTINUE; 00095 } 00096 00097 utest::v1::status_t utest::v1::verbose_case_failure_handler(const Case *const /*source*/, const failure_t failure) 00098 { 00099 UTEST_LOG_FUNCTION(); 00100 if (!(failure.reason & REASON_ASSERTION)) { 00101 verbose_test_failure_handler(failure); 00102 } 00103 if (failure.reason & (REASON_TEST_TEARDOWN | REASON_CASE_TEARDOWN)) return STATUS_ABORT; 00104 if (failure.reason & REASON_IGNORE) return STATUS_IGNORE; 00105 return STATUS_CONTINUE; 00106 } 00107 00108 #endif
Generated on Tue Jul 12 2022 13:55:03 by
1.7.2