cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

ksyms_module.c (1692B)


      1// SPDX-License-Identifier: GPL-2.0
      2/* Copyright (c) 2021 Facebook */
      3
      4#include <test_progs.h>
      5#include <network_helpers.h>
      6#include "test_ksyms_module.lskel.h"
      7#include "test_ksyms_module.skel.h"
      8
      9static void test_ksyms_module_lskel(void)
     10{
     11	struct test_ksyms_module_lskel *skel;
     12	int err;
     13	LIBBPF_OPTS(bpf_test_run_opts, topts,
     14		.data_in = &pkt_v4,
     15		.data_size_in = sizeof(pkt_v4),
     16		.repeat = 1,
     17	);
     18
     19	if (!env.has_testmod) {
     20		test__skip();
     21		return;
     22	}
     23
     24	skel = test_ksyms_module_lskel__open_and_load();
     25	if (!ASSERT_OK_PTR(skel, "test_ksyms_module_lskel__open_and_load"))
     26		return;
     27	err = bpf_prog_test_run_opts(skel->progs.load.prog_fd, &topts);
     28	if (!ASSERT_OK(err, "bpf_prog_test_run"))
     29		goto cleanup;
     30	ASSERT_EQ(topts.retval, 0, "retval");
     31	ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym");
     32cleanup:
     33	test_ksyms_module_lskel__destroy(skel);
     34}
     35
     36static void test_ksyms_module_libbpf(void)
     37{
     38	struct test_ksyms_module *skel;
     39	int err;
     40	LIBBPF_OPTS(bpf_test_run_opts, topts,
     41		.data_in = &pkt_v4,
     42		.data_size_in = sizeof(pkt_v4),
     43		.repeat = 1,
     44	);
     45
     46	if (!env.has_testmod) {
     47		test__skip();
     48		return;
     49	}
     50
     51	skel = test_ksyms_module__open_and_load();
     52	if (!ASSERT_OK_PTR(skel, "test_ksyms_module__open"))
     53		return;
     54	err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.load), &topts);
     55	if (!ASSERT_OK(err, "bpf_prog_test_run"))
     56		goto cleanup;
     57	ASSERT_EQ(topts.retval, 0, "retval");
     58	ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym");
     59cleanup:
     60	test_ksyms_module__destroy(skel);
     61}
     62
     63void test_ksyms_module(void)
     64{
     65	if (test__start_subtest("lskel"))
     66		test_ksyms_module_lskel();
     67	if (test__start_subtest("libbpf"))
     68		test_ksyms_module_libbpf();
     69}