summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2017-10-24 02:53:09 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-24 21:47:47 -0400
commita678be5cc747bafc8c66f2fe00a103422587a5eb (patch)
treec2d0ca52a82c862c8e2a5623ba2d76fdb9a19052 /samples
parente87c6bc3852b981e71c757be20771546ce9f76f3 (diff)
bpf: add a test case to test single tp multiple bpf attachment
The bpf sample program syscall_tp is modified to show attachment of more than bpf programs for a particular kernel tracepoint. Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples')
-rw-r--r--samples/bpf/syscall_tp_user.c66
1 files changed, 53 insertions, 13 deletions
diff --git a/samples/bpf/syscall_tp_user.c b/samples/bpf/syscall_tp_user.c
index a3cb91ebf4e7..9169d3207f18 100644
--- a/samples/bpf/syscall_tp_user.c
+++ b/samples/bpf/syscall_tp_user.c
@@ -23,6 +23,13 @@
23 * This requires kernel CONFIG_FTRACE_SYSCALLS to be set. 23 * This requires kernel CONFIG_FTRACE_SYSCALLS to be set.
24 */ 24 */
25 25
26static void usage(const char *cmd)
27{
28 printf("USAGE: %s [-i num_progs] [-h]\n", cmd);
29 printf(" -i num_progs # number of progs of the test\n");
30 printf(" -h # help\n");
31}
32
26static void verify_map(int map_id) 33static void verify_map(int map_id)
27{ 34{
28 __u32 key = 0; 35 __u32 key = 0;
@@ -32,22 +39,29 @@ static void verify_map(int map_id)
32 fprintf(stderr, "map_lookup failed: %s\n", strerror(errno)); 39 fprintf(stderr, "map_lookup failed: %s\n", strerror(errno));
33 return; 40 return;
34 } 41 }
35 if (val == 0) 42 if (val == 0) {
36 fprintf(stderr, "failed: map #%d returns value 0\n", map_id); 43 fprintf(stderr, "failed: map #%d returns value 0\n", map_id);
44 return;
45 }
46 val = 0;
47 if (bpf_map_update_elem(map_id, &key, &val, BPF_ANY) != 0) {
48 fprintf(stderr, "map_update failed: %s\n", strerror(errno));
49 return;
50 }
37} 51}
38 52
39int main(int argc, char **argv) 53static int test(char *filename, int num_progs)
40{ 54{
41 struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; 55 int i, fd, map0_fds[num_progs], map1_fds[num_progs];
42 char filename[256];
43 int fd;
44 56
45 setrlimit(RLIMIT_MEMLOCK, &r); 57 for (i = 0; i < num_progs; i++) {
46 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); 58 if (load_bpf_file(filename)) {
47 59 fprintf(stderr, "%s", bpf_log_buf);
48 if (load_bpf_file(filename)) { 60 return 1;
49 fprintf(stderr, "%s", bpf_log_buf); 61 }
50 return 1; 62 printf("prog #%d: map ids %d %d\n", i, map_fd[0], map_fd[1]);
63 map0_fds[i] = map_fd[0];
64 map1_fds[i] = map_fd[1];
51 } 65 }
52 66
53 /* current load_bpf_file has perf_event_open default pid = -1 67 /* current load_bpf_file has perf_event_open default pid = -1
@@ -64,8 +78,34 @@ int main(int argc, char **argv)
64 close(fd); 78 close(fd);
65 79
66 /* verify the map */ 80 /* verify the map */
67 verify_map(map_fd[0]); 81 for (i = 0; i < num_progs; i++) {
68 verify_map(map_fd[1]); 82 verify_map(map0_fds[i]);
83 verify_map(map1_fds[i]);
84 }
69 85
70 return 0; 86 return 0;
71} 87}
88
89int main(int argc, char **argv)
90{
91 struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
92 int opt, num_progs = 1;
93 char filename[256];
94
95 while ((opt = getopt(argc, argv, "i:h")) != -1) {
96 switch (opt) {
97 case 'i':
98 num_progs = atoi(optarg);
99 break;
100 case 'h':
101 default:
102 usage(argv[0]);
103 return 0;
104 }
105 }
106
107 setrlimit(RLIMIT_MEMLOCK, &r);
108 snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
109
110 return test(filename, num_progs);
111}