-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/kernel: Add test for constructors in C
Make sure constructors are run even when not using C++. Signed-off-by: Keith Packard <[email protected]>
- Loading branch information
1 parent
2dd73b3
commit 3cd79fe
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 Keith Packard | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <errno.h> | ||
#include <zephyr/tc_util.h> | ||
#include <zephyr/ztest.h> | ||
/** | ||
* @addtogroup kernel_common_tests | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* @brief Test if constructors work | ||
* | ||
*/ | ||
|
||
static int constructor_value; | ||
|
||
#define CONSTRUCTOR_VALUE 1 | ||
|
||
void | ||
__attribute__((__constructor__)) | ||
__constructor_init(void) | ||
{ | ||
constructor_value = CONSTRUCTOR_VALUE; | ||
} | ||
|
||
ZTEST(constructor, test_constructor) | ||
{ | ||
zassert_equal(constructor_value, CONSTRUCTOR_VALUE, | ||
"constructor test failed: constructor not called"); | ||
} | ||
|
||
extern void *common_setup(void); | ||
ZTEST_SUITE(constructor, NULL, common_setup, NULL, NULL, NULL); | ||
|
||
/** | ||
* @} | ||
*/ |