aboutsummaryrefslogtreecommitdiff
path: root/components/messaging/ffa/libsp/test/mock_assert.h
blob: 33a03d5c4ee34010ad239ee2a017bcf227cd90af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* SPDX-License-Identifier: BSD-3-Clause */
/*
 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
 */

#ifndef LIBSP_TEST_MOCK_ASSERT_H_
#define LIBSP_TEST_MOCK_ASSERT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <setjmp.h>

typedef jmp_buf assert_environment_t;

/*
 * SETUP_ASSERT_ENVIRONMENT
 * Both expect_assert and setjmp must be called without putting them into a new
 * function. The only way is to use an operator between them. Logical operators
 * would introduce branches which could introduce uncovered branches. The
 * solution is use arithmetic operators. expect_assert always return 0 so the
 * value of the sum is determined by the setjmp return value.
 *
 * Example usage:
 * assert_environment_t env;
 *
 * if (SETUP_ASSERT_ENVIRONMENT(env) {
 *     function_with_assert_fail();
 * }
 */
#define SETUP_ASSERT_ENVIRONMENT(env) (expect_assert(&env) + (setjmp(env) == 0))

int expect_assert(assert_environment_t *env);

#ifdef __cplusplus
}
#endif

#endif /* LIBSP_TEST_MOCK_ASSERT_H_ */