Skip to contentSkip to conversation

selftests/landlock: Fix trace variant formatting

PATCH In review Mickaël Salaün 2 participants 4 messages Sep 7 – Sep 11

Subsystems (3)
lore
Share & tools
lore

Mickaël Salaün

author maintainer
#0 lore raw

PATCH 1/2 selftests/landlock: Fix trace variant formatting

Group-wide clang-format exclusions also cover comments and unrelated initializers, hiding which construct needs protection and leaving some variant fields bin-packed.

Use per-variant guards and format designated fields one per line. End each guard after the macro header when clang-format preserves the initializer. Keep the initializer guarded only where re-enabling clang-format would bin-pack its fields.

---
 tools/testing/selftests/landlock/net_test.c   | 13 ++--
 .../landlock/scoped_abstract_unix_test.c      | 56 ++++++++++++-----
 tools/testing/selftests/landlock/trace_test.c | 62 ++++++++++++++-----
 3 files changed, 95 insertions(+), 36 deletions(-)
tools/testing/selftests/landlock/net_test.c +8 -5
index a18761e0fd82..0d13556c50f2 100644
@@ -3569,31 +3569,34 @@ FIXTURE_VARIANT(trace_net_connect) {
 	bool deny_connect;
 };
 
-/* clang-format off */
-
 /* Denied connect(): sport=0, dport=<denied port>. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_net_connect, connect_denied) {
+	/* clang-format on */
 	.handled = LANDLOCK_ACCESS_NET_CONNECT_TCP,
 	.bind_base_first = false,
 	.deny_connect = true,
 };
 
 /* Denied bind(): sport=<denied port>, dport=0. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_net_connect, bind_fields) {
+	/* clang-format on */
 	.handled = LANDLOCK_ACCESS_NET_BIND_TCP,
 	.bind_base_first = false,
 	.deny_connect = false,
 };
 
 /* Denied connect() after an allowed bind(): the connect fields (sport=0). */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_net_connect, connect_after_bind) {
-	.handled = LANDLOCK_ACCESS_NET_BIND_TCP | LANDLOCK_ACCESS_NET_CONNECT_TCP,
+	/* clang-format on */
+	.handled = LANDLOCK_ACCESS_NET_BIND_TCP |
+		   LANDLOCK_ACCESS_NET_CONNECT_TCP,
 	.bind_base_first = true,
 	.deny_connect = true,
 };
 
-/* clang-format on */
-
 /*
  * A denied TCP bind(2) or connect(2) emits one deny_access_net event.  The port
  * is reported in the field matching the denied operation, in host endianness
tools/testing/selftests/landlock/scoped_abstract_unix_test.c +40 -16

101 lines not on this page · raw message

tools/testing/selftests/landlock/trace_test.c +47 -15

92 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 2/2 selftests/landlock: Fix disconnected variant formatting

The s3d1_s4d1_disconnected_rename_even variant is missing the formatting guard used by its neighbors. This leaves its opening brace attached to the FIXTURE_VARIANT_ADD() invocation and its clang-format enable marker unmatched.

Restore the per-variant guard. End it after the macro header so the initializer remains managed by clang-format.

---
 tools/testing/selftests/landlock/fs_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/landlock/fs_test.c +2 -1
index 18dbdb99aeba..d0be84e572f5 100644
@@ -5958,8 +5958,9 @@ FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s3d1_s4d1_new_parent_create) {
 	.expected_exchange_result = EXDEV,
 };
 
+/* clang-format off */
 FIXTURE_VARIANT_ADD(layout4_disconnected_leafs,
-		    s3d1_s4d1_disconnected_rename_even){
+		    s3d1_s4d1_disconnected_rename_even) {
 	/* clang-format on */
 	.allowed_s3d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG,
 	.allowed_s4d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG,
Signature · 1 line
2.55.0
reviewer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] selftests/landlock: Fix disconnected variant formatting

Quoted 32 lines · Mickaël Salaün

The s3d1_s4d1_disconnected_rename_even variant is missing the formatting guard used by its neighbors. This leaves its opening brace attached to the FIXTURE_VARIANT_ADD() invocation and its clang-format enable marker unmatched.

Restore the per-variant guard. End it after the macro header so the initializer remains managed by clang-format.

---
 tools/testing/selftests/landlock/fs_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/landlock/fs_test.c +2 -1
index 18dbdb99aeba..d0be84e572f5 100644
@@ -5958,8 +5958,9 @@ FIXTURE_VARIANT_ADD(layout4_disconnected_leafs, s3d1_s4d1_new_parent_create) {
 	.expected_exchange_result = EXDEV,
 };
 
