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 /* This is a copy of the basic_test unit test without a custom setup handler being provided.
00017 */
00018 
00019 #include "mbed.h"
00020 #include "greentea-client/test_env.h"
00021 #include "utest/utest.h"
00022 #include "unity/unity.h"
00023 #include "utest/utest_stack_trace.h"
00024 
00025 using namespace utest::v1;
00026 
00027 void test_simple() {
00028     UTEST_LOG_FUNCTION();
00029     TEST_ASSERT_EQUAL(0, 0);
00030 }
00031 
00032 utest::v1::status_t test_repeats_setup(const Case *const source, const size_t index_of_case) {
00033     UTEST_LOG_FUNCTION();
00034     // Call the default handler for proper reporting
00035     utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case);
00036     utest_printf("Setting up for '%s'\n", source->get_description ());
00037     return status;
00038 }
00039 control_t test_repeats(const size_t call_count) {
00040     UTEST_LOG_FUNCTION();
00041     TEST_ASSERT_NOT_EQUAL(3, call_count);
00042     // Specify how often this test is repeated ie. n total calls
00043     return (call_count < 2) ? CaseRepeatAll : CaseNext;
00044 }
00045 
00046 
00047 // Specify all your test cases here
00048 Case cases[] = {
00049     Case("Simple Test", test_simple),
00050     Case("Repeating Test", test_repeats_setup, test_repeats)
00051 };
00052 
00053 // Declare your test specification. If no custom setup handler is provided then
00054 // the default handler will be used.
00055 Specification specification(cases);
00056 
00057 extern void utest_run(const Specification& specification);
00058 
00059 int main()
00060 {
00061     UTEST_LOG_FUNCTION();
00062     Harness::run(specification);
00063 }