diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/bpf/bpf_util.h | 38 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_lru_map.c | 8 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_maps.c | 7 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_verifier.c | 2 |
4 files changed, 49 insertions, 6 deletions
diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h new file mode 100644 index 000000000000..84a5d1823f02 --- /dev/null +++ b/tools/testing/selftests/bpf/bpf_util.h @@ -0,0 +1,38 @@ +#ifndef __BPF_UTIL__ +#define __BPF_UTIL__ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +static inline unsigned int bpf_num_possible_cpus(void) +{ + static const char *fcpu = "/sys/devices/system/cpu/possible"; + unsigned int start, end, possible_cpus = 0; + char buff[128]; + FILE *fp; + + fp = fopen(fcpu, "r"); + if (!fp) { + printf("Failed to open %s: '%s'!\n", fcpu, strerror(errno)); + exit(1); + } + + while (fgets(buff, sizeof(buff), fp)) { + if (sscanf(buff, "%u-%u", &start, &end) == 2) { + possible_cpus = start == 0 ? end + 1 : 0; + break; + } + } + + fclose(fp); + if (!possible_cpus) { + printf("Failed to retrieve # possible CPUs!\n"); + exit(1); + } + + return possible_cpus; +} + +#endif /* __BPF_UTIL__ */ diff --git a/tools/testing/selftests/bpf/test_lru_map.c b/tools/testing/selftests/bpf/test_lru_map.c index 627757ed7836..b13fed534d76 100644 --- a/tools/testing/selftests/bpf/test_lru_map.c +++ b/tools/testing/selftests/bpf/test_lru_map.c @@ -12,10 +12,14 @@ #include <string.h> #include <assert.h> #include <sched.h> -#include <sys/wait.h> #include <stdlib.h> #include <time.h> + +#include <sys/wait.h> +#include <sys/resource.h> + #include "bpf_sys.h" +#include "bpf_util.h" #define LOCAL_FREE_TARGET (128) #define PERCPU_FREE_TARGET (16) @@ -559,7 +563,7 @@ int main(int argc, char **argv) assert(!setrlimit(RLIMIT_MEMLOCK, &r)); - nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + nr_cpus = bpf_num_possible_cpus(); assert(nr_cpus != -1); printf("nr_cpus:%d\n\n", nr_cpus); diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index ee384f02cb6e..eedfef8d2946 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -22,6 +22,7 @@ #include <linux/bpf.h> #include "bpf_sys.h" +#include "bpf_util.h" static int map_flags; @@ -110,7 +111,7 @@ static void test_hashmap(int task, void *data) static void test_hashmap_percpu(int task, void *data) { - unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + unsigned int nr_cpus = bpf_num_possible_cpus(); long long value[nr_cpus]; long long key, next_key; int expected_key_mask = 0; @@ -258,7 +259,7 @@ static void test_arraymap(int task, void *data) static void test_arraymap_percpu(int task, void *data) { - unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + unsigned int nr_cpus = bpf_num_possible_cpus(); int key, next_key, fd, i; long values[nr_cpus]; @@ -313,7 +314,7 @@ static void test_arraymap_percpu(int task, void *data) static void test_arraymap_percpu_many_keys(void) { - unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + unsigned int nr_cpus = bpf_num_possible_cpus(); unsigned int nr_keys = 20000; long values[nr_cpus]; int key, fd, i; diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 0ef8eaf6cea7..3c4a1fbba2a0 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -285,7 +285,7 @@ static struct bpf_test tests[] = { BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, 1234567), BPF_EXIT_INSN(), }, - .errstr = "invalid func 1234567", + .errstr = "invalid func unknown#1234567", .result = REJECT, }, { |