Message ID | 20210621113804.26179-3-rpalethorpe@suse.com |
---|---|
State | Superseded |
Headers | show |
Series | [1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix | expand |
Hi Richie, > +#if LTPLIB > +#define TEST(SCALL) _Pragma("GCC error \"Do not use TEST macro in library\"") > +#define TEST_VOID(SCALL) _Pragma("GCC error \"Do not use TEST_VOID macro in library\"") It'd be nice to document "Do not use TEST() macro in library" in LTP Library API Writing Guidelines [1]. Kind regards, Petr [1] https://github.com/linux-test-project/ltp/wiki/LTP-Library-API-Writing-Guidelines
Hello, Petr Vorel <pvorel@suse.cz> writes: > Hi Richie, > >> +#if LTPLIB >> +#define TEST(SCALL) _Pragma("GCC error \"Do not use TEST macro in library\"") >> +#define TEST_VOID(SCALL) _Pragma("GCC error \"Do not use TEST_VOID macro in library\"") > > It'd be nice to document "Do not use TEST() macro in library" in LTP Library API > Writing Guidelines [1]. Yes, I will submit this in the Sparse patch set today. > > Kind regards, > Petr > > [1] https://github.com/linux-test-project/ltp/wiki/LTP-Library-API-Writing-Guidelines
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h index 89dfe5a31..9017fd042 100644 --- a/include/tst_test_macros.h +++ b/include/tst_test_macros.h @@ -6,6 +6,10 @@ #ifndef TST_TEST_MACROS_H__ #define TST_TEST_MACROS_H__ +#if LTPLIB +#define TEST(SCALL) _Pragma("GCC error \"Do not use TEST macro in library\"") +#define TEST_VOID(SCALL) _Pragma("GCC error \"Do not use TEST_VOID macro in library\"") +#else #define TEST(SCALL) \ do { \ errno = 0; \ @@ -19,6 +23,7 @@ SCALL; \ TST_ERR = errno; \ } while (0) +#endif extern long TST_RET; extern int TST_ERR;
As we define LTPLIB on library code, the preprocessor itself can be used to detect when the TEST[_VOID] macros are expanded in the library. If an API header is not included by any library translation units. Then this will not work. This is true at least for Fuzzy Sync. Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- include/tst_test_macros.h | 5 +++++ 1 file changed, 5 insertions(+)