diff options
author | Imre Kis <imre.kis@arm.com> | 2020-11-30 20:52:38 +0100 |
---|---|---|
committer | György Szing <gyorgy.szing@arm.com> | 2021-02-02 10:00:13 +0000 |
commit | 721104fedfac828690af6a318fb8d1d255f436b3 (patch) | |
tree | a8177d04d4430c9686f69575ec30fec5efa60a5d /components/messaging/ffa/libsp/test/mock_assert.cpp | |
parent | 28088349d8f4a2c9d6af60945c41ad24a41d36be (diff) | |
download | trusted-services-721104fedfac828690af6a318fb8d1d255f436b3.tar.gz |
libsp: Add mock assert implementation
Assertion failures can be expected from tests and an exception-like
behavior is implemented to prevent executing code after a failed
assert.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I0ed0951baab40a449018d61926daded2f6a970ed
Diffstat (limited to 'components/messaging/ffa/libsp/test/mock_assert.cpp')
-rw-r--r-- | components/messaging/ffa/libsp/test/mock_assert.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/components/messaging/ffa/libsp/test/mock_assert.cpp b/components/messaging/ffa/libsp/test/mock_assert.cpp new file mode 100644 index 000000000..f79021a36 --- /dev/null +++ b/components/messaging/ffa/libsp/test/mock_assert.cpp @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2020-2021, Arm Limited. All rights reserved. + */ + +#include "mock_assert.h" +#include <assert.h> +#include <CppUTest/TestHarness.h> +#include <CppUTestExt/MockSupport.h> + +int expect_assert(assert_environment_t *env) +{ + mock().expectOneCall("__assert_fail").andReturnValue(env); + return 0; +} + +void __assert_fail(const char *assertion, const char *file, unsigned int line, + const char *function) +{ + (void)assertion; + (void)file; + (void)line; + (void)function; + + assert_environment_t *env = (assert_environment_t *)mock() + .actualCall("__assert_fail") + .returnPointerValue(); + longjmp(*env, 1); +} |