Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/TESTS/mbedmicro-mbed/cpp/main.cpp@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* mbed Microcontroller Library |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2017 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 3 | * |
marcozecchini | 0:9fca2b23d0ba | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 5 | * you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 6 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 7 | * |
marcozecchini | 0:9fca2b23d0ba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 9 | * |
marcozecchini | 0:9fca2b23d0ba | 10 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 13 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 14 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 15 | */ |
marcozecchini | 0:9fca2b23d0ba | 16 | #include "greentea-client/test_env.h" |
marcozecchini | 0:9fca2b23d0ba | 17 | |
marcozecchini | 0:9fca2b23d0ba | 18 | #define PATTERN_CHECK_VALUE 0xF0F0ADAD |
marcozecchini | 0:9fca2b23d0ba | 19 | |
marcozecchini | 0:9fca2b23d0ba | 20 | class Test { |
marcozecchini | 0:9fca2b23d0ba | 21 | |
marcozecchini | 0:9fca2b23d0ba | 22 | private: |
marcozecchini | 0:9fca2b23d0ba | 23 | const char* name; |
marcozecchini | 0:9fca2b23d0ba | 24 | const int pattern; |
marcozecchini | 0:9fca2b23d0ba | 25 | |
marcozecchini | 0:9fca2b23d0ba | 26 | public: |
marcozecchini | 0:9fca2b23d0ba | 27 | Test(const char* _name, bool print_message=true) : name(_name), pattern(PATTERN_CHECK_VALUE) { |
marcozecchini | 0:9fca2b23d0ba | 28 | if (print_message) { |
marcozecchini | 0:9fca2b23d0ba | 29 | print("init"); |
marcozecchini | 0:9fca2b23d0ba | 30 | } |
marcozecchini | 0:9fca2b23d0ba | 31 | } |
marcozecchini | 0:9fca2b23d0ba | 32 | |
marcozecchini | 0:9fca2b23d0ba | 33 | void print(const char *message) { |
marcozecchini | 0:9fca2b23d0ba | 34 | printf("%s::%s\n", name, message); |
marcozecchini | 0:9fca2b23d0ba | 35 | } |
marcozecchini | 0:9fca2b23d0ba | 36 | |
marcozecchini | 0:9fca2b23d0ba | 37 | bool check_init(void) { |
marcozecchini | 0:9fca2b23d0ba | 38 | bool result = (pattern == PATTERN_CHECK_VALUE); |
marcozecchini | 0:9fca2b23d0ba | 39 | print(result ? "check_init: OK" : "check_init: ERROR"); |
marcozecchini | 0:9fca2b23d0ba | 40 | return result; |
marcozecchini | 0:9fca2b23d0ba | 41 | } |
marcozecchini | 0:9fca2b23d0ba | 42 | |
marcozecchini | 0:9fca2b23d0ba | 43 | void stack_test(void) { |
marcozecchini | 0:9fca2b23d0ba | 44 | print("stack_test"); |
marcozecchini | 0:9fca2b23d0ba | 45 | Test t("Stack"); |
marcozecchini | 0:9fca2b23d0ba | 46 | t.hello(); |
marcozecchini | 0:9fca2b23d0ba | 47 | } |
marcozecchini | 0:9fca2b23d0ba | 48 | |
marcozecchini | 0:9fca2b23d0ba | 49 | void hello(void) { |
marcozecchini | 0:9fca2b23d0ba | 50 | print("hello"); |
marcozecchini | 0:9fca2b23d0ba | 51 | } |
marcozecchini | 0:9fca2b23d0ba | 52 | |
marcozecchini | 0:9fca2b23d0ba | 53 | ~Test() { |
marcozecchini | 0:9fca2b23d0ba | 54 | print("destroy"); |
marcozecchini | 0:9fca2b23d0ba | 55 | } |
marcozecchini | 0:9fca2b23d0ba | 56 | }; |
marcozecchini | 0:9fca2b23d0ba | 57 | |
marcozecchini | 0:9fca2b23d0ba | 58 | /* Check C++ startup initialisation */ |
marcozecchini | 0:9fca2b23d0ba | 59 | Test s("Static", false); |
marcozecchini | 0:9fca2b23d0ba | 60 | |
marcozecchini | 0:9fca2b23d0ba | 61 | /* EXPECTED OUTPUT: |
marcozecchini | 0:9fca2b23d0ba | 62 | ******************* |
marcozecchini | 0:9fca2b23d0ba | 63 | Static::init |
marcozecchini | 0:9fca2b23d0ba | 64 | Static::stack_test |
marcozecchini | 0:9fca2b23d0ba | 65 | Stack::init |
marcozecchini | 0:9fca2b23d0ba | 66 | Stack::hello |
marcozecchini | 0:9fca2b23d0ba | 67 | Stack::destroy |
marcozecchini | 0:9fca2b23d0ba | 68 | Static::check_init: OK |
marcozecchini | 0:9fca2b23d0ba | 69 | Heap::init |
marcozecchini | 0:9fca2b23d0ba | 70 | Heap::hello |
marcozecchini | 0:9fca2b23d0ba | 71 | Heap::destroy |
marcozecchini | 0:9fca2b23d0ba | 72 | *******************/ |
marcozecchini | 0:9fca2b23d0ba | 73 | int main (void) { |
marcozecchini | 0:9fca2b23d0ba | 74 | GREENTEA_SETUP(10, "default_auto"); |
marcozecchini | 0:9fca2b23d0ba | 75 | |
marcozecchini | 0:9fca2b23d0ba | 76 | bool result = true; |
marcozecchini | 0:9fca2b23d0ba | 77 | for (;;) |
marcozecchini | 0:9fca2b23d0ba | 78 | { |
marcozecchini | 0:9fca2b23d0ba | 79 | s.print("init"); |
marcozecchini | 0:9fca2b23d0ba | 80 | // Global stack object simple test |
marcozecchini | 0:9fca2b23d0ba | 81 | s.stack_test(); |
marcozecchini | 0:9fca2b23d0ba | 82 | if (s.check_init() == false) |
marcozecchini | 0:9fca2b23d0ba | 83 | { |
marcozecchini | 0:9fca2b23d0ba | 84 | result = false; |
marcozecchini | 0:9fca2b23d0ba | 85 | break; |
marcozecchini | 0:9fca2b23d0ba | 86 | } |
marcozecchini | 0:9fca2b23d0ba | 87 | |
marcozecchini | 0:9fca2b23d0ba | 88 | // Heap test object simple test |
marcozecchini | 0:9fca2b23d0ba | 89 | Test *m = new Test("Heap"); |
marcozecchini | 0:9fca2b23d0ba | 90 | m->hello(); |
marcozecchini | 0:9fca2b23d0ba | 91 | |
marcozecchini | 0:9fca2b23d0ba | 92 | if (m->check_init() == false) |
marcozecchini | 0:9fca2b23d0ba | 93 | { |
marcozecchini | 0:9fca2b23d0ba | 94 | result = false; |
marcozecchini | 0:9fca2b23d0ba | 95 | } |
marcozecchini | 0:9fca2b23d0ba | 96 | delete m; |
marcozecchini | 0:9fca2b23d0ba | 97 | break; |
marcozecchini | 0:9fca2b23d0ba | 98 | } |
marcozecchini | 0:9fca2b23d0ba | 99 | |
marcozecchini | 0:9fca2b23d0ba | 100 | GREENTEA_TESTSUITE_RESULT(result); |
marcozecchini | 0:9fca2b23d0ba | 101 | } |