Committer:
nexpaq
Date:
Fri Nov 04 20:27:58 2016 +0000
Revision:
0:6c56fb4bc5f0
Moving to library for sharing updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 /*
nexpaq 0:6c56fb4bc5f0 2 * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
nexpaq 0:6c56fb4bc5f0 3 * SPDX-License-Identifier: Apache-2.0
nexpaq 0:6c56fb4bc5f0 4 *
nexpaq 0:6c56fb4bc5f0 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
nexpaq 0:6c56fb4bc5f0 6 * not use this file except in compliance with the License.
nexpaq 0:6c56fb4bc5f0 7 * You may obtain a copy of the License at
nexpaq 0:6c56fb4bc5f0 8 *
nexpaq 0:6c56fb4bc5f0 9 * http://www.apache.org/licenses/LICENSE-2.0
nexpaq 0:6c56fb4bc5f0 10 *
nexpaq 0:6c56fb4bc5f0 11 * Unless required by applicable law or agreed to in writing, software
nexpaq 0:6c56fb4bc5f0 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
nexpaq 0:6c56fb4bc5f0 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nexpaq 0:6c56fb4bc5f0 14 * See the License for the specific language governing permissions and
nexpaq 0:6c56fb4bc5f0 15 * limitations under the License.
nexpaq 0:6c56fb4bc5f0 16 */
nexpaq 0:6c56fb4bc5f0 17 #include <stdio.h>
nexpaq 0:6c56fb4bc5f0 18 #include <string.h>
nexpaq 0:6c56fb4bc5f0 19 #include <utility> // std::pair
nexpaq 0:6c56fb4bc5f0 20 #include "mbed.h"
nexpaq 0:6c56fb4bc5f0 21 #include "greentea-client/test_env.h"
nexpaq 0:6c56fb4bc5f0 22 #include "unity/unity.h"
nexpaq 0:6c56fb4bc5f0 23 #include "utest/utest.h"
nexpaq 0:6c56fb4bc5f0 24
nexpaq 0:6c56fb4bc5f0 25 using namespace utest::v1;
nexpaq 0:6c56fb4bc5f0 26
nexpaq 0:6c56fb4bc5f0 27 #define PATTERN_CHECK_VALUE 0xF0F0ADAD
nexpaq 0:6c56fb4bc5f0 28
nexpaq 0:6c56fb4bc5f0 29 class CppTestCaseHelperClass {
nexpaq 0:6c56fb4bc5f0 30 private:
nexpaq 0:6c56fb4bc5f0 31 const char* name;
nexpaq 0:6c56fb4bc5f0 32 const unsigned pattern;
nexpaq 0:6c56fb4bc5f0 33
nexpaq 0:6c56fb4bc5f0 34 public:
nexpaq 0:6c56fb4bc5f0 35 CppTestCaseHelperClass(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) {
nexpaq 0:6c56fb4bc5f0 36 print("init");
nexpaq 0:6c56fb4bc5f0 37 }
nexpaq 0:6c56fb4bc5f0 38
nexpaq 0:6c56fb4bc5f0 39 void print(const char *message) {
nexpaq 0:6c56fb4bc5f0 40 printf("%s::%s\n", name, message);
nexpaq 0:6c56fb4bc5f0 41 }
nexpaq 0:6c56fb4bc5f0 42
nexpaq 0:6c56fb4bc5f0 43 bool check_init(void) {
nexpaq 0:6c56fb4bc5f0 44 bool result = (pattern == PATTERN_CHECK_VALUE);
nexpaq 0:6c56fb4bc5f0 45 print(result ? "check_init: OK" : "check_init: ERROR");
nexpaq 0:6c56fb4bc5f0 46 return result;
nexpaq 0:6c56fb4bc5f0 47 }
nexpaq 0:6c56fb4bc5f0 48
nexpaq 0:6c56fb4bc5f0 49 void stack_test(void) {
nexpaq 0:6c56fb4bc5f0 50 print("stack_test");
nexpaq 0:6c56fb4bc5f0 51 CppTestCaseHelperClass t("Stack");
nexpaq 0:6c56fb4bc5f0 52 t.hello();
nexpaq 0:6c56fb4bc5f0 53 }
nexpaq 0:6c56fb4bc5f0 54
nexpaq 0:6c56fb4bc5f0 55 void hello(void) {
nexpaq 0:6c56fb4bc5f0 56 print("hello");
nexpaq 0:6c56fb4bc5f0 57 }
nexpaq 0:6c56fb4bc5f0 58
nexpaq 0:6c56fb4bc5f0 59 ~CppTestCaseHelperClass() {
nexpaq 0:6c56fb4bc5f0 60 print("destroy");
nexpaq 0:6c56fb4bc5f0 61 }
nexpaq 0:6c56fb4bc5f0 62 };
nexpaq 0:6c56fb4bc5f0 63
nexpaq 0:6c56fb4bc5f0 64
nexpaq 0:6c56fb4bc5f0 65 void test_case_basic() {
nexpaq 0:6c56fb4bc5f0 66 TEST_ASSERT_TRUE(true);
nexpaq 0:6c56fb4bc5f0 67 TEST_ASSERT_FALSE(false);
nexpaq 0:6c56fb4bc5f0 68 TEST_ASSERT_EQUAL_STRING("The quick brown fox jumps over the lazy dog",
nexpaq 0:6c56fb4bc5f0 69 "The quick brown fox jumps over the lazy dog");
nexpaq 0:6c56fb4bc5f0 70 }
nexpaq 0:6c56fb4bc5f0 71
nexpaq 0:6c56fb4bc5f0 72 void test_case_blinky() {
nexpaq 0:6c56fb4bc5f0 73 static DigitalOut myled(LED1);
nexpaq 0:6c56fb4bc5f0 74 const int cnt_max = 1024;
nexpaq 0:6c56fb4bc5f0 75 for (int cnt = 0; cnt < cnt_max; ++cnt) {
nexpaq 0:6c56fb4bc5f0 76 myled = !myled;
nexpaq 0:6c56fb4bc5f0 77 }
nexpaq 0:6c56fb4bc5f0 78 }
nexpaq 0:6c56fb4bc5f0 79
nexpaq 0:6c56fb4bc5f0 80 void test_case_cpp_stack() {
nexpaq 0:6c56fb4bc5f0 81 // Check C++ start-up initialisation
nexpaq 0:6c56fb4bc5f0 82 CppTestCaseHelperClass s("Static");
nexpaq 0:6c56fb4bc5f0 83
nexpaq 0:6c56fb4bc5f0 84 // Global stack object simple test
nexpaq 0:6c56fb4bc5f0 85 s.stack_test();
nexpaq 0:6c56fb4bc5f0 86 TEST_ASSERT_TRUE_MESSAGE(s.check_init(), "s.check_init() failed");
nexpaq 0:6c56fb4bc5f0 87 }
nexpaq 0:6c56fb4bc5f0 88
nexpaq 0:6c56fb4bc5f0 89 void test_case_cpp_heap() {
nexpaq 0:6c56fb4bc5f0 90 // Heap test object simple test
nexpaq 0:6c56fb4bc5f0 91 CppTestCaseHelperClass *m = new CppTestCaseHelperClass("Heap");
nexpaq 0:6c56fb4bc5f0 92 m->hello();
nexpaq 0:6c56fb4bc5f0 93 TEST_ASSERT_TRUE_MESSAGE(m->check_init(), "m->check_init() failed");
nexpaq 0:6c56fb4bc5f0 94 delete m;
nexpaq 0:6c56fb4bc5f0 95 }
nexpaq 0:6c56fb4bc5f0 96
nexpaq 0:6c56fb4bc5f0 97 utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
nexpaq 0:6c56fb4bc5f0 98 greentea_case_failure_abort_handler(source, reason);
nexpaq 0:6c56fb4bc5f0 99 return STATUS_CONTINUE;
nexpaq 0:6c56fb4bc5f0 100 }
nexpaq 0:6c56fb4bc5f0 101
nexpaq 0:6c56fb4bc5f0 102 // Generic test cases
nexpaq 0:6c56fb4bc5f0 103 Case cases[] = {
nexpaq 0:6c56fb4bc5f0 104 Case("Basic", test_case_basic, greentea_failure_handler),
nexpaq 0:6c56fb4bc5f0 105 Case("Blinky", test_case_blinky, greentea_failure_handler),
nexpaq 0:6c56fb4bc5f0 106 Case("C++ stack", test_case_cpp_stack, greentea_failure_handler),
nexpaq 0:6c56fb4bc5f0 107 Case("C++ heap", test_case_cpp_heap, greentea_failure_handler)
nexpaq 0:6c56fb4bc5f0 108 };
nexpaq 0:6c56fb4bc5f0 109
nexpaq 0:6c56fb4bc5f0 110 utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
nexpaq 0:6c56fb4bc5f0 111 GREENTEA_SETUP(20, "default_auto");
nexpaq 0:6c56fb4bc5f0 112 return greentea_test_setup_handler(number_of_cases);
nexpaq 0:6c56fb4bc5f0 113 }
nexpaq 0:6c56fb4bc5f0 114
nexpaq 0:6c56fb4bc5f0 115 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
nexpaq 0:6c56fb4bc5f0 116
nexpaq 0:6c56fb4bc5f0 117 int main() {
nexpaq 0:6c56fb4bc5f0 118 Harness::run(specification);
nexpaq 0:6c56fb4bc5f0 119 }