Skip to contentSkip to conversation

selftests/bpf: Fix test_attach_probe

PATCH Applied Alexei Starovoitov 4 participants 4 messages Dec 19, 2019

Subsystems (5)
lore
Share & tools
lore

Alexei Starovoitov

author maintainer
#0 lore raw

PATCH 1/1 selftests/bpf: Fix test_attach_probe

Fix two issues in test_attach_probe:
1. it was not able to parse /proc/self/maps beyond the first line, since %s means parse string until white space.
2. offset has to be accounted for otherwise uprobed address is incorrect.

Fixes 1e8611bbdfc9 ("selftests/bpf: add kprobe/uprobe selftests")
---
 tools/testing/selftests/bpf/prog_tests/attach_probe.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/attach_probe.c +4 -3
index 5ed90ede2f1d..a0ee87c8e1ea 100644
@@ -3,7 +3,7 @@
 #include "test_attach_probe.skel.h"
 
 ssize_t get_base_addr() {
-	size_t start;
+	size_t start, offset;
 	char buf[256];
 	FILE *f;
 
@@ -11,10 +11,11 @@ ssize_t get_base_addr() {
 	if (!f)
 		return -errno;
 
-	while (fscanf(f, "%zx-%*x %s %*s\n", &start, buf) == 2) {
+	while (fscanf(f, "%zx-%*x %s %zx %*[^\n]\n",
+		      &start, buf, &offset) == 3) {
 		if (strcmp(buf, "r-xp") == 0) {
 			fclose(f);
-			return start;
+			return start - offset;
 		}
 	}
 
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Alexei Starovoitov

Fix two issues in test_attach_probe:
1. it was not able to parse /proc/self/maps beyond the first line, since %s means parse string until white space.
2. offset has to be accounted for otherwise uprobed address is incorrect.

Fixes 1e8611bbdfc9 ("selftests/bpf: add kprobe/uprobe selftests")
Acked-by on v1 1/1
#2 lore raw
In reply to Alexei Starovoitov
Quoted 9 lines · Alexei Starovoitov

Fix two issues in test_attach_probe:
1. it was not able to parse /proc/self/maps beyond the first line, since %s means parse string until white space.
2. offset has to be accounted for otherwise uprobed address is incorrect.

Fixes 1e8611bbdfc9 ("selftests/bpf: add kprobe/uprobe selftests")

---

Thanks for fixing!

Quoted 17 lines
 tools/testing/selftests/bpf/prog_tests/attach_probe.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1 -1
index 5ed90ede2f1d..a0ee87c8e1ea 100644
@@ -3,7 +3,7 @@
 #include "test_attach_probe.skel.h"
 
 ssize_t get_base_addr() {
-       size_t start;
+       size_t start, offset;
        char buf[256];
        FILE *f;
 

tools/testing/selftests/bpf/prog_tests/attach_probe.c ssize_t get_base_addr() { · line 14

Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +1 -1
@@ -11,10 +11,11 @@ ssize_t get_base_addr() {
        if (!f)
                return -errno;
 
-       while (fscanf(f, "%zx-%*x %s %*s\n", &start, buf) == 2) {
+       while (fscanf(f, "%zx-%*x %s %zx %*[^\n]\n",

never new [^<chars>] is possible, very nice!

Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/attach_probe.c +2 -2
+                     &start, buf, &offset) == 3) {
                if (strcmp(buf, "r-xp") == 0) {
                        fclose(f);
-                       return start;
+                       return start - offset;
                }
        }
 
--

2.23.0

maintainer Applied
#3 lore raw
In reply to Alexei Starovoitov
Quoted 7 lines · Alexei Starovoitov

Fix two issues in test_attach_probe:
1. it was not able to parse /proc/self/maps beyond the first line, since %s means parse string until white space.
2. offset has to be accounted for otherwise uprobed address is incorrect.

Fixes 1e8611bbdfc9 ("selftests/bpf: add kprobe/uprobe selftests")

Applied, thanks!