Software APIs
status_report_unittest_c.c
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#include "sw/device/lib/base/status_report_unittest_c.h"
6
7#include "sw/device/lib/base/status.h"
8
9/* This part of the test needs to be written in C because the TRY
10 * macro is not polyglot. Specifically, the TRY macros uses
11 * INTO_STATUS that relies on _Generic which is C only (although
12 * the header could probably provide a different version of the
13 * code for C++. */
14
15#define MODULE_ID MAKE_MODULE_ID('g', 'o', 'd')
16status_t sudo_god(void) { return PERMISSION_DENIED(); }
17#undef MODULE_ID
18
19#define MODULE_ID MAKE_MODULE_ID('p', 's', 'y')
20status_t think_deeply(void) {
21 TRY(sudo_god());
22 return OK_STATUS();
23}
24#undef MODULE_ID
25
26#define MODULE_ID MAKE_MODULE_ID('t', 'h', 'k')
27status_t think(void) {
28 if (!status_ok(think_deeply()))
29 return ABORTED();
30 return OK_STATUS();
31}
32#undef MODULE_ID
33
34#define MODULE_ID MAKE_MODULE_ID('u', 'n', 't')
35
36status_t status_report_unittest_c(void) {
37 // Artificially report an OK status just to make sure that the status printer
38 // can handle those as well. The value is very large on purpose to exercise
39 // the fact that the status code of Ok can use a lot more bits than error.
40 status_report(OK_STATUS(654321));
41 TRY(think());
42 return OK_STATUS();
43}
44#undef MODULE_ID