subsys/testsuite: rearrange for standard use of extern "C"

Consistently place C++ use of extern "C" after all include directives,
within the negative branch of _ASMLANGUAGE if used.

Background from issue #17997:

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2019-08-12 17:00:35 -05:00 committed by Ioannis Glaropoulos
commit c0d33975d1
4 changed files with 34 additions and 5 deletions

View file

@ -20,10 +20,6 @@
#ifndef __ZTEST_H__
#define __ZTEST_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup ztest Zephyr testing suite
*/
@ -44,21 +40,30 @@ extern "C" {
/* FIXME: Properly integrate with Zephyr's arch specific code */
#define CONFIG_X86 1
#define CONFIG_PRINTK 1
#ifdef __cplusplus
extern "C" {
#endif
struct esf;
typedef struct esf z_arch_esf_t;
#ifdef __cplusplus
}
#endif
#endif /* KERNEL */
#include <sys/printk.h>
#define PRINT printk
#include <zephyr.h>
#include <ztest_assert.h>
#include <ztest_mock.h>
#include <ztest_test.h>
#include <tc_util.h>
#ifdef __cplusplus
extern "C" {
#endif
void test_main(void);
#ifdef __cplusplus

View file

@ -19,6 +19,10 @@
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
void ztest_test_fail(void);
#if CONFIG_ZTEST_ASSERT_VERBOSE == 0
@ -214,4 +218,8 @@ static inline void z_zassert(int cond,
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __ZTEST_ASSERT_H__ */

View file

@ -91,6 +91,10 @@
#include <zephyr/types.h>
#ifdef __cplusplus
extern "C" {
#endif
void z_init_mock(void);
int z_cleanup_mock(void);
@ -101,6 +105,10 @@ void z_ztest_check_expected_value(const char *fn, const char *param,
void z_ztest_returns_value(const char *fn, uintptr_t value);
uintptr_t z_ztest_get_return_value(const char *fn);
#ifdef __cplusplus
}
#endif
#else /* !CONFIG_ZTEST_MOCKING */
#define z_init_mock()

View file

@ -15,6 +15,10 @@
#include <app_memory/app_memdomain.h>
#ifdef __cplusplus
extern "C" {
#endif
struct unit_test {
const char *name;
void (*test)(void);
@ -171,4 +175,8 @@ extern struct k_mem_domain ztest_mem_domain;
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __ZTEST_ASSERT_H__ */