diff --git a/.github/workflows/library_go_tests.yml b/.github/workflows/library_go_tests.yml index d416495b54..8c9a5bf3e3 100644 --- a/.github/workflows/library_go_tests.yml +++ b/.github/workflows/library_go_tests.yml @@ -34,7 +34,12 @@ jobs: # the sys.path workaround for generated Dafny doesn't work on Windows. # Note: only tests use the sys.path workaround, not source code. # Windows source code is tested downstream (ex. ESDK-Python CI). - # windows-latest, + # TODO: clarify the comment above given: + # Go tests should be performed on a + # windows machine because packages in StandardLibrary (Time_) uses + # the syscall package, which does not contain the same functions/types + # across operating systems. + windows-latest, ubuntu-22.04, macos-13, ] diff --git a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs.go b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs.go index b5547d3124..99d985ce91 100644 --- a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs.go +++ b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs.go @@ -1,7 +1,6 @@ package _Time import ( - "syscall" "time" "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers" @@ -35,13 +34,4 @@ func CurrentRelativeTimeMilli() int64 { func (CompanionStruct_Default___) GetProcessCpuTimeMillis() int64 { return GetProcessCpuTimeMillis() -} - -func GetProcessCpuTimeMillis() int64 { - var usage syscall.Rusage - err := syscall.Getrusage(syscall.RUSAGE_SELF, &usage) - if err != nil { - return 0 - } - return (usage.Utime.Nano() + usage.Stime.Nano()) / 1000000 -} +} \ No newline at end of file diff --git a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs_unix.go b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs_unix.go new file mode 100644 index 0000000000..c9be6056bb --- /dev/null +++ b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs_unix.go @@ -0,0 +1,19 @@ +//go:build !windows +// +build !windows + +package _Time + +import ( + "syscall" +) + + + +func GetProcessCpuTimeMillis() int64 { + var usage syscall.Rusage + err := syscall.Getrusage(syscall.RUSAGE_SELF, &usage) + if err != nil { + return 0 + } + return (usage.Utime.Nano() + usage.Stime.Nano()) / 1000000 +} diff --git a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs_windows.go b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs_windows.go new file mode 100644 index 0000000000..201e1a81a0 --- /dev/null +++ b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs_windows.go @@ -0,0 +1,23 @@ +//go:build windows +// +build windows + +package _Time + +import ( + "golang.org/x/sys/windows" +) + + +func GetProcessCpuTimeMillis() int64 { + windows.GetCurrentProcessId() + var proc_handle windows.Handle + var err error + if proc_handle, err = windows.OpenProcess(windows.PROCESS_QUERY_INFORMATION|windows.PROCESS_VM_READ, false, uint32(windows.GetCurrentProcessId())); err != nil { + return 0 + } + var creation_time, exit_time, kernel_time, user_time *windows.Filetime + if err = windows.GetProcessTimes(proc_handle, creation_time, exit_time, kernel_time, user_time); err != nil { + return 0 + } + return (int64(kernel_time.Nanoseconds()) + int64(user_time.Nanoseconds())) / 1000000 +} diff --git a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.mod b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.mod index 7a151ff5de..f5e5cfb506 100644 --- a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.mod +++ b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.mod @@ -1,7 +1,9 @@ module github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library -go 1.23.0 +go 1.24.0 require github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2 require github.com/google/uuid v1.6.0 + +require golang.org/x/sys v0.36.0 // indirect diff --git a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.sum b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.sum index 3640b3bcbb..935db29d2a 100644 --- a/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.sum +++ b/StandardLibrary/runtimes/go/ImplementationFromDafny-go/go.sum @@ -2,3 +2,5 @@ github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2 h1:g/xAj4F7Zt9wXJ6QjfbfocVi/ZYlAF github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2/go.mod h1:l2Tm4N2DKuq3ljONC2vOATeM9PUpXbIc8SgXdwwqEto= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=