Mistake on this page?
Report an issue in GitHub or email us
utest_default_handlers.h
1 /****************************************************************************
2  * Copyright (c) 2015, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  ****************************************************************************
17  */
18 
19 #ifndef UTEST_DEFAULT_HANDLER_H
20 #define UTEST_DEFAULT_HANDLER_H
21 
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include "utest/utest_types.h"
26 
27 
28 namespace utest {
29 /** \addtogroup frameworks */
30 /** @{*/
31 namespace v1 {
32 
33  /** Default handler hint.
34  *
35  * Use this handler to indicate the you want the default handler to be called.
36  * This type automatically casts itself into the appropriate handler type, when possible.
37  * Use the constants to default a handler unambigously.
38  */
39  static const struct
40  {
41  ///@cond IGNORE
42  // Doxygen can't parse these implicit conversion operators properly, remove from
43  // doc build
44  operator test_setup_handler_t() const { return test_setup_handler_t(1); }
45  operator test_teardown_handler_t() const { return test_teardown_handler_t(1); }
46  operator test_failure_handler_t() const { return test_failure_handler_t(1); }
47 
48  operator case_setup_handler_t() const { return case_setup_handler_t(1); }
49  operator case_teardown_handler_t() const { return case_teardown_handler_t(1); }
50  operator case_failure_handler_t() const { return case_failure_handler_t(1); }
51  ///@endcond
53 
54  /** Ignore handler hint.
55  *
56  * Use this handler to indicate the you want to ignore this handler and it will not be called.
57  * This type automatically casts itself into the appropriate handler type, when possible.
58  * Use the constants to ignore a handler unambigously.
59  */
60  static const struct
61  {
62  ///@cond IGNORE
63  // Doxygen can't parse these implicit conversion operators properly, remove from
64  // doc build
65  operator case_handler_t() const { return case_handler_t(NULL); }
66  operator case_control_handler_t() const { return case_control_handler_t(NULL); }
67  operator case_call_count_handler_t() const { return case_call_count_handler_t(NULL); }
68 
69  operator test_setup_handler_t() const { return test_setup_handler_t(NULL); }
70  operator test_teardown_handler_t() const { return test_teardown_handler_t(NULL); }
71  operator test_failure_handler_t() const { return test_failure_handler_t(NULL); }
72 
73  operator case_setup_handler_t() const { return case_setup_handler_t(NULL); }
74  operator case_teardown_handler_t() const { return case_teardown_handler_t(NULL); }
75  operator case_failure_handler_t() const { return case_failure_handler_t(NULL); }
76  ///@endcond
78 
79  /** A table of handlers.
80  *
81  * This structure stores all modifyable handlers and provides accessors to
82  * filter out the default handler.
83  * So if this structure contains handlers, and you want to use these handlers
84  * as a default backup, you can use the `get_handler` function to choose the right handler.
85  *
86  * Example:
87  * @code
88  * const handler_t defaults = { ... }; // your default handlers
89  * // will return the handler in defaults.
90  * test_setup_handler_t handler = defaults.get_handler(default_handler);
91  * // you will still need to manually check the handler before executing it
92  * if (handler != ignore_handler) handler(...);
93  *
94  * extern test_teardown_handler_t custom_handler(...);
95  * // will return `custom_handler`
96  * test_teardown_handler_t handler = defaults.get_handler(custom_handler);
97  * // you will still need to manually check the handler before executing it
98  * if (handler != ignore_handler) handler(...);
99  * @endcode
100  */
101  struct handlers_t
102  {
103  test_setup_handler_t test_setup;
104  test_teardown_handler_t test_teardown;
105  test_failure_handler_t test_failure;
106 
107  case_setup_handler_t case_setup;
108  case_teardown_handler_t case_teardown;
109  case_failure_handler_t case_failure;
110 
111  inline test_setup_handler_t get_handler(test_setup_handler_t handler) const {
112  if (handler == default_handler) return test_setup;
113  return handler;
114  }
115  inline test_teardown_handler_t get_handler(test_teardown_handler_t handler) const {
116  if (handler == default_handler) return test_teardown;
117  return handler;
118  }
119  inline test_failure_handler_t get_handler(test_failure_handler_t handler) const {
120  if (handler == default_handler) return test_failure;
121  return handler;
122  }
123 
124  inline case_setup_handler_t get_handler(case_setup_handler_t handler) const {
125  if (handler == default_handler) return case_setup;
126  return handler;
127  }
128  inline case_teardown_handler_t get_handler(case_teardown_handler_t handler) const {
129  if (handler == default_handler) return case_teardown;
130  return handler;
131  }
132  inline case_failure_handler_t get_handler(case_failure_handler_t handler) const {
133  if (handler == default_handler) return case_failure;
134  return handler;
135  }
136  };
137 
138  /// Prints the number of tests to run and continues.
139  utest::v1::status_t verbose_test_setup_handler (const size_t number_of_cases);
140  /// Prints the number of tests that passed and failed with a reason if provided.
141  void verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure);
142  /// Prints the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` and then dies.
143  void verbose_test_failure_handler (const failure_t failure);
144 
145  /// Prints the index and description of the case being run and continues.
146  utest::v1::status_t verbose_case_setup_handler (const Case *const source, const size_t index_of_case);
147  /// Prints the number of tests that passed and failed with a reason if provided within this case and continues.
148  utest::v1::status_t verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure);
149  /// Prints the reason of the failure and continues, unless the teardown handler failed, for which it aborts.
150  utest::v1::status_t verbose_case_failure_handler (const Case *const source, const failure_t reason);
151 
152  /// Default greentea test case set up handler
153  #define UTEST_DEFAULT_GREENTEA_TIMEOUT 10 //Seconds
154  #define UTEST_DEFAULT_HOST_TEST_NAME "default_auto"
155 
156  utest::v1::status_t default_greentea_test_setup_handler (const size_t number_of_cases);
157 
158  /// Requests the start test case from greentea and continues.
159  /// Example usage:
160  /// utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
161  /// GREENTEA_SETUP(5, "default_auto");
162  /// return greentea_test_setup_handler(number_of_cases);
163  /// }
164  ///
165  /// Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
166  utest::v1::status_t greentea_test_setup_handler (const size_t number_of_cases);
167 
168  /// Reports the test results to greentea.
169  void greentea_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure);
170  /// Reports the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` to greentea and then dies.
171  void greentea_test_failure_handler (const failure_t failure);
172 
173  /// Registers the test case setup with greentea.
174  utest::v1::status_t greentea_case_setup_handler (const Case *const source, const size_t index_of_case);
175  /// Registers the test case teardown with greentea.
176  utest::v1::status_t greentea_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure);
177  /// Reports the failure to greentea and then aborts.
178  utest::v1::status_t greentea_case_failure_abort_handler (const Case *const source, const failure_t reason);
179  /// Reports the failure to greentea and then continues.
180  utest::v1::status_t greentea_case_failure_continue_handler(const Case *const source, const failure_t reason);
181 
182  /// Notify greentea of testcase name.
183  void greentea_testcase_notification_handler(const char *testcase);
184 
185  /// The verbose default handlers that always continue on failure
186  extern const handlers_t verbose_continue_handlers;
187 
188  /// The greentea default handlers that always abort on the first encountered failure
189  extern const handlers_t greentea_abort_handlers;
190 
191  /// The greentea default handlers that always continue on failure
192  extern const handlers_t greentea_continue_handlers;
193 
194  /// The selftest default handlers that always abort on _any_ assertion failure, otherwise continue
195  extern const handlers_t selftest_handlers;
196 
197  /// The greentea aborting handlers are the default
198  extern const handlers_t& default_handlers;
199 
200 } // namespace v1
201 } // namespace utest
202 
203 #endif // UTEST_DEFAULT_HANDLER_H
204 
205 /** @}*/
Test case wrapper class.
Definition: utest_case.h:108
void verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure)
Prints the number of tests that passed and failed with a reason if provided.
void greentea_test_failure_handler(const failure_t failure)
Reports the failure for REASON_TEST_SETUP and REASON_TEST_TEARDOWN to greentea and then dies...
const handlers_t greentea_abort_handlers
The greentea default handlers that always abort on the first encountered failure. ...
utest::v1::status_t verbose_case_setup_handler(const Case *const source, const size_t index_of_case)
Prints the index and description of the case being run and continues.
A table of handlers.
utest::v1::status_t(* case_setup_handler_t)(const Case *const source, const size_t index_of_case)
Test case setup handler.
Definition: utest_types.h:326
utest::v1::status_t verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
Prints the number of tests that passed and failed with a reason if provided within this case and cont...
static const struct utest::v1::@372 ignore_handler
Ignore handler hint.
utest::v1::status_t verbose_case_failure_handler(const Case *const source, const failure_t reason)
Prints the reason of the failure and continues, unless the teardown handler failed, for which it aborts.
utest::v1::status_t(* case_teardown_handler_t)(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
Test case teardown handler.
Definition: utest_types.h:372
Contains the reason and location of the failure.
Definition: utest_types.h:92
const handlers_t greentea_continue_handlers
The greentea default handlers that always continue on failure.
utest::v1::status_t greentea_test_setup_handler(const size_t number_of_cases)
Requests the start test case from greentea and continues.
utest::v1::status_t(* test_setup_handler_t)(const size_t number_of_cases)
Test setup handler.
Definition: utest_types.h:287
const handlers_t selftest_handlers
The selftest default handlers that always abort on any assertion failure, otherwise continue...
void greentea_testcase_notification_handler(const char *testcase)
Notify greentea of testcase name.
void(* test_teardown_handler_t)(const size_t passed, const size_t failed, const failure_t failure)
Test teardown handler.
Definition: utest_types.h:302
const handlers_t & default_handlers
The greentea aborting handlers are the default.
void(* test_failure_handler_t)(const failure_t reason)
Test failure handler.
Definition: utest_types.h:311
static const struct utest::v1::@371 default_handler
Default handler hint.
utest::v1::status_t greentea_case_setup_handler(const Case *const source, const size_t index_of_case)
Registers the test case setup with greentea.
utest::v1::status_t verbose_test_setup_handler(const size_t number_of_cases)
Prints the number of tests to run and continues.
const handlers_t verbose_continue_handlers
The verbose default handlers that always continue on failure.
utest::v1::status_t greentea_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure)
Registers the test case teardown with greentea.
void(* case_handler_t)(void)
Primitive test case handler.
Definition: utest_types.h:334
utest::v1::status_t(* case_failure_handler_t)(const Case *const source, const failure_t reason)
Test case failure handler.
Definition: utest_types.h:386
void verbose_test_failure_handler(const failure_t failure)
Prints the failure for REASON_TEST_SETUP and REASON_TEST_TEARDOWN and then dies.
utest::v1::status_t greentea_case_failure_abort_handler(const Case *const source, const failure_t reason)
Reports the failure to greentea and then aborts.
control_t(* case_call_count_handler_t)(const size_t call_count)
Test case handler (repeatable)
Definition: utest_types.h:356
utest::v1::status_t greentea_case_failure_continue_handler(const Case *const source, const failure_t reason)
Reports the failure to greentea and then continues.
control_t(* case_control_handler_t)(void)
Complex test case handler.
Definition: utest_types.h:344
void greentea_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure)
Reports the test results to greentea.
status_t
status_t
Definition: utest_types.h:52
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.