1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef FWK_TEST_H
9 #define FWK_TEST_H
10 
11 /*!
12  * \addtogroup GroupLibFramework Framework
13  * \{
14  */
15 
16 /*!
17  * \defgroup GroupTest Test
18  *
19  * \{
20  */
21 
22 /*!
23  * \brief Define a test case description.
24  *
25  * \param FUNC Test case function name.
26  *
27  * \return A test case description.
28  */
29 #define FWK_TEST_CASE(FUNC) { .name = #FUNC, .test_execute = FUNC }
30 
31 /*!
32  * \brief Test case description.
33  */
34 struct fwk_test_case_desc {
35     /*! Test case name */
36     const char *name;
37 
38     /*!
39      * \brief Pointer to the test case execution function.
40      *
41      * \return None.
42      *
43      * \note A test case is identified as having successfully completed if
44      *      execution returns from this function. Test case execution functions
45      *      should use the assert() macro from the C standard library to check
46      *      test conditions.
47      */
48     void (*test_execute)(void);
49 };
50 
51 /*!
52  * \brief Test suite description.
53  */
54 struct fwk_test_suite_desc {
55     /*! Test suite name */
56     const char *name;
57 
58     /*!
59      * \brief Pointer to a test suite setup function.
60      *
61      * \details This function should be used to initialize and configure a test
62      *      fixture or to execute expensive routines that could otherwise be
63      *      done within a test case setup function.
64      *
65      * \retval ::FWK_SUCCESS The test suite environment was successfully set up.
66      * \return Any of the other error codes defined by the framework.
67      *
68      * \note May be NULL, in which case the test suite is considered to have no
69      *      setup function. In the event that test suite setup fails, the test
70      *      suite is not executed.
71      */
72     int (*test_suite_setup)(void);
73 
74     /*!
75      * \brief Pointer to a test suite teardown function.
76      *
77      * \return None.
78      *
79      * \note May be NULL, in which case the test suite is considered to have no
80      *      teardown function.
81      */
82     void (*test_suite_teardown)(void);
83 
84     /*!
85      * \brief Pointer to a test case setup function.
86      *
87      * \details This function should be used to ensure test cases are running in
88      *      a known, sane environment prior to execution.
89      *
90      * \return None.
91      *
92      * \note May be NULL, in which case the test case is considered to have no
93      *      setup function.
94      */
95     void (*test_case_setup)(void);
96 
97     /*!
98      * \brief Pointer to a test case teardown function.
99      *
100      * \return None.
101      *
102      * \note May be NULL, in which case the test case is considered to have no
103      *      teardown function.
104      */
105     void (*test_case_teardown)(void);
106 
107     /*! Number of test cases */
108     unsigned int test_case_count;
109 
110     /*! Pointer to array of test cases */
111     const struct fwk_test_case_desc *test_case_table;
112 };
113 
114 /*!
115  * \}
116  */
117 
118 /*!
119  * \}
120  */
121 
122 #endif /* FWK_TEST_H */
123