Skip to content

Commit

Permalink
testdata: add big-endian binaries
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Leoshkevich <[email protected]>
  • Loading branch information
iii-i committed May 4, 2020
1 parent 364d17d commit 3db7828
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 12 deletions.
7 changes: 5 additions & 2 deletions elf_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ebpf

import (
"flag"
"fmt"
"path/filepath"
"reflect"
"strings"
Expand All @@ -11,7 +12,8 @@ import (
)

func TestLoadCollectionSpec(t *testing.T) {
files, err := filepath.Glob("testdata/loader-*.elf")
pattern := fmt.Sprintf("testdata/loader-*-%s.elf", testutils.GetHostEndianness())
files, err := filepath.Glob(pattern)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -209,7 +211,8 @@ func TestCollectionSpecDetach(t *testing.T) {
}

func TestLoadInvalidMap(t *testing.T) {
_, err := LoadCollectionSpec("testdata/invalid_map.elf")
path := fmt.Sprintf("testdata/invalid_map-%s.elf", testutils.GetHostEndianness())
_, err := LoadCollectionSpec(path)
t.Log(err)
if err == nil {
t.Fatal("should be fail")
Expand Down
2 changes: 1 addition & 1 deletion internal/btf/btf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestParseCurrentKernelBTF(t *testing.T) {
}

func TestLoadSpecFromElf(t *testing.T) {
fh, err := os.Open("../../testdata/loader-clang-9.elf")
fh, err := os.Open(fmt.Sprintf("../../testdata/loader-clang-9-%s.elf", testutils.GetHostEndianness()));
if err != nil {
t.Fatal(err)
}
Expand Down
15 changes: 15 additions & 0 deletions internal/testutils/endianness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testutils

import (
"encoding/binary"

"github.com/cilium/ebpf/internal"
)

func GetHostEndianness() string {
if internal.NativeEndian == binary.LittleEndian {
return "el"
} else {
return "eb"
}
}
21 changes: 12 additions & 9 deletions testdata/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
LLVM_PREFIX ?= /usr/bin
CLANG ?= $(LLVM_PREFIX)/clang
CFLAGS := -target bpf -O2 -g -Wall -Werror $(CFLAGS)

.PHONY: all clean
all: loader-clang-6.0.elf loader-clang-7.elf loader-clang-8.elf loader-clang-9.elf rewrite.elf invalid_map.elf
all: loader-clang-6.0-el.elf loader-clang-7-el.elf loader-clang-8-el.elf loader-clang-9-el.elf rewrite-el.elf invalid_map-el.elf \
loader-clang-6.0-eb.elf loader-clang-7-eb.elf loader-clang-8-eb.elf loader-clang-9-eb.elf rewrite-eb.elf invalid_map-eb.elf

clean:
-$(RM) *.elf

loader-%.elf: loader.c
$* -target bpf -O2 -g \
-Wall -Werror \
-c $< -o $@
loader-%-el.elf: loader.c
$* $(CFLAGS) -mlittle-endian -c $< -o $@

%.elf : %.c
$(CLANG) -target bpf -O2 -g \
-Wall -Werror \
-c $< -o $@
loader-%-eb.elf: loader.c
$* $(CFLAGS) -mbig-endian -c $< -o $@

%-el.elf: %.c
$(CLANG) $(CFLAGS) -mlittle-endian -c $< -o $@

%-eb.elf : %.c
$(CLANG) $(CFLAGS) -mbig-endian -c $< -o $@
Binary file added testdata/invalid_map-eb.elf
Binary file not shown.
File renamed without changes.
Binary file added testdata/loader-clang-6.0-eb.elf
Binary file not shown.
File renamed without changes.
Binary file added testdata/loader-clang-7-eb.elf
Binary file not shown.
File renamed without changes.
Binary file added testdata/loader-clang-8-eb.elf
Binary file not shown.
File renamed without changes.
Binary file added testdata/loader-clang-9-eb.elf
Binary file not shown.
File renamed without changes.
Binary file added testdata/rewrite-eb.elf
Binary file not shown.
File renamed without changes.

0 comments on commit 3db7828

Please sign in to comment.