TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_framework.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __TEST_FRAMEWORK_H__
9 #define __TEST_FRAMEWORK_H__
10 
11 #include <stdarg.h>
12 #include <stdint.h>
13 #include <stdio.h>
14 
15 #include "tfm_log_raw.h"
16 #include "test_framework_helpers.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
25 };
26 
27 struct test_result_t {
29  const char *info_msg;
32  const char *filename;
33  uint32_t line;
34 };
35 
41 typedef void TEST_FUN(struct test_result_t *ret);
42 
43 struct test_t {
44  TEST_FUN * const test;
45  const char *name;
46  const char *desc;
47  struct test_result_t ret;
48 };
49 
50 struct test_suite_t;
51 
57 typedef void TESTSUITE_REG(struct test_suite_t *p_test_suite);
58 
59 struct test_suite_t {
60  TESTSUITE_REG * const freg;
63  struct test_t *test_list;
64  uint32_t list_size;
65  const char *name;
67 };
68 
78 };
79 
87 const char *test_err_to_str(enum test_suite_err_t err);
88 
100 enum test_suite_err_t set_testsuite(const char *name,
101  struct test_t *test_list, uint32_t size,
102  struct test_suite_t *p_ts);
103 
112 enum test_suite_err_t run_testsuite(struct test_suite_t *test_suite);
113 
119 void show_tests(const struct test_suite_t *ts);
120 
134 void set_test_failed(const char *info_msg, const char *filename, uint32_t line,
135  struct test_result_t *ret);
136 
137 #define TEST_FAIL(info_msg) set_test_failed(info_msg, __FILE__, __LINE__, ret)
138 
139 #define TEST_LOG(...) tfm_log_printf(__VA_ARGS__)
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* __TEST_FRAMEWORK_H__ */
TEST_FUN *const test
enum test_suite_err_t set_testsuite(const char *name, struct test_t *test_list, uint32_t size, struct test_suite_t *p_ts)
Sets test suite parameters.
void TESTSUITE_REG(struct test_suite_t *p_test_suite)
Registers test in the testsuite structure and sets the name.
uint32_t list_size
void show_tests(const struct test_suite_t *ts)
Prints all test in the the given test suite.
const char * info_msg
void set_test_failed(const char *info_msg, const char *filename, uint32_t line, struct test_result_t *ret)
Sets test failure state and information in the test_result_t structure.
const char * filename
enum test_status_t val
const char * name
TESTSUITE_REG *const freg
struct test_t * test_list
const char * name
struct test_result_t ret
enum test_status_t val
enum test_suite_err_t run_testsuite(struct test_suite_t *test_suite)
Runs the given test suite.
test_status_t
void TEST_FUN(struct test_result_t *ret)
Runs the test.
const char * desc
test_suite_err_t
const char * test_err_to_str(enum test_suite_err_t err)
Translates the test suite error into a string.