9
9
"os"
10
10
"os/exec"
11
11
"path/filepath"
12
+ "runtime"
12
13
"strings"
13
14
"testing"
14
15
@@ -416,6 +417,18 @@ func TestMultipleSourceFiles(t *testing.T) {
416
417
t .Fatal ("No go.mod file in" , modRoot )
417
418
}
418
419
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
+
419
432
dir := t .TempDir ()
420
433
421
434
// Create two source files with different functions
@@ -448,7 +461,7 @@ func TestMultipleSourceFiles(t *testing.T) {
448
461
"-go-package" , "main" ,
449
462
"-output-dir" , modDir ,
450
463
"-cc" , testutils .ClangBin (t ),
451
- "-target" , "bpfel,bpfeb" ,
464
+ "-target" , target ,
452
465
"bar" ,
453
466
filepath .Join (dir , "func1.c" ),
454
467
filepath .Join (dir , "func2.c" ),
@@ -469,25 +482,20 @@ func main() {
469
482
println(obj.Func2)
470
483
}` )
471
484
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 )
491
499
}
492
500
}
493
501
0 commit comments