Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 /* mbed Microcontroller Library
00003  * Copyright (c) 2013-2015 ARM Limited
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may 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,
00013  * WITHOUT 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 "mbed.h"
00018 #include "greentea-client/test_env.h"
00019 #include "utest/utest.h"
00020 #include "unity/unity.h"
00021 
00022 
00023 using namespace utest::v1;
00024 
00025 static bool failure_is_in_setup = false;
00026 
00027 void never_call_case()
00028 {
00029     TEST_FAIL_MESSAGE("Case handler should have never been called!");
00030 }
00031 Case cases[] =
00032 {
00033     Case("dummy test", never_call_case)
00034 };
00035 
00036 // this setup handler fails
00037 utest::v1::status_t failing_setup_handler(const size_t number_of_cases)
00038 {
00039     GREENTEA_SETUP(5, "default_auto");
00040 
00041     utest::v1::status_t status = greentea_test_setup_handler(number_of_cases);
00042 
00043     failure_is_in_setup = true;
00044     TEST_FAIL_MESSAGE("Explicit assertion failure in test setup handler!");
00045     return status;
00046 };
00047 
00048 void test_failure_handler(const failure_t failure)
00049 {
00050     if (failure_is_in_setup) {
00051         failure_is_in_setup = false;
00052         TEST_ASSERT_EQUAL(REASON_ASSERTION, failure.reason);
00053         TEST_ASSERT_EQUAL(LOCATION_TEST_SETUP, failure.location);
00054         verbose_test_failure_handler(failure);
00055 
00056         // pretend to greentea that we actally executed one test case
00057         greentea_case_setup_handler(cases, 0);
00058         greentea_case_teardown_handler(cases, 1, 0, REASON_NONE);
00059 
00060         // pretend to greentea that the test was successful
00061         greentea_test_teardown_handler(1, 0, REASON_NONE);
00062         while(1) ;
00063     }
00064     else {
00065         selftest_handlers.test_failure(failure);
00066     }
00067 }
00068 
00069 const handlers_t custom_handlers = {
00070     greentea_abort_handlers.test_setup,
00071     greentea_abort_handlers.test_teardown,
00072     test_failure_handler,
00073     greentea_abort_handlers.case_setup,
00074     greentea_abort_handlers.case_teardown,
00075     greentea_abort_handlers.case_failure
00076 };
00077 
00078 Specification specification(failing_setup_handler, cases, custom_handlers);
00079 
00080 int main()
00081 {
00082     Harness::run(specification);
00083 }