99 "os"
1010 "os/exec"
1111 "path/filepath"
12+ "runtime"
1213 "strings"
1314 "testing"
1415
@@ -416,6 +417,18 @@ func TestMultipleSourceFiles(t *testing.T) {
416417 t .Fatal ("No go.mod file in" , modRoot )
417418 }
418419
420+ // bpftool appears to support the endianness of the machine it is running on.
421+ //Determine native endianness based on GOARCH
422+ var target string
423+ switch runtime .GOARCH {
424+ case "amd64" , "arm64" , "riscv64" :
425+ target = "bpfel" // little-endian
426+ case "s390x" , "ppc64" :
427+ target = "bpfeb" // big-endian
428+ default :
429+ t .Fatalf ("Unsupported architecture: %s" , runtime .GOARCH )
430+ }
431+
419432 dir := t .TempDir ()
420433
421434 // Create two source files with different functions
@@ -448,7 +461,7 @@ func TestMultipleSourceFiles(t *testing.T) {
448461 "-go-package" , "main" ,
449462 "-output-dir" , modDir ,
450463 "-cc" , testutils .ClangBin (t ),
451- "-target" , "bpfel,bpfeb" ,
464+ "-target" , target ,
452465 "bar" ,
453466 filepath .Join (dir , "func1.c" ),
454467 filepath .Join (dir , "func2.c" ),
@@ -469,25 +482,20 @@ func main() {
469482 println(obj.Func2)
470483}` )
471484
472- // Test compilation for different architectures
473- for _ , arch := range []string {"amd64" , "arm64" , "s390x" } {
474- t .Run (arch , func (t * testing.T ) {
475- goBuild := exec .Command ("go" , "build" , "-mod=mod" , "-o" , "/dev/null" )
476- goBuild .Dir = modDir
477- goBuild .Env = append (os .Environ (),
478- "GOOS=linux" ,
479- "GOARCH=" + arch ,
480- "GOPROXY=off" ,
481- "GOSUMDB=off" ,
482- )
483- out , err := goBuild .CombinedOutput ()
484- if err != nil {
485- if out := string (out ); out != "" {
486- t .Log (out )
487- }
488- t .Error ("Can't compile package:" , err )
489- }
490- })
485+ // Test compilation for the native architecture
486+ goBuild := exec .Command ("go" , "build" , "-mod=mod" , "-o" , "/dev/null" )
487+ goBuild .Dir = modDir
488+ goBuild .Env = append (os .Environ (),
489+ "GOOS=linux" ,
490+ "GOPROXY=off" ,
491+ "GOSUMDB=off" ,
492+ )
493+ out , err := goBuild .CombinedOutput ()
494+ if err != nil {
495+ if out := string (out ); out != "" {
496+ t .Log (out )
497+ }
498+ t .Error ("Can't compile package:" , err )
491499 }
492500}
493501
0 commit comments