Skip to content

Port mbed TLS self test to greentea #2603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions TESTS/mbedtls/selftest/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* mbed Microcontroller Library
* Copyright (c) 2016 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "rtos.h"

using namespace utest::v1;

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif

#include "mbedtls/sha256.h"
#include "mbedtls/sha512.h"
#include "mbedtls/entropy.h"
#include "mbedtls/entropy_poll.h"

#include <string.h>

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#include <stdlib.h>
#define mbedtls_printf printf
#define mbedtls_snprintf snprintf
#define mbedtls_exit exit
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
#endif

#define MBEDTLS_SELF_TEST_TEST_CASE(self_test_function) \
void self_test_function ## _test_case() { \
int ret = self_test_function(0); \
TEST_ASSERT_EQUAL(ret, 0); \
}

#if defined(MBEDTLS_SELF_TEST)

#if defined(MBEDTLS_SHA256_C)
MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_sha256_self_test)
#endif

#if defined(MBEDTLS_SHA512_C)
MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_sha512_self_test)
#endif

#if defined(MBEDTLS_ENTROPY_C)
MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_entropy_self_test)
#endif

#else
#warning "MBEDTLS_SELF_TEST not enabled"
#endif /* MBEDTLS_SELF_TEST */

Case cases[] = {
#if defined(MBEDTLS_SELF_TEST)

#if defined(MBEDTLS_SHA256_C)
Case("mbedtls_sha256_self_test", mbedtls_sha256_self_test_test_case),
#endif

#if defined(MBEDTLS_SHA512_C)
Case("mbedtls_sha512_self_test", mbedtls_sha512_self_test_test_case),
#endif

#if defined(MBEDTLS_ENTROPY_C)
Case("mbedtls_entropy_self_test", mbedtls_entropy_self_test_test_case),
#endif

#endif /* MBEDTLS_SELF_TEST */
};

utest::v1::status_t test_setup(const size_t num_cases) {
GREENTEA_SETUP(120, "default_auto");
return verbose_test_setup_handler(num_cases);
}

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}