Knight KE / Mbed OS Game_Master
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2016 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 
00017 #include "mbed.h"
00018 #include "greentea-client/test_env.h"
00019 #include "unity.h"
00020 #include "utest.h"
00021 #include "rtos.h"
00022 
00023 using namespace utest::v1;
00024 
00025 #if !defined(MBEDTLS_CONFIG_FILE)
00026 #include "mbedtls/config.h"
00027 #else
00028 #include MBEDTLS_CONFIG_FILE
00029 #endif
00030 
00031 #include "mbedtls/sha256.h"
00032 #include "mbedtls/sha512.h"
00033 #include "mbedtls/entropy.h"
00034 #include "mbedtls/entropy_poll.h"
00035 
00036 #include <string.h>
00037 
00038 #if defined(MBEDTLS_PLATFORM_C)
00039 #include "mbedtls/platform.h"
00040 #else
00041 #include <stdio.h>
00042 #define mbedtls_printf     printf
00043 #endif
00044 
00045 #define MBEDTLS_SELF_TEST_TEST_CASE(self_test_function) \
00046     void self_test_function ## _test_case() {           \
00047         int ret = self_test_function(0);                \
00048         TEST_ASSERT_EQUAL(ret, 0);                      \
00049     }
00050 
00051 #if defined(MBEDTLS_SELF_TEST)
00052 
00053 #if defined(MBEDTLS_SHA256_C)
00054 MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_sha256_self_test)
00055 #endif
00056 
00057 #if defined(MBEDTLS_SHA512_C)
00058 MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_sha512_self_test)
00059 #endif
00060 
00061 #if defined(MBEDTLS_ENTROPY_C)
00062 MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_entropy_self_test)
00063 #endif
00064 
00065 #else
00066 #warning "MBEDTLS_SELF_TEST not enabled"
00067 #endif /* MBEDTLS_SELF_TEST */
00068 
00069 Case cases[] = {
00070 #if defined(MBEDTLS_SELF_TEST)
00071 
00072 #if defined(MBEDTLS_SHA256_C)
00073     Case("mbedtls_sha256_self_test", mbedtls_sha256_self_test_test_case),
00074 #endif
00075 
00076 #if defined(MBEDTLS_SHA512_C)
00077     Case("mbedtls_sha512_self_test", mbedtls_sha512_self_test_test_case),
00078 #endif
00079 
00080 #if defined(MBEDTLS_ENTROPY_C)
00081     Case("mbedtls_entropy_self_test", mbedtls_entropy_self_test_test_case),
00082 #endif
00083 
00084 #endif /* MBEDTLS_SELF_TEST */
00085 };
00086 
00087 utest::v1::status_t test_setup(const size_t num_cases) {
00088     GREENTEA_SETUP(120, "default_auto");
00089     return verbose_test_setup_handler(num_cases);
00090 }
00091 
00092 Specification specification(test_setup, cases);
00093 
00094 int main() {
00095     int ret = 0;
00096 #if defined(MBEDTLS_PLATFORM_C)
00097     mbedtls_platform_context platform_ctx;
00098     if((ret = mbedtls_platform_setup(&platform_ctx))!= 0)
00099     {
00100         mbedtls_printf("Mbed TLS selftest failed! mbedtls_platform_setup returned %d\n", ret);
00101         return 1;
00102     }
00103 #endif
00104     ret = (Harness::run(specification) ? 0 : 1);
00105 #if defined(MBEDTLS_PLATFORM_C)
00106     mbedtls_platform_teardown(&platform_ctx);
00107 #endif
00108     return ret;
00109 }
00110