0001
0002
0003 #include <test_progs.h>
0004
0005 const char *err_str;
0006 bool found;
0007
0008 static int libbpf_debug_print(enum libbpf_print_level level,
0009 const char *format, va_list args)
0010 {
0011 char *log_buf;
0012
0013 if (level != LIBBPF_WARN ||
0014 strcmp(format, "libbpf: \n%s\n")) {
0015 vprintf(format, args);
0016 return 0;
0017 }
0018
0019 log_buf = va_arg(args, char *);
0020 if (!log_buf)
0021 goto out;
0022 if (err_str && strstr(log_buf, err_str) == 0)
0023 found = true;
0024 out:
0025 printf(format, log_buf);
0026 return 0;
0027 }
0028
0029 extern int extra_prog_load_log_flags;
0030
0031 static int check_load(const char *file)
0032 {
0033 struct bpf_object *obj = NULL;
0034 struct bpf_program *prog;
0035 int err;
0036
0037 found = false;
0038
0039 obj = bpf_object__open_file(file, NULL);
0040 err = libbpf_get_error(obj);
0041 if (err)
0042 return err;
0043
0044 prog = bpf_object__next_program(obj, NULL);
0045 if (!prog) {
0046 err = -ENOENT;
0047 goto err_out;
0048 }
0049
0050 bpf_program__set_flags(prog, BPF_F_TEST_RND_HI32);
0051 bpf_program__set_log_level(prog, extra_prog_load_log_flags);
0052
0053 err = bpf_object__load(obj);
0054
0055 err_out:
0056 bpf_object__close(obj);
0057 return err;
0058 }
0059
0060 struct test_def {
0061 const char *file;
0062 const char *err_str;
0063 };
0064
0065 void test_test_global_funcs(void)
0066 {
0067 struct test_def tests[] = {
0068 { "test_global_func1.o", "combined stack size of 4 calls is 544" },
0069 { "test_global_func2.o" },
0070 { "test_global_func3.o" , "the call stack of 8 frames" },
0071 { "test_global_func4.o" },
0072 { "test_global_func5.o" , "expected pointer to ctx, but got PTR" },
0073 { "test_global_func6.o" , "modified ctx ptr R2" },
0074 { "test_global_func7.o" , "foo() doesn't return scalar" },
0075 { "test_global_func8.o" },
0076 { "test_global_func9.o" },
0077 { "test_global_func10.o", "invalid indirect read from stack" },
0078 { "test_global_func11.o", "Caller passes invalid args into func#1" },
0079 { "test_global_func12.o", "invalid mem access 'mem_or_null'" },
0080 { "test_global_func13.o", "Caller passes invalid args into func#1" },
0081 { "test_global_func14.o", "reference type('FWD S') size cannot be determined" },
0082 { "test_global_func15.o", "At program exit the register R0 has value" },
0083 { "test_global_func16.o", "invalid indirect read from stack" },
0084 { "test_global_func17.o", "Caller passes invalid args into func#1" },
0085 };
0086 libbpf_print_fn_t old_print_fn = NULL;
0087 int err, i, duration = 0;
0088
0089 old_print_fn = libbpf_set_print(libbpf_debug_print);
0090
0091 for (i = 0; i < ARRAY_SIZE(tests); i++) {
0092 const struct test_def *test = &tests[i];
0093
0094 if (!test__start_subtest(test->file))
0095 continue;
0096
0097 err_str = test->err_str;
0098 err = check_load(test->file);
0099 CHECK_FAIL(!!err ^ !!err_str);
0100 if (err_str)
0101 CHECK(found, "", "expected string '%s'", err_str);
0102 }
0103 libbpf_set_print(old_print_fn);
0104 }