linux/tools/testing/selftests
Daniel Borkmann 78a5a93c1e bpf, tests: fix endianness selection
I noticed that test_l4lb was failing in selftests:

  # ./test_progs
  test_pkt_access:PASS:ipv4 77 nsec
  test_pkt_access:PASS:ipv6 44 nsec
  test_xdp:PASS:ipv4 2933 nsec
  test_xdp:PASS:ipv6 1500 nsec
  test_l4lb:PASS:ipv4 377 nsec
  test_l4lb:PASS:ipv6 544 nsec
  test_l4lb:FAIL:stats 6297600000 200000
  test_tcp_estats:PASS: 0 nsec
  Summary: 7 PASSED, 1 FAILED

Tracking down the issue actually revealed that endianness selection
in bpf_endian.h is broken when compiled with clang with bpf target.
test_pkt_access.c, test_l4lb.c is compiled with __BYTE_ORDER as
__BIG_ENDIAN, test_xdp.c as __LITTLE_ENDIAN! test_l4lb noticeably
fails, because the test accounts bytes via bpf_ntohs(ip6h->payload_len)
and bpf_ntohs(iph->tot_len), and compares them against a defined
value and given a wrong endianness, the test outcome is different,
of course.

Turns out that there are actually two bugs: i) when we do __BYTE_ORDER
comparison with __LITTLE_ENDIAN/__BIG_ENDIAN, then depending on the
include order we see different outcomes. Reason is that __BYTE_ORDER
is undefined due to missing endian.h include. Before we include the
asm/byteorder.h (e.g. through linux/in.h), then __BYTE_ORDER equals
__LITTLE_ENDIAN since both are undefined, after the include which
correctly pulls in linux/byteorder/little_endian.h, __LITTLE_ENDIAN
is defined, but given __BYTE_ORDER is still undefined, we match on
__BYTE_ORDER equals to __BIG_ENDIAN since __BIG_ENDIAN is also
undefined at that point, sigh. ii) But even that would be wrong,
since when compiling the test cases with clang, one can select between
bpfeb and bpfel targets for cross compilation. Hence, we can also not
rely on what the system's endian.h provides, but we need to look at
the compiler's defined endianness. The compiler defines __BYTE_ORDER__,
and we can match __ORDER_LITTLE_ENDIAN__ and __ORDER_BIG_ENDIAN__,
which also reflects targets bpf (native), bpfel, bpfeb correctly,
thus really only rely on that. After patch:

  # ./test_progs
  test_pkt_access:PASS:ipv4 74 nsec
  test_pkt_access:PASS:ipv6 42 nsec
  test_xdp:PASS:ipv4 2340 nsec
  test_xdp:PASS:ipv6 1461 nsec
  test_l4lb:PASS:ipv4 400 nsec
  test_l4lb:PASS:ipv6 530 nsec
  test_tcp_estats:PASS: 0 nsec
  Summary: 7 PASSED, 0 FAILED

Fixes: 43bcf707cc ("bpf: fix _htons occurences in test_progs")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-08 16:17:29 -04:00
..
bpf bpf, tests: fix endianness selection 2017-06-08 16:17:29 -04:00
breakpoints selftests: breakpoints: allow to cross-compile for aarch64/arm64 2017-04-21 11:25:26 -06:00
capabilities selftests: remove duplicated all and clean target 2017-01-05 13:41:35 -07:00
cpu-hotplug
cpufreq selftests: create cpufreq kconfig fragments 2017-04-27 08:42:18 -06:00
drivers/gpu drm/i915: Provide a hook for selftests 2017-02-13 20:45:21 +00:00
efivarfs selftests: remove duplicated all and clean target 2017-01-05 13:41:35 -07:00
exec selftests: enable O and KBUILD_OUTPUT 2017-01-05 13:42:22 -07:00
filesystems
firmware driver core patches for 4.11-rc1 2017-02-22 11:44:32 -08:00
ftrace selftests/ftrace: Add a testcase for many kprobe events 2017-05-26 22:37:00 -04:00
futex selftests: futex: override clean in lib.mk to fix warnings 2017-04-25 09:47:21 -06:00
gpio selftests: gpio: fix clean target to remove all generated files and dirs 2017-04-25 09:49:50 -06:00
ia64
intel_pstate selftests/intel_pstate: Update makefile to match new style 2017-01-19 10:30:40 -07:00
ipc selftests: ipc add missing generated file to .gitignore 2017-01-11 09:51:03 -07:00
kcmp selftests: enable O and KBUILD_OUTPUT 2017-01-05 13:42:22 -07:00
lib selftests: lib: add config fragment for bitmap, printf and prime numbers tests 2017-04-11 09:37:53 -06:00
locking locking/ww_mutex: Add ww_mutex to tools/testing/selftests 2017-01-14 11:37:17 +01:00
media_tests
membarrier selftests: remove duplicated all and clean target 2017-01-05 13:41:35 -07:00
memfd selftests: remove CROSS_COMPILE in dedicated Makefile 2017-01-05 13:42:11 -07:00
memory-hotplug
mount selftests: add default rules for c source file 2017-01-05 13:42:01 -07:00
mqueue selftests: remove duplicated all and clean target 2017-01-05 13:41:35 -07:00
net selftests/net: Fix broken test case in psock_fanout 2017-04-25 11:56:17 -04:00
networking/timestamping
nsfs selftests: remove duplicated all and clean target 2017-01-05 13:41:35 -07:00
ntb
powerpc selftests/powerpc: Fix TM resched DSCR test with some compilers 2017-05-19 19:46:34 +10:00
prctl
pstore selftests: add EXTRA_CLEAN for clean target 2017-01-05 13:42:17 -07:00
ptp
ptrace selftests: remove duplicated all and clean target 2017-01-05 13:41:35 -07:00
rcutorture torture: Use correct path for Kconfig fragment for duplicates 2017-04-19 09:29:19 -07:00
seccomp selftests: remove duplicated all and clean target 2017-01-05 13:41:35 -07:00
sigaltstack tools/testing/selftests/sigaltstack/sas.c: improve output of sigaltstack testcase 2017-02-27 18:43:45 -08:00
size selftests: add default rules for c source file 2017-01-05 13:42:01 -07:00
splice selftests: splice: override clean in lib.mk to fix warnings 2017-04-27 08:05:04 -06:00
static_keys
sync selftests: sync: override clean in lib.mk to fix warnings 2017-04-27 08:05:14 -06:00
sysctl
timers linux-kselftest-4.12-rc1 2017-05-08 20:43:30 -07:00
user
vDSO
vm linux-kselftest-4.12-rc1 2017-05-08 20:43:30 -07:00
watchdog selftests: watchdog: accept multiple params on command line 2017-05-02 10:48:24 -06:00
x86 linux-kselftest-4.12-rc1 2017-05-08 20:43:30 -07:00
zram selftests: add EXTRA_CLEAN for clean target 2017-01-05 13:42:17 -07:00
.gitignore selftests: add gpio generated files to .gitignore 2017-04-25 09:49:38 -06:00
gen_kselftest_tar.sh
kselftest_install.sh
kselftest.h
lib.mk selftests: lib.mk: define CLEAN macro to allow Makefiles to override clean 2017-04-25 09:46:45 -06:00
Makefile selftests/Makefile: Add missed PHONY targets 2017-04-21 11:24:58 -06:00