+/* clang-format off */
 FIXTURE_VARIANT_ADD(layout4_disconnected_leafs,
-		    s3d1_s4d1_disconnected_rename_even){
+		    s3d1_s4d1_disconnected_rename_even) {
 	/* clang-format on */
 	.allowed_s3d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG,
 	.allowed_s4d1 = LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_MAKE_REG,
Signature · 1 line
2.55.0
reviewer Reviewed-by on v1 1/2
#3 lore raw
In reply to Mickaël Salaün
Quoted 269 lines · Mickaël Salaün

Group-wide clang-format exclusions also cover comments and unrelated initializers, hiding which construct needs protection and leaving some variant fields bin-packed.

Use per-variant guards and format designated fields one per line. End each guard after the macro header when clang-format preserves the initializer. Keep the initializer guarded only where re-enabling clang-format would bin-pack its fields.

---
 tools/testing/selftests/landlock/net_test.c   | 13 ++--
 .../landlock/scoped_abstract_unix_test.c      | 56 ++++++++++++-----
 tools/testing/selftests/landlock/trace_test.c | 62 ++++++++++++++-----
 3 files changed, 95 insertions(+), 36 deletions(-)
tools/testing/selftests/landlock/net_test.c +8 -5
index a18761e0fd82..0d13556c50f2 100644
@@ -3569,31 +3569,34 @@ FIXTURE_VARIANT(trace_net_connect) {
 	bool deny_connect;
 };
 
-/* clang-format off */
-
 /* Denied connect(): sport=0, dport=<denied port>. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_net_connect, connect_denied) {
+	/* clang-format on */
 	.handled = LANDLOCK_ACCESS_NET_CONNECT_TCP,
 	.bind_base_first = false,
 	.deny_connect = true,
 };
 
 /* Denied bind(): sport=<denied port>, dport=0. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_net_connect, bind_fields) {
+	/* clang-format on */
 	.handled = LANDLOCK_ACCESS_NET_BIND_TCP,
 	.bind_base_first = false,
 	.deny_connect = false,
 };
 
 /* Denied connect() after an allowed bind(): the connect fields (sport=0). */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_net_connect, connect_after_bind) {
-	.handled = LANDLOCK_ACCESS_NET_BIND_TCP | LANDLOCK_ACCESS_NET_CONNECT_TCP,
+	/* clang-format on */
+	.handled = LANDLOCK_ACCESS_NET_BIND_TCP |
+		   LANDLOCK_ACCESS_NET_CONNECT_TCP,
 	.bind_base_first = true,
 	.deny_connect = true,
 };
 
-/* clang-format on */
-
 /*
  * A denied TCP bind(2) or connect(2) emits one deny_access_net event.  The port
  * is reported in the field matching the denied operation, in host endianness
tools/testing/selftests/landlock/scoped_abstract_unix_test.c +40 -16
index eed684d4c364..54bc4081cd56 100644
@@ -1268,27 +1268,38 @@ FIXTURE_VARIANT(trace_unix) {
 	size_t name_len;
 };
 
-/* clang-format off */
-
 /* Stream: sandboxed client connect() to an unsandboxed peer (peer_domain=0). */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, stream_denied) {
-	.sock_type = SOCK_STREAM, .sandbox = true,
-	.sandbox_target = false, .expect_denied = 1,
+	/* clang-format on */
+	.sock_type = SOCK_STREAM,
+	.sandbox = true,
+	.sandbox_target = false,
+	.expect_denied = 1,
 };
 
 /* Stream: peer socket owned by a domain, so peer_domain != 0. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, stream_denied_scoped_peer) {
-	.sock_type = SOCK_STREAM, .sandbox = true,
-	.sandbox_target = true, .expect_denied = 1,
+	/* clang-format on */
+	.sock_type = SOCK_STREAM,
+	.sandbox = true,
+	.sandbox_target = true,
+	.expect_denied = 1,
 };
 
 /* Stream: unsandboxed client, connect() succeeds, no event. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, stream_allowed) {
-	.sock_type = SOCK_STREAM, .sandbox = false,
-	.sandbox_target = false, .expect_denied = 0,
+	/* clang-format on */
+	.sock_type = SOCK_STREAM,
+	.sandbox = false,
+	.sandbox_target = false,
+	.expect_denied = 0,
 };
 
 /* Stream: lower abstract-name length boundary. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, stream_denied_empty_name) {
 	.sock_type = SOCK_STREAM,
 	.sandbox = true,
@@ -1297,9 +1308,12 @@ FIXTURE_VARIANT_ADD(trace_unix, stream_denied_empty_name) {
 	.name = "",
 	.name_len = 0,
 };
+/* clang-format on */
 
 /* Stream: upper abstract-name length boundary. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, stream_denied_max_name) {
+	/* clang-format on */
 	.sock_type = SOCK_STREAM,
 	.sandbox = true,
 	.sandbox_target = false,
