All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix
@ 2021-06-21 11:38 Richard Palethorpe
  2021-06-21 11:38 ` [LTP] [PATCH 2/3] API: Remove TEST macro usage from library headers Richard Palethorpe
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Richard Palethorpe @ 2021-06-21 11:38 UTC (permalink / raw)
  To: ltp

We have to explicitly add the header directory.

Also allow the TEST macro fix to replace multiple variables.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 scripts/coccinelle/libltp-test-macro.cocci |  4 +++-
 scripts/coccinelle/run-spatch.sh           | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/scripts/coccinelle/libltp-test-macro.cocci b/scripts/coccinelle/libltp-test-macro.cocci
index 7563d23aa..937d6c94f 100644
--- a/scripts/coccinelle/libltp-test-macro.cocci
+++ b/scripts/coccinelle/libltp-test-macro.cocci
@@ -24,7 +24,7 @@ virtual fix
 
  TEST(...)
 
- ...
+ <...
 
 (
 - TST_RET
@@ -37,6 +37,8 @@ virtual fix
 + TERRNO
 )
 
+ ...>
+
 // Replace TEST in all functions where it occurs only at the start. It
 // is slightly complicated by adding a newline if a statement appears
 // on the line after TEST(). It is not clear to me what the rules are
diff --git a/scripts/coccinelle/run-spatch.sh b/scripts/coccinelle/run-spatch.sh
index e8e6f47d8..978998cd1 100755
--- a/scripts/coccinelle/run-spatch.sh
+++ b/scripts/coccinelle/run-spatch.sh
@@ -25,6 +25,12 @@ libltp_spatch() {
 	       -D fix \
 	       --include-headers \
 	       $*
+	spatch --dir include \
+	       --use-gitgrep \
+	       --in-place \
+	       -D fix \
+	       --include-headers \
+	       $*
     else
 	spatch --dir lib \
 	       --ignore lib/parse_opts.c \
@@ -33,6 +39,10 @@ libltp_spatch() {
 	       --use-gitgrep \
 	       --include-headers \
 	       $*
+	spatch --dir include \
+	       --use-gitgrep \
+	       --include-headers \
+	       $*
     fi
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 2/3] API: Remove TEST macro usage from library headers
  2021-06-21 11:38 [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix Richard Palethorpe
@ 2021-06-21 11:38 ` Richard Palethorpe
  2021-06-21 11:38 ` [LTP] [PATCH 3/3] API: Cause GCC/Clang to blow up when TEST is used in the library Richard Palethorpe
  2021-08-10 15:17 ` [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix Cyril Hrubis
  2 siblings, 0 replies; 6+ messages in thread
From: Richard Palethorpe @ 2021-06-21 11:38 UTC (permalink / raw)
  To: ltp

Technically the headers are part of the test translation unit. However
we think of them as being part of the API. So we should also remove
TEST from here.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Suggested-by: Li Wang <liwang@redhat.com>
---
 include/lapi/clone.h             |  6 ++++--
 include/lapi/fsmount.h           | 10 ++++++----
 include/lapi/init_module.h       |  6 ++++--
 include/lapi/io_uring.h          |  9 +++++----
 include/lapi/name_to_handle_at.h |  7 ++++---
 include/lapi/openat2.h           |  6 ++++--
 6 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/include/lapi/clone.h b/include/lapi/clone.h
index 81db443c9..5bf51d90e 100644
--- a/include/lapi/clone.h
+++ b/include/lapi/clone.h
@@ -39,10 +39,12 @@ static inline int clone3(struct clone_args *args, size_t size)
 
 static inline void clone3_supported_by_kernel(void)
 {
+	long ret;
+
 	if ((tst_kvercmp(5, 3, 0)) < 0) {
 		/* Check if the syscall is backported on an older kernel */
-		TEST(syscall(__NR_clone3, NULL, 0));
-		if (TST_RET == -1 && TST_ERR == ENOSYS)
+		ret = syscall(__NR_clone3, NULL, 0);
+		if (ret == -1 && errno == ENOSYS)
 			tst_brk(TCONF, "Test not supported on kernel version < v5.3");
 	}
 }
diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
index d6ebed9b4..dc39c8791 100644
--- a/include/lapi/fsmount.h
+++ b/include/lapi/fsmount.h
@@ -133,12 +133,14 @@ enum fsconfig_command {
 
 static inline void fsopen_supported_by_kernel(void)
 {
+	long ret;
+
 	if ((tst_kvercmp(5, 2, 0)) < 0) {
 		/* Check if the syscall is backported on an older kernel */
-		TEST(syscall(__NR_fsopen, NULL, 0));
-		if (TST_RET != -1)
-			SAFE_CLOSE(TST_RET);
-		else if (TST_ERR == ENOSYS)
+		ret = syscall(__NR_fsopen, NULL, 0);
+		if (ret != -1)
+			SAFE_CLOSE(ret);
+		else if (errno == ENOSYS)
 			tst_brk(TCONF, "Test not supported on kernel version < v5.2");
 	}
 }
diff --git a/include/lapi/init_module.h b/include/lapi/init_module.h
index 14eaabee6..48464a2e4 100644
--- a/include/lapi/init_module.h
+++ b/include/lapi/init_module.h
@@ -24,10 +24,12 @@ static inline int finit_module(int fd, const char *param_values, int flags)
 
 static inline void finit_module_supported_by_kernel(void)
 {
+       long ret;
+
        if ((tst_kvercmp(3, 8, 0)) < 0) {
                /* Check if the syscall is backported on an older kernel */
-               TEST(syscall(__NR_finit_module, 0, "", 0));
-               if (TST_RET == -1 && TST_ERR == ENOSYS)
+               ret = syscall(__NR_finit_module, 0, "", 0);
+               if (ret == -1 && errno == ENOSYS)
                        tst_brk(TCONF, "Test not supported on kernel version < v3.8");
        }
 }
diff --git a/include/lapi/io_uring.h b/include/lapi/io_uring.h
index 897ed7c64..e5c879951 100644
--- a/include/lapi/io_uring.h
+++ b/include/lapi/io_uring.h
@@ -296,11 +296,12 @@ static inline int io_uring_enter(int fd, unsigned int to_submit,
 
 static inline void io_uring_setup_supported_by_kernel(void)
 {
+	long ret;
 	if ((tst_kvercmp(5, 1, 0)) < 0) {
-		TEST(syscall(__NR_io_uring_setup, NULL, 0));
-		if (TST_RET != -1)
-			SAFE_CLOSE(TST_RET);
-		else if (TST_ERR == ENOSYS)
+		ret = syscall(__NR_io_uring_setup, NULL, 0);
+		if (ret != -1)
+			SAFE_CLOSE(ret);
+		else if (errno == ENOSYS)
 			tst_brk(TCONF,
 				"Test not supported on kernel version < v5.1");
 	}
diff --git a/include/lapi/name_to_handle_at.h b/include/lapi/name_to_handle_at.h
index 275db4ae0..3f081f1c0 100644
--- a/include/lapi/name_to_handle_at.h
+++ b/include/lapi/name_to_handle_at.h
@@ -34,6 +34,7 @@ static inline int open_by_handle_at(int mount_fd, struct file_handle *handle,
 static inline struct file_handle *
 allocate_file_handle(int dfd, const char *pathname)
 {
+	long ret;
 	struct file_handle fh = {}, *fhp;
 	int mount_id;
 
@@ -41,9 +42,9 @@ allocate_file_handle(int dfd, const char *pathname)
 	 * Make an initial call to name_to_handle_at() to discover the size
 	 * required for the file handle.
 	 */
-	TEST(name_to_handle_at(dfd, pathname, &fh, &mount_id, 0));
-	if (TST_RET != -1 || TST_ERR != EOVERFLOW) {
-		tst_res(TFAIL | TTERRNO,
+	ret = name_to_handle_at(dfd, pathname, &fh, &mount_id, 0);
+	if (ret != -1 || errno != EOVERFLOW) {
+		tst_res(TFAIL | TERRNO,
 			"name_to_handle_at() should fail with EOVERFLOW");
 		return NULL;
 	}
diff --git a/include/lapi/openat2.h b/include/lapi/openat2.h
index d4154c26e..46804a441 100644
--- a/include/lapi/openat2.h
+++ b/include/lapi/openat2.h
@@ -62,10 +62,12 @@ struct open_how_pad {
 
 static inline void openat2_supported_by_kernel(void)
 {
+	long ret;
+
 	if ((tst_kvercmp(5, 6, 0)) < 0) {
 		/* Check if the syscall is backported on an older kernel */
-		TEST(syscall(__NR_openat2, -1, NULL, NULL, 0));
-		if (TST_RET == -1 && TST_ERR == ENOSYS)
+		ret = syscall(__NR_openat2, -1, NULL, NULL, 0);
+		if (ret == -1 && errno == ENOSYS)
 			tst_brk(TCONF, "Test not supported on kernel version < v5.6");
 	}
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 3/3] API: Cause GCC/Clang to blow up when TEST is used in the library
  2021-06-21 11:38 [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix Richard Palethorpe
  2021-06-21 11:38 ` [LTP] [PATCH 2/3] API: Remove TEST macro usage from library headers Richard Palethorpe
@ 2021-06-21 11:38 ` Richard Palethorpe
  2021-06-28 14:52   ` Petr Vorel
  2021-08-10 15:17 ` [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix Cyril Hrubis
  2 siblings, 1 reply; 6+ messages in thread
From: Richard Palethorpe @ 2021-06-21 11:38 UTC (permalink / raw)
  To: ltp

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(+)

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;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 3/3] API: Cause GCC/Clang to blow up when TEST is used in the library
  2021-06-21 11:38 ` [LTP] [PATCH 3/3] API: Cause GCC/Clang to blow up when TEST is used in the library Richard Palethorpe
@ 2021-06-28 14:52   ` Petr Vorel
  2021-06-29  7:15     ` Richard Palethorpe
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Vorel @ 2021-06-28 14:52 UTC (permalink / raw)
  To: ltp

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 3/3] API: Cause GCC/Clang to blow up when TEST is used in the library
  2021-06-28 14:52   ` Petr Vorel
@ 2021-06-29  7:15     ` Richard Palethorpe
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Palethorpe @ 2021-06-29  7:15 UTC (permalink / raw)
  To: ltp

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


-- 
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix
  2021-06-21 11:38 [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix Richard Palethorpe
  2021-06-21 11:38 ` [LTP] [PATCH 2/3] API: Remove TEST macro usage from library headers Richard Palethorpe
  2021-06-21 11:38 ` [LTP] [PATCH 3/3] API: Cause GCC/Clang to blow up when TEST is used in the library Richard Palethorpe
@ 2021-08-10 15:17 ` Cyril Hrubis
  2 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2021-08-10 15:17 UTC (permalink / raw)
  To: ltp

Hi!
Pushed the first two patches, thanks.

I guess that we no longer need the third since we do have 'make check'
now.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-08-10 15:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 11:38 [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix Richard Palethorpe
2021-06-21 11:38 ` [LTP] [PATCH 2/3] API: Remove TEST macro usage from library headers Richard Palethorpe
2021-06-21 11:38 ` [LTP] [PATCH 3/3] API: Cause GCC/Clang to blow up when TEST is used in the library Richard Palethorpe
2021-06-28 14:52   ` Petr Vorel
2021-06-29  7:15     ` Richard Palethorpe
2021-08-10 15:17 ` [LTP] [PATCH 1/3] scripts/coccinelle: Add headers to lib checks and fix macro fix Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.