From: Martin KaFai Lau <martin.lau@linux.dev>
To: Jordan Rife <jrife@google.com>
Cc: linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
Shuah Khan <shuah@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Daan De Meyer <daan.j.demeyer@gmail.com>,
bpf@vger.kernel.org
Subject: Re: [PATCH v1 bpf-next 5/8] selftests/bpf: Factor out load_path and defines from test_sock_addr
Date: Tue, 2 Apr 2024 16:14:02 -0700 [thread overview]
Message-ID: <59c52263-edd2-4585-b4f0-28c8d92d572c@linux.dev> (raw)
In-Reply-To: <20240329191907.1808635-6-jrife@google.com>
On 3/29/24 12:18 PM, Jordan Rife wrote:
> diff --git a/tools/testing/selftests/bpf/sock_addr_helpers.c b/tools/testing/selftests/bpf/sock_addr_helpers.c
> new file mode 100644
> index 0000000000000..ff2eb09870f16
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/sock_addr_helpers.c
> @@ -0,0 +1,46 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#include <bpf/bpf.h>
> +#include <bpf/libbpf.h>
> +
> +#include "cgroup_helpers.h"
> +#include "sock_addr_helpers.h"
> +#include "testing_helpers.h"
> +
> +int load_path(const char *path, enum bpf_attach_type attach_type,
> + bool expect_reject)
> +{
> + struct bpf_object *obj;
> + struct bpf_program *prog;
> + int err;
> +
> + obj = bpf_object__open_file(path, NULL);
Although it works, it is heading to the opposite direction by reusing things
from the older test_sock_addr.c.
test_sock_addr.c should have been moved to the test_progs. It is not run by bpf
CI and bits get rotten [e.g. the bug fix in patch 8]. There is also old practice
like bpf_object__open_file() should have been replaced with the skeleton
__open_and_load() instead of refactoring it out to create new use cases.
The newer prog_tests/sock_addr.c was created when adding AF_UNIX support. It has
a very similar setup as the older test_sock_addr.c and the intention was to
finally retire test_sock_addr.c. e.g. It also has "load_fn loadfn" but is done
with skeleton, the program is also attached to cgroup...etc.
Instead of adding a new sock_addr_kern.c in patch 7, it probably will be easier
to add the kernel socket tests into the existing prog_tests/sock_addr.c.
Also setup the netns and veth in the prog_tests/sock_addr.c instead of calling
out the test_sock_addr.sh (which should also go away eventually), there are
examples in prog_tests/ (e.g. mptcp.c).
> + err = libbpf_get_error(obj);
> + if (err) {
> + log_err(">>> Opening BPF object (%s) error.\n", path);
> + return -1;
> + }
> +
> + prog = bpf_object__next_program(obj, NULL);
> + if (!prog)
> + goto err_out;
> +
> + bpf_program__set_type(prog, BPF_PROG_TYPE_CGROUP_SOCK_ADDR);
> + bpf_program__set_expected_attach_type(prog, attach_type);
> + bpf_program__set_flags(prog, testing_prog_flags());
> +
> + err = bpf_object__load(obj);
> + if (err) {
> + if (!expect_reject)
> + log_err(">>> Loading program (%s) error.\n", path);
> + goto err_out;
> + }
> +
> + return bpf_program__fd(prog);
> +err_out:
> + bpf_object__close(obj);
> + return -1;
> +}
next prev parent reply other threads:[~2024-04-02 23:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 19:18 [PATCH v1 bpf-next 0/8] selftests/bpf: Add sockaddr tests for kernel networking Jordan Rife
2024-03-29 19:18 ` [PATCH v1 bpf-next 1/8] selftests/bpf: Introduce sock_addr_testmod Jordan Rife
2024-03-29 22:09 ` Andrii Nakryiko
2024-03-29 22:09 ` Andrii Nakryiko
2024-04-02 17:57 ` Martin KaFai Lau
2024-04-02 18:14 ` Jordan Rife
2024-03-29 19:18 ` [PATCH v1 bpf-next 2/8] selftests/bpf: Add module load helpers Jordan Rife
2024-03-29 19:18 ` [PATCH v1 bpf-next 3/8] selftests/bpf: Factor out cmp_addr Jordan Rife
2024-03-29 19:18 ` [PATCH v1 bpf-next 4/8] selftests/bpf: Add recv_msg_from_client to network helpers Jordan Rife
2024-04-02 22:33 ` Martin KaFai Lau
2024-03-29 19:18 ` [PATCH v1 bpf-next 5/8] selftests/bpf: Factor out load_path and defines from test_sock_addr Jordan Rife
2024-04-02 23:14 ` Martin KaFai Lau [this message]
2024-04-03 0:05 ` Jordan Rife
2024-03-29 19:18 ` [PATCH v1 bpf-next 6/8] selftests/bpf: Add setup/cleanup subcommands Jordan Rife
2024-03-29 19:18 ` [PATCH v1 bpf-next 7/8] selftests/bpf: Add sock_addr_kern prog_test Jordan Rife
2024-03-29 19:18 ` [PATCH v1 bpf-next 8/8] selftests/bpf: Fix bind program for big endian systems Jordan Rife
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=59c52263-edd2-4585-b4f0-28c8d92d572c@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daan.j.demeyer@gmail.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jrife@google.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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