All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pony Sew <poony20115@gmail.com>
To: bpf <bpf@vger.kernel.org>
Subject: How do I implement bpf_prog_test_run with BPF CO-RE?
Date: Mon, 17 Jan 2022 15:15:32 +0800	[thread overview]
Message-ID: <CAK-59YH9+w4VMuHC2ECUsChZ=0nJRmQeKkcAwXFt2ugfmWHZWA@mail.gmail.com> (raw)

Hello.
It seems like before bpf_prog_test_run is called, you need to call
bpf_prog_load. But in BPF CO-RE program, we already have
<program>_bpf__open and <program>_bpf__load which basically does the
same thing. My code look approximately like this:

-----test1_load.c---------------
#include <cgreen/cgreen.h>

Ensure(Load, load_test){
    /* should I call bpf_prog_load here? */
    bpf_prog_test_run(/* parameters */);
    /* what about bpf_object__close? */
}

TestSuite *load_tests() {
    TestSuite *suite = create_test_suite();
    return suite;
}

-----bpf_firewall.bpf.c---------
 #include "vmlinux.h"
 #include <bpf/bpf_helpers.h>

SEC("xdp_prog")
int xdp_prog_main(struct xdp_md *ctx){
    /* main program */
}

 char LICENSE[] SEC("license") = "GPL";

------bpf_firewall.c---------------
#include <cgreen/cgreen.h>
#include <bpf/libbpf.h>
#include <bpf/bpf.h>
#include "bpf_firewall.skel.h"

TestSuite *load_tests();

int main(int argc, char **argv) {
    struct bpf_firewall_bpf *obj;
    int err = 0;

    obj = bpf_firewall_bpf__open();

    err = bpf_firewall_bpf__load(obj);

    err = bpf_firewall_bpf__attach(obj);

    TestSuite *suite = create_test_suite();
    add_suite(suite, load_tests());
    run_test_suite(suite, create_text_reporter());

    bpf_firewall_bpf__destroy(obj);
    return 0;
}

How do I implement bpf_prog_test_run with BPF CO-RE?

Best regards,
Poony.

             reply	other threads:[~2022-01-17  7:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17  7:15 Pony Sew [this message]
2022-01-19 12:12 ` How do I implement bpf_prog_test_run with BPF CO-RE? Mauricio Vásquez Bernal
2022-01-20 21:57 ` Andrii Nakryiko

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='CAK-59YH9+w4VMuHC2ECUsChZ=0nJRmQeKkcAwXFt2ugfmWHZWA@mail.gmail.com' \
    --to=poony20115@gmail.com \
    --cc=bpf@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.