Skip to content

Commit

Permalink
all: add rest of wasip1 files
Browse files Browse the repository at this point in the history
Add debug/elf, go/types, io/ioutil, log/syslog, mime, path/filepath,
testing and time package changes for wasip1.

Fixes golang#58141

Co-authored-by: Richard Musiol <[email protected]>
Co-authored-by: Achille Roussel <[email protected]>
Co-authored-by: Julien Fabre <[email protected]>
Co-authored-by: Evan Phoenix <[email protected]>
Change-Id: I49b66946acc90fdf09ed9223096bfec9a1e5b923
  • Loading branch information
5 people committed Apr 3, 2023
1 parent 75c1d2c commit eb155b4
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/debug/elf/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func TestCompressedSection(t *testing.T) {
func TestNoSectionOverlaps(t *testing.T) {
// Ensure cmd/link outputs sections without overlaps.
switch runtime.GOOS {
case "aix", "android", "darwin", "ios", "js", "plan9", "windows":
case "aix", "android", "darwin", "ios", "js", "plan9", "windows", "wasip1":
t.Skipf("cmd/link doesn't produce ELF binaries on %s", runtime.GOOS)
}
_ = net.ResolveIPAddr // force dynamic linkage
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Only run where builders (build.golang.org) have
// access to compiled packages for import.
//
//go:build !android && !ios && !js
//go:build !android && !ios && !js && !wasip1

package types_test

Expand Down
4 changes: 4 additions & 0 deletions src/io/ioutil/ioutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
. "io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
)

Expand Down Expand Up @@ -70,6 +71,9 @@ func TestReadOnlyWriteFile(t *testing.T) {
if os.Getuid() == 0 {
t.Skipf("Root can write to read-only files anyway, so skip the read-only test.")
}
if runtime.GOOS == "wasip1" {
t.Skip("file permissions are not supported by wasip1")
}

// We don't want to use TempFile directly, since that opens a file for us as 0600.
tempDir, err := TempDir("", t.Name())
Expand Down
2 changes: 1 addition & 1 deletion src/log/syslog/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !windows && !plan9 && !js
//go:build !windows && !plan9 && !js && !wasip1

package syslog

Expand Down
2 changes: 1 addition & 1 deletion src/mime/type_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm)
//go:build unix || (js && wasm) || (wasip1 && wasm)

package mime

Expand Down
4 changes: 2 additions & 2 deletions src/path/filepath/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ func testWalk(t *testing.T, walk func(string, fs.WalkDirFunc) error, errVisit in
// Test permission errors. Only possible if we're not root
// and only on some file systems (AFS, FAT). To avoid errors during
// all.bash on those file systems, skip during go test -short.
if runtime.GOOS == "windows" {
t.Skip("skipping on Windows")
if runtime.GOOS == "windows" || runtime.GOOS == "wasip1" {
t.Skip("skipping on " + runtime.GOOS)
}
if os.Getuid() == 0 {
t.Skip("skipping as root")
Expand Down
2 changes: 1 addition & 1 deletion src/path/filepath/path_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm)
//go:build unix || (js && wasm) || (wasip1 && wasm)

package filepath

Expand Down
2 changes: 1 addition & 1 deletion src/testing/run_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

// TODO(@musiol, @odeke-em): re-unify this entire file back into
// example.go when js/wasm gets an os.Pipe implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build js
//go:build js || wasip1

package testing

Expand Down
13 changes: 13 additions & 0 deletions src/time/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package time

import "runtime"

func init() {
// Force US/Pacific for time zone tests.
ForceUSPacificForTesting()
Expand Down Expand Up @@ -36,6 +38,17 @@ func disablePlatformSources() (undo func()) {
var Interrupt = interrupt
var DaysIn = daysIn

func init() {
if runtime.GOOS == "wasip1" {
// There is no mechanism in wasi to interrupt the call to poll_oneoff
// used to implement runtime.usleep so this function does nothing, which
// somewhat defeats the purpose of TestSleep but we are still better off
// validating that time elapses when the process calls time.Sleep than
// skipping the test altogether.
Interrupt = func() {}
}
}

func empty(arg any, seq uintptr) {}

// Test that a runtimeTimer with a period that would overflow when on
Expand Down
2 changes: 1 addition & 1 deletion src/time/sys_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm)
//go:build unix || (js && wasm) || (wasip1 && wasm)

package time

Expand Down
14 changes: 14 additions & 0 deletions src/time/zoneinfo_wasip1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build wasip1 && wasm

package time

// in wasip1 zoneinfo is managed by the runtime.
var platformZoneSources = []string{}

func initLocal() {
localLoc.name = "Local"
}
42 changes: 21 additions & 21 deletions test/codegen/comparisons.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,30 +268,30 @@ func CmpToZero(a, b, d int32, e, f int64, deOptC0, deOptC1 bool) int32 {
func CmpLogicalToZero(a, b, c uint32, d, e uint64) uint64 {

// ppc64x:"ANDCC",-"CMPW"
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
// js/wasm/:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
if a&63 == 0 {
return 1
}

// ppc64x:"ANDCC",-"CMP"
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
// js/wasm/:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
if d&255 == 0 {
return 1
}

// ppc64x:"ANDCC",-"CMP"
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
// js/wasm/:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
if d&e == 0 {
return 1
}
// ppc64x:"ORCC",-"CMP"
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
// js/wasm/:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
if d|e == 0 {
return 1
}

// ppc64x:"XORCC",-"CMP"
// wasm:"I64Eqz","I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
// js/wasm/:"I64Eqz","I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
if e^d == 0 {
return 1
}
Expand Down Expand Up @@ -508,79 +508,79 @@ func UintGeqOne(a uint8, b uint16, c uint32, d uint64) int {
}

func CmpToZeroU_ex1(a uint8, b uint16, c uint32, d uint64) int {
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if 0 < a {
return 1
}
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if 0 < b {
return 1
}
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if 0 < c {
return 1
}
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if 0 < d {
return 1
}
return 0
}

func CmpToZeroU_ex2(a uint8, b uint16, c uint32, d uint64) int {
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if a <= 0 {
return 1
}
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if b <= 0 {
return 1
}
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if c <= 0 {
return 1
}
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if d <= 0 {
return 1
}
return 0
}

func CmpToOneU_ex1(a uint8, b uint16, c uint32, d uint64) int {
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if a < 1 {
return 1
}
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if b < 1 {
return 1
}
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if c < 1 {
return 1
}
// wasm:"I64Eqz"-"I64LtU"
// js/wasm/:"I64Eqz"-"I64LtU"
if d < 1 {
return 1
}
return 0
}

func CmpToOneU_ex2(a uint8, b uint16, c uint32, d uint64) int {
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if 1 <= a {
return 1
}
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if 1 <= b {
return 1
}
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if 1 <= c {
return 1
}
// wasm:"I64Eqz"-"I64LeU"
// js/wasm/:"I64Eqz"-"I64LeU"
if 1 <= d {
return 1
}
Expand Down
22 changes: 11 additions & 11 deletions test/codegen/condmove.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func cmovint(c int) int {
// amd64:"CMOVQLT"
// arm64:"CSEL\tLT"
// ppc64x:"ISEL\t[$]0"
// wasm:"Select"
// js/wasm/:"Select"
return x
}

Expand All @@ -25,7 +25,7 @@ func cmovchan(x, y chan int) chan int {
// amd64:"CMOVQNE"
// arm64:"CSEL\tNE"
// ppc64x:"ISEL\t[$]2"
// wasm:"Select"
// js/wasm/:"Select"
return x
}

Expand All @@ -36,7 +36,7 @@ func cmovuintptr(x, y uintptr) uintptr {
// amd64:"CMOVQ(HI|CS)"
// arm64:"CSNEG\tLS"
// ppc64x:"ISEL\t[$]1"
// wasm:"Select"
// js/wasm/:"Select"
return x
}

Expand All @@ -47,7 +47,7 @@ func cmov32bit(x, y uint32) uint32 {
// amd64:"CMOVL(HI|CS)"
// arm64:"CSNEG\t(LS|HS)"
// ppc64x:"ISEL\t[$]1"
// wasm:"Select"
// js/wasm/:"Select"
return x
}

Expand All @@ -58,7 +58,7 @@ func cmov16bit(x, y uint16) uint16 {
// amd64:"CMOVW(HI|CS)"
// arm64:"CSNEG\t(LS|HS)"
// ppc64x:"ISEL\t[$]0"
// wasm:"Select"
// js/wasm/:"Select"
return x
}

Expand All @@ -72,7 +72,7 @@ func cmovfloateq(x, y float64) int {
// amd64:"CMOVQNE","CMOVQPC"
// arm64:"CSEL\tEQ"
// ppc64x:"ISEL\t[$]2"
// wasm:"Select"
// js/wasm/:"Select"
return a
}

Expand All @@ -84,7 +84,7 @@ func cmovfloatne(x, y float64) int {
// amd64:"CMOVQNE","CMOVQPS"
// arm64:"CSEL\tNE"
// ppc64x:"ISEL\t[$]2"
// wasm:"Select"
// js/wasm/:"Select"
return a
}

Expand All @@ -111,7 +111,7 @@ func cmovfloatint2(x, y float64) float64 {
// amd64:"CMOVQHI"
// arm64:"CSEL\tMI"
// ppc64x:"ISEL\t[$]0"
// wasm:"Select"
// js/wasm/:"Select"
r = r - ldexp(y, rexp-yexp)
}
return r
Expand All @@ -126,7 +126,7 @@ func cmovloaded(x [4]int, y int) int {
// amd64:"CMOVQNE"
// arm64:"CSEL\tNE"
// ppc64x:"ISEL\t[$]2"
// wasm:"Select"
// js/wasm/:"Select"
return y
}

Expand All @@ -138,7 +138,7 @@ func cmovuintptr2(x, y uintptr) uintptr {
// amd64:"CMOVQEQ"
// arm64:"CSEL\tEQ"
// ppc64x:"ISEL\t[$]2"
// wasm:"Select"
// js/wasm/:"Select"
return a
}

Expand All @@ -151,7 +151,7 @@ func cmovfloatmove(x, y int) float64 {
// amd64:-"CMOV"
// arm64:-"CSEL"
// ppc64x:-"ISEL"
// wasm:-"Select"
// js/wasm/:-"Select"
return a
}

Expand Down
Loading

0 comments on commit eb155b4

Please sign in to comment.