netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: shuah@kernel.org, keescook@chromium.org
Cc: luto@amacapital.net, wad@chromium.org,
	linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@fb.com,
	Tim.Bird@sony.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH v3 2/6] kselftest: factor out list manipulation to a helper
Date: Mon, 16 Mar 2020 15:56:42 -0700	[thread overview]
Message-ID: <20200316225647.3129354-3-kuba@kernel.org> (raw)
In-Reply-To: <20200316225647.3129354-1-kuba@kernel.org>

Kees suggest to factor out the list append code to a macro,
since following commits need it, which leads to code duplication.

Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/testing/selftests/kselftest_harness.h | 42 ++++++++++++---------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 5336b26506ab..aaf58fffc8f7 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -631,6 +631,29 @@
 	} \
 } while (0); OPTIONAL_HANDLER(_assert)
 
+/* List helpers */
+#define __LIST_APPEND(head, item) \
+{ \
+	/* Circular linked list where only prev is circular. */ \
+	if (head == NULL) { \
+		head = item; \
+		item->next = NULL; \
+		item->prev = item; \
+		return;	\
+	} \
+	if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { \
+		item->next = NULL; \
+		item->prev = head->prev; \
+		item->prev->next = item; \
+		head->prev = item; \
+	} else { \
+		item->next = head; \
+		item->next->prev = item; \
+		item->prev = item; \
+		head = item; \
+	} \
+}
+
 /* Contains all the information for test execution and status checking. */
 struct __test_metadata {
 	const char *name;
@@ -665,24 +688,7 @@ static int __constructor_order;
 static inline void __register_test(struct __test_metadata *t)
 {
 	__test_count++;
-	/* Circular linked list where only prev is circular. */
-	if (__test_list == NULL) {
-		__test_list = t;
-		t->next = NULL;
-		t->prev = t;
-		return;
-	}
-	if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) {
-		t->next = NULL;
-		t->prev = __test_list->prev;
-		t->prev->next = t;
-		__test_list->prev = t;
-	} else {
-		t->next = __test_list;
-		t->next->prev = t;
-		t->prev = t;
-		__test_list = t;
-	}
+	__LIST_APPEND(__test_list, t);
 }
 
 static inline int __bail(int for_realz, bool no_print, __u8 step)
-- 
2.24.1


  parent reply	other threads:[~2020-03-16 22:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-16 22:56 [PATCH v3 0/6] kselftest: add fixture parameters Jakub Kicinski
2020-03-16 22:56 ` [PATCH v3 1/6] selftests/seccomp: use correct FIXTURE macro Jakub Kicinski
2020-03-17 20:22   ` Kees Cook
2020-03-16 22:56 ` Jakub Kicinski [this message]
2020-03-17 20:22   ` [PATCH v3 2/6] kselftest: factor out list manipulation to a helper Kees Cook
2020-03-16 22:56 ` [PATCH v3 3/6] kselftest: create fixture objects Jakub Kicinski
2020-03-17 20:23   ` Kees Cook
2020-03-16 22:56 ` [PATCH v3 4/6] kselftest: run tests by fixture Jakub Kicinski
2020-03-17 20:25   ` Kees Cook
2020-03-16 22:56 ` [PATCH v3 5/6] kselftest: add fixture parameters Jakub Kicinski
2020-03-17 20:36   ` Kees Cook
2020-03-16 22:56 ` [PATCH v3 5/6] kselftest: add fixture variants Jakub Kicinski
2020-03-17 20:37   ` Kees Cook
2020-03-16 22:56 ` [PATCH v3 6/6] selftests: tls: run all tests for TLS 1.2 and TLS 1.3 Jakub Kicinski
2020-03-17 20:46   ` Kees Cook
2020-03-16 22:59 ` [PATCH v3 0/6] kselftest: add fixture parameters Jakub Kicinski
2020-03-17 20:47   ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200316225647.3129354-3-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=Tim.Bird@sony.com \
    --cc=keescook@chromium.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=wad@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).