bpf_verif_scale.c 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2019 Facebook
#include <test_progs.h>
static int libbpf_debug_print(enum libbpf_print_level level,
			      const char *format, va_list args)
{
	if (level != LIBBPF_DEBUG)
		return 0;

	if (!strstr(format, "verifier log"))
		return 0;
	return vfprintf(stderr, "%s", args);
}

15
static int check_load(const char *file, enum bpf_prog_type type)
16 17
{
	struct bpf_prog_load_attr attr;
18
	struct bpf_object *obj = NULL;
19 20 21 22
	int err, prog_fd;

	memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
	attr.file = file;
23
	attr.prog_type = type;
24 25 26 27 28 29 30 31 32 33
	attr.log_level = 4;
	err = bpf_prog_load_xattr(&attr, &obj, &prog_fd);
	bpf_object__close(obj);
	if (err)
		error_cnt++;
	return err;
}

void test_bpf_verif_scale(void)
{
34 35 36 37 38 39 40
	const char *scale[] = {
		"./test_verif_scale1.o", "./test_verif_scale2.o", "./test_verif_scale3.o"
	};
	const char *pyperf[] = {
		"./pyperf50.o",	"./pyperf100.o", "./pyperf180.o"
	};
	int err, i;
41 42 43 44

	if (verifier_stats)
		libbpf_set_print(libbpf_debug_print);

45 46 47 48 49 50 51 52 53
	for (i = 0; i < ARRAY_SIZE(scale); i++) {
		err = check_load(scale[i], BPF_PROG_TYPE_SCHED_CLS);
		printf("test_scale:%s:%s\n", scale[i], err ? "FAIL" : "OK");
	}

	for (i = 0; i < ARRAY_SIZE(pyperf); i++) {
		err = check_load(pyperf[i], BPF_PROG_TYPE_RAW_TRACEPOINT);
		printf("test_scale:%s:%s\n", pyperf[i], err ? "FAIL" : "OK");
	}
54
}