selftests: vdso: Add a selftest for vDSO getcpu()
Subsystems (2)
v2 cover selftests: vdso: Add a selftest for vDSO getcpu()
This series does a bit of a cleanup of the existing tests for the vDSO in kselftest and then adds a new test for getcpu().
v2: Silence checkpatch
Mark Brown (3):
selftests: vdso: Rename vdso_test to vdso_test_gettimeofday
selftests: vdso: Use a header file to prototype parse_vdso API
selftests: vdso: Add a selftest for vDSO getcpu()
tools/testing/selftests/vDSO/.gitignore | 2 +
tools/testing/selftests/vDSO/Makefile | 5 +-
tools/testing/selftests/vDSO/parse_vdso.c | 24 +--------
tools/testing/selftests/vDSO/parse_vdso.h | 31 +++++++++++
.../selftests/vDSO/vdso_standalone_test_x86.c | 4 +-
.../testing/selftests/vDSO/vdso_test_getcpu.c | 54 +++++++++++++++++++
.../{vdso_test.c => vdso_test_gettimeofday.c} | 10 ++--
7 files changed, 96 insertions(+), 34 deletions(-)
create mode 100644 tools/testing/selftests/vDSO/parse_vdso.h
create mode 100644 tools/testing/selftests/vDSO/vdso_test_getcpu.c
rename tools/testing/selftests/vDSO/{vdso_test.c => vdso_test_gettimeofday.c} (84%)Signature · 1 line
2.20.1
PATCH v2 1/3 selftests: vdso: Rename vdso_test to vdso_test_gettimeofday
Currently the vDSO kselftests have a test called vdso_test which tests the vDSO implementation of gettimeofday(). In preparation for adding tests for other vDSO functionality rename this test to reflect what's going on.
---
tools/testing/selftests/vDSO/.gitignore | 1 +
tools/testing/selftests/vDSO/Makefile | 4 ++--
.../selftests/vDSO/{vdso_test.c => vdso_test_gettimeofday.c} | 5 +++--
3 files changed, 6 insertions(+), 4 deletions(-)
rename tools/testing/selftests/vDSO/{vdso_test.c => vdso_test_gettimeofday.c} (89%)tools/testing/selftests/vDSO/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only vdso_test +vdso_test_gettimeofday vdso_standalone_test_x86
tools/testing/selftests/vDSO/Makefile +2 -2
@@ -4,7 +4,7 @@ include ../lib.mk uname_M := $(shell uname -m 2>/dev/null || echo not) ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) -TEST_GEN_PROGS := $(OUTPUT)/vdso_test +TEST_GEN_PROGS := $(OUTPUT)/vdso_test_gettimeofday ifeq ($(ARCH),x86) TEST_GEN_PROGS += $(OUTPUT)/vdso_standalone_test_x86 endif
@@ -17,7 +17,7 @@ LDLIBS += -lgcc_s endif all: $(TEST_GEN_PROGS) -$(OUTPUT)/vdso_test: parse_vdso.c vdso_test.c +$(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c $(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c $(CC) $(CFLAGS) $(CFLAGS_vdso_standalone_test_x86) \ vdso_standalone_test_x86.c parse_vdso.c \
tools/testing/selftests/vDSO/vdso_test_gettimeofday.c renamed from tools/testing/selftests/vDSO/vdso_test.c +3 -2
@@ -1,10 +1,11 @@// SPDX-License-Identifier: GPL-2.0-only /* -* vdso_test.c: Sample code to test parse_vdso.c +* vdso_test_gettimeofday.c: Sample code to test parse_vdso.c and +* vDSO gettimeofday() * Copyright (c) 2014 Andy Lutomirski * * Compile with: -* gcc -std=gnu99 vdso_test.c parse_vdso.c +* gcc -std=gnu99 vdso_test_gettimeofday.c parse_vdso_gettimeofday.c * * Tested on x86, 32-bit and 64-bit. It may work on other architectures, too. */
Signature · 1 line
2.20.1
PATCH v2 2/3 selftests: vdso: Use a header file to prototype parse_vdso API
In reply to Mark BrownBoth vdso_test_gettimeofday and vdso_standalone_test_x86 use the library in parse_vdso.c but each separately declares the API it offers which is not ideal. Create a header file with prototypes of the functions and use it in both the library and the tests to ensure that the same prototypes are used throughout.
--- tools/testing/selftests/vDSO/parse_vdso.c | 24 +------------- tools/testing/selftests/vDSO/parse_vdso.h | 31 +++++++++++++++++++ .../selftests/vDSO/vdso_standalone_test_x86.c | 4 +-- .../selftests/vDSO/vdso_test_gettimeofday.c | 5 +-- 4 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 tools/testing/selftests/vDSO/parse_vdso.h
tools/testing/selftests/vDSO/parse_vdso.c +1 -23
@@ -21,29 +21,7 @@#include <limits.h> #include <elf.h> -/* -* To use this vDSO parser, first call one of the vdso_init_* functions. -* If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR -* to vdso_init_from_sysinfo_ehdr. Otherwise pass auxv to vdso_init_from_auxv. -* Then call vdso_sym for each symbol you want. For example, to look up -* gettimeofday on x86_64, use: -* -* <some pointer> = vdso_sym("LINUX_2.6", "gettimeofday"); -* or -* <some pointer> = vdso_sym("LINUX_2.6", "__vdso_gettimeofday"); -* -* vdso_sym will return 0 if the symbol doesn't exist or if the init function -* failed or was not called. vdso_sym is a little slow, so its return value -* should be cached. -* -* vdso_sym is threadsafe; the init functions are not. -* -* These are the prototypes: -*/ -extern void vdso_init_from_auxv (void *auxv); -extern void vdso_init_from_sysinfo_ehdr (uintptr_t base); -extern void *vdso_sym (const char *version,const char *name); - +#include "parse_vdso.h" /* And here's the code. */ #ifndef ELF_BITS
tools/testing/selftests/vDSO/parse_vdso.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef PARSE_VDSO_H +#define PARSE_VDSO_H + +#include <stdint.h> + +/* +* To use this vDSO parser, first call one of the vdso_init_* functions. +* If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR +* to vdso_init_from_sysinfo_ehdr. Otherwise pass auxv to vdso_init_from_auxv. +* Then call vdso_sym for each symbol you want. For example, to look up +* gettimeofday on x86_64, use: +* +* <some pointer> = vdso_sym("LINUX_2.6", "gettimeofday"); +* or +* <some pointer> = vdso_sym("LINUX_2.6", "__vdso_gettimeofday"); +* +* vdso_sym will return 0 if the symbol doesn't exist or if the init function +* failed or was not called. vdso_sym is a little slow, so its return value +* should be cached. +* +* vdso_sym is threadsafe; the init functions are not. +* +* These are the prototypes: +*/ +extern void *vdso_sym (const char *version,const char *name); +extern void vdso_init_from_sysinfo_ehdr (uintptr_t base); +extern void vdso_init_from_auxv (void *auxv); + +#endif
tools/testing/selftests/vDSO/vdso_standalone_test_x86.c +1 -3
@@ -16,9 +16,7 @@#include <unistd.h> #include <stdint.h> -extern void *vdso_sym (const char *version,const char *name); -extern void vdso_init_from_sysinfo_ehdr (uintptr_t base); -extern void vdso_init_from_auxv (void *auxv); +#include "parse_vdso.h" /* We need a libc functions... */ int strcmp (const char *a,const char *b)
tools/testing/selftests/vDSO/vdso_test_gettimeofday.c +1 -4
@@ -17,10 +17,7 @@#include <sys/time.h> #include "../kselftest.h" - -extern void *vdso_sym (const char *version,const char *name); -extern void vdso_init_from_sysinfo_ehdr (uintptr_t base); -extern void vdso_init_from_auxv (void *auxv); +#include "parse_vdso.h" /* * ARM64's vDSO exports its gettimeofday() implementation with a different
Signature · 1 line
2.20.1
shuah
maintainerRe: [PATCH v2 2/3] selftests: vdso: Use a header file to prototype parse_vdso API
Quoted 76 lines · Mark Brown
Both
vdso_test_gettimeofdayandvdso_standalone_test_x86use the library inparse_vdso.cbut each separately declares the API it offers which is not ideal. Create a header file with prototypes of the functions and use it in both the library and the tests to ensure that the same prototypes are used throughout.Signed-off-by Mark Brown <[email protected]>--- tools/testing/selftests/vDSO/parse_vdso.c | 24 +------------- tools/testing/selftests/vDSO/parse_vdso.h | 31 +++++++++++++++++++ .../selftests/vDSO/vdso_standalone_test_x86.c | 4 +-- .../selftests/vDSO/vdso_test_gettimeofday.c | 5 +-- 4 files changed, 34 insertions(+), 30 deletions(-)create mode 100644
tools/testing/selftests/vDSO/parse_vdso.htools/testing/selftests/vDSO/parse_vdso.c +1
-23@@ -21,29 +21,7 @@#include <limits.h> #include <elf.h> -/* -* To use this vDSO parser, first call one of the vdso_init_* functions. -* If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR -* to vdso_init_from_sysinfo_ehdr. Otherwise pass auxv to vdso_init_from_auxv. -* Then call vdso_sym for each symbol you want. For example, to look up -* gettimeofday on x86_64, use: -* -* <some pointer> = vdso_sym("LINUX_2.6", "gettimeofday"); -* or -* <some pointer> = vdso_sym("LINUX_2.6", "__vdso_gettimeofday"); -* -* vdso_sym will return 0 if the symbol doesn't exist or if the init function -* failed or was not called. vdso_sym is a little slow, so its return value -* should be cached. -* -* vdso_sym is threadsafe; the init functions are not. -* -* These are the prototypes: -*/ -extern void vdso_init_from_auxv (void *auxv); -extern void vdso_init_from_sysinfo_ehdr (uintptr_t base); -extern void *vdso_sym (const char *version,const char *name); - +#include "parse_vdso.h" /* And here's the code. */ #ifndef ELF_BITS tools/testing/selftests/vDSO/parse_vdso.h new file +20
-0@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef PARSE_VDSO_H +#define PARSE_VDSO_H + +#include <stdint.h> + +/* +* To use this vDSO parser, first call one of the vdso_init_* functions. +* If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR +* to vdso_init_from_sysinfo_ehdr. Otherwise pass auxv to vdso_init_from_auxv. +* Then call vdso_sym for each symbol you want. For example, to look up +* gettimeofday on x86_64, use: +* +* <some pointer> = vdso_sym("LINUX_2.6", "gettimeofday"); +* or +* <some pointer> = vdso_sym("LINUX_2.6", "__vdso_gettimeofday"); +* +* vdso_sym will return 0 if the symbol doesn't exist or if the init function +* failed or was not called. vdso_sym is a little slow, so its return value
tools/testing/selftests/vDSO/parse_vdso.h line 30
Quoted 10 lines
tools/testing/selftests/vDSO/parse_vdso.h new file +10
-0+* should be cached. +* +* vdso_sym is threadsafe; the init functions are not. +* +* These are the prototypes: +*/ +extern void *vdso_sym (const char *version,const char *name); +extern void vdso_init_from_sysinfo_ehdr (uintptr_t base); +extern void vdso_init_from_auxv (void *auxv); +
Please remove these externs. I understand it is must a move. Might as well clean this up.
Send me v3 for just this one.
thanks,
-- Shuah
PATCH v2 3/3 selftests: vdso: Add a selftest for vDSO getcpu()
In reply to Mark BrownProvide a very basic selftest for getcpu() which similarly to our existing test for gettimeofday() looks up the function in the vDSO and prints the results it gets if the function exists and succeeds.
--- tools/testing/selftests/vDSO/.gitignore | 1 + tools/testing/selftests/vDSO/Makefile | 3 +- .../testing/selftests/vDSO/vdso_test_getcpu.c | 54 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/vDSO/vdso_test_getcpu.c
tools/testing/selftests/vDSO/.gitignore +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only vdso_test vdso_test_gettimeofday +vdso_test_getcpu vdso_standalone_test_x86
tools/testing/selftests/vDSO/Makefile +2 -1
@@ -4,7 +4,7 @@ include ../lib.mk uname_M := $(shell uname -m 2>/dev/null || echo not) ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) -TEST_GEN_PROGS := $(OUTPUT)/vdso_test_gettimeofday +TEST_GEN_PROGS := $(OUTPUT)/vdso_test_gettimeofday $(OUTPUT)/vdso_test_getcpu ifeq ($(ARCH),x86) TEST_GEN_PROGS += $(OUTPUT)/vdso_standalone_test_x86 endif
@@ -18,6 +18,7 @@ endif all: $(TEST_GEN_PROGS) $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c +$(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c $(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c $(CC) $(CFLAGS) $(CFLAGS_vdso_standalone_test_x86) \ vdso_standalone_test_x86.c parse_vdso.c \
tools/testing/selftests/vDSO/vdso_test_getcpu.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.20.1