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.
Fork of mbed-os by
main.cpp
00001 /* 00002 * Copyright (c) 2013-2016, 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 #include <stdio.h> 00018 #include <string.h> 00019 #include <utility> // std::pair 00020 #include "mbed.h" 00021 #include "greentea-client/test_env.h" 00022 #include "unity/unity.h" 00023 #include "utest/utest.h" 00024 00025 using namespace utest::v1; 00026 00027 #define PATTERN_CHECK_VALUE 0xF0F0ADAD 00028 00029 class CppTestCaseHelperClass { 00030 private: 00031 const char* name; 00032 const unsigned pattern; 00033 00034 public: 00035 CppTestCaseHelperClass(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) { 00036 print("init"); 00037 } 00038 00039 void print(const char *message) { 00040 printf("%s::%s\n", name, message); 00041 } 00042 00043 bool check_init(void) { 00044 bool result = (pattern == PATTERN_CHECK_VALUE); 00045 print(result ? "check_init: OK" : "check_init: ERROR"); 00046 return result; 00047 } 00048 00049 void stack_test(void) { 00050 print("stack_test"); 00051 CppTestCaseHelperClass t("Stack"); 00052 t.hello(); 00053 } 00054 00055 void hello(void) { 00056 print("hello"); 00057 } 00058 00059 ~CppTestCaseHelperClass() { 00060 print("destroy"); 00061 } 00062 }; 00063 00064 00065 void test_case_basic() { 00066 TEST_ASSERT_TRUE(true); 00067 TEST_ASSERT_FALSE(false); 00068 TEST_ASSERT_EQUAL_STRING("The quick brown fox jumps over the lazy dog", 00069 "The quick brown fox jumps over the lazy dog"); 00070 } 00071 00072 void test_case_blinky() { 00073 static DigitalOut myled(LED1); 00074 const int cnt_max = 1024; 00075 for (int cnt = 0; cnt < cnt_max; ++cnt) { 00076 myled = !myled; 00077 } 00078 } 00079 00080 void test_case_cpp_stack() { 00081 // Check C++ start-up initialisation 00082 CppTestCaseHelperClass s("Static"); 00083 00084 // Global stack object simple test 00085 s.stack_test(); 00086 TEST_ASSERT_TRUE_MESSAGE(s.check_init(), "s.check_init() failed"); 00087 } 00088 00089 void test_case_cpp_heap() { 00090 // Heap test object simple test 00091 CppTestCaseHelperClass *m = new CppTestCaseHelperClass("Heap"); 00092 m->hello(); 00093 TEST_ASSERT_TRUE_MESSAGE(m->check_init(), "m->check_init() failed"); 00094 delete m; 00095 } 00096 00097 utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { 00098 greentea_case_failure_abort_handler(source, reason); 00099 return STATUS_CONTINUE; 00100 } 00101 00102 // Generic test cases 00103 Case cases[] = { 00104 Case("Basic", test_case_basic, greentea_failure_handler), 00105 Case("Blinky", test_case_blinky, greentea_failure_handler), 00106 Case("C++ stack", test_case_cpp_stack, greentea_failure_handler), 00107 Case("C++ heap", test_case_cpp_heap, greentea_failure_handler) 00108 }; 00109 00110 utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { 00111 GREENTEA_SETUP(20, "default_auto"); 00112 return greentea_test_setup_handler(number_of_cases); 00113 } 00114 00115 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); 00116 00117 int main() { 00118 Harness::run(specification); 00119 }
Generated on Tue Jul 12 2022 13:15:57 by