@@ -1309,25 +1323,35 @@ FIXTURE_VARIANT_ADD(trace_unix, stream_denied_max_name) {
 };
 
 /* Datagram: sandboxed client sendto() an unsandboxed peer (peer_domain=0). */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, dgram_denied) {
-	.sock_type = SOCK_DGRAM, .sandbox = true,
-	.sandbox_target = false, .expect_denied = 1,
+	/* clang-format on */
+	.sock_type = SOCK_DGRAM,
+	.sandbox = true,
+	.sandbox_target = false,
+	.expect_denied = 1,
 };
 
 /* Datagram: peer socket owned by a domain, so peer_domain != 0. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, dgram_denied_scoped_peer) {
-	.sock_type = SOCK_DGRAM, .sandbox = true,
-	.sandbox_target = true, .expect_denied = 1,
+	/* clang-format on */
+	.sock_type = SOCK_DGRAM,
+	.sandbox = true,
+	.sandbox_target = true,
+	.expect_denied = 1,
 };
 
 /* Datagram: unsandboxed client, sendto() succeeds, no event. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_unix, dgram_allowed) {
-	.sock_type = SOCK_DGRAM, .sandbox = false,
-	.sandbox_target = false, .expect_denied = 0,
+	/* clang-format on */
+	.sock_type = SOCK_DGRAM,
+	.sandbox = false,
+	.sandbox_target = false,
+	.expect_denied = 0,
 };
 
-/* clang-format on */
-
 /*
  * A sandboxed thread reaching an abstract unix socket peer through connect(2)
  * (stream) or sendto(2) (datagram) is denied and emits
tools/testing/selftests/landlock/trace_test.c +47 -15
index afdaf8511b3a..a28a2ac55687 100644
@@ -1243,45 +1243,77 @@ FIXTURE_VARIANT(trace_enforce) {
 	int no_new_privs;
 };
 
-/* clang-format off */
-
 /* Single thread, no flags: prctl-backed no_new_privs. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_enforce, single) {
-	.nthreads = 0, .flags = 0,
-	.total = 1, .complete = 1, .process_wide = 1, .no_new_privs = 1,
+	.nthreads = 0,
+	.flags = 0,
+	.total = 1,
+	.complete = 1,
+	.process_wide = 1,
+	.no_new_privs = 1,
 };
+/* clang-format on */
 
 /* Single thread: the NO_NEW_PRIVS flag sets no_new_privs (no prctl). */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_enforce, no_new_privs) {
-	.nthreads = 0, .flags = LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS,
-	.total = 1, .complete = 1, .process_wide = 1, .no_new_privs = 1,
+	.nthreads = 0,
+	.flags = LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS,
+	.total = 1,
+	.complete = 1,
+	.process_wide = 1,
+	.no_new_privs = 1,
 };
+/* clang-format on */
 
 /* TSYNC on a lone thread still concludes, process-wide. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_enforce, tsync_single) {
-	.nthreads = 0, .flags = LANDLOCK_RESTRICT_SELF_TSYNC,
-	.total = 1, .complete = 1, .process_wide = 1, .no_new_privs = 1,
+	.nthreads = 0,
+	.flags = LANDLOCK_RESTRICT_SELF_TSYNC,
+	.total = 1,
+	.complete = 1,
+	.process_wide = 1,
+	.no_new_privs = 1,
 };
+/* clang-format on */
 
 /* TSYNC sweeps N siblings; the caller's prctl-backed nnp propagates to all. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_enforce, tsync_multithread) {
-	.nthreads = 3, .flags = LANDLOCK_RESTRICT_SELF_TSYNC,
-	.total = 4, .complete = 1, .process_wide = 4, .no_new_privs = 4,
+	.nthreads = 3,
+	.flags = LANDLOCK_RESTRICT_SELF_TSYNC,
+	.total = 4,
+	.complete = 1,
+	.process_wide = 4,
+	.no_new_privs = 4,
 };
+/* clang-format on */
 
 /* TSYNC + NO_NEW_PRIVS flag sets nnp on the caller and every swept sibling. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_enforce, tsync_no_new_privs) {
+	/* clang-format on */
 	.nthreads = 3,
-	.flags = LANDLOCK_RESTRICT_SELF_TSYNC | LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS,
-	.total = 4, .complete = 1, .process_wide = 4, .no_new_privs = 4,
+	.flags = LANDLOCK_RESTRICT_SELF_TSYNC |
+		 LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS,
+	.total = 4,
+	.complete = 1,
+	.process_wide = 4,
+	.no_new_privs = 4,
 };
 
 /* Non-TSYNC on a multi-threaded process enforces only the caller. */
+/* clang-format off */
 FIXTURE_VARIANT_ADD(trace_enforce, multithread_non_tsync) {
-	.nthreads = 3, .flags = 0,
-	.total = 1, .complete = 1, .process_wide = 0, .no_new_privs = 1,
+	.nthreads = 3,
+	.flags = 0,
+	.total = 1,
+	.complete = 1,
+	.process_wide = 0,
+	.no_new_privs = 1,
 };
-
 /* clang-format on */
 
 /*
Signature · 1 line
2.55.0