Skip to content

Commit 4c9ccd0

Browse files
authored
Merge pull request #2603 from andresag01/mbedtls_self_test
Port mbed TLS self test to greentea
2 parents 2564a83 + d6f40b6 commit 4c9ccd0

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

TESTS/mbedtls/selftest/main.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2016 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "mbed.h"
18+
#include "greentea-client/test_env.h"
19+
#include "unity.h"
20+
#include "utest.h"
21+
#include "rtos.h"
22+
23+
using namespace utest::v1;
24+
25+
#if !defined(MBEDTLS_CONFIG_FILE)
26+
#include "mbedtls/config.h"
27+
#else
28+
#include MBEDTLS_CONFIG_FILE
29+
#endif
30+
31+
#include "mbedtls/sha256.h"
32+
#include "mbedtls/sha512.h"
33+
#include "mbedtls/entropy.h"
34+
#include "mbedtls/entropy_poll.h"
35+
36+
#include <string.h>
37+
38+
#if defined(MBEDTLS_PLATFORM_C)
39+
#include "mbedtls/platform.h"
40+
#else
41+
#include <stdio.h>
42+
#include <stdlib.h>
43+
#define mbedtls_printf printf
44+
#define mbedtls_snprintf snprintf
45+
#define mbedtls_exit exit
46+
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
47+
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
48+
#endif
49+
50+
#define MBEDTLS_SELF_TEST_TEST_CASE(self_test_function) \
51+
void self_test_function ## _test_case() { \
52+
int ret = self_test_function(0); \
53+
TEST_ASSERT_EQUAL(ret, 0); \
54+
}
55+
56+
#if defined(MBEDTLS_SELF_TEST)
57+
58+
#if defined(MBEDTLS_SHA256_C)
59+
MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_sha256_self_test)
60+
#endif
61+
62+
#if defined(MBEDTLS_SHA512_C)
63+
MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_sha512_self_test)
64+
#endif
65+
66+
#if defined(MBEDTLS_ENTROPY_C)
67+
MBEDTLS_SELF_TEST_TEST_CASE(mbedtls_entropy_self_test)
68+
#endif
69+
70+
#else
71+
#warning "MBEDTLS_SELF_TEST not enabled"
72+
#endif /* MBEDTLS_SELF_TEST */
73+
74+
Case cases[] = {
75+
#if defined(MBEDTLS_SELF_TEST)
76+
77+
#if defined(MBEDTLS_SHA256_C)
78+
Case("mbedtls_sha256_self_test", mbedtls_sha256_self_test_test_case),
79+
#endif
80+
81+
#if defined(MBEDTLS_SHA512_C)
82+
Case("mbedtls_sha512_self_test", mbedtls_sha512_self_test_test_case),
83+
#endif
84+
85+
#if defined(MBEDTLS_ENTROPY_C)
86+
Case("mbedtls_entropy_self_test", mbedtls_entropy_self_test_test_case),
87+
#endif
88+
89+
#endif /* MBEDTLS_SELF_TEST */
90+
};
91+
92+
utest::v1::status_t test_setup(const size_t num_cases) {
93+
GREENTEA_SETUP(120, "default_auto");
94+
return verbose_test_setup_handler(num_cases);
95+
}
96+
97+
Specification specification(test_setup, cases);
98+
99+
int main() {
100+
return !Harness::run(specification);
101+
}
102+

0 commit comments

Comments
 (0)