]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Handle prog/attach type comparison in veristat
authorMykyta Yatsenko <yatsenko@meta.com>
Mon, 6 Jan 2025 14:43:21 +0000 (14:43 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 7 Jan 2025 01:07:49 +0000 (17:07 -0800)
Implemented handling of prog type and attach type stats comparison in
veristat.
To test this change:
```
./veristat pyperf600.bpf.o -o csv > base1.csv
./veristat pyperf600.bpf.o -o csv > base2.csv
./veristat -C base2.csv base1.csv -o csv
...,raw_tracepoint,raw_tracepoint,MATCH,
...,cgroup_inet_ingress,cgroup_inet_ingress,MATCH
```

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20250106144321.32337-1-mykyta.yatsenko5@gmail.com
tools/testing/selftests/bpf/veristat.c

index 476bf95cf684296409cbcd990bd271070fa66923..974c808f932112f0cce6558de3f5c4248b52cc10 100644 (file)
@@ -1688,9 +1688,42 @@ static int parse_stat_value(const char *str, enum stat_id id, struct verif_stats
                st->stats[id] = val;
                break;
        }
-       case PROG_TYPE:
-       case ATTACH_TYPE:
+       case PROG_TYPE: {
+               enum bpf_prog_type prog_type = 0;
+               const char *type;
+
+               while ((type = libbpf_bpf_prog_type_str(prog_type)))  {
+                       if (strcmp(type, str) == 0) {
+                               st->stats[id] = prog_type;
+                               break;
+                       }
+                       prog_type++;
+               }
+
+               if (!type) {
+                       fprintf(stderr, "Unrecognized prog type %s\n", str);
+                       return -EINVAL;
+               }
                break;
+       }
+       case ATTACH_TYPE: {
+               enum bpf_attach_type attach_type = 0;
+               const char *type;
+
+               while ((type = libbpf_bpf_attach_type_str(attach_type)))  {
+                       if (strcmp(type, str) == 0) {
+                               st->stats[id] = attach_type;
+                               break;
+                       }
+                       attach_type++;
+               }
+
+               if (!type) {
+                       fprintf(stderr, "Unrecognized attach type %s\n", str);
+                       return -EINVAL;
+               }
+               break;
+       }
        default:
                fprintf(stderr, "Unrecognized stat #%d\n", id);
                return -EINVAL;