@@ -5,23 +5,18 @@ package plan9asm
55
66import (
77 "os"
8- "os/exec"
98 "path/filepath"
10- "runtime"
119 "strings"
1210 "testing"
1311)
1412
1513func TestStdlibInternalRuntimeSys_ARM64_Compile (t * testing.T ) {
16- if runtime .GOARCH != "arm64" {
17- t .Skip ("host is not arm64" )
18- }
1914 llc , _ , ok := findLlcAndClang (t )
2015 if ! ok {
2116 t .Skip ("llc not found" )
2217 }
2318
24- goroot := runtime . GOROOT ( )
19+ goroot := testGOROOT ( t )
2520 src , err := os .ReadFile (filepath .Join (goroot , "src" , "internal" , "runtime" , "sys" , "dit_arm64.s" ))
2621 if err != nil {
2722 if os .IsNotExist (err ) {
@@ -61,24 +56,49 @@ func TestStdlibInternalRuntimeSys_ARM64_Compile(t *testing.T) {
6156 },
6257 }
6358 ll , err := Translate (file , Options {
64- TargetTriple : testTargetTriple ( runtime . GOOS , runtime . GOARCH ) ,
59+ TargetTriple : arm64LinuxGNUTriple ,
6560 ResolveSym : resolve ,
6661 Sigs : sigs ,
67- Goarch : runtime . GOARCH ,
62+ Goarch : "arm64" ,
6863 })
6964 if err != nil {
7065 t .Fatal (err )
7166 }
7267
73- tmp := t .TempDir ()
74- llPath := filepath .Join (tmp , "dit.ll" )
75- objPath := filepath .Join (tmp , "dit.o" )
76- if err := os .WriteFile (llPath , []byte (ll ), 0644 ); err != nil {
68+ compileLLVMToObject (t , llc , arm64LinuxGNUTriple , "dit.ll" , "dit.o" , ll )
69+ }
70+
71+ func TestTranslateGoModule_StdlibInternalRuntimeSys_ARM64_Compile (t * testing.T ) {
72+ llc , _ , ok := findLlcAndClang (t )
73+ if ! ok {
74+ t .Skip ("llc not found" )
75+ }
76+
77+ goroot := testGOROOT (t )
78+ src , err := os .ReadFile (filepath .Join (goroot , "src" , "internal" , "runtime" , "sys" , "dit_arm64.s" ))
79+ if err != nil {
80+ if os .IsNotExist (err ) {
81+ t .Skip ("internal/runtime/sys/dit_arm64.s not present in this GOROOT" )
82+ }
7783 t .Fatal (err )
7884 }
79- cmd := exec .Command (llc , "-filetype=obj" , llPath , "-o" , objPath )
80- out , err := cmd .CombinedOutput ()
85+ pkg := mustGoPackage (t , "internal/runtime/sys" , `package sys
86+ func EnableDIT() bool
87+ func DITEnabled() bool
88+ func DisableDIT()
89+ ` )
90+
91+ tr , err := TranslateGoModule (pkg , src , GoModuleOptions {
92+ FileName : "dit_arm64.s" ,
93+ GOOS : "linux" ,
94+ GOARCH : "arm64" ,
95+ TargetTriple : arm64LinuxGNUTriple ,
96+ ResolveSym : testResolveSym ("internal/runtime/sys" ),
97+ })
8198 if err != nil {
82- t .Fatalf ( "llc failed: %v \n %s" , err , string ( out ) )
99+ t .Fatal ( err )
83100 }
101+ defer tr .Module .Dispose ()
102+
103+ compileLLVMToObject (t , llc , arm64LinuxGNUTriple , "dit-gomod.ll" , "dit-gomod.o" , tr .Module .String ())
84104}
0 commit comments