Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "mbed.h"
00017 #include "greentea-client/test_env.h"
00018 #include "utest/utest.h"
00019 #include "unity/unity.h"
00020 #include "utest/utest_stack_trace.h"
00021 
00022 using namespace utest::v1;
00023 
00024 void test_simple() {
00025     UTEST_LOG_FUNCTION();
00026     TEST_ASSERT_EQUAL(0, 0);
00027 }
00028 
00029 utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) {
00030     UTEST_LOG_FUNCTION();
00031     // Call the default handler for proper reporting
00032     utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case);
00033     utest_printf("Setting up for '%s'\n", source->get_description ());
00034     return status;
00035 }
00036 control_t test_repeats(const size_t call_count) {
00037     UTEST_LOG_FUNCTION();
00038     TEST_ASSERT_NOT_EQUAL(3, call_count);
00039     // Specify how often this test is repeated ie. n total calls
00040     return (call_count < 2) ? CaseRepeatAll : CaseNext;
00041 }
00042 
00043 // Custom setup handler required for proper Greentea support
00044 utest::v1::status_t greentea_setup(const size_t number_of_cases) {
00045     UTEST_LOG_FUNCTION();
00046     GREENTEA_SETUP(20, "default_auto");
00047     // Call the default reporting function
00048     return greentea_test_setup_handler(number_of_cases);
00049 }
00050 
00051 // Specify all your test cases here
00052 Case cases[] = {
00053     Case("Simple Test", test_simple),
00054     Case("Repeating Test", test_repeats_setup, test_repeats)
00055 };
00056 
00057 // Declare your test specification with a custom setup handler
00058 Specification specification(greentea_setup, cases);
00059 
00060 extern void utest_run(const Specification& specification);
00061 
00062 int main()
00063 {
00064     UTEST_LOG_FUNCTION();
00065     // Run the specification only AFTER setting the custom scheduler.
00066     Harness::run(specification);
00067 }