Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Johan Almbladh <johan.almbladh@anyfinetworks.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org, iii@linux.ibm.com,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	Johan Almbladh <johan.almbladh@anyfinetworks.com>
Subject: [PATCH bpf-next v3 02/13] bpf/tests: Reduce memory footprint of test suite
Date: Thu,  9 Sep 2021 16:32:52 +0200	[thread overview]
Message-ID: <20210909143303.811171-3-johan.almbladh@anyfinetworks.com> (raw)
In-Reply-To: <20210909143303.811171-1-johan.almbladh@anyfinetworks.com>

The test suite used to call any fill_helper callbacks to generate eBPF
program data for all test cases at once. This caused ballooning memory
requirements as more extensive test cases were added. Now the each
fill_helper is called before the test is run and the allocated memory
released afterwards, before the next test case is processed.

Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
---
 lib/test_bpf.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index c8bd3e9ab10a..f0651dc6450b 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -8694,8 +8694,6 @@ static __init int find_test_index(const char *test_name)
 
 static __init int prepare_bpf_tests(void)
 {
-	int i;
-
 	if (test_id >= 0) {
 		/*
 		 * if a test_id was specified, use test_range to
@@ -8739,23 +8737,11 @@ static __init int prepare_bpf_tests(void)
 		}
 	}
 
-	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		if (tests[i].fill_helper &&
-		    tests[i].fill_helper(&tests[i]) < 0)
-			return -ENOMEM;
-	}
-
 	return 0;
 }
 
 static __init void destroy_bpf_tests(void)
 {
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		if (tests[i].fill_helper)
-			kfree(tests[i].u.ptr.insns);
-	}
 }
 
 static bool exclude_test(int test_id)
@@ -8959,7 +8945,19 @@ static __init int test_bpf(void)
 
 		pr_info("#%d %s ", i, tests[i].descr);
 
+		if (tests[i].fill_helper &&
+		    tests[i].fill_helper(&tests[i]) < 0) {
+			pr_cont("FAIL to prog_fill\n");
+			continue;
+		}
+
 		fp = generate_filter(i, &err);
+
+		if (tests[i].fill_helper) {
+			kfree(tests[i].u.ptr.insns);
+			tests[i].u.ptr.insns = NULL;
+		}
+
 		if (fp == NULL) {
 			if (err == 0) {
 				pass_cnt++;
-- 
2.30.2


  parent reply	other threads:[~2021-09-09 14:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 14:32 [PATCH bpf-next v3 00/13] bpf/tests: Extend JIT test suite coverage Johan Almbladh
2021-09-09 14:32 ` [PATCH bpf-next v3 01/13] bpf/tests: Allow different number of runs per test case Johan Almbladh
2021-09-09 14:32 ` Johan Almbladh [this message]
2021-09-09 14:32 ` [PATCH bpf-next v3 03/13] bpf/tests: Add exhaustive tests of ALU shift values Johan Almbladh
2021-09-09 14:32 ` [PATCH bpf-next v3 04/13] bpf/tests: Add exhaustive tests of ALU operand magnitudes Johan Almbladh
2021-09-09 14:32 ` [PATCH bpf-next v3 05/13] bpf/tests: Add exhaustive tests of JMP " Johan Almbladh
2021-09-09 14:32 ` [PATCH bpf-next v3 06/13] bpf/tests: Add staggered JMP and JMP32 tests Johan Almbladh
2021-09-09 14:32 ` [PATCH bpf-next v3 07/13] bpf/tests: Add exhaustive test of LD_IMM64 immediate magnitudes Johan Almbladh
2021-09-09 14:32 ` [PATCH bpf-next v3 08/13] bpf/tests: Add test case flag for verifier zero-extension Johan Almbladh
2021-09-09 14:32 ` [PATCH bpf-next v3 09/13] bpf/tests: Add JMP tests with small offsets Johan Almbladh
2021-09-09 14:33 ` [PATCH bpf-next v3 10/13] bpf/tests: Add JMP tests with degenerate conditional Johan Almbladh
2021-09-09 14:33 ` [PATCH bpf-next v3 11/13] bpf/tests: Expand branch conversion JIT test Johan Almbladh
2021-09-09 14:33 ` [PATCH bpf-next v3 12/13] bpf/tests: Add more BPF_END byte order conversion tests Johan Almbladh
2021-09-09 14:33 ` [PATCH bpf-next v3 13/13] bpf/tests: Add tail call limit test with external function call Johan Almbladh
2021-09-10 19:47   ` Daniel Borkmann

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=20210909143303.811171-3-johan.almbladh@anyfinetworks.com \
    --to=johan.almbladh@anyfinetworks.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=iii@linux.ibm.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    --subject='Re: [PATCH bpf-next v3 02/13] bpf/tests: Reduce memory footprint of test suite' \
    /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

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).