From patchwork Wed Jul 31 19:31:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kui-Feng Lee X-Patchwork-Id: 13749102 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CEA638DE9 for ; Wed, 31 Jul 2024 19:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722454308; cv=none; b=FXtcJNTXmpjv9IJvAZfvevYR31SpvBAcwOekKOdxrqeE6bkZzJcwAjiV1eMiN6b9fPNmwrrbkxXp73YjdcshNo2kn9zs+cH4LrJ73GplzyQQktGOueVjwpnSGQXYKS1hIV/+8WY8gM2L9pSPgkPcr4mlprtlQjdmd+86Pw84780= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722454308; c=relaxed/simple; bh=mgK9W8AJsIdqaqYy9KkSuqQR2qr/WW/vpfJkd4OJ6js=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c7EUdsAmY7MhcgpMhH4bPcQcgAJCgtLLnoFyJtCUdY+ZjULh5QFa+PFtncSbdOKBInL4RXIxxomRz8hlFVvEd/R8ZzMEFwjD1cSgrnKw/aCBPovQ2Tt43LVBKuNNYd1HuhklP2PyhgeFCqvhgHxaszPxw+lEpZ+jZ2hAoC+7hnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f2cY0jWp; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f2cY0jWp" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-66108213e88so47706767b3.1 for ; Wed, 31 Jul 2024 12:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722454306; x=1723059106; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H4mFPljQET7AapU/qTKvnasJovVikC0o4oEPVPsKMic=; b=f2cY0jWppV/auc2Y6StW9eM7u+ENrPJLiVHIEYt5x8Y9ubce63hIo+5IiPvkJtjgtj JH5iwZ+hcY8vX3ePe2VRRlgmHrVfERMqMFsq95xgCpFzNH4g23IKLqZsX5ktU2hzka44 EbV+xlRBLxLfEY5b6CjNlePJLz+Tf9SF720oKjEP3YfL7MFoBFkQr89Wr2Xo+E8vxmSE nbiirHpbR5Pn7f/izKRYPYanB3Tfl7TiB9sQVDYMgBUT/YjKeKSOrMPlPSMu9hvVVjsH c1qRefmu2chNwqjhSrOOePXoW+DYdIXu77seLuYD/LKtqig7bY5CDlLr1NUjoJO0plXI VKOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722454306; x=1723059106; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H4mFPljQET7AapU/qTKvnasJovVikC0o4oEPVPsKMic=; b=X4q4ukwxsYU1cOUR96nNn5ZYSaK3rE1v1nNeq3r69zAH/ZPIbBXmxACtpng+gun7GN S+1Z6f13kg7R+KV63lI00390HUcFAzo/6jxeeKM8ZLvKSermfdEODcXun2/vjZp9EIpV zvA7jPlLI8C0E25Ixj3eJgFxZy9NdG9nBIF6ASLcO/GuPxbLl1FsjJgE992SL/odx4uM 5tJ0SqIflG3O5hZdC0qw8thxaDdz70B3rZSecyNw08B7G3Df8rXkdIQvkvHsIyhRBYop o3GV5uPEG4dwPtRI5NHBrx2w5MD+imIByZslM6HjUBRPptWXIVE94irDLvZomlKg7J/6 HGGQ== X-Gm-Message-State: AOJu0Yzx6GtueVud/qvB8/f4NjhcABuQYzi7/cCgMi42qDC48T6bfvh8 X1bGa56BzjKnvMIyJmITgRhQV0sBDtEcgITac7/D87XMeY3nSPd8Og29+lXY X-Google-Smtp-Source: AGHT+IHvXFonRM1yga6QwZr2Yk+kAhbX5gamYhQFgRUtDp5n/fszdclc/Vw61w24EdCf2uO5XNgU6A== X-Received: by 2002:a81:8785:0:b0:65f:dfd9:b23d with SMTP id 00721157ae682-6874d3e50c6mr1828217b3.17.1722454306070; Wed, 31 Jul 2024 12:31:46 -0700 (PDT) Received: from kickker.attlocal.net ([2600:1700:6cf8:1240:c6db:9dfe:1d13:3b2e]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6756b024ab1sm30891597b3.91.2024.07.31.12.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 12:31:45 -0700 (PDT) From: Kui-Feng Lee To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev, song@kernel.org, kernel-team@meta.com, andrii@kernel.org, sdf@fomichev.me, geliang@kernel.org Cc: sinquersw@gmail.com, kuifeng@meta.com, Kui-Feng Lee Subject: [PATCH bpf-next v4 2/6] selftests/bpf: Add the traffic monitor option to test_progs. Date: Wed, 31 Jul 2024 12:31:36 -0700 Message-Id: <20240731193140.758210-3-thinker.li@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731193140.758210-1-thinker.li@gmail.com> References: <20240731193140.758210-1-thinker.li@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Add option '-m' to test_progs to accept names and patterns of test cases. This option will be used later to enable traffic monitor that capture network packets generated by test cases. Signed-off-by: Kui-Feng Lee --- tools/testing/selftests/bpf/test_progs.c | 85 +++++++++++++++++------- tools/testing/selftests/bpf/test_progs.h | 2 + 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index ab54d8420603..95643cd3119a 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -170,6 +170,7 @@ struct prog_test_def { void (*run_serial_test)(void); bool should_run; bool need_cgroup_cleanup; + bool should_tmon; }; /* Override C runtime library's usleep() implementation to ensure nanosleep() @@ -207,46 +208,59 @@ static bool should_run(struct test_selector *sel, int num, const char *name) return num < sel->num_set_len && sel->num_set[num]; } -static bool should_run_subtest(struct test_selector *sel, - struct test_selector *subtest_sel, - int subtest_num, - const char *test_name, - const char *subtest_name) +static bool match_subtest(struct test_filter_set *filter, + const char *test_name, + const char *subtest_name) { int i, j; - for (i = 0; i < sel->blacklist.cnt; i++) { - if (glob_match(test_name, sel->blacklist.tests[i].name)) { - if (!sel->blacklist.tests[i].subtest_cnt) - return false; - - for (j = 0; j < sel->blacklist.tests[i].subtest_cnt; j++) { - if (glob_match(subtest_name, - sel->blacklist.tests[i].subtests[j])) - return false; - } - } - } - - for (i = 0; i < sel->whitelist.cnt; i++) { - if (glob_match(test_name, sel->whitelist.tests[i].name)) { - if (!sel->whitelist.tests[i].subtest_cnt) + for (i = 0; i < filter->cnt; i++) { + if (glob_match(test_name, filter->tests[i].name)) { + if (!filter->tests[i].subtest_cnt) return true; - for (j = 0; j < sel->whitelist.tests[i].subtest_cnt; j++) { + for (j = 0; j < filter->tests[i].subtest_cnt; j++) { if (glob_match(subtest_name, - sel->whitelist.tests[i].subtests[j])) + filter->tests[i].subtests[j])) return true; } } } + return false; +} + +static bool should_run_subtest(struct test_selector *sel, + struct test_selector *subtest_sel, + int subtest_num, + const char *test_name, + const char *subtest_name) +{ + if (match_subtest(&sel->blacklist, test_name, subtest_name)) + return false; + + if (match_subtest(&sel->whitelist, test_name, subtest_name)) + return true; + if (!sel->whitelist.cnt && !subtest_sel->num_set) return true; return subtest_num < subtest_sel->num_set_len && subtest_sel->num_set[subtest_num]; } +static bool should_tmon(struct test_selector *sel, int num, const char *name) +{ + int i; + + for (i = 0; i < sel->whitelist.cnt; i++) { + if (glob_match(name, sel->whitelist.tests[i].name) && + !sel->whitelist.tests[i].subtest_cnt) + return true; + } + + return false; +} + static char *test_result(bool failed, bool skipped) { return failed ? "FAIL" : (skipped ? "SKIP" : "OK"); @@ -920,6 +934,10 @@ bool test__start_subtest(const char *subtest_name) return false; } + subtest_state->should_tmon = match_subtest(&env.tmon_selector.whitelist, + test->test_name, + subtest_name); + env.subtest_state = subtest_state; stdio_hijack_init(&subtest_state->log_buf, &subtest_state->log_cnt); @@ -1099,7 +1117,8 @@ enum ARG_KEYS { ARG_TEST_NAME_GLOB_DENYLIST = 'd', ARG_NUM_WORKERS = 'j', ARG_DEBUG = -1, - ARG_JSON_SUMMARY = 'J' + ARG_JSON_SUMMARY = 'J', + ARG_TRAFFIC_MONITOR = 'm', }; static const struct argp_option opts[] = { @@ -1126,6 +1145,8 @@ static const struct argp_option opts[] = { { "debug", ARG_DEBUG, NULL, 0, "print extra debug information for test_progs." }, { "json-summary", ARG_JSON_SUMMARY, "FILE", 0, "Write report in json format to this file."}, + { "traffic-monitor", ARG_TRAFFIC_MONITOR, "NAMES", 0, + "Monitor network traffic of tests with name matching the pattern (supports '*' wildcard)." }, {}, }; @@ -1337,6 +1358,18 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) break; case ARGP_KEY_END: break; + case ARG_TRAFFIC_MONITOR: { + if (arg[0] == '@') + err = parse_test_list_file(arg + 1, + &env->tmon_selector.whitelist, + true); + else + err = parse_test_list(arg, + &env->tmon_selector.whitelist, + true); + + break; + } default: return ARGP_ERR_UNKNOWN; } @@ -2168,6 +2201,9 @@ int main(int argc, char **argv) test->test_num, test->test_name, test->test_name, test->test_name); exit(EXIT_ERR_SETUP_INFRA); } + if (test->should_run) + test->should_tmon = should_tmon(&env.tmon_selector, + test->test_num, test->test_name); } /* ignore workers if we are just listing */ @@ -2252,6 +2288,7 @@ int main(int argc, char **argv) free_test_selector(&env.test_selector); free_test_selector(&env.subtest_selector); + free_test_selector(&env.tmon_selector); free_test_states(); if (env.succ_cnt + env.fail_cnt + env.skip_cnt == 0) diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h index 5d4e61fa26a1..ceda86a5a524 100644 --- a/tools/testing/selftests/bpf/test_progs.h +++ b/tools/testing/selftests/bpf/test_progs.h @@ -74,6 +74,7 @@ struct subtest_state { int error_cnt; bool skipped; bool filtered; + bool should_tmon; FILE *stdout_saved; }; @@ -98,6 +99,7 @@ struct test_state { struct test_env { struct test_selector test_selector; struct test_selector subtest_selector; + struct test_selector tmon_selector; bool verifier_stats; bool debug; enum verbosity verbosity;