Software APIs
ottf_test_config.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_TEST_CONFIG_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_TEST_CONFIG_H_
7 
8 /**
9  * Communication interfaces that can be used as the OTTF console.
10  */
11 typedef enum ottf_console_type {
12  kOttfConsoleUart = 0,
13  kOttfConsoleSpiDevice,
14 } ottf_console_type_t;
15 
16 typedef struct ottf_console {
17  /**
18  * Communication interface type to use for the OTTF console (see
19  * `ottf_console_type_t` above).
20  */
21  ottf_console_type_t type;
22  /**
23  * Base address of the communication IP interface to use for the OTTF console.
24  */
25  uintptr_t base_addr;
26  /**
27  * Indicates if the test may clobber (i.e., reconfigure it and use it during
28  * the test for another purpose) the OTTF console, and if the OTTF should
29  * reconfigure it before printing the test status.
30  */
33 
34 /**
35  * Configuration variables for an on-device test.
36  *
37  * This type represents configuration values for an on-device test, which allow
38  * tests to configure the behavior of the OpenTitan Test Framework (OTTF).
39  *
40  * WARNING: DO NOT REARRANGE THE MEMBERS IN THIS STRUCT. THE FIRST MEMBER IS
41  * ACCESSED BY OTTF ISR ASSEMBLY WHICH EXPECTS A SPECIFIC CONFIGURATION.
42  *
43  * However, new fields can be safely added to this struct without affecting any
44  * tests; the "default" value of all fields should be zero (or NULL, or
45  * equivalent).
46  *
47  * See `kOttfTestConfig`.
48  */
49 typedef struct ottf_test_config {
50  /**
51  * If true, `test_main()` is run as a FreeRTOS task, enabling test writers
52  * to spawn additional (concurrent) FreeRTOS tasks within the
53  * `test_main()` execution context.
54  *
55  * If false, `test_main()` is executed on bare-metal, and cannot spawn
56  * additional concurrent execution contexts. This is useful for tests that
57  * do not require concurrency, and seek to minimize simulation runtime.
58  */
60 
61  /**
62  * The communication peripheral to use as the test console, i.e. where test
63  * status and error messages are written to. Typically UART0, but other
64  * communication peripherals may be supported.
65  */
67 
68  /**
69  * Indicates that this test will utilize the UART to receive commands from
70  * a test harness and that the UART should enable software flow control.
71  * Note that requesting flow control will unmask the external interrupt and
72  * enable interrupt handling before `test_main` begins.
73  */
75 
76  /**
77  * Indicates that this test needs an explicit clear of the RSTMGR reset_reason
78  * register. This may be necessary for tests that execute with the OTP
79  * configuration OWNER_SW_CFG_ROM_PRESERVE_RESET_REASON_EN set to true.
80  */
82 
83  /**
84  */
85  bool silence_console_prints;
86 
87  /**
88  * Name of the file in which `kOttfTestConfig` is defined. Most of the time,
89  * this will be the file that defines `test_main()`.
90  */
91  const char *file;
93 
94 /**
95  * Helper macro for defining the `kOttfTestConfig` symbol in test files.
96  *
97  * While the `kOttfTestConfig` struct can be defined directly, tests should
98  * prefer this macro since it handles the definition of the `file` field.
99  *
100  * A test with default options should use:
101  *
102  * OTTF_DEFINE_TEST_CONFIG();
103  *
104  * A test that wants to enable concurrency and can also clobber UART should use:
105  *
106  * OTTF_DEFINE_TEST_CONFIG(.enable_concurrency = true,
107  * .console.test_may_clobber = true, );
108  *
109  */
110 #define OTTF_DEFINE_TEST_CONFIG(...) \
111  const ottf_test_config_t kOttfTestConfig = {.file = __FILE__, __VA_ARGS__}
112 
113 /**
114  * Global test configuration.
115  *
116  * This symbol should be defined externally in a standalone SW test. For most
117  * tests, this will just look like the following:
118  *
119  * OTTF_DEFINE_TEST_CONFIG();
120  *
121  * The zero values of all of the fields will behave like sane defaults.
122  *
123  * This value needs to be provided as a global so that the initialization code
124  * that runs before `test_main()` is executed can take note of it.
125  */
126 extern const ottf_test_config_t kOttfTestConfig;
127 
128 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_OTTF_TEST_CONFIG_H_