kvm test Makefile doesn't fully support cross-builds and installs.
UNAME_M = $(shell uname -m) variable is used to define the target
programs and libraries to be built from arch specific sources in
sub-directories.
For cross-builds to work, UNAME_M has to map to ARCH and arch specific
directories and targets in this Makefile.
UNAME_M variable to used to run the compiles pointing to the right arch
directories and build the right targets for these supported architectures.
TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable.
LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable.
x86_64 targets are named to include x86_64 as a suffix and directories
for includes are in x86_64 sub-directory. s390x and aarch64 follow the
same convention. "uname -m" doesn't result in the correct mapping for
s390x and aarch64. Fix it to set UNAME_M correctly for s390x and aarch64
cross-builds.
In addition, Makefile doesn't create arch sub-directories in the case of
relocatable builds and test programs under s390x and x86_64 directories
fail to build. This is a problem for native and cross-builds. Fix it to
create all necessary directories keying off of TEST_GEN_PROGS.
The following use-cases work with this change:
Native x86_64:
make O=/tmp/kselftest -C tools/testing/selftests TARGETS=kvm install \
INSTALL_PATH=$HOME/x86_64
arm64 cross-build:
make O=$HOME/arm64_build/ ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- defconfig
make O=$HOME/arm64_build/ ARCH=arm64 HOSTCC=gcc \
CROSS_COMPILE=aarch64-linux-gnu- all
make kselftest-install TARGETS=kvm O=$HOME/arm64_build ARCH=arm64 \
HOSTCC=gcc CROSS_COMPILE=aarch64-linux-gnu-
s390x cross-build:
make O=$HOME/s390x_build/ ARCH=s390 HOSTCC=gcc \
CROSS_COMPILE=s390x-linux-gnu- defconfig
make O=$HOME/s390x_build/ ARCH=s390 HOSTCC=gcc \
CROSS_COMPILE=s390x-linux-gnu- all
make kselftest-install TARGETS=kvm O=$HOME/s390x_build/ ARCH=s390 \
HOSTCC=gcc CROSS_COMPILE=s390x-linux-gnu- all
No regressions in the following use-cases:
make -C tools/testing/selftests TARGETS=kvm
make kselftest-all TARGETS=kvm
Signed-off-by: Shuah Khan <skhan(a)linuxfoundation.org>
---
tools/testing/selftests/kvm/Makefile | 29 +++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 712a2ddd2a27..b728c0a0f9b2 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -5,8 +5,34 @@ all:
top_srcdir = ../../../..
KSFT_KHDR_INSTALL := 1
+
+# For cross-builds to work, UNAME_M has to map to ARCH and arch specific
+# directories and targets in this Makefile. "uname -m" doesn't map to
+# arch specific sub-directory names.
+#
+# UNAME_M variable to used to run the compiles pointing to the right arch
+# directories and build the right targets for these supported architectures.
+#
+# TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable.
+# LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable.
+#
+# x86_64 targets are named to include x86_64 as a suffix and directories
+# for includes are in x86_64 sub-directory. s390x and aarch64 follow the
+# same convention. "uname -m" doesn't result in the correct mapping for
+# s390x and aarch64.
+#
+# No change necessary for x86_64
UNAME_M := $(shell uname -m)
+# Set UNAME_M for arm64 compile/install to work
+ifeq ($(ARCH),arm64)
+ UNAME_M := aarch64
+endif
+# Set UNAME_M s390x compile/install to work
+ifeq ($(ARCH),s390)
+ UNAME_M := s390x
+endif
+
LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c
LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c
LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
@@ -53,7 +79,7 @@ LIBKVM += $(LIBKVM_$(UNAME_M))
INSTALL_HDR_PATH = $(top_srcdir)/usr
LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
-LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include
+LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
@@ -84,6 +110,7 @@ $(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c
$(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
$(AR) crs $@ $^
+x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
all: $(STATIC_LIBS)
$(TEST_GEN_PROGS): $(STATIC_LIBS)
--
2.20.1
Liu Yiding <liuyd.fnst(a)cn.fujitsu.com> wrote:
> Hi, all.
>
> Our team works on testing kernel commit and reporting regression.
>
> Tool selftests is important to us.
>
> Recently i enabled netfilter in out testing env, i met below failed
> subtests.
>
> ```
>
> "kernel-selftests.netfilter.nft_nat.sh.fail": [
> "kernel-selftests.netfilter.conntrack_icmp_related.sh.fail": [
> "kernel-selftests.netfilter.nft_flowtable.sh.fail": [
> "kernel-selftests.netfilter.nft_concat_range.sh.fail": [
>
> ```
>
> Our testing env:
>
>
> It looks that i missed some modules or i get wrong config of nftables. I had
> opend kconfig mentioned in netfilter/config.
Maybe its incomplete. From a quick glance, all of these should be on:
# CONFIG_NFT_OBJREF is not set
# CONFIG_NFT_NAT is not set
# CONFIG_NF_FLOW_TABLE is not set
# CONFIG_NF_TABLES_NETDEV is not set
Hi, Andrey.
I noticed you add test_sysctl to tools/bpf, so drop this problem to you.
When I run selftests: bpf: test_sysctl, failed with
"(test_sysctl.c:1490: errno: Permission denied) >>> Loading program
(./test_sysctl_prog.o) error."
Testing env: "Debian GNU/Linux 9 (stretch)"
kernel: 5.7.0-rc2 5.7.0-rc1 5.6 both failed
Whole run log and kconfig please see the attatchment.
Error info
```
root@vm-snb-42
/usr/src/perf_selftests-x86_64-rhel-7.6-kselftests-ae83d0b416db002fe95601e7f97f64b59514d936/tools/testing/selftests/bpf#
./test_sysctl
Test case: sysctl wrong attach_type .. [PASS]
Test case: sysctl:read allow all .. [PASS]
Test case: sysctl:read deny all .. [PASS]
[snip]
libbpf: -- END LOG --
libbpf: failed to load program 'cgroup/sysctl'
libbpf: failed to load object './test_sysctl_prog.o'
(test_sysctl.c:1490: errno: Permission denied) >>> Loading program
(./test_sysctl_prog.o) error.
Test case: C prog: read tcp_mem .. [FAIL]
Summary: 37 PASSED, 3 FAILED
```
--
Best Regards.
Ma Xinjian
It is possible to get multiple records from trace during test and then more
than 4 arguments are assigned to ARGS. This situation results in the failure
of kprobe_args_type.tc. For example:
-----------------------------------------------------------
grep testprobe trace
ftracetest-5902 [001] d... 111195.682227: testprobe: (_do_fork+0x0/0x460) arg1=334823024 arg2=334823024 arg3=0x13f4fe70 arg4=7
pmlogger-5949 [000] d... 111195.709898: testprobe: (_do_fork+0x0/0x460) arg1=345308784 arg2=345308784 arg3=0x1494fe70 arg4=7
grep testprobe trace
sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'
ARGS='334823024 334823024 0x13f4fe70 7
345308784 345308784 0x1494fe70 7'
-----------------------------------------------------------
We don't care which process calls do_fork so just check the first record to
fix the issue.
Signed-off-by: Xiao Yang <yangx.jy(a)cn.fujitsu.com>
---
.../testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc
index 1bcb67dcae26..81490ecaaa92 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
echo 0 > events/kprobes/testprobe/enable
: "Confirm the arguments is recorded in given types correctly"
- ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+ ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
check_types $ARGS $width
: "Clear event for next loop"
--
2.25.1
On Sat, Apr 18, 2020 at 11:28 PM Alan Maguire <alan.maguire(a)oracle.com> wrote:
>
>
> On Fri, 17 Apr 2020, David Gow wrote:
>
> > This patchset contains everything needed to integrate KASAN and KUnit.
> >
> > KUnit will be able to:
> > (1) Fail tests when an unexpected KASAN error occurs
> > (2) Pass tests when an expected KASAN error occurs
> >
> > Convert KASAN tests to KUnit with the exception of copy_user_test
> > because KUnit is unable to test those.
> >
>
> I tried building and running and things look good but I am
> still seeing the three failures I reported before, even with
> CONFIG_AMD_MEM_ENCRYPT not set. My config is attached if you
> want to try and reproduce at your end. Oddly this config was
> working before IIRC (once CONFIG_AMD_MEM_ENCRYPT was not set).
>
> Here's the failures:
>
> # kasan_memchr: EXPECTATION FAILED at lib/test_kasan.c:545
> Expected fail_data.report_expected == fail_data.report_found, but
> fail_data.report_expected == 1
> fail_data.report_found == 0
> not ok 31 - kasan_memchr
> # kasan_memcmp: EXPECTATION FAILED at lib/test_kasan.c:566
> Expected fail_data.report_expected == fail_data.report_found, but
> fail_data.report_expected == 1
> fail_data.report_found == 0
> not ok 32 - kasan_memcmp
I was able to reproduce these (along with a kasan_strings) failure,
and the cause seems to be some combination of __builtin functions
being inlined by the compiler and potentially dead code elimination,
as fixed by Daniel Axtens here:
https://lkml.org/lkml/2020/4/23/708
I've sent out v7 of the patchset[1], which I've rebased on top of
Daniel's patches, and can no longer reproduce those test failures with
your .config.
Cheers,
-- David
[1]: https://lkml.org/lkml/2020/4/24/80
Hi Andrii.
sorry to bother you again.
I run bpf: test_progs on debian 9, and failed with"Segmentation fault".
CONFIG_DEBUG_INFO_BTF was enabled in kconfig.
Testing env: "Debian GNU/Linux 9 (stretch)"
kernel: v5.7-rc2 v5.6 both failed
Whole run log and kconfig please see the attatchment.
Error info
```
root@vm-snb-42
/usr/src/perf_selftests-x86_64-rhel-7.6-kselftests-ae83d0b416db002fe95601e7f97f64b59514d936/tools/testing/selftests/bpf#
./test_progs
#1 attach_probe:OK
#2 bpf_obj_id:OK
#3/1 dctcp:OK
[snip]
libbpf: bpf_fentry_test1 is not found in vmlinux BTF
libbpf: failed to load object 'fentry_test'
libbpf: failed to load BPF skeleton 'fentry_test': -2
test_fentry_fexit:FAIL:fentry_skel_load fentry skeleton failed
#13 fentry_fexit:FAIL
libbpf: bpf_fentry_test1 is not found in vmlinux BTF
libbpf: failed to load object 'fentry_test'
libbpf: failed to load BPF skeleton 'fentry_test': -2
test_fentry_test:FAIL:fentry_skel_load fentry skeleton failed
#14 fentry_test:FAIL
#15 fexit_bpf2bpf:OK
libbpf: bpf_fentry_test1 is not found in vmlinux BTF
test_fexit_stress:FAIL:find_vmlinux_btf_id failed: -2
#16 fexit_stress:FAIL
libbpf: bpf_fentry_test1 is not found in vmlinux BTF
libbpf: failed to load object 'fexit_test'
libbpf: failed to load BPF skeleton 'fexit_test': -2
test_fexit_test:FAIL:fexit_skel_load fexit skeleton failed
#17 fexit_test:FAIL
#18 flow_dissector:OK
#19 flow_dissector_load_bytes:OK
#20 flow_dissector_reattach:OK
#21 get_stack_raw_tp:OK
#22 global_data:OK
#23 global_data_init:OK
test_kfree_skb:PASS:prog_load sched cls 0 nsec
libbpf: eth_type_trans is not found in vmlinux BTF
libbpf: failed to load object './kfree_skb.o'
test_kfree_skb:FAIL:prog_load raw tp err -22 errno 1
#24 kfree_skb:FAIL
#25 l4lb_all:OK
#26/1 pin_raw_tp:OK
#26/2 pin_tp_btf:OK
#26 link_pinning:OK
#27 map_lock:OK
Segmentation fault
```
--
Best Regards.
Ma Xinjian
Hi Andrii.
I noticed you add tools/testing/selftests/bpf/progs/test_btf_*, so drop
this problem to you.
I failed to run bpf: test_btf on debian9(stretch), hope you can give me
some suggestion.
Testing env: "Debian GNU/Linux 9 (stretch)"
kernel: 5.7.0-rc2 5.6 both failed
Description: run bpf: test_btf failed with ""Arg#0 type PTR in
test_long_fname_2() is not supported yet.""
Whole run log and kconfig please see the attatchment.
Error info
```
root@vm-snb-42
/usr/src/perf_selftests-x86_64-rhel-7.6-kselftests-ae83d0b416db002fe95601e7f97f64b59514d936/tools/testing/selftests/bpf#
./test_btf
BTF raw test[1] (struct test #1): OK
BTF raw test[2] (struct test #2): OK
BTF raw test[3] (struct test #3 Invalid member offset): OK
[snip]
BTF libbpf test[1] (test_btf_haskv.o): libbpf: load bpf program failed:
Invalid argument
libbpf: -- BEGIN DUMP LOG ---
libbpf:
Validating test_long_fname_2() func#1...
Arg#0 type PTR in test_long_fname_2() is not supported yet.
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
peak_states 0 mark_read 0
libbpf: -- END LOG --
libbpf: failed to load program 'dummy_tracepoint'
libbpf: failed to load object 'test_btf_haskv.o'
do_test_file:4201:FAIL bpf_object__load: -4007
BTF libbpf test[2] (test_btf_newkv.o): libbpf: load bpf program failed:
Invalid argument
libbpf: -- BEGIN DUMP LOG ---
libbpf:
Validating test_long_fname_2() func#1...
Arg#0 type PTR in test_long_fname_2() is not supported yet.
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
peak_states 0 mark_read 0
libbpf: -- END LOG --
libbpf: failed to load program 'dummy_tracepoint'
libbpf: failed to load object 'test_btf_newkv.o'
do_test_file:4201:FAIL bpf_object__load: -4007
BTF libbpf test[3] (test_btf_nokv.o): libbpf: load bpf program failed:
Invalid argument
libbpf: -- BEGIN DUMP LOG ---
libbpf:
Validating test_long_fname_2() func#1...
Arg#0 type PTR in test_long_fname_2() is not supported yet.
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0
peak_states 0 mark_read 0
libbpf: -- END LOG --
libbpf: failed to load program 'dummy_tracepoint'
libbpf: failed to load object 'test_btf_nokv.o'
do_test_file:4201:FAIL bpf_object__load: -4007
[snip]
```
--
Best Regards.
Ma Xinjian