mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| feac8ca0f9 |
+8
-10
@@ -92,20 +92,16 @@ commands:
|
|||||||
- /go/pkg/mod
|
- /go/pkg/mod
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-oldest:
|
test-llvm15-go122:
|
||||||
# This tests our lowest supported versions of Go and LLVM, to make sure at
|
|
||||||
# least the smoke tests still pass.
|
|
||||||
docker:
|
docker:
|
||||||
- image: golang:1.22-bullseye
|
- image: golang:1.22-bullseye
|
||||||
steps:
|
steps:
|
||||||
- test-linux:
|
- test-linux:
|
||||||
llvm: "15"
|
llvm: "15"
|
||||||
resource_class: large
|
resource_class: large
|
||||||
test-newest:
|
test-llvm20-go124:
|
||||||
# This tests the latest supported LLVM version when linking against system
|
|
||||||
# libraries.
|
|
||||||
docker:
|
docker:
|
||||||
- image: golang:1.25-bullseye
|
- image: golang:1.24-bullseye
|
||||||
steps:
|
steps:
|
||||||
- test-linux:
|
- test-linux:
|
||||||
llvm: "20"
|
llvm: "20"
|
||||||
@@ -114,6 +110,8 @@ jobs:
|
|||||||
workflows:
|
workflows:
|
||||||
test-all:
|
test-all:
|
||||||
jobs:
|
jobs:
|
||||||
- test-oldest
|
# This tests our lowest supported versions of Go and LLVM, to make sure at
|
||||||
# disable this test, since CircleCI seems unable to download due to rate-limits on Dockerhub.
|
# least the smoke tests still pass.
|
||||||
# - test-newest
|
- test-llvm15-go122
|
||||||
|
# This tests LLVM 20 support when linking against system libraries.
|
||||||
|
- test-llvm20-go124
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
HOMEBREW_NO_AUTO_UPDATE=1 brew install qemu binaryen
|
HOMEBREW_NO_AUTO_UPDATE=1 brew install qemu binaryen
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- name: Extract TinyGo version
|
- name: Extract TinyGo version
|
||||||
id: version
|
id: version
|
||||||
run: ./.github/workflows/tinygo-extract-version.sh | tee -a "$GITHUB_OUTPUT"
|
run: ./.github/workflows/tinygo-extract-version.sh | tee -a "$GITHUB_OUTPUT"
|
||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v6
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.1'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Restore LLVM source cache
|
- name: Restore LLVM source cache
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
@@ -79,7 +79,7 @@ jobs:
|
|||||||
rm -rf llvm-project
|
rm -rf llvm-project
|
||||||
make llvm-source
|
make llvm-source
|
||||||
# install dependencies
|
# install dependencies
|
||||||
HOMEBREW_NO_AUTO_UPDATE=1 brew install ninja
|
HOMEBREW_NO_AUTO_UPDATE=1 brew install cmake ninja
|
||||||
# build!
|
# build!
|
||||||
make llvm-build
|
make llvm-build
|
||||||
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
|
find llvm-build -name CMakeFiles -prune -exec rm -r '{}' \;
|
||||||
@@ -130,11 +130,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
brew install llvm@${{ matrix.version }}
|
brew install llvm@${{ matrix.version }}
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v4
|
||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v6
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.1'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Build TinyGo (LLVM ${{ matrix.version }})
|
- name: Build TinyGo (LLVM ${{ matrix.version }})
|
||||||
run: go install -tags=llvm${{ matrix.version }}
|
run: go install -tags=llvm${{ matrix.version }}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ jobs:
|
|||||||
# statically linked binary.
|
# statically linked binary.
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: golang:1.25-alpine
|
image: golang:1.24-alpine
|
||||||
outputs:
|
outputs:
|
||||||
version: ${{ steps.version.outputs.version }}
|
version: ${{ steps.version.outputs.version }}
|
||||||
steps:
|
steps:
|
||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
# tar: needed for actions/cache@v4
|
# tar: needed for actions/cache@v4
|
||||||
# git+openssh: needed for checkout (I think?)
|
# git+openssh: needed for checkout (I think?)
|
||||||
# ruby: needed to install fpm
|
# ruby: needed to install fpm
|
||||||
run: apk add tar git openssh make g++ ruby-dev mold
|
run: apk add tar git openssh make g++ ruby-dev
|
||||||
- name: Work around CVE-2022-24765
|
- name: Work around CVE-2022-24765
|
||||||
# We're not on a multi-user machine, so this is safe.
|
# We're not on a multi-user machine, so this is safe.
|
||||||
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||||
@@ -73,7 +73,7 @@ jobs:
|
|||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
id: cache-llvm-build
|
id: cache-llvm-build
|
||||||
with:
|
with:
|
||||||
key: llvm-build-20-linux-alpine-v1
|
key: llvm-build-20-linux-alpine-v2
|
||||||
path: llvm-build
|
path: llvm-build
|
||||||
- name: Build LLVM
|
- name: Build LLVM
|
||||||
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
|
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
|
||||||
@@ -137,7 +137,7 @@ jobs:
|
|||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.0'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Install wasmtime
|
- name: Install wasmtime
|
||||||
uses: bytecodealliance/actions/wasmtime/setup@v1
|
uses: bytecodealliance/actions/wasmtime/setup@v1
|
||||||
@@ -181,7 +181,7 @@ jobs:
|
|||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.0'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Install Node.js
|
- name: Install Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
@@ -222,7 +222,7 @@ jobs:
|
|||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
id: cache-llvm-build
|
id: cache-llvm-build
|
||||||
with:
|
with:
|
||||||
key: llvm-build-20-linux-asserts-v1
|
key: llvm-build-20-linux-asserts-v2
|
||||||
path: llvm-build
|
path: llvm-build
|
||||||
- name: Build LLVM
|
- name: Build LLVM
|
||||||
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
|
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
|
||||||
@@ -298,7 +298,7 @@ jobs:
|
|||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.0'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Restore LLVM source cache
|
- name: Restore LLVM source cache
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
@@ -329,7 +329,7 @@ jobs:
|
|||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
id: cache-llvm-build
|
id: cache-llvm-build
|
||||||
with:
|
with:
|
||||||
key: llvm-build-20-linux-${{ matrix.goarch }}-v1
|
key: llvm-build-20-linux-${{ matrix.goarch }}-v4
|
||||||
path: llvm-build
|
path: llvm-build
|
||||||
- name: Build LLVM
|
- name: Build LLVM
|
||||||
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
|
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ jobs:
|
|||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.0'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Restore cached LLVM source
|
- name: Restore cached LLVM source
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
@@ -147,7 +147,7 @@ jobs:
|
|||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.0'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Download TinyGo build
|
- name: Download TinyGo build
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
@@ -177,7 +177,7 @@ jobs:
|
|||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.0'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Download TinyGo build
|
- name: Download TinyGo build
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
@@ -213,7 +213,7 @@ jobs:
|
|||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.0'
|
go-version: '1.24'
|
||||||
cache: true
|
cache: true
|
||||||
- name: Download TinyGo build
|
- name: Download TinyGo build
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@
|
|||||||
url = https://github.com/tinygo-org/stm32-svd
|
url = https://github.com/tinygo-org/stm32-svd
|
||||||
[submodule "lib/musl"]
|
[submodule "lib/musl"]
|
||||||
path = lib/musl
|
path = lib/musl
|
||||||
url = https://github.com/tinygo-org/musl-libc.git
|
url = git://git.musl-libc.org/musl
|
||||||
[submodule "lib/binaryen"]
|
[submodule "lib/binaryen"]
|
||||||
path = lib/binaryen
|
path = lib/binaryen
|
||||||
url = https://github.com/WebAssembly/binaryen.git
|
url = https://github.com/WebAssembly/binaryen.git
|
||||||
|
|||||||
@@ -1,55 +1,3 @@
|
|||||||
0.39.0
|
|
||||||
---
|
|
||||||
* **general**
|
|
||||||
- all: add Go 1.25 support
|
|
||||||
- net: update to latest tinygo net package
|
|
||||||
- docs: clarify build verification step for macOS users
|
|
||||||
- Add flag to skip Renesas SVD builds
|
|
||||||
* **build**
|
|
||||||
- Makefile: install missing dlmalloc files
|
|
||||||
- flash: add -o flag support to save built binary (Fixes #4937) (#4942)
|
|
||||||
- fix: update version of clang to 17 to accommodate latest Go 1.25 docker base image
|
|
||||||
* **ci**
|
|
||||||
- chore: update all CI builds to test Go 1.25 release
|
|
||||||
- fix: disable test-newest since CircleCI seems unable to download due to rate-limits on Dockerhub
|
|
||||||
- ci: rename some jobs to avoid churn on every Go/LLVM version bump
|
|
||||||
- ci: make the goroutines test less racy
|
|
||||||
- tests: de-flake goroutines test
|
|
||||||
* **compiler**
|
|
||||||
- compiler: implement internal/abi.Escape
|
|
||||||
* **main**
|
|
||||||
- main: show the compiler error (if any) for `tinygo test -c`
|
|
||||||
- chore: correct GOOS=js name in error messages for WASM
|
|
||||||
* **machine**
|
|
||||||
- machine: add international keys
|
|
||||||
- machine: remove some unnecessary "// peripherals:" comments
|
|
||||||
- machine: add I2C pin comments
|
|
||||||
- machine: standardize I2C errors with "i2c:" prefix
|
|
||||||
- machine: make I2C usable in the simulator
|
|
||||||
- fix: add SPI and I2C to teensy 4.1 (#4943)
|
|
||||||
- `rp2`: use the correct channel mask for rp2350 ADC; hold lock during read (#4938)
|
|
||||||
- `rp2`: disable digital input for analog inputs
|
|
||||||
* **runtime**
|
|
||||||
- runtime: ensure time.Sleep(d) sleeps at least d
|
|
||||||
- runtime: stub out weak pointer support
|
|
||||||
- runtime: implement dummy AddCleanup
|
|
||||||
- runtime: enable multi-core scheduler for rp2350
|
|
||||||
- `internal/task`: use -stack-size flag when starting a new thread
|
|
||||||
- `internal/task`: add SA_RESTART flag to GC interrupts
|
|
||||||
- `internal/task`: a few small correctness fixes
|
|
||||||
- `internal/gclayout`: make gclayout values constants
|
|
||||||
- darwin: add threading support and use it by default
|
|
||||||
* **standard library**
|
|
||||||
- `sync`: implement sync.Swap
|
|
||||||
- `reflect`: implement Method.IsExported
|
|
||||||
* **testing**
|
|
||||||
- testing: stub out testing.B.Loop
|
|
||||||
* **targets**
|
|
||||||
- `stm32`: add support for the STM32L031G6U6
|
|
||||||
- add metro-rp2350 board definition (#4989)
|
|
||||||
- `rp2040/rp2350`: set the default stack size to 8k for rp2040/rp2350 based boards where this was not already the case
|
|
||||||
|
|
||||||
|
|
||||||
0.38.0
|
0.38.0
|
||||||
---
|
---
|
||||||
* **general**
|
* **general**
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
# tinygo-llvm stage obtains the llvm source for TinyGo
|
# tinygo-llvm stage obtains the llvm source for TinyGo
|
||||||
FROM golang:1.25 AS tinygo-llvm
|
FROM golang:1.24 AS tinygo-llvm
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y apt-utils make cmake clang-17 ninja-build && \
|
apt-get install -y apt-utils make cmake clang-15 ninja-build && \
|
||||||
rm -rf \
|
rm -rf \
|
||||||
/var/lib/apt/lists/* \
|
/var/lib/apt/lists/* \
|
||||||
/var/log/* \
|
/var/log/* \
|
||||||
@@ -33,7 +33,7 @@ RUN cd /tinygo/ && \
|
|||||||
|
|
||||||
# tinygo-compiler copies the compiler build over to a base Go container (without
|
# tinygo-compiler copies the compiler build over to a base Go container (without
|
||||||
# all the build tools etc).
|
# all the build tools etc).
|
||||||
FROM golang:1.25 AS tinygo-compiler
|
FROM golang:1.24 AS tinygo-compiler
|
||||||
|
|
||||||
# Copy tinygo build.
|
# Copy tinygo build.
|
||||||
COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo
|
COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo
|
||||||
|
|||||||
+12
-43
@@ -79,26 +79,6 @@ ifeq (1, $(STATIC))
|
|||||||
BINARYEN_OPTION += -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static"
|
BINARYEN_OPTION += -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Optimize the binary size for Linux.
|
|
||||||
# These flags may work on other platforms, but have only been tested on Linux.
|
|
||||||
ifeq ($(uname),Linux)
|
|
||||||
HAS_MOLD := $(shell command -v ld.mold 2> /dev/null)
|
|
||||||
HAS_LLD := $(shell command -v ld.lld 2> /dev/null)
|
|
||||||
LLVM_CFLAGS := -ffunction-sections -fdata-sections -fvisibility=hidden
|
|
||||||
LLVM_LDFLAGS := -Wl,--gc-sections
|
|
||||||
ifneq ($(HAS_MOLD),)
|
|
||||||
# Mold might be slightly faster.
|
|
||||||
LLVM_LDFLAGS += -fuse-ld=mold -Wl,--icf=all
|
|
||||||
else ifneq ($(HAS_LLD),)
|
|
||||||
# LLD is more commonly available.
|
|
||||||
LLVM_LDFLAGS += -fuse-ld=lld -Wl,--icf=all
|
|
||||||
endif
|
|
||||||
LLVM_OPTION += \
|
|
||||||
-DCMAKE_C_FLAGS="$(LLVM_CFLAGS)" \
|
|
||||||
-DCMAKE_CXX_FLAGS="$(LLVM_CFLAGS)"
|
|
||||||
CGO_LDFLAGS += $(LLVM_LDFLAGS)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Cross compiling support.
|
# Cross compiling support.
|
||||||
ifneq ($(CROSS),)
|
ifneq ($(CROSS),)
|
||||||
CC = $(CROSS)-gcc
|
CC = $(CROSS)-gcc
|
||||||
@@ -363,6 +343,7 @@ TEST_PACKAGES_FAST = \
|
|||||||
path \
|
path \
|
||||||
reflect \
|
reflect \
|
||||||
sync \
|
sync \
|
||||||
|
testing \
|
||||||
testing/iotest \
|
testing/iotest \
|
||||||
text/scanner \
|
text/scanner \
|
||||||
unicode \
|
unicode \
|
||||||
@@ -479,15 +460,11 @@ TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_WINDOWS)
|
|||||||
TEST_IOFS := false
|
TEST_IOFS := false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic|^Fuzz'
|
|
||||||
|
|
||||||
# Test known-working standard library packages.
|
# Test known-working standard library packages.
|
||||||
# TODO: parallelize, and only show failing tests (no implied -v flag).
|
# TODO: parallelize, and only show failing tests (no implied -v flag).
|
||||||
.PHONY: tinygo-test
|
.PHONY: tinygo-test
|
||||||
tinygo-test:
|
tinygo-test:
|
||||||
@# TestExtraMethods: used by many crypto packages and uses reflect.Type.Method which is not implemented.
|
$(TINYGO) test $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
|
||||||
@# TestParseAndBytesRoundTrip/P256/Generic: relies on t.Skip() which is not implemented
|
|
||||||
$(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
|
|
||||||
@# io/fs requires os.ReadDir, not yet supported on windows or wasi. It also
|
@# io/fs requires os.ReadDir, not yet supported on windows or wasi. It also
|
||||||
@# requires a large stack-size. Hence, io/fs is only run conditionally.
|
@# requires a large stack-size. Hence, io/fs is only run conditionally.
|
||||||
@# For more details, see the comments on issue #3143.
|
@# For more details, see the comments on issue #3143.
|
||||||
@@ -495,7 +472,7 @@ ifeq ($(TEST_IOFS),true)
|
|||||||
$(TINYGO) test -stack-size=6MB io/fs
|
$(TINYGO) test -stack-size=6MB io/fs
|
||||||
endif
|
endif
|
||||||
tinygo-test-fast:
|
tinygo-test-fast:
|
||||||
$(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_HOST)
|
$(TINYGO) test $(TEST_PACKAGES_HOST)
|
||||||
tinygo-bench:
|
tinygo-bench:
|
||||||
$(TINYGO) test -bench . $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
|
$(TINYGO) test -bench . $(TEST_PACKAGES_HOST) $(TEST_PACKAGES_SLOW)
|
||||||
tinygo-bench-fast:
|
tinygo-bench-fast:
|
||||||
@@ -503,18 +480,18 @@ tinygo-bench-fast:
|
|||||||
|
|
||||||
# Same thing, except for wasi rather than the current platform.
|
# Same thing, except for wasi rather than the current platform.
|
||||||
tinygo-test-wasm:
|
tinygo-test-wasm:
|
||||||
$(TINYGO) test -target wasm $(TEST_SKIP_FLAG) $(TEST_PACKAGES_WASM)
|
$(TINYGO) test -target wasm $(TEST_PACKAGES_WASM)
|
||||||
tinygo-test-wasi:
|
tinygo-test-wasi:
|
||||||
$(TINYGO) test -target wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
|
$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
|
||||||
tinygo-test-wasip1:
|
tinygo-test-wasip1:
|
||||||
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
|
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
|
||||||
tinygo-test-wasip1-fast:
|
tinygo-test-wasip1-fast:
|
||||||
$(TINYGO) test -target=wasip1 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
|
$(TINYGO) test -target=wasip1 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
|
||||||
|
|
||||||
tinygo-test-wasip2-slow:
|
tinygo-test-wasip2-slow:
|
||||||
$(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_SLOW)
|
$(TINYGO) test -target=wasip2 $(TEST_PACKAGES_SLOW)
|
||||||
tinygo-test-wasip2-fast:
|
tinygo-test-wasip2-fast:
|
||||||
$(TINYGO) test -target=wasip2 $(TEST_SKIP_FLAG) $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
|
$(TINYGO) test -target=wasip2 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
|
||||||
|
|
||||||
tinygo-test-wasip2-sum-slow:
|
tinygo-test-wasip2-sum-slow:
|
||||||
TINYGO=$(TINYGO) \
|
TINYGO=$(TINYGO) \
|
||||||
@@ -540,7 +517,7 @@ tinygo-bench-wasip2-fast:
|
|||||||
|
|
||||||
# Run tests on riscv-qemu since that one provides a large amount of memory.
|
# Run tests on riscv-qemu since that one provides a large amount of memory.
|
||||||
tinygo-test-baremetal:
|
tinygo-test-baremetal:
|
||||||
$(TINYGO) test -target riscv-qemu $(TEST_SKIP_FLAG) $(TEST_PACKAGES_BAREMETAL)
|
$(TINYGO) test -target riscv-qemu $(TEST_PACKAGES_BAREMETAL)
|
||||||
|
|
||||||
# Test external packages in a large corpus.
|
# Test external packages in a large corpus.
|
||||||
test-corpus:
|
test-corpus:
|
||||||
@@ -794,8 +771,6 @@ endif
|
|||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=gopher-badge examples/blinky1
|
$(TINYGO) build -size short -o test.hex -target=gopher-badge examples/blinky1
|
||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=gopher-arcade examples/blinky1
|
|
||||||
@$(MD5SUM) test.hex
|
|
||||||
$(TINYGO) build -size short -o test.hex -target=ae-rp2040 examples/echo
|
$(TINYGO) build -size short -o test.hex -target=ae-rp2040 examples/echo
|
||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=thumby examples/echo
|
$(TINYGO) build -size short -o test.hex -target=thumby examples/echo
|
||||||
@@ -806,8 +781,6 @@ endif
|
|||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=pico-plus2 examples/blinky1
|
$(TINYGO) build -size short -o test.hex -target=pico-plus2 examples/blinky1
|
||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=metro-rp2350 examples/blinky1
|
|
||||||
@$(MD5SUM) test.hex
|
|
||||||
$(TINYGO) build -size short -o test.hex -target=waveshare-rp2040-tiny examples/echo
|
$(TINYGO) build -size short -o test.hex -target=waveshare-rp2040-tiny examples/echo
|
||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
# test pwm
|
# test pwm
|
||||||
@@ -972,7 +945,7 @@ endif
|
|||||||
|
|
||||||
|
|
||||||
wasmtest:
|
wasmtest:
|
||||||
cd ./tests/wasm && $(GO) test .
|
$(GO) test ./tests/wasm
|
||||||
|
|
||||||
build/release: tinygo gen-device $(if $(filter 1,$(USE_SYSTEM_BINARYEN)),,binaryen)
|
build/release: tinygo gen-device $(if $(filter 1,$(USE_SYSTEM_BINARYEN)),,binaryen)
|
||||||
@mkdir -p build/release/tinygo/bin
|
@mkdir -p build/release/tinygo/bin
|
||||||
@@ -1119,7 +1092,6 @@ endif
|
|||||||
tools:
|
tools:
|
||||||
cd internal/tools && go generate -tags tools ./
|
cd internal/tools && go generate -tags tools ./
|
||||||
|
|
||||||
LINTDIRS=src/os/ src/reflect/
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: tools ## Lint source tree
|
lint: tools ## Lint source tree
|
||||||
revive -version
|
revive -version
|
||||||
@@ -1127,10 +1099,7 @@ lint: tools ## Lint source tree
|
|||||||
# revive.toml isn't flexible enough to filter out just one kind of error from a checker, so do it with grep here.
|
# revive.toml isn't flexible enough to filter out just one kind of error from a checker, so do it with grep here.
|
||||||
# Can't use grep with friendly formatter. Plain output isn't too bad, though.
|
# Can't use grep with friendly formatter. Plain output isn't too bad, though.
|
||||||
# Use 'grep .' to get rid of stray blank line
|
# Use 'grep .' to get rid of stray blank line
|
||||||
revive -config revive.toml compiler/... $$( find $(LINTDIRS) -type f -name '*.go' ) \
|
revive -config revive.toml compiler/... src/{os,reflect}/*.go | grep -v "should have comment or be unexported" | grep '.' | awk '{print}; END {exit NR>0}'
|
||||||
| grep -v "should have comment or be unexported" \
|
|
||||||
| grep '.' \
|
|
||||||
| awk '{print}; END {exit NR>0}'
|
|
||||||
|
|
||||||
SPELLDIRSCMD=find . -depth 1 -type d | egrep -wv '.git|lib|llvm|src'; find src -depth 1 | egrep -wv 'device|internal|net|vendor'; find src/internal -depth 1 -type d | egrep -wv src/internal/wasi
|
SPELLDIRSCMD=find . -depth 1 -type d | egrep -wv '.git|lib|llvm|src'; find src -depth 1 | egrep -wv 'device|internal|net|vendor'; find src/internal -depth 1 -type d | egrep -wv src/internal/wasi
|
||||||
.PHONY: spell
|
.PHONY: spell
|
||||||
|
|||||||
+3
-6
@@ -30,10 +30,7 @@ var BoehmGC = Library{
|
|||||||
// Use a minimal environment.
|
// Use a minimal environment.
|
||||||
"-DNO_MSGBOX_ON_ERROR", // don't call MessageBoxA on Windows
|
"-DNO_MSGBOX_ON_ERROR", // don't call MessageBoxA on Windows
|
||||||
"-DDONT_USE_ATEXIT",
|
"-DDONT_USE_ATEXIT",
|
||||||
"-DNO_GETENV", // smaller binary, more predictable configuration
|
"-DNO_GETENV",
|
||||||
"-DNO_CLOCK", // don't use system clock
|
|
||||||
"-DNO_DEBUGGING", // reduce code size
|
|
||||||
"-DGC_NO_FINALIZATION", // finalization is not used at the moment
|
|
||||||
|
|
||||||
// Special flag to work around the lack of __data_start in ld.lld.
|
// Special flag to work around the lack of __data_start in ld.lld.
|
||||||
// TODO: try to fix this in LLVM/lld directly so we don't have to
|
// TODO: try to fix this in LLVM/lld directly so we don't have to
|
||||||
@@ -42,8 +39,6 @@ var BoehmGC = Library{
|
|||||||
|
|
||||||
// Do not scan the stack. We have our own mechanism to do this.
|
// Do not scan the stack. We have our own mechanism to do this.
|
||||||
"-DSTACK_NOT_SCANNED",
|
"-DSTACK_NOT_SCANNED",
|
||||||
"-DNO_PROC_STAT", // we scan the stack manually (don't read /proc/self/stat on Linux)
|
|
||||||
"-DSTACKBOTTOM=0", // dummy value, we scan the stack manually
|
|
||||||
|
|
||||||
// Assertions can be enabled while debugging GC issues.
|
// Assertions can be enabled while debugging GC issues.
|
||||||
//"-DGC_ASSERTIONS",
|
//"-DGC_ASSERTIONS",
|
||||||
@@ -68,6 +63,7 @@ var BoehmGC = Library{
|
|||||||
"blacklst.c",
|
"blacklst.c",
|
||||||
"dbg_mlc.c",
|
"dbg_mlc.c",
|
||||||
"dyn_load.c",
|
"dyn_load.c",
|
||||||
|
"finalize.c",
|
||||||
"headers.c",
|
"headers.c",
|
||||||
"mach_dep.c",
|
"mach_dep.c",
|
||||||
"malloc.c",
|
"malloc.c",
|
||||||
@@ -75,6 +71,7 @@ var BoehmGC = Library{
|
|||||||
"mark_rts.c",
|
"mark_rts.c",
|
||||||
"misc.c",
|
"misc.c",
|
||||||
"new_hblk.c",
|
"new_hblk.c",
|
||||||
|
"obj_map.c",
|
||||||
"os_dep.c",
|
"os_dep.c",
|
||||||
"reclaim.c",
|
"reclaim.c",
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1046,7 +1046,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
// Special format for the ESP family of chips (parsed by the ROM
|
// Special format for the ESP family of chips (parsed by the ROM
|
||||||
// bootloader).
|
// bootloader).
|
||||||
result.Binary = filepath.Join(tmpdir, "main"+outext)
|
result.Binary = filepath.Join(tmpdir, "main"+outext)
|
||||||
err := makeESPFirmwareImage(result.Executable, result.Binary, outputBinaryFormat)
|
err := makeESPFirmareImage(result.Executable, result.Binary, outputBinaryFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
|
|||||||
|
|
||||||
// Version range supported by TinyGo.
|
// Version range supported by TinyGo.
|
||||||
const minorMin = 19
|
const minorMin = 19
|
||||||
const minorMax = 25
|
const minorMax = 24
|
||||||
|
|
||||||
// Check that we support this Go toolchain version.
|
// Check that we support this Go toolchain version.
|
||||||
gorootMajor, gorootMinor, err := goenv.GetGorootVersion()
|
gorootMajor, gorootMinor, err := goenv.GetGorootVersion()
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ type espImageSegment struct {
|
|||||||
data []byte
|
data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeESPFirmwareImage converts an input ELF file to an image file for an ESP32 or
|
// makeESPFirmareImage converts an input ELF file to an image file for an ESP32 or
|
||||||
// ESP8266 chip. This is a special purpose image format just for the ESP chip
|
// ESP8266 chip. This is a special purpose image format just for the ESP chip
|
||||||
// family, and is parsed by the on-chip mask ROM bootloader.
|
// family, and is parsed by the on-chip mask ROM bootloader.
|
||||||
//
|
//
|
||||||
@@ -31,7 +31,7 @@ type espImageSegment struct {
|
|||||||
// https://github.com/espressif/esptool/wiki/Firmware-Image-Format
|
// https://github.com/espressif/esptool/wiki/Firmware-Image-Format
|
||||||
// https://github.com/espressif/esp-idf/blob/8fbb63c2a701c22ccf4ce249f43aded73e134a34/components/bootloader_support/include/esp_image_format.h#L58
|
// https://github.com/espressif/esp-idf/blob/8fbb63c2a701c22ccf4ce249f43aded73e134a34/components/bootloader_support/include/esp_image_format.h#L58
|
||||||
// https://github.com/espressif/esptool/blob/master/esptool.py
|
// https://github.com/espressif/esptool/blob/master/esptool.py
|
||||||
func makeESPFirmwareImage(infile, outfile, format string) error {
|
func makeESPFirmareImage(infile, outfile, format string) error {
|
||||||
inf, err := elf.Open(infile)
|
inf, err := elf.Open(infile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ func TestBinarySize(t *testing.T) {
|
|||||||
// This is a small number of very diverse targets that we want to test.
|
// This is a small number of very diverse targets that we want to test.
|
||||||
tests := []sizeTest{
|
tests := []sizeTest{
|
||||||
// microcontrollers
|
// microcontrollers
|
||||||
{"hifive1b", "examples/echo", 3884, 280, 0, 2268},
|
{"hifive1b", "examples/echo", 3836, 280, 0, 2268},
|
||||||
{"microbit", "examples/serial", 2852, 360, 8, 2272},
|
{"microbit", "examples/serial", 2916, 388, 8, 2272},
|
||||||
{"wioterminal", "examples/pininterrupt", 7337, 1491, 116, 6912},
|
{"wioterminal", "examples/pininterrupt", 7361, 1491, 116, 6912},
|
||||||
|
|
||||||
// TODO: also check wasm. Right now this is difficult, because
|
// TODO: also check wasm. Right now this is difficult, because
|
||||||
// wasm binaries are run through wasm-opt and therefore the
|
// wasm binaries are run through wasm-opt and therefore the
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ func (b *builder) createInlineAsm(args []ssa.Value) (llvm.Value, error) {
|
|||||||
// provided immediately. For example:
|
// provided immediately. For example:
|
||||||
//
|
//
|
||||||
// arm.AsmFull(
|
// arm.AsmFull(
|
||||||
// "str {value}, [{result}]",
|
// "str {value}, {result}",
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "value": 1,
|
// "value": 1
|
||||||
// "result": uintptr(unsafe.Pointer(&dest)),
|
// "result": &dest,
|
||||||
// })
|
// })
|
||||||
func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) {
|
func (b *builder) createInlineAsmFull(instr *ssa.CallCommon) (llvm.Value, error) {
|
||||||
asmString := constant.StringVal(instr.Args[0].(*ssa.Const).Value)
|
asmString := constant.StringVal(instr.Args[0].(*ssa.Const).Value)
|
||||||
|
|||||||
@@ -121,29 +121,6 @@ func (b *builder) createKeepAliveImpl() {
|
|||||||
b.CreateRetVoid()
|
b.CreateRetVoid()
|
||||||
}
|
}
|
||||||
|
|
||||||
// createAbiEscapeImpl implements the generic internal/abi.Escape function. It
|
|
||||||
// currently only supports pointer types.
|
|
||||||
func (b *builder) createAbiEscapeImpl() {
|
|
||||||
b.createFunctionStart(true)
|
|
||||||
|
|
||||||
// The first parameter is assumed to be a pointer. This is checked at the
|
|
||||||
// call site of createAbiEscapeImpl.
|
|
||||||
pointerValue := b.getValue(b.fn.Params[0], getPos(b.fn))
|
|
||||||
|
|
||||||
// Create an equivalent of the following C code, which is basically just a
|
|
||||||
// nop but ensures the pointerValue is kept alive:
|
|
||||||
//
|
|
||||||
// __asm__ __volatile__("" : : "r"(pointerValue))
|
|
||||||
//
|
|
||||||
// It should be portable to basically everything as the "r" register type
|
|
||||||
// exists basically everywhere.
|
|
||||||
asmType := llvm.FunctionType(b.dataPtrType, []llvm.Type{b.dataPtrType}, false)
|
|
||||||
asmFn := llvm.InlineAsm(asmType, "", "=r,0", true, false, 0, false)
|
|
||||||
result := b.createCall(asmType, asmFn, []llvm.Value{pointerValue}, "")
|
|
||||||
|
|
||||||
b.CreateRet(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
var mathToLLVMMapping = map[string]string{
|
var mathToLLVMMapping = map[string]string{
|
||||||
"math.Ceil": "llvm.ceil.f64",
|
"math.Ceil": "llvm.ceil.f64",
|
||||||
"math.Exp": "llvm.exp.f64",
|
"math.Exp": "llvm.exp.f64",
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ func Version() int {
|
|||||||
return major
|
return major
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByteOrder returns the byte order for the given target triple. Most targets are little
|
// Return the byte order for the given target triple. Most targets are little
|
||||||
// endian, but for example MIPS can be big-endian.
|
// endian, but for example MIPS can be big-endian.
|
||||||
func ByteOrder(target string) binary.ByteOrder {
|
func ByteOrder(target string) binary.ByteOrder {
|
||||||
if strings.HasPrefix(target, "mips-") {
|
if strings.HasPrefix(target, "mips-") {
|
||||||
|
|||||||
+4
-32
@@ -253,23 +253,6 @@ func (c *compilerContext) maybeCreateSyntheticFunction(fn *ssa.Function, llvmFn
|
|||||||
// The exception is the package initializer, which does appear in the
|
// The exception is the package initializer, which does appear in the
|
||||||
// *ssa.Package members and so shouldn't be created here.
|
// *ssa.Package members and so shouldn't be created here.
|
||||||
if fn.Synthetic != "" && fn.Synthetic != "package initializer" && fn.Synthetic != "generic function" && fn.Synthetic != "range-over-func yield" {
|
if fn.Synthetic != "" && fn.Synthetic != "package initializer" && fn.Synthetic != "generic function" && fn.Synthetic != "range-over-func yield" {
|
||||||
if origin := fn.Origin(); origin != nil && origin.RelString(nil) == "internal/abi.Escape" {
|
|
||||||
// This is a special implementation or internal/abi.Escape, which
|
|
||||||
// can only really be implemented in the compiler.
|
|
||||||
// For simplicity we'll only implement pointer parameters for now.
|
|
||||||
if _, ok := fn.Params[0].Type().Underlying().(*types.Pointer); ok {
|
|
||||||
irbuilder := c.ctx.NewBuilder()
|
|
||||||
defer irbuilder.Dispose()
|
|
||||||
b := newBuilder(c, irbuilder, fn)
|
|
||||||
b.createAbiEscapeImpl()
|
|
||||||
llvmFn.SetLinkage(llvm.LinkOnceODRLinkage)
|
|
||||||
llvmFn.SetUnnamedAddr(true)
|
|
||||||
}
|
|
||||||
// If the parameter is not of a pointer type, it will be left
|
|
||||||
// unimplemented. This will result in a linker error if the function
|
|
||||||
// is really called, making it clear it needs to be implemented.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(fn.Blocks) == 0 {
|
if len(fn.Blocks) == 0 {
|
||||||
c.addError(fn.Pos(), "missing function body")
|
c.addError(fn.Pos(), "missing function body")
|
||||||
return
|
return
|
||||||
@@ -630,7 +613,7 @@ func (c *compilerContext) addStandardAttributes(llvmFn llvm.Value) {
|
|||||||
// linkName is equal to .RelString(nil) on a global and extern is false, but for
|
// linkName is equal to .RelString(nil) on a global and extern is false, but for
|
||||||
// some symbols this is different (due to //go:extern for example).
|
// some symbols this is different (due to //go:extern for example).
|
||||||
type globalInfo struct {
|
type globalInfo struct {
|
||||||
linkName string // go:extern, go:linkname
|
linkName string // go:extern
|
||||||
extern bool // go:extern
|
extern bool // go:extern
|
||||||
align int // go:align
|
align int // go:align
|
||||||
section string // go:section
|
section string // go:section
|
||||||
@@ -715,14 +698,14 @@ func (c *compilerContext) getGlobalInfo(g *ssa.Global) globalInfo {
|
|||||||
// Check for //go: pragmas, which may change the link name (among others).
|
// Check for //go: pragmas, which may change the link name (among others).
|
||||||
doc := c.astComments[info.linkName]
|
doc := c.astComments[info.linkName]
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
info.parsePragmas(doc, c, g)
|
info.parsePragmas(doc)
|
||||||
}
|
}
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse //go: pragma comments from the source. In particular, it parses the
|
// Parse //go: pragma comments from the source. In particular, it parses the
|
||||||
// //go:extern and //go:linkname pragmas on globals.
|
// //go:extern pragma on globals.
|
||||||
func (info *globalInfo) parsePragmas(doc *ast.CommentGroup, c *compilerContext, g *ssa.Global) {
|
func (info *globalInfo) parsePragmas(doc *ast.CommentGroup) {
|
||||||
for _, comment := range doc.List {
|
for _, comment := range doc.List {
|
||||||
if !strings.HasPrefix(comment.Text, "//go:") {
|
if !strings.HasPrefix(comment.Text, "//go:") {
|
||||||
continue
|
continue
|
||||||
@@ -743,17 +726,6 @@ func (info *globalInfo) parsePragmas(doc *ast.CommentGroup, c *compilerContext,
|
|||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
info.section = parts[1]
|
info.section = parts[1]
|
||||||
}
|
}
|
||||||
case "//go:linkname":
|
|
||||||
if len(parts) != 3 || parts[1] != g.Name() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Only enable go:linkname when the package imports "unsafe".
|
|
||||||
// This is a slightly looser requirement than what gc uses: gc
|
|
||||||
// requires the file to import "unsafe", not the package as a
|
|
||||||
// whole.
|
|
||||||
if hasUnsafeImport(g.Pkg.Pkg) {
|
|
||||||
info.linkName = parts[2]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
-3
@@ -206,7 +206,7 @@ entry:
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -107,8 +107,8 @@ select.body: ; preds = %select.next
|
|||||||
|
|
||||||
declare { i32, i1 } @runtime.chanSelect(ptr, ptr, i32, i32, ptr, i32, i32, ptr) #1
|
declare { i32, i1 } @runtime.chanSelect(ptr, ptr, i32, i32, ptr, i32, i32, ptr) #1
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
||||||
attributes #4 = { nounwind }
|
attributes #4 = { nounwind }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -93,6 +93,6 @@ entry:
|
|||||||
ret i8 %0
|
ret i8 %0
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -44,7 +44,7 @@ entry:
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -135,7 +135,7 @@ entry:
|
|||||||
ret %runtime._interface %1
|
ret %runtime._interface %1
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -57,7 +57,7 @@ entry:
|
|||||||
ret ptr %s.data
|
ret ptr %s.data
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -171,9 +171,9 @@ declare i32 @llvm.smax.i32(i32, i32) #4
|
|||||||
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
|
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
|
||||||
declare i32 @llvm.umax.i32(i32, i32) #4
|
declare i32 @llvm.umax.i32(i32, i32) #4
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
|
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
|
||||||
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
|
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
|
||||||
attributes #5 = { nounwind }
|
attributes #5 = { nounwind }
|
||||||
|
|||||||
+9
-9
@@ -192,13 +192,13 @@ entry:
|
|||||||
unreachable
|
unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-gowrapper"="main.regularFunction" }
|
attributes #3 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-gowrapper"="main.regularFunction" }
|
||||||
attributes #4 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-gowrapper"="main.inlineFunctionGoroutine$1" }
|
attributes #4 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-gowrapper"="main.inlineFunctionGoroutine$1" }
|
||||||
attributes #5 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-gowrapper"="main.closureFunctionGoroutine$1" }
|
attributes #5 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-gowrapper"="main.closureFunctionGoroutine$1" }
|
||||||
attributes #6 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-gowrapper" }
|
attributes #6 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-gowrapper" }
|
||||||
attributes #7 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-invoke"="reflect/methods.Print(string)" "tinygo-methods"="reflect/methods.Print(string)" }
|
attributes #7 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-invoke"="reflect/methods.Print(string)" "tinygo-methods"="reflect/methods.Print(string)" }
|
||||||
attributes #8 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-gowrapper"="interface:{Print:func:{basic:string}{}}.Print$invoke" }
|
attributes #8 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-gowrapper"="interface:{Print:func:{basic:string}{}}.Print$invoke" }
|
||||||
attributes #9 = { nounwind }
|
attributes #9 = { nounwind }
|
||||||
|
|||||||
Vendored
+7
-7
@@ -130,11 +130,11 @@ entry:
|
|||||||
|
|
||||||
declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(ptr, ptr, ptr) #6
|
declare %runtime._string @"interface:{Error:func:{}{basic:string}}.Error$invoke"(ptr, ptr, ptr) #6
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-methods"="reflect/methods.Error() string" }
|
attributes #3 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-methods"="reflect/methods.Error() string" }
|
||||||
attributes #4 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-methods"="reflect/methods.String() string" }
|
attributes #4 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-methods"="reflect/methods.String() string" }
|
||||||
attributes #5 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-invoke"="main.$methods.foo(int) uint8" "tinygo-methods"="reflect/methods.String() string; main.$methods.foo(int) uint8" }
|
attributes #5 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-invoke"="main.$methods.foo(int) uint8" "tinygo-methods"="reflect/methods.String() string; main.$methods.foo(int) uint8" }
|
||||||
attributes #6 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "tinygo-invoke"="reflect/methods.Error() string" "tinygo-methods"="reflect/methods.Error() string" }
|
attributes #6 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "tinygo-invoke"="reflect/methods.Error() string" "tinygo-methods"="reflect/methods.Error() string" }
|
||||||
attributes #7 = { nounwind }
|
attributes #7 = { nounwind }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -44,7 +44,7 @@ entry:
|
|||||||
ret ptr %x
|
ret ptr %x
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|||||||
Vendored
+10
-10
@@ -93,13 +93,13 @@ entry:
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "wasm-export-name"="extern_func" }
|
attributes #3 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "wasm-export-name"="extern_func" }
|
||||||
attributes #4 = { inlinehint nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #4 = { inlinehint nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #5 = { noinline nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #5 = { noinline nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #6 = { noinline nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "wasm-export-name"="exportedFunctionInSection" }
|
attributes #6 = { noinline nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "wasm-export-name"="exportedFunctionInSection" }
|
||||||
attributes #7 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "wasm-import-module"="modulename" "wasm-import-name"="import1" }
|
attributes #7 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "wasm-import-module"="modulename" "wasm-import-name"="import1" }
|
||||||
attributes #8 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "wasm-import-module"="foobar" "wasm-import-name"="imported" }
|
attributes #8 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "wasm-import-module"="foobar" "wasm-import-name"="imported" }
|
||||||
attributes #9 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" "wasm-export-name"="exported" }
|
attributes #9 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" "wasm-export-name"="exported" }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -322,7 +322,7 @@ unsafe.Slice.throw: ; preds = %entry
|
|||||||
unreachable
|
unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|||||||
Vendored
+3
-3
@@ -97,7 +97,7 @@ lookup.throw: ; preds = %entry
|
|||||||
unreachable
|
unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { nounwind }
|
attributes #3 = { nounwind }
|
||||||
|
|||||||
Vendored
+4
-4
@@ -132,9 +132,9 @@ entry:
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #1 = { "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #2 = { nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #3 = { noinline nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+call-indirect-overlong,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
|
attributes #3 = { noinline nounwind "target-features"="+bulk-memory,+bulk-memory-opt,+mutable-globals,+nontrapping-fptoint,+sign-ext,-call-indirect-overlong,-multivalue,-reference-types" }
|
||||||
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
||||||
attributes #5 = { nounwind }
|
attributes #5 = { nounwind }
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ go 1.22.0
|
|||||||
require (
|
require (
|
||||||
github.com/aykevl/go-wasm v0.0.2-0.20250317121156-42b86c494139
|
github.com/aykevl/go-wasm v0.0.2-0.20250317121156-42b86c494139
|
||||||
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2
|
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee
|
||||||
|
github.com/chromedp/chromedp v0.7.6
|
||||||
github.com/gofrs/flock v0.8.1
|
github.com/gofrs/flock v0.8.1
|
||||||
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
|
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
|
||||||
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf
|
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf
|
||||||
@@ -22,7 +24,13 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/chromedp/sysutil v1.0.0 // indirect
|
||||||
github.com/creack/goselect v0.1.2 // indirect
|
github.com/creack/goselect v0.1.2 // indirect
|
||||||
|
github.com/gobwas/httphead v0.1.0 // indirect
|
||||||
|
github.com/gobwas/pool v0.2.1 // indirect
|
||||||
|
github.com/gobwas/ws v1.1.0 // indirect
|
||||||
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/stretchr/testify v1.8.4 // indirect
|
github.com/stretchr/testify v1.8.4 // indirect
|
||||||
golang.org/x/text v0.22.0 // indirect
|
golang.org/x/text v0.22.0 // indirect
|
||||||
|
|||||||
@@ -2,16 +2,33 @@ github.com/aykevl/go-wasm v0.0.2-0.20250317121156-42b86c494139 h1:2O/WuAt8J5id3k
|
|||||||
github.com/aykevl/go-wasm v0.0.2-0.20250317121156-42b86c494139/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw=
|
github.com/aykevl/go-wasm v0.0.2-0.20250317121156-42b86c494139/go.mod h1:7sXyiaA0WtSogCu67R2252fQpVmJMh9JWJ9ddtGkpWw=
|
||||||
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI=
|
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2 h1:oMCHnXa6CCCafdPDbMh/lWRhRByN0VFLvv+g+ayx1SI=
|
||||||
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
|
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20211126220118-81fa0469ad77/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee h1:+SFdIVfQpG0s0DHYzou0kgfE0n0ZjKPwbiRJsXrZegU=
|
||||||
|
github.com/chromedp/cdproto v0.0.0-20220113222801-0725d94bb6ee/go.mod h1:At5TxYYdxkbQL0TSefRjhLE3Q0lgvqKKMSFUglJ7i1U=
|
||||||
|
github.com/chromedp/chromedp v0.7.6 h1:2juGaktzjwULlsn+DnvIZXFUckEp5xs+GOBroaea+jA=
|
||||||
|
github.com/chromedp/chromedp v0.7.6/go.mod h1:ayT4YU/MGAALNfOg9gNrpGSAdnU51PMx+FCeuT1iXzo=
|
||||||
|
github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic=
|
||||||
|
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
|
||||||
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
|
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
|
||||||
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||||
|
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||||
|
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||||
|
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||||
|
github.com/gobwas/ws v1.1.0 h1:7RFti/xnNkMJnrK7D1yQ/iCIB5OrrY/54/H930kIbHA=
|
||||||
|
github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
|
||||||
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
|
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
|
||||||
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
||||||
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg=
|
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg=
|
||||||
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
|
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
|
||||||
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf h1:FtEj8sfIcaaBfAKrE1Cwb61YDtYq9JxChK1c7AKce7s=
|
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf h1:FtEj8sfIcaaBfAKrE1Cwb61YDtYq9JxChK1c7AKce7s=
|
||||||
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf/go.mod h1:yrqSXGoD/4EKfF26AOGzscPOgTTJcyAwM2rpixWT+t4=
|
github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf/go.mod h1:yrqSXGoD/4EKfF26AOGzscPOgTTJcyAwM2rpixWT+t4=
|
||||||
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
|
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||||
|
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||||
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 h1:6J+qramlHVLmiBOgRiBOnQkno8uprqG6YFFQTt6uYIw=
|
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 h1:6J+qramlHVLmiBOgRiBOnQkno8uprqG6YFFQTt6uYIw=
|
||||||
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892/go.mod h1:Pb6XcsXyropB9LNHhnqaknG/vEwYztLkQzVCHv8sQ3M=
|
github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892/go.mod h1:Pb6XcsXyropB9LNHhnqaknG/vEwYztLkQzVCHv8sQ3M=
|
||||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
@@ -25,6 +42,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
|||||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/mattn/go-tty v0.0.4 h1:NVikla9X8MN0SQAqCYzpGyXv0jY7MNl3HOWD2dkle7E=
|
github.com/mattn/go-tty v0.0.4 h1:NVikla9X8MN0SQAqCYzpGyXv0jY7MNl3HOWD2dkle7E=
|
||||||
github.com/mattn/go-tty v0.0.4/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3pxse28=
|
github.com/mattn/go-tty v0.0.4/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3pxse28=
|
||||||
|
github.com/orisano/pixelmatch v0.0.0-20210112091706-4fa4c7ba91d5 h1:1SoBaSPudixRecmlHXb/GxmaD3fLMtHIDN13QujwQuc=
|
||||||
|
github.com/orisano/pixelmatch v0.0.0-20210112091706-4fa4c7ba91d5/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs=
|
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs=
|
||||||
@@ -44,6 +63,8 @@ golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// Version of TinyGo.
|
// Version of TinyGo.
|
||||||
// Update this value before release of new version of software.
|
// Update this value before release of new version of software.
|
||||||
const version = "0.40.0-dev"
|
const version = "0.39.0-dev"
|
||||||
|
|
||||||
// Return TinyGo version, either in the form 0.30.0 or as a development version
|
// Return TinyGo version, either in the form 0.30.0 or as a development version
|
||||||
// (like 0.30.0-dev-abcd012).
|
// (like 0.30.0-dev-abcd012).
|
||||||
|
|||||||
@@ -577,7 +577,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
|||||||
// runtime instead of at compile time. But we need to
|
// runtime instead of at compile time. But we need to
|
||||||
// revert any changes made by the call first.
|
// revert any changes made by the call first.
|
||||||
if r.debug {
|
if r.debug {
|
||||||
fmt.Fprintln(os.Stderr, indent+"!! revert because of error:", callErr.Error())
|
fmt.Fprintln(os.Stderr, indent+"!! revert because of error:", callErr.Err)
|
||||||
}
|
}
|
||||||
callMem.revert()
|
callMem.revert()
|
||||||
err := r.runAtRuntime(fn, inst, locals, &mem, indent)
|
err := r.runAtRuntime(fn, inst, locals, &mem, indent)
|
||||||
|
|||||||
+1
-1
Submodule lib/bdwgc updated: 7577ca7c2d...1166f11f7d
@@ -256,6 +256,7 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
|
|||||||
"reflect/": false,
|
"reflect/": false,
|
||||||
"runtime/": false,
|
"runtime/": false,
|
||||||
"sync/": true,
|
"sync/": true,
|
||||||
|
"testing/": true,
|
||||||
"tinygo/": false,
|
"tinygo/": false,
|
||||||
"unique/": false,
|
"unique/": false,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,8 +291,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
|
|||||||
})
|
})
|
||||||
|
|
||||||
if testConfig.CompileOnly {
|
if testConfig.CompileOnly {
|
||||||
// Return the compiler error, if there is one.
|
return true, nil
|
||||||
return true, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
importPath := strings.TrimSuffix(result.ImportPath, ".test")
|
importPath := strings.TrimSuffix(result.ImportPath, ".test")
|
||||||
@@ -340,17 +339,8 @@ func dirsToModuleRootAbs(maindir, modroot string) []string {
|
|||||||
return dirs
|
return dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateOutputFormat checks if the output file extension matches the expected format
|
|
||||||
func validateOutputFormat(outpath, expectedExt string) error {
|
|
||||||
actualExt := filepath.Ext(outpath)
|
|
||||||
if actualExt != expectedExt {
|
|
||||||
return fmt.Errorf("output format %s does not match target format %s", actualExt, expectedExt)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flash builds and flashes the built binary to the given serial port.
|
// Flash builds and flashes the built binary to the given serial port.
|
||||||
func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
|
func Flash(pkgName, port string, options *compileopts.Options) error {
|
||||||
config, err := builder.NewConfig(options)
|
config, err := builder.NewConfig(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -399,24 +389,13 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
|
|||||||
if !options.Work {
|
if !options.Work {
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
}
|
}
|
||||||
// Validate output format before building
|
|
||||||
if outpath != "" {
|
|
||||||
if err := validateOutputFormat(outpath, fileExt); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Build the binary.
|
// Build the binary.
|
||||||
result, err := builder.Build(pkgName, fileExt, tmpdir, config)
|
result, err := builder.Build(pkgName, fileExt, tmpdir, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save output file if specified (after build, before flashing)
|
|
||||||
if outpath != "" {
|
|
||||||
if err := copyFile(result.Binary, outpath); err != nil {
|
|
||||||
return fmt.Errorf("failed to save output file: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// do we need port reset to put MCU into bootloader mode?
|
// do we need port reset to put MCU into bootloader mode?
|
||||||
if config.Target.PortReset == "true" && flashMethod != "openocd" {
|
if config.Target.PortReset == "true" && flashMethod != "openocd" {
|
||||||
port, err := getDefaultPort(port, config.Target.SerialPort)
|
port, err := getDefaultPort(port, config.Target.SerialPort)
|
||||||
@@ -1318,11 +1297,6 @@ extension at all.`
|
|||||||
(https://tinygo.org/docs/reference/microcontrollers/).
|
(https://tinygo.org/docs/reference/microcontrollers/).
|
||||||
Examples: "arduino-nano", "d1mini", "xiao".
|
Examples: "arduino-nano", "d1mini", "xiao".
|
||||||
|
|
||||||
-o={filename}:
|
|
||||||
Save the built binary to the specified output file. The file
|
|
||||||
format must match the target's expected format (e.g., .hex,
|
|
||||||
.uf2). Both flashing and saving will be performed.
|
|
||||||
|
|
||||||
-monitor:
|
-monitor:
|
||||||
Start the serial monitor (see below) immediately after
|
Start the serial monitor (see below) immediately after
|
||||||
flashing. However, some microcontrollers need a split second
|
flashing. However, some microcontrollers need a split second
|
||||||
@@ -1653,7 +1627,7 @@ func main() {
|
|||||||
flag.BoolVar(&flagTest, "test", false, "supply -test flag to go list")
|
flag.BoolVar(&flagTest, "test", false, "supply -test flag to go list")
|
||||||
}
|
}
|
||||||
var outpath string
|
var outpath string
|
||||||
if command == "help" || command == "build" || command == "test" || command == "flash" {
|
if command == "help" || command == "build" || command == "test" {
|
||||||
flag.StringVar(&outpath, "o", "", "output filename")
|
flag.StringVar(&outpath, "o", "", "output filename")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1804,7 +1778,7 @@ func main() {
|
|||||||
case "flash", "gdb", "lldb":
|
case "flash", "gdb", "lldb":
|
||||||
pkgName := filepath.ToSlash(flag.Arg(0))
|
pkgName := filepath.ToSlash(flag.Arg(0))
|
||||||
if command == "flash" {
|
if command == "flash" {
|
||||||
err := Flash(pkgName, *port, outpath, options)
|
err := Flash(pkgName, *port, options)
|
||||||
printBuildOutput(err, *flagJSON)
|
printBuildOutput(err, *flagJSON)
|
||||||
} else {
|
} else {
|
||||||
if !options.Debug {
|
if !options.Debug {
|
||||||
@@ -1890,7 +1864,6 @@ func main() {
|
|||||||
wd = ""
|
wd = ""
|
||||||
}
|
}
|
||||||
diagnostics.CreateDiagnostics(err).WriteTo(os.Stderr, wd)
|
diagnostics.CreateDiagnostics(err).WriteTo(os.Stderr, wd)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
if !passed {
|
if !passed {
|
||||||
select {
|
select {
|
||||||
|
|||||||
+3
-3
@@ -35,8 +35,8 @@ func Monitor(executable, port string, config *compileopts.Config) error {
|
|||||||
// Use the RTT interface, which is documented (in part) here:
|
// Use the RTT interface, which is documented (in part) here:
|
||||||
// https://wiki.segger.com/RTT
|
// https://wiki.segger.com/RTT
|
||||||
|
|
||||||
// Try to find the "_SEGGER_RTT" symbol (machine.rttSerialInstance)
|
// Try to find the "machine.rttSerialInstance" symbol, which is the RTT
|
||||||
// symbol, which is the RTT control block.
|
// control block.
|
||||||
file, err := elf.Open(executable)
|
file, err := elf.Open(executable)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not open ELF file to determine RTT control block: %w", err)
|
return fmt.Errorf("could not open ELF file to determine RTT control block: %w", err)
|
||||||
@@ -48,7 +48,7 @@ func Monitor(executable, port string, config *compileopts.Config) error {
|
|||||||
}
|
}
|
||||||
var address uint64
|
var address uint64
|
||||||
for _, symbol := range symbols {
|
for _, symbol := range symbols {
|
||||||
if symbol.Name == "_SEGGER_RTT" {
|
if symbol.Name == "machine.rttSerialInstance" {
|
||||||
address = symbol.Value
|
address = symbol.Value
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,10 +63,6 @@ func SecCertificateCopyData(cert CFRef) ([]byte, error) {
|
|||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func SecTrustCopyCertificateChain(trustObj CFRef) (CFRef, error) {
|
|
||||||
return 0, errors.New("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func SecTrustEvaluateWithError(trustObj CFRef) (int, error) {
|
func SecTrustEvaluateWithError(trustObj CFRef) (int, error) {
|
||||||
return 0, errors.New("not implemented")
|
return 0, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ func Asm(asm string)
|
|||||||
// recognizes template values in the form {name}, like so:
|
// recognizes template values in the form {name}, like so:
|
||||||
//
|
//
|
||||||
// arm.AsmFull(
|
// arm.AsmFull(
|
||||||
// "str {value}, [{result}]",
|
// "str {value}, {result}",
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "value": 1,
|
// "value": 1
|
||||||
// "result": uintptr(unsafe.Pointer(&dest)),
|
// "result": &dest,
|
||||||
// })
|
// })
|
||||||
//
|
//
|
||||||
// You can use {} in the asm string (which expands to a register) to set the
|
// You can use {} in the asm string (which expands to a register) to set the
|
||||||
|
|||||||
@@ -1,6 +1,29 @@
|
|||||||
.syntax unified
|
.syntax unified
|
||||||
.cfi_sections .debug_frame
|
.cfi_sections .debug_frame
|
||||||
|
|
||||||
|
.section .text.HardFault_Handler
|
||||||
|
.global HardFault_Handler
|
||||||
|
.type HardFault_Handler, %function
|
||||||
|
HardFault_Handler:
|
||||||
|
.cfi_startproc
|
||||||
|
// Put the old stack pointer in the first argument, for easy debugging. This
|
||||||
|
// is especially useful on Cortex-M0, which supports far fewer debug
|
||||||
|
// facilities.
|
||||||
|
mov r0, sp
|
||||||
|
|
||||||
|
// Load the default stack pointer from address 0 so that we can call normal
|
||||||
|
// functions again that expect a working stack. However, it will corrupt the
|
||||||
|
// old stack so the function below must not attempt to recover from this
|
||||||
|
// fault.
|
||||||
|
movs r3, #0
|
||||||
|
ldr r3, [r3]
|
||||||
|
mov sp, r3
|
||||||
|
|
||||||
|
// Continue handling this error in Go.
|
||||||
|
bl handleHardFault
|
||||||
|
.cfi_endproc
|
||||||
|
.size HardFault_Handler, .-HardFault_Handler
|
||||||
|
|
||||||
// This is a convenience function for semihosting support.
|
// This is a convenience function for semihosting support.
|
||||||
// At some point, this should be replaced by inline assembly.
|
// At some point, this should be replaced by inline assembly.
|
||||||
.section .text.SemihostingCall
|
.section .text.SemihostingCall
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ func Asm(asm string)
|
|||||||
// recognizes template values in the form {name}, like so:
|
// recognizes template values in the form {name}, like so:
|
||||||
//
|
//
|
||||||
// arm.AsmFull(
|
// arm.AsmFull(
|
||||||
// "str {value}, [{result}]",
|
// "str {value}, {result}",
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "value": 1,
|
// "value": 1
|
||||||
// "result": uintptr(unsafe.Pointer(&dest)),
|
// "result": &dest,
|
||||||
// })
|
// })
|
||||||
//
|
//
|
||||||
// You can use {} in the asm string (which expands to a register) to set the
|
// You can use {} in the asm string (which expands to a register) to set the
|
||||||
|
|||||||
+3
-3
@@ -10,10 +10,10 @@ func Asm(asm string)
|
|||||||
// recognizes template values in the form {name}, like so:
|
// recognizes template values in the form {name}, like so:
|
||||||
//
|
//
|
||||||
// arm.AsmFull(
|
// arm.AsmFull(
|
||||||
// "str {value}, [{result}]",
|
// "str {value}, {result}",
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "value": 1,
|
// "value": 1
|
||||||
// "result": uintptr(unsafe.Pointer(&dest)),
|
// "result": &dest,
|
||||||
// })
|
// })
|
||||||
//
|
//
|
||||||
// You can use {} in the asm string (which expands to a register) to set the
|
// You can use {} in the asm string (which expands to a register) to set the
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ func Asm(asm string)
|
|||||||
// recognizes template values in the form {name}, like so:
|
// recognizes template values in the form {name}, like so:
|
||||||
//
|
//
|
||||||
// arm.AsmFull(
|
// arm.AsmFull(
|
||||||
// "st {value}, [{result}]",
|
// "st {value}, {result}",
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "value": 1,
|
// "value": 1
|
||||||
// "result": uintptr(unsafe.Pointer(&dest)),
|
// "result": &dest,
|
||||||
// })
|
// })
|
||||||
//
|
//
|
||||||
// You can use {} in the asm string (which expands to a register) to set the
|
// You can use {} in the asm string (which expands to a register) to set the
|
||||||
|
|||||||
@@ -8,10 +8,3 @@ import "unsafe"
|
|||||||
func NoEscape(p unsafe.Pointer) unsafe.Pointer {
|
func NoEscape(p unsafe.Pointer) unsafe.Pointer {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func Escape[T any](x T) T {
|
|
||||||
// This function is either implemented in the compiler, or left undefined
|
|
||||||
// for some variation of T. The body of this function should not be compiled
|
|
||||||
// as-is.
|
|
||||||
panic("internal/abi.Escape: unreachable (implemented in the compiler)")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ void tinygo_task_init(void *mainTask, pthread_t *thread, int *numCPU, void *cont
|
|||||||
// Using pthread_kill, we can still send the signal to a specific thread.
|
// Using pthread_kill, we can still send the signal to a specific thread.
|
||||||
struct sigaction act = { 0 };
|
struct sigaction act = { 0 };
|
||||||
act.sa_handler = tinygo_task_gc_pause;
|
act.sa_handler = tinygo_task_gc_pause;
|
||||||
act.sa_flags = SA_RESTART;
|
|
||||||
sigaction(taskPauseSignal, &act, NULL);
|
sigaction(taskPauseSignal, &act, NULL);
|
||||||
|
|
||||||
// Obtain the number of CPUs available on program start (for NumCPU).
|
// Obtain the number of CPUs available on program start (for NumCPU).
|
||||||
@@ -101,7 +100,7 @@ static void* start_wrapper(void *arg) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Start a new goroutine in an OS thread.
|
// Start a new goroutine in an OS thread.
|
||||||
int tinygo_task_start(uintptr_t fn, void *args, void *task, pthread_t *thread, uintptr_t *stackTop, uintptr_t stackSize, void *context) {
|
int tinygo_task_start(uintptr_t fn, void *args, void *task, pthread_t *thread, uintptr_t *stackTop, void *context) {
|
||||||
// Sanity check. Should get optimized away.
|
// Sanity check. Should get optimized away.
|
||||||
if (sizeof(pthread_t) != sizeof(void*)) {
|
if (sizeof(pthread_t) != sizeof(void*)) {
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
@@ -118,11 +117,7 @@ int tinygo_task_start(uintptr_t fn, void *args, void *task, pthread_t *thread, u
|
|||||||
#else
|
#else
|
||||||
sem_init(&state.startlock, 0, 0);
|
sem_init(&state.startlock, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
pthread_attr_t attrs;
|
int result = pthread_create(thread, NULL, &start_wrapper, &state);
|
||||||
pthread_attr_init(&attrs);
|
|
||||||
pthread_attr_setstacksize(&attrs, stackSize);
|
|
||||||
int result = pthread_create(thread, &attrs, &start_wrapper, &state);
|
|
||||||
pthread_attr_destroy(&attrs);
|
|
||||||
|
|
||||||
// Wait until the thread has been created and read all state_pass variables.
|
// Wait until the thread has been created and read all state_pass variables.
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func start(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
|
|||||||
// and the stop-the-world GC won't see threads that haven't started yet or
|
// and the stop-the-world GC won't see threads that haven't started yet or
|
||||||
// are not fully started yet.
|
// are not fully started yet.
|
||||||
activeTaskLock.Lock()
|
activeTaskLock.Lock()
|
||||||
errCode := tinygo_task_start(fn, args, t, &t.state.thread, &t.state.stackTop, stackSize)
|
errCode := tinygo_task_start(fn, args, t, &t.state.thread, &t.state.stackTop)
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
runtimePanic("could not start thread")
|
runtimePanic("could not start thread")
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ func tinygo_task_init(t *Task, thread *threadID, numCPU *int32)
|
|||||||
// Here same as for tinygo_task_init.
|
// Here same as for tinygo_task_init.
|
||||||
//
|
//
|
||||||
//go:linkname tinygo_task_start tinygo_task_start
|
//go:linkname tinygo_task_start tinygo_task_start
|
||||||
func tinygo_task_start(fn uintptr, args unsafe.Pointer, t *Task, thread *threadID, stackTop *uintptr, stackSize uintptr) int32
|
func tinygo_task_start(fn uintptr, args unsafe.Pointer, t *Task, thread *threadID, stackTop *uintptr) int32
|
||||||
|
|
||||||
// Pause the thread by sending it a signal.
|
// Pause the thread by sending it a signal.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ const (
|
|||||||
P09 Pin = 9
|
P09 Pin = 9
|
||||||
P10 Pin = 10
|
P10 Pin = 10
|
||||||
P11 Pin = 11
|
P11 Pin = 11
|
||||||
P12 Pin = 12 // peripherals: I2C0 SDA
|
P12 Pin = 12
|
||||||
P13 Pin = 13 // peripherals: I2C0 SCL
|
P13 Pin = 13
|
||||||
P14 Pin = 14
|
P14 Pin = 14
|
||||||
P15 Pin = 15
|
P15 Pin = 15
|
||||||
P16 Pin = 16
|
P16 Pin = 16
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
//go:build gopher_arcade
|
|
||||||
|
|
||||||
package machine
|
|
||||||
|
|
||||||
// Return the current CPU frequency in hertz.
|
|
||||||
func CPUFrequency() uint32 {
|
|
||||||
return 8000000
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
P5 Pin = PB0
|
|
||||||
P6 Pin = PB1
|
|
||||||
P7 Pin = PB2
|
|
||||||
P2 Pin = PB3
|
|
||||||
P3 Pin = PB4
|
|
||||||
P1 Pin = PB5
|
|
||||||
|
|
||||||
LED = P1
|
|
||||||
BUTTON_LEFT = P7
|
|
||||||
BUTTON_RIGHT = P5
|
|
||||||
SPEAKER = P6
|
|
||||||
)
|
|
||||||
@@ -1,183 +0,0 @@
|
|||||||
//go:build metro_rp2350
|
|
||||||
|
|
||||||
package machine
|
|
||||||
|
|
||||||
// GPIO pins
|
|
||||||
const (
|
|
||||||
GP0 Pin = GPIO0
|
|
||||||
GP1 Pin = GPIO1
|
|
||||||
GP2 Pin = GPIO2
|
|
||||||
GP3 Pin = GPIO3
|
|
||||||
GP4 Pin = GPIO4
|
|
||||||
GP5 Pin = GPIO5
|
|
||||||
GP6 Pin = GPIO6
|
|
||||||
GP7 Pin = GPIO7
|
|
||||||
GP8 Pin = GPIO8
|
|
||||||
GP9 Pin = GPIO9
|
|
||||||
GP10 Pin = GPIO10
|
|
||||||
GP11 Pin = GPIO11
|
|
||||||
GP12 Pin = GPIO12
|
|
||||||
GP13 Pin = GPIO13
|
|
||||||
GP14 Pin = GPIO14
|
|
||||||
GP15 Pin = GPIO15
|
|
||||||
GP16 Pin = GPIO16
|
|
||||||
GP17 Pin = GPIO17
|
|
||||||
GP18 Pin = GPIO18
|
|
||||||
GP19 Pin = GPIO19
|
|
||||||
GP20 Pin = GPIO20
|
|
||||||
GP21 Pin = GPIO21
|
|
||||||
GP22 Pin = GPIO22
|
|
||||||
GP23 Pin = GPIO23
|
|
||||||
GP24 Pin = GPIO24
|
|
||||||
GP25 Pin = GPIO25
|
|
||||||
GP26 Pin = GPIO26
|
|
||||||
GP27 Pin = GPIO27
|
|
||||||
GP28 Pin = GPIO28
|
|
||||||
GP29 Pin = GPIO29
|
|
||||||
GP30 Pin = GPIO30
|
|
||||||
GP31 Pin = GPIO31
|
|
||||||
GP32 Pin = GPIO32
|
|
||||||
GP33 Pin = GPIO33
|
|
||||||
GP34 Pin = GPIO34
|
|
||||||
GP35 Pin = GPIO35
|
|
||||||
GP36 Pin = GPIO36
|
|
||||||
GP37 Pin = GPIO37
|
|
||||||
GP38 Pin = GPIO38
|
|
||||||
GP39 Pin = GPIO39
|
|
||||||
GP40 Pin = GPIO40
|
|
||||||
GP41 Pin = GPIO41
|
|
||||||
GP42 Pin = GPIO42
|
|
||||||
GP43 Pin = GPIO43
|
|
||||||
GP44 Pin = GPIO44
|
|
||||||
GP45 Pin = GPIO45
|
|
||||||
GP46 Pin = GPIO46
|
|
||||||
|
|
||||||
// Boot button
|
|
||||||
BUTTON Pin = GPIO24
|
|
||||||
|
|
||||||
// Onboard LED
|
|
||||||
LED Pin = GPIO23
|
|
||||||
|
|
||||||
// Onboard NeoPixel
|
|
||||||
NEOPIXEL Pin = GPIO25
|
|
||||||
WS2812 Pin = GPIO25
|
|
||||||
|
|
||||||
// Onboard crystal oscillator frequency, in MHz.
|
|
||||||
xoscFreq = 12 // MHz
|
|
||||||
)
|
|
||||||
|
|
||||||
// Arduino-header digital pins
|
|
||||||
const (
|
|
||||||
RX Pin = GPIO1
|
|
||||||
TX Pin = GPIO0
|
|
||||||
D2 Pin = GPIO2
|
|
||||||
D3 Pin = GPIO3
|
|
||||||
D4 Pin = GPIO4
|
|
||||||
D5 Pin = GPIO5
|
|
||||||
D6 Pin = GPIO6
|
|
||||||
D7 Pin = GPIO7
|
|
||||||
D8 Pin = GPIO8
|
|
||||||
D9 Pin = GPIO9
|
|
||||||
D10 Pin = GPIO10
|
|
||||||
D11 Pin = GPIO11
|
|
||||||
D22 Pin = GPIO22
|
|
||||||
D23 Pin = GPIO23
|
|
||||||
)
|
|
||||||
|
|
||||||
// Arduino-header analog pins
|
|
||||||
const (
|
|
||||||
A0 Pin = GPIO41
|
|
||||||
A1 Pin = GPIO42
|
|
||||||
A2 Pin = GPIO43
|
|
||||||
A3 Pin = GPIO44
|
|
||||||
A4 Pin = GPIO45
|
|
||||||
A5 Pin = GPIO46
|
|
||||||
)
|
|
||||||
|
|
||||||
// I2C Default pins on Raspberry Pico.
|
|
||||||
const (
|
|
||||||
I2C0_SDA_PIN = GP20
|
|
||||||
I2C0_SCL_PIN = GP21
|
|
||||||
|
|
||||||
I2C1_SDA_PIN = GP2
|
|
||||||
I2C1_SCL_PIN = GP3
|
|
||||||
)
|
|
||||||
|
|
||||||
// SPI default pins
|
|
||||||
const (
|
|
||||||
// Default Serial Clock Bus 0 for SPI communications
|
|
||||||
SPI0_SCK_PIN = GPIO18
|
|
||||||
// Default Serial Out Bus 0 for SPI communications
|
|
||||||
SPI0_SDO_PIN = GPIO19 // Tx
|
|
||||||
// Default Serial In Bus 0 for SPI communications
|
|
||||||
SPI0_SDI_PIN = GPIO16 // Rx
|
|
||||||
|
|
||||||
// Default Serial Clock Bus 1 for SPI communications
|
|
||||||
SPI1_SCK_PIN = GPIO30
|
|
||||||
// Default Serial Out Bus 1 for SPI communications
|
|
||||||
SPI1_SDO_PIN = GPIO31 // Tx
|
|
||||||
// Default Serial In Bus 1 for SPI communications
|
|
||||||
SPI1_SDI_PIN = GPIO28 // Rx
|
|
||||||
|
|
||||||
// SPI header pins
|
|
||||||
MOSI Pin = SPI1_SDO_PIN
|
|
||||||
MISO Pin = SPI1_SDI_PIN
|
|
||||||
SCK Pin = SPI1_SCK_PIN
|
|
||||||
)
|
|
||||||
|
|
||||||
// SD card reader pins
|
|
||||||
const (
|
|
||||||
SD_SCK = GPIO34
|
|
||||||
SD_MOSI = GPIO35
|
|
||||||
SD_MISO = GPIO36
|
|
||||||
SDIO_DATA1 = GPIO37
|
|
||||||
SDIO_DATA2 = GPIO38
|
|
||||||
SD_CS = GPIO39
|
|
||||||
SD_CARD_DETECT = GPIO40
|
|
||||||
)
|
|
||||||
|
|
||||||
// HSTX pins
|
|
||||||
const (
|
|
||||||
CKN Pin = GPIO15
|
|
||||||
CKP Pin = GPIO14
|
|
||||||
D0N Pin = GPIO19
|
|
||||||
D0P Pin = GPIO18
|
|
||||||
D1N Pin = GPIO17
|
|
||||||
D1P Pin = GPIO16
|
|
||||||
D2N Pin = GPIO13
|
|
||||||
D2P Pin = GPIO12
|
|
||||||
D26 Pin = GPIO26
|
|
||||||
D27 Pin = GPIO27
|
|
||||||
SCL Pin = GPIO21
|
|
||||||
SDA Pin = GPIO20
|
|
||||||
)
|
|
||||||
|
|
||||||
// USB host header pins
|
|
||||||
const (
|
|
||||||
USB_HOST_DATA_PLUS Pin = GPIO32
|
|
||||||
USB_HOST_DATA_MINUS Pin = GPIO33
|
|
||||||
USB_HOST_5V_POWER Pin = GPIO29
|
|
||||||
)
|
|
||||||
|
|
||||||
// UART pins
|
|
||||||
const (
|
|
||||||
UART0_TX_PIN = GPIO0
|
|
||||||
UART0_RX_PIN = GPIO1
|
|
||||||
UART1_TX_PIN = GPIO8
|
|
||||||
UART1_RX_PIN = GPIO9
|
|
||||||
UART_TX_PIN = UART0_TX_PIN
|
|
||||||
UART_RX_PIN = UART0_RX_PIN
|
|
||||||
)
|
|
||||||
|
|
||||||
var DefaultUART = UART0
|
|
||||||
|
|
||||||
// USB identifiers
|
|
||||||
const (
|
|
||||||
usb_STRING_PRODUCT = "Metro RP2350"
|
|
||||||
usb_STRING_MANUFACTURER = "Adafruit"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
usb_VID uint16 = 0x239A
|
|
||||||
usb_PID uint16 = 0x814E
|
|
||||||
)
|
|
||||||
@@ -78,14 +78,14 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error) {
|
|||||||
// Allow scheduler to run
|
// Allow scheduler to run
|
||||||
gosched()
|
gosched()
|
||||||
|
|
||||||
// Handle first occurrence of error by ensuring STOP sent on bus
|
// Handle errors by ensuring STOP sent on bus
|
||||||
if err == nil && i2c.Bus.EVENTS_ERROR.Get() != 0 {
|
if i2c.Bus.EVENTS_ERROR.Get() != 0 {
|
||||||
err = twiCError(i2c.Bus.ERRORSRC.Get())
|
|
||||||
if i2c.Bus.EVENTS_STOPPED.Get() == 0 {
|
if i2c.Bus.EVENTS_STOPPED.Get() == 0 {
|
||||||
// STOP cannot be sent during SUSPEND
|
// STOP cannot be sent during SUSPEND
|
||||||
i2c.Bus.TASKS_RESUME.Set(1)
|
i2c.Bus.TASKS_RESUME.Set(1)
|
||||||
i2c.Bus.TASKS_STOP.Set(1)
|
i2c.Bus.TASKS_STOP.Set(1)
|
||||||
}
|
}
|
||||||
|
err = twiCError(i2c.Bus.ERRORSRC.Get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,6 @@ func machineInit() {
|
|||||||
|
|
||||||
// Peripheral clocks should now all be running
|
// Peripheral clocks should now all be running
|
||||||
unresetBlockWait(RESETS_RESET_Msk)
|
unresetBlockWait(RESETS_RESET_Msk)
|
||||||
|
|
||||||
// DBGPAUSE pauses the timer when a debugger is connected. This prevents
|
|
||||||
// sleep functions from ever returning, so disable it.
|
|
||||||
timer.setDbgPause(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:linkname ticks runtime.machineTicks
|
//go:linkname ticks runtime.machineTicks
|
||||||
|
|||||||
@@ -100,8 +100,7 @@ func ReadTemperature() (millicelsius int32) {
|
|||||||
rp.ADC.CS.SetBits(rp.ADC_CS_TS_EN)
|
rp.ADC.CS.SetBits(rp.ADC_CS_TS_EN)
|
||||||
|
|
||||||
// T = 27 - (ADC_voltage - 0.706)/0.001721
|
// T = 27 - (ADC_voltage - 0.706)/0.001721
|
||||||
// 1/0.001721 ≈ 581
|
return (27000<<16 - (int32(thermChan.getVoltage())-706<<16)*581) >> 16
|
||||||
return int32(((int64(27000) << 16) - ((int64(thermChan.getVoltage()) - (int64(706) << 16)) * 581)) >> 16)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForReady spins waiting for the ADC peripheral to become ready.
|
// waitForReady spins waiting for the ADC peripheral to become ready.
|
||||||
|
|||||||
@@ -101,15 +101,3 @@ func (tmr *timerType) lightSleep(us uint64) {
|
|||||||
// Disable interrupt
|
// Disable interrupt
|
||||||
intr.Disable()
|
intr.Disable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// setDbgPause sets whether this timer is paused when a debugger is connected.
|
|
||||||
func (tmr *timerType) setDbgPause(enable bool) {
|
|
||||||
const bitPos = 1
|
|
||||||
const bitMask = 0b11
|
|
||||||
val := uint32(0b00)
|
|
||||||
if enable {
|
|
||||||
// Disable timer when debugger is connected to either core.
|
|
||||||
val = 0b11
|
|
||||||
}
|
|
||||||
tmr.dbgPause.ReplaceBits(val, bitMask, bitPos)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -104,9 +104,7 @@ func (uart *UART) SetBaudRate(br uint32) {
|
|||||||
func (uart *UART) writeByte(c byte) error {
|
func (uart *UART) writeByte(c byte) error {
|
||||||
// wait until buffer is not full
|
// wait until buffer is not full
|
||||||
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_TXFF) {
|
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_TXFF) {
|
||||||
if !interrupt.In() {
|
gosched()
|
||||||
gosched()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
@@ -116,9 +114,7 @@ func (uart *UART) writeByte(c byte) error {
|
|||||||
|
|
||||||
func (uart *UART) flush() {
|
func (uart *UART) flush() {
|
||||||
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_BUSY) {
|
for uart.Bus.UARTFR.HasBits(rp.UART0_UARTFR_BUSY) {
|
||||||
if !interrupt.In() {
|
gosched()
|
||||||
gosched()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// This symbol name is known by the compiler, see monitor.go.
|
// This symbol name is known by the compiler, see monitor.go.
|
||||||
//
|
|
||||||
//go:linkname rttSerialInstance _SEGGER_RTT
|
|
||||||
var rttSerialInstance rttSerial
|
var rttSerialInstance rttSerial
|
||||||
|
|
||||||
var Serial = &rttSerialInstance
|
var Serial = &rttSerialInstance
|
||||||
|
|||||||
+1
-1
Submodule src/net updated: bb43b40f19...77be3968d1
@@ -12,6 +12,7 @@ package os
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
_ "unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DevNull = "/dev/null"
|
const DevNull = "/dev/null"
|
||||||
|
|||||||
@@ -127,11 +127,6 @@ type Method struct {
|
|||||||
Index int // index for Type.Method
|
Index int // index for Type.Method
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsExported reports whether the method is exported.
|
|
||||||
func (m Method) IsExported() bool {
|
|
||||||
return m.PkgPath == ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// The following Type type has been copied almost entirely from
|
// The following Type type has been copied almost entirely from
|
||||||
// https://github.com/golang/go/blob/go1.15/src/reflect/type.go#L27-L212.
|
// https://github.com/golang/go/blob/go1.15/src/reflect/type.go#L27-L212.
|
||||||
// Some methods have been commented out as they haven't yet been implemented.
|
// Some methods have been commented out as they haven't yet been implemented.
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ func (it *MapIter) Next() bool {
|
|||||||
return ((*reflectlite.MapIter)(it)).Next()
|
return ((*reflectlite.MapIter)(it)).Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *MapIter) Reset(v Value) {
|
func (iter *MapIter) Reset(v Value) {
|
||||||
(*reflectlite.MapIter)(it).Reset(v.Value)
|
(*reflectlite.MapIter)(iter).Reset(v.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Value) Set(x Value) {
|
func (v Value) Set(x Value) {
|
||||||
|
|||||||
@@ -30,9 +30,7 @@ func SetPanicOnFault(enabled bool) bool {
|
|||||||
|
|
||||||
func WriteHeapDump(fd uintptr)
|
func WriteHeapDump(fd uintptr)
|
||||||
|
|
||||||
// Unimplemented.
|
func SetTraceback(level string)
|
||||||
func SetTraceback(level string) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetMemoryLimit(limit int64) int64 {
|
func SetMemoryLimit(limit int64) int64 {
|
||||||
return limit
|
return limit
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
func Callers(skip int, pc []uintptr) int {
|
func Callers(skip int, pc []uintptr) int {
|
||||||
if len(pc) > 0 {
|
|
||||||
// The testing package expects at least one caller in all cases.
|
|
||||||
pc[0] = 0
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,9 +93,6 @@ func runtimePanicAt(addr unsafe.Pointer, msg string) {
|
|||||||
trap()
|
trap()
|
||||||
}
|
}
|
||||||
if hasReturnAddr {
|
if hasReturnAddr {
|
||||||
// Note: the string "panic: runtime error at " is also used in
|
|
||||||
// runtime_cortexm_hardfault.go. It is kept the same so that the string
|
|
||||||
// can be deduplicated by the compiler.
|
|
||||||
printstring("panic: runtime error at ")
|
printstring("panic: runtime error at ")
|
||||||
printptr(uintptr(addr) - callInstSize)
|
printptr(uintptr(addr) - callInstSize)
|
||||||
printstring(": ")
|
printstring(": ")
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
package runtime
|
|
||||||
|
|
||||||
import _ "unsafe"
|
|
||||||
|
|
||||||
// TODO: Use hardware when available
|
|
||||||
//
|
|
||||||
//go:linkname vgetrandom
|
|
||||||
func vgetrandom(p []byte, flags uint32) (ret int, supported bool) { return 0, false }
|
|
||||||
|
|
||||||
//go:linkname fatal crypto/internal/sysrand.fatal
|
|
||||||
func fatal(msg string) { runtimePanic(msg) }
|
|
||||||
@@ -57,12 +57,6 @@ func memzero(ptr unsafe.Pointer, size uintptr)
|
|||||||
// the current stack pointer in a platform-independent way.
|
// the current stack pointer in a platform-independent way.
|
||||||
func stacksave() unsafe.Pointer
|
func stacksave() unsafe.Pointer
|
||||||
|
|
||||||
// Special LLVM intrinsic that returns the SP register on entry to the calling
|
|
||||||
// function.
|
|
||||||
//
|
|
||||||
//export llvm.sponentry.p0
|
|
||||||
func llvm_sponentry() unsafe.Pointer
|
|
||||||
|
|
||||||
//export strlen
|
//export strlen
|
||||||
func strlen(ptr unsafe.Pointer) uintptr
|
func strlen(ptr unsafe.Pointer) uintptr
|
||||||
|
|
||||||
@@ -112,33 +106,6 @@ func UnlockOSThread() {
|
|||||||
// point of the call.
|
// point of the call.
|
||||||
func KeepAlive(x interface{})
|
func KeepAlive(x interface{})
|
||||||
|
|
||||||
// AddCleanup is a dummy cleanup implementation. It doesn't do any cleaning up.
|
|
||||||
//
|
|
||||||
// We base this on the following loophole in the official runtime.AddCleanup
|
|
||||||
// documentation:
|
|
||||||
//
|
|
||||||
// > The cleanup(arg) call is not always guaranteed to run; in particular it is
|
|
||||||
// > not guaranteed to run before program exit.
|
|
||||||
//
|
|
||||||
// So it's technically correct (the best kind of correct) to not run any
|
|
||||||
// cleanups. But of course, this can lead to resource leaks so cleanups may need
|
|
||||||
// to be implemented eventually.
|
|
||||||
func AddCleanup[T, S any](ptr *T, cleanup func(S), arg S) Cleanup {
|
|
||||||
return Cleanup{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Cleanup struct{}
|
|
||||||
|
|
||||||
func (c Cleanup) Stop() {}
|
|
||||||
|
|
||||||
//go:linkname registerWeakPointer weak.runtime_registerWeakPointer
|
|
||||||
func registerWeakPointer(ptr unsafe.Pointer) unsafe.Pointer {
|
|
||||||
// TODO: unimplemented.
|
|
||||||
// I hope not implementing this won't break anything, like packages that
|
|
||||||
// expect weak pointers to be GC'd before they actually are.
|
|
||||||
return ptr
|
|
||||||
}
|
|
||||||
|
|
||||||
var godebugUpdate func(string, string)
|
var godebugUpdate func(string, string)
|
||||||
|
|
||||||
//go:linkname godebug_setUpdate internal/godebug.setUpdate
|
//go:linkname godebug_setUpdate internal/godebug.setUpdate
|
||||||
@@ -181,19 +148,3 @@ func getAuxv() []uintptr {
|
|||||||
func cgo_errno() uintptr {
|
func cgo_errno() uintptr {
|
||||||
return uintptr(*libc_errno_location())
|
return uintptr(*libc_errno_location())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unimplemented.
|
|
||||||
var MemProfileRate int = 0
|
|
||||||
|
|
||||||
// Unimplemented.
|
|
||||||
func SetBlockProfileRate(rate int) {
|
|
||||||
}
|
|
||||||
|
|
||||||
var mutexProfileFraction int
|
|
||||||
|
|
||||||
// Unimplemented.
|
|
||||||
func SetMutexProfileFraction(rate int) int {
|
|
||||||
previous := mutexProfileFraction
|
|
||||||
mutexProfileFraction = rate
|
|
||||||
return previous
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,25 +2,39 @@
|
|||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
// This function is called at HardFault.
|
// This function is called at HardFault.
|
||||||
|
// Before this function is called, the stack pointer is reset to the initial
|
||||||
|
// stack pointer (loaded from address 0x0) and the previous stack pointer is
|
||||||
|
// passed as an argument to this function. This allows for easy inspection of
|
||||||
|
// the stack the moment a HardFault occurs, but it means that the stack will be
|
||||||
|
// corrupted by this function and thus this handler must not attempt to recover.
|
||||||
//
|
//
|
||||||
// For details, see:
|
// For details, see:
|
||||||
// https://community.arm.com/developer/ip-products/system/f/embedded-forum/3257/debugging-a-cortex-m0-hard-fault
|
// https://community.arm.com/developer/ip-products/system/f/embedded-forum/3257/debugging-a-cortex-m0-hard-fault
|
||||||
// https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/
|
// https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/
|
||||||
//
|
//
|
||||||
//export HardFault_Handler
|
//export handleHardFault
|
||||||
func HardFault_Handler() {
|
func handleHardFault(sp *interruptStack) {
|
||||||
// Obtain the stack pointer as it was on entry to the HardFault. It contains
|
print("fatal error: ")
|
||||||
// the registers that were pushed by the NVIC and that we can now read back
|
if uintptr(unsafe.Pointer(sp)) < 0x20000000 {
|
||||||
// to print the PC value at the time of the hard fault, for example.
|
print("stack overflow")
|
||||||
sp := (*interruptStack)(llvm_sponentry())
|
} else {
|
||||||
|
// TODO: try to find the cause of the hard fault. Especially on
|
||||||
// Note: by reusing the string "panic: runtime error at " we save a little
|
// Cortex-M3 and higher it is possible to find more detailed information
|
||||||
// bit in terms of code size as the string can be deduplicated.
|
// in special status registers.
|
||||||
print("panic: runtime error at ", sp.PC, ": HardFault with sp=", sp)
|
print("HardFault")
|
||||||
// TODO: try to find the cause of the hard fault. Especially on Cortex-M3
|
}
|
||||||
// and higher it is possible to find more detailed information in special
|
print(" with sp=", sp)
|
||||||
// status registers.
|
if uintptr(unsafe.Pointer(&sp.PC)) >= 0x20000000 {
|
||||||
|
// Only print the PC if it points into memory.
|
||||||
|
// It may not point into memory during a stack overflow, so check that
|
||||||
|
// first before accessing the stack.
|
||||||
|
print(" pc=", sp.PC)
|
||||||
|
}
|
||||||
println()
|
println()
|
||||||
abort()
|
abort()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,8 @@ const (
|
|||||||
|
|
||||||
// See runtime_cortexm_hardfault.go
|
// See runtime_cortexm_hardfault.go
|
||||||
//
|
//
|
||||||
//export HardFault_Handler
|
//go:export handleHardFault
|
||||||
func HardFault_Handler() {
|
func handleHardFault(sp *interruptStack) {
|
||||||
// Obtain the stack pointer as it was on entry to the HardFault. It contains
|
|
||||||
// the registers that were pushed by the NVIC and that we can now read back
|
|
||||||
// to print the PC value at the time of the hard fault, for example.
|
|
||||||
sp := (*interruptStack)(llvm_sponentry())
|
|
||||||
|
|
||||||
fault := GetFaultStatus()
|
fault := GetFaultStatus()
|
||||||
spValid := !fault.Bus().ImpreciseDataBusError()
|
spValid := !fault.Bus().ImpreciseDataBusError()
|
||||||
|
|
||||||
|
|||||||
@@ -1,380 +0,0 @@
|
|||||||
//go:build rp2040 || rp2350
|
|
||||||
|
|
||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/arm"
|
|
||||||
"device/rp"
|
|
||||||
"internal/task"
|
|
||||||
"machine"
|
|
||||||
"machine/usb/cdc"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"runtime/volatile"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const numCPU = 2
|
|
||||||
const numSpinlocks = 32
|
|
||||||
|
|
||||||
// machineTicks is provided by package machine.
|
|
||||||
func machineTicks() uint64
|
|
||||||
|
|
||||||
// machineLightSleep is provided by package machine.
|
|
||||||
func machineLightSleep(uint64)
|
|
||||||
|
|
||||||
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
|
||||||
func ticks() timeUnit {
|
|
||||||
t := machineTicks()
|
|
||||||
return timeUnit(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
|
||||||
return int64(ticks) * 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
func nanosecondsToTicks(ns int64) timeUnit {
|
|
||||||
return timeUnit(ns / 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sleepTicks(d timeUnit) {
|
|
||||||
if hasScheduler {
|
|
||||||
// With scheduler, sleepTicks may return early if an interrupt or
|
|
||||||
// event fires - so scheduler can schedule any go routines now
|
|
||||||
// eligible to run
|
|
||||||
machineLightSleep(uint64(d))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Busy loop
|
|
||||||
sleepUntil := ticks() + d
|
|
||||||
for ticks() < sleepUntil {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Currently sleeping core, or 0xff.
|
|
||||||
// Must only be accessed with the scheduler lock held.
|
|
||||||
var sleepingCore uint8 = 0xff
|
|
||||||
|
|
||||||
// Return whether another core is sleeping.
|
|
||||||
// May only be called with the scheduler lock held.
|
|
||||||
func hasSleepingCore() bool {
|
|
||||||
return sleepingCore != 0xff
|
|
||||||
}
|
|
||||||
|
|
||||||
// Almost identical to sleepTicks, except that it will unlock/lock the scheduler
|
|
||||||
// while sleeping and is interruptible by interruptSleepTicksMulticore.
|
|
||||||
// This may only be called with the scheduler lock held.
|
|
||||||
func sleepTicksMulticore(d timeUnit) {
|
|
||||||
sleepingCore = uint8(currentCPU())
|
|
||||||
|
|
||||||
// Note: interruptSleepTicksMulticore will be able to interrupt this, since
|
|
||||||
// it executes the "sev" instruction which would make sleepTicks return
|
|
||||||
// immediately without sleeping. Even if it happens while configuring the
|
|
||||||
// sleep operation.
|
|
||||||
|
|
||||||
schedulerLock.Unlock()
|
|
||||||
sleepTicks(d)
|
|
||||||
schedulerLock.Lock()
|
|
||||||
|
|
||||||
sleepingCore = 0xff
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interrupt an ongoing call to sleepTicksMulticore on another core.
|
|
||||||
func interruptSleepTicksMulticore(wakeup timeUnit) {
|
|
||||||
arm.Asm("sev")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Number of cores that are currently in schedulerUnlockAndWait.
|
|
||||||
// It is possible for both cores to be sleeping, if the program is waiting for
|
|
||||||
// an interrupt (or is deadlocked).
|
|
||||||
var waitingCore uint8
|
|
||||||
|
|
||||||
// Put the scheduler to sleep, since there are no tasks to run.
|
|
||||||
// This will unlock the scheduler lock, and must be called with the scheduler
|
|
||||||
// lock held.
|
|
||||||
func schedulerUnlockAndWait() {
|
|
||||||
waitingCore++
|
|
||||||
schedulerLock.Unlock()
|
|
||||||
arm.Asm("wfe")
|
|
||||||
schedulerLock.Lock()
|
|
||||||
waitingCore--
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wake another core, if one is sleeping. Must be called with the scheduler lock
|
|
||||||
// held.
|
|
||||||
func schedulerWake() {
|
|
||||||
if waitingCore != 0 {
|
|
||||||
arm.Asm("sev")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the current core number: 0 or 1.
|
|
||||||
func currentCPU() uint32 {
|
|
||||||
return rp.SIO.CPUID.Get()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the secondary cores for this chip.
|
|
||||||
// On the RP2040/RP2350, there is only one other core to start.
|
|
||||||
func startSecondaryCores() {
|
|
||||||
// Start the second core of the RP2040/RP2350.
|
|
||||||
// See sections 2.8.2 and 5.3 in the datasheets for RP2040 and RP2350 respectively.
|
|
||||||
seq := 0
|
|
||||||
for {
|
|
||||||
cmd := core1StartSequence[seq]
|
|
||||||
if cmd == 0 {
|
|
||||||
multicore_fifo_drain()
|
|
||||||
arm.Asm("sev")
|
|
||||||
}
|
|
||||||
multicore_fifo_push_blocking(cmd)
|
|
||||||
response := multicore_fifo_pop_blocking()
|
|
||||||
if cmd != response {
|
|
||||||
seq = 0
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
seq = seq + 1
|
|
||||||
if seq >= len(core1StartSequence) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable the FIFO interrupt for the GC stop the world phase.
|
|
||||||
// We can only do this after we don't need the FIFO anymore for starting the
|
|
||||||
// second core.
|
|
||||||
intr := interrupt.New(sioIrqFifoProc0, func(intr interrupt.Interrupt) {
|
|
||||||
switch rp.SIO.FIFO_RD.Get() {
|
|
||||||
case 1:
|
|
||||||
gcInterruptHandler(0)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
intr.Enable()
|
|
||||||
intr.SetPriority(0xff)
|
|
||||||
}
|
|
||||||
|
|
||||||
var core1StartSequence = [...]uint32{
|
|
||||||
0, 0, 1,
|
|
||||||
uint32(uintptr(unsafe.Pointer(&__isr_vector))),
|
|
||||||
uint32(uintptr(unsafe.Pointer(&stack1TopSymbol))),
|
|
||||||
uint32(exportedFuncPtr(runCore1)),
|
|
||||||
}
|
|
||||||
|
|
||||||
//go:extern __isr_vector
|
|
||||||
var __isr_vector [0]uint32
|
|
||||||
|
|
||||||
//go:extern _stack1_top
|
|
||||||
var stack1TopSymbol [0]uint32
|
|
||||||
|
|
||||||
// The function that is started on the second core.
|
|
||||||
//
|
|
||||||
//export tinygo_runCore1
|
|
||||||
func runCore1() {
|
|
||||||
// Clear sticky bit that seems to have been set while starting this core.
|
|
||||||
rp.SIO.FIFO_ST.Set(rp.SIO_FIFO_ST_ROE)
|
|
||||||
|
|
||||||
// Enable the FIFO interrupt, mainly used for the stop-the-world phase of
|
|
||||||
// the GC.
|
|
||||||
// Use the lowest possible priority (highest priority value), so that other
|
|
||||||
// interrupts can still happen while the GC is running.
|
|
||||||
intr := interrupt.New(sioIrqFifoProc1, func(intr interrupt.Interrupt) {
|
|
||||||
switch rp.SIO.FIFO_RD.Get() {
|
|
||||||
case 1:
|
|
||||||
gcInterruptHandler(1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
intr.Enable()
|
|
||||||
intr.SetPriority(0xff)
|
|
||||||
|
|
||||||
// Now start running the scheduler on this core.
|
|
||||||
schedulerLock.Lock()
|
|
||||||
scheduler(false)
|
|
||||||
schedulerLock.Unlock()
|
|
||||||
|
|
||||||
// The main function returned.
|
|
||||||
exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The below multicore_fifo_* functions have been translated from the Raspberry
|
|
||||||
// Pi Pico SDK.
|
|
||||||
|
|
||||||
func multicore_fifo_rvalid() bool {
|
|
||||||
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_VLD != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func multicore_fifo_wready() bool {
|
|
||||||
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_RDY != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func multicore_fifo_drain() {
|
|
||||||
for multicore_fifo_rvalid() {
|
|
||||||
rp.SIO.FIFO_RD.Get()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func multicore_fifo_push_blocking(data uint32) {
|
|
||||||
for !multicore_fifo_wready() {
|
|
||||||
}
|
|
||||||
rp.SIO.FIFO_WR.Set(data)
|
|
||||||
arm.Asm("sev")
|
|
||||||
}
|
|
||||||
|
|
||||||
func multicore_fifo_pop_blocking() uint32 {
|
|
||||||
for !multicore_fifo_rvalid() {
|
|
||||||
arm.Asm("wfe")
|
|
||||||
}
|
|
||||||
|
|
||||||
return rp.SIO.FIFO_RD.Get()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value used to communicate between the GC core and the other (paused) cores.
|
|
||||||
var gcSignalWait volatile.Register8
|
|
||||||
|
|
||||||
// The GC interrupted this core for the stop-the-world phase.
|
|
||||||
// This function handles that, and only returns after the stop-the-world phase
|
|
||||||
// ended.
|
|
||||||
func gcInterruptHandler(hartID uint32) {
|
|
||||||
// Let the GC know we're ready.
|
|
||||||
gcScanState.Add(1)
|
|
||||||
arm.Asm("sev")
|
|
||||||
|
|
||||||
// Wait until we get a signal to start scanning.
|
|
||||||
for gcSignalWait.Get() == 0 {
|
|
||||||
arm.Asm("wfe")
|
|
||||||
}
|
|
||||||
gcSignalWait.Set(0)
|
|
||||||
|
|
||||||
// Scan the stack(s) of this core.
|
|
||||||
scanCurrentStack()
|
|
||||||
if !task.OnSystemStack() {
|
|
||||||
// Mark system stack.
|
|
||||||
markRoots(task.SystemStack(), coreStackTop(hartID))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Signal we've finished scanning.
|
|
||||||
gcScanState.Store(1)
|
|
||||||
arm.Asm("sev")
|
|
||||||
|
|
||||||
// Wait until we get a signal that the stop-the-world phase has ended.
|
|
||||||
for gcSignalWait.Get() == 0 {
|
|
||||||
arm.Asm("wfe")
|
|
||||||
}
|
|
||||||
gcSignalWait.Set(0)
|
|
||||||
|
|
||||||
// Signal we received the signal and are going to exit the interrupt.
|
|
||||||
gcScanState.Add(1)
|
|
||||||
arm.Asm("sev")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pause the given core by sending it an interrupt.
|
|
||||||
func gcPauseCore(core uint32) {
|
|
||||||
rp.SIO.FIFO_WR.Set(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Signal the given core that it can resume one step.
|
|
||||||
// This is called twice after gcPauseCore: the first time to scan the stack of
|
|
||||||
// the core, and the second time to end the stop-the-world phase.
|
|
||||||
func gcSignalCore(core uint32) {
|
|
||||||
gcSignalWait.Set(1)
|
|
||||||
arm.Asm("sev")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the stack top (highest address) of the system stack of the given
|
|
||||||
// core.
|
|
||||||
func coreStackTop(core uint32) uintptr {
|
|
||||||
switch core {
|
|
||||||
case 0:
|
|
||||||
return uintptr(unsafe.Pointer(&stackTopSymbol))
|
|
||||||
case 1:
|
|
||||||
return uintptr(unsafe.Pointer(&stack1TopSymbol))
|
|
||||||
default:
|
|
||||||
runtimePanic("unexpected core")
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// These spinlocks are needed by the runtime.
|
|
||||||
var (
|
|
||||||
printLock = spinLock{id: 20}
|
|
||||||
schedulerLock = spinLock{id: 21}
|
|
||||||
atomicsLock = spinLock{id: 22}
|
|
||||||
futexLock = spinLock{id: 23}
|
|
||||||
)
|
|
||||||
|
|
||||||
func resetSpinLocks() {
|
|
||||||
for i := uint8(0); i < numSpinlocks; i++ {
|
|
||||||
l := &spinLock{id: i}
|
|
||||||
l.spinlock().Set(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral.
|
|
||||||
type spinLock struct {
|
|
||||||
id uint8
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the spinlock register: rp.SIO.SPINLOCKx
|
|
||||||
func (l *spinLock) spinlock() *volatile.Register32 {
|
|
||||||
return (*volatile.Register32)(unsafe.Add(unsafe.Pointer(&rp.SIO.SPINLOCK0), l.id*4))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *spinLock) Lock() {
|
|
||||||
// Wait for the lock to be available.
|
|
||||||
spinlock := l.spinlock()
|
|
||||||
for spinlock.Get() == 0 {
|
|
||||||
arm.Asm("wfe")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *spinLock) Unlock() {
|
|
||||||
l.spinlock().Set(0)
|
|
||||||
arm.Asm("sev")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait until a signal is received, indicating that it can resume from the
|
|
||||||
// spinloop.
|
|
||||||
func spinLoopWait() {
|
|
||||||
arm.Asm("wfe")
|
|
||||||
}
|
|
||||||
|
|
||||||
func waitForEvents() {
|
|
||||||
arm.Asm("wfe")
|
|
||||||
}
|
|
||||||
|
|
||||||
func putchar(c byte) {
|
|
||||||
machine.Serial.WriteByte(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getchar() byte {
|
|
||||||
for machine.Serial.Buffered() == 0 {
|
|
||||||
Gosched()
|
|
||||||
}
|
|
||||||
v, _ := machine.Serial.ReadByte()
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func buffered() int {
|
|
||||||
return machine.Serial.Buffered()
|
|
||||||
}
|
|
||||||
|
|
||||||
// machineInit is provided by package machine.
|
|
||||||
func machineInit()
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machineInit()
|
|
||||||
|
|
||||||
cdc.EnableUSBCDC()
|
|
||||||
machine.USBDev.Configure(machine.UARTConfig{})
|
|
||||||
machine.InitSerial()
|
|
||||||
}
|
|
||||||
|
|
||||||
func prerun() {
|
|
||||||
// Reset spinlocks before the full machineInit() so the scheduler doesn't
|
|
||||||
// hang waiting for schedulerLock after a soft reset.
|
|
||||||
resetSpinLocks()
|
|
||||||
}
|
|
||||||
|
|
||||||
//export Reset_Handler
|
|
||||||
func main() {
|
|
||||||
preinit()
|
|
||||||
prerun()
|
|
||||||
run()
|
|
||||||
exit(0)
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,365 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"device/arm"
|
||||||
"device/rp"
|
"device/rp"
|
||||||
|
"internal/task"
|
||||||
|
"machine"
|
||||||
|
"machine/usb/cdc"
|
||||||
|
"runtime/interrupt"
|
||||||
|
"runtime/volatile"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const numCPU = 2
|
||||||
sioIrqFifoProc0 = rp.IRQ_SIO_IRQ_PROC0
|
|
||||||
sioIrqFifoProc1 = rp.IRQ_SIO_IRQ_PROC1
|
// machineTicks is provided by package machine.
|
||||||
|
func machineTicks() uint64
|
||||||
|
|
||||||
|
// machineLightSleep is provided by package machine.
|
||||||
|
func machineLightSleep(uint64)
|
||||||
|
|
||||||
|
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
||||||
|
func ticks() timeUnit {
|
||||||
|
t := machineTicks()
|
||||||
|
return timeUnit(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||||
|
return int64(ticks) * 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func nanosecondsToTicks(ns int64) timeUnit {
|
||||||
|
return timeUnit(ns / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sleepTicks(d timeUnit) {
|
||||||
|
if hasScheduler {
|
||||||
|
// With scheduler, sleepTicks may return early if an interrupt or
|
||||||
|
// event fires - so scheduler can schedule any go routines now
|
||||||
|
// eligible to run
|
||||||
|
machineLightSleep(uint64(d))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Busy loop
|
||||||
|
sleepUntil := ticks() + d
|
||||||
|
for ticks() < sleepUntil {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currently sleeping core, or 0xff.
|
||||||
|
// Must only be accessed with the scheduler lock held.
|
||||||
|
var sleepingCore uint8 = 0xff
|
||||||
|
|
||||||
|
// Return whether another core is sleeping.
|
||||||
|
// May only be called with the scheduler lock held.
|
||||||
|
func hasSleepingCore() bool {
|
||||||
|
return sleepingCore != 0xff
|
||||||
|
}
|
||||||
|
|
||||||
|
// Almost identical to sleepTicks, except that it will unlock/lock the scheduler
|
||||||
|
// while sleeping and is interruptible by interruptSleepTicksMulticore.
|
||||||
|
// This may only be called with the scheduler lock held.
|
||||||
|
func sleepTicksMulticore(d timeUnit) {
|
||||||
|
sleepingCore = uint8(currentCPU())
|
||||||
|
|
||||||
|
// Note: interruptSleepTicksMulticore will be able to interrupt this, since
|
||||||
|
// it executes the "sev" instruction which would make sleepTicks return
|
||||||
|
// immediately without sleeping. Even if it happens while configuring the
|
||||||
|
// sleep operation.
|
||||||
|
|
||||||
|
schedulerLock.Unlock()
|
||||||
|
sleepTicks(d)
|
||||||
|
schedulerLock.Lock()
|
||||||
|
|
||||||
|
sleepingCore = 0xff
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interrupt an ongoing call to sleepTicksMulticore on another core.
|
||||||
|
func interruptSleepTicksMulticore(wakeup timeUnit) {
|
||||||
|
arm.Asm("sev")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Number of cores that are currently in schedulerUnlockAndWait.
|
||||||
|
// It is possible for both cores to be sleeping, if the program is waiting for
|
||||||
|
// an interrupt (or is deadlocked).
|
||||||
|
var waitingCore uint8
|
||||||
|
|
||||||
|
// Put the scheduler to sleep, since there are no tasks to run.
|
||||||
|
// This will unlock the scheduler lock, and must be called with the scheduler
|
||||||
|
// lock held.
|
||||||
|
func schedulerUnlockAndWait() {
|
||||||
|
waitingCore++
|
||||||
|
schedulerLock.Unlock()
|
||||||
|
arm.Asm("wfe")
|
||||||
|
schedulerLock.Lock()
|
||||||
|
waitingCore--
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wake another core, if one is sleeping. Must be called with the scheduler lock
|
||||||
|
// held.
|
||||||
|
func schedulerWake() {
|
||||||
|
if waitingCore != 0 {
|
||||||
|
arm.Asm("sev")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the current core number: 0 or 1.
|
||||||
|
func currentCPU() uint32 {
|
||||||
|
return rp.SIO.CPUID.Get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the secondary cores for this chip.
|
||||||
|
// On the RP2040, there is only one other core to start.
|
||||||
|
func startSecondaryCores() {
|
||||||
|
// Start the second core of the RP2040.
|
||||||
|
// See section 2.8.2 in the datasheet.
|
||||||
|
seq := 0
|
||||||
|
for {
|
||||||
|
cmd := core1StartSequence[seq]
|
||||||
|
if cmd == 0 {
|
||||||
|
multicore_fifo_drain()
|
||||||
|
arm.Asm("sev")
|
||||||
|
}
|
||||||
|
multicore_fifo_push_blocking(cmd)
|
||||||
|
response := multicore_fifo_pop_blocking()
|
||||||
|
if cmd != response {
|
||||||
|
seq = 0
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seq = seq + 1
|
||||||
|
if seq >= len(core1StartSequence) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable the FIFO interrupt for the GC stop the world phase.
|
||||||
|
// We can only do this after we don't need the FIFO anymore for starting the
|
||||||
|
// second core.
|
||||||
|
intr := interrupt.New(rp.IRQ_SIO_IRQ_PROC0, func(intr interrupt.Interrupt) {
|
||||||
|
switch rp.SIO.FIFO_RD.Get() {
|
||||||
|
case 1:
|
||||||
|
gcInterruptHandler(0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
intr.Enable()
|
||||||
|
intr.SetPriority(0xff)
|
||||||
|
}
|
||||||
|
|
||||||
|
var core1StartSequence = [...]uint32{
|
||||||
|
0, 0, 1,
|
||||||
|
uint32(uintptr(unsafe.Pointer(&__isr_vector))),
|
||||||
|
uint32(uintptr(unsafe.Pointer(&stack1TopSymbol))),
|
||||||
|
uint32(exportedFuncPtr(runCore1)),
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:extern __isr_vector
|
||||||
|
var __isr_vector [0]uint32
|
||||||
|
|
||||||
|
//go:extern _stack1_top
|
||||||
|
var stack1TopSymbol [0]uint32
|
||||||
|
|
||||||
|
// The function that is started on the second core.
|
||||||
|
//
|
||||||
|
//export tinygo_runCore1
|
||||||
|
func runCore1() {
|
||||||
|
// Clear sticky bit that seems to have been set while starting this core.
|
||||||
|
rp.SIO.FIFO_ST.Set(rp.SIO_FIFO_ST_ROE)
|
||||||
|
|
||||||
|
// Enable the FIFO interrupt, mainly used for the stop-the-world phase of
|
||||||
|
// the GC.
|
||||||
|
// Use the lowest possible priority (highest priority value), so that other
|
||||||
|
// interrupts can still happen while the GC is running.
|
||||||
|
intr := interrupt.New(rp.IRQ_SIO_IRQ_PROC1, func(intr interrupt.Interrupt) {
|
||||||
|
switch rp.SIO.FIFO_RD.Get() {
|
||||||
|
case 1:
|
||||||
|
gcInterruptHandler(1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
intr.Enable()
|
||||||
|
intr.SetPriority(0xff)
|
||||||
|
|
||||||
|
// Now start running the scheduler on this core.
|
||||||
|
schedulerLock.Lock()
|
||||||
|
scheduler(false)
|
||||||
|
schedulerLock.Unlock()
|
||||||
|
|
||||||
|
// The main function returned.
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The below multicore_fifo_* functions have been translated from the Raspberry
|
||||||
|
// Pi Pico SDK.
|
||||||
|
|
||||||
|
func multicore_fifo_rvalid() bool {
|
||||||
|
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_VLD != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func multicore_fifo_wready() bool {
|
||||||
|
return rp.SIO.FIFO_ST.Get()&rp.SIO_FIFO_ST_RDY != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func multicore_fifo_drain() {
|
||||||
|
for multicore_fifo_rvalid() {
|
||||||
|
rp.SIO.FIFO_RD.Get()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func multicore_fifo_push_blocking(data uint32) {
|
||||||
|
for !multicore_fifo_wready() {
|
||||||
|
}
|
||||||
|
rp.SIO.FIFO_WR.Set(data)
|
||||||
|
arm.Asm("sev")
|
||||||
|
}
|
||||||
|
|
||||||
|
func multicore_fifo_pop_blocking() uint32 {
|
||||||
|
for !multicore_fifo_rvalid() {
|
||||||
|
arm.Asm("wfe")
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp.SIO.FIFO_RD.Get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value used to communicate between the GC core and the other (paused) cores.
|
||||||
|
var gcSignalWait volatile.Register8
|
||||||
|
|
||||||
|
// The GC interrupted this core for the stop-the-world phase.
|
||||||
|
// This function handles that, and only returns after the stop-the-world phase
|
||||||
|
// ended.
|
||||||
|
func gcInterruptHandler(hartID uint32) {
|
||||||
|
// Let the GC know we're ready.
|
||||||
|
gcScanState.Add(1)
|
||||||
|
arm.Asm("sev")
|
||||||
|
|
||||||
|
// Wait until we get a signal to start scanning.
|
||||||
|
for gcSignalWait.Get() == 0 {
|
||||||
|
arm.Asm("wfe")
|
||||||
|
}
|
||||||
|
gcSignalWait.Set(0)
|
||||||
|
|
||||||
|
// Scan the stack(s) of this core.
|
||||||
|
scanCurrentStack()
|
||||||
|
if !task.OnSystemStack() {
|
||||||
|
// Mark system stack.
|
||||||
|
markRoots(task.SystemStack(), coreStackTop(hartID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signal we've finished scanning.
|
||||||
|
gcScanState.Store(1)
|
||||||
|
arm.Asm("sev")
|
||||||
|
|
||||||
|
// Wait until we get a signal that the stop-the-world phase has ended.
|
||||||
|
for gcSignalWait.Get() == 0 {
|
||||||
|
arm.Asm("wfe")
|
||||||
|
}
|
||||||
|
gcSignalWait.Set(0)
|
||||||
|
|
||||||
|
// Signal we received the signal and are going to exit the interrupt.
|
||||||
|
gcScanState.Add(1)
|
||||||
|
arm.Asm("sev")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause the given core by sending it an interrupt.
|
||||||
|
func gcPauseCore(core uint32) {
|
||||||
|
rp.SIO.FIFO_WR.Set(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signal the given core that it can resume one step.
|
||||||
|
// This is called twice after gcPauseCore: the first time to scan the stack of
|
||||||
|
// the core, and the second time to end the stop-the-world phase.
|
||||||
|
func gcSignalCore(core uint32) {
|
||||||
|
gcSignalWait.Set(1)
|
||||||
|
arm.Asm("sev")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the stack top (highest address) of the system stack of the given
|
||||||
|
// core.
|
||||||
|
func coreStackTop(core uint32) uintptr {
|
||||||
|
switch core {
|
||||||
|
case 0:
|
||||||
|
return uintptr(unsafe.Pointer(&stackTopSymbol))
|
||||||
|
case 1:
|
||||||
|
return uintptr(unsafe.Pointer(&stack1TopSymbol))
|
||||||
|
default:
|
||||||
|
runtimePanic("unexpected core")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// These spinlocks are needed by the runtime.
|
||||||
|
var (
|
||||||
|
printLock = spinLock{id: 0}
|
||||||
|
schedulerLock = spinLock{id: 1}
|
||||||
|
atomicsLock = spinLock{id: 2}
|
||||||
|
futexLock = spinLock{id: 3}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A hardware spinlock, one of the 32 spinlocks defined in the SIO peripheral.
|
||||||
|
type spinLock struct {
|
||||||
|
id uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the spinlock register: rp.SIO.SPINLOCKx
|
||||||
|
func (l *spinLock) spinlock() *volatile.Register32 {
|
||||||
|
return (*volatile.Register32)(unsafe.Add(unsafe.Pointer(&rp.SIO.SPINLOCK0), l.id*4))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *spinLock) Lock() {
|
||||||
|
// Wait for the lock to be available.
|
||||||
|
spinlock := l.spinlock()
|
||||||
|
for spinlock.Get() == 0 {
|
||||||
|
// TODO: use wfe and send an event when unlocking so the CPU can go to
|
||||||
|
// sleep while waiting for the lock.
|
||||||
|
// Unfortunately when doing that, time.Sleep() seems to hang somewhere.
|
||||||
|
// This needs some debugging to figure out.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *spinLock) Unlock() {
|
||||||
|
l.spinlock().Set(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait until a signal is received, indicating that it can resume from the
|
||||||
|
// spinloop.
|
||||||
|
func spinLoopWait() {
|
||||||
|
arm.Asm("wfe")
|
||||||
|
}
|
||||||
|
|
||||||
|
func waitForEvents() {
|
||||||
|
arm.Asm("wfe")
|
||||||
|
}
|
||||||
|
|
||||||
|
func putchar(c byte) {
|
||||||
|
machine.Serial.WriteByte(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getchar() byte {
|
||||||
|
for machine.Serial.Buffered() == 0 {
|
||||||
|
Gosched()
|
||||||
|
}
|
||||||
|
v, _ := machine.Serial.ReadByte()
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func buffered() int {
|
||||||
|
return machine.Serial.Buffered()
|
||||||
|
}
|
||||||
|
|
||||||
|
// machineInit is provided by package machine.
|
||||||
|
func machineInit()
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
machineInit()
|
||||||
|
|
||||||
|
cdc.EnableUSBCDC()
|
||||||
|
machine.USBDev.Configure(machine.UARTConfig{})
|
||||||
|
machine.InitSerial()
|
||||||
|
}
|
||||||
|
|
||||||
|
//export Reset_Handler
|
||||||
|
func main() {
|
||||||
|
preinit()
|
||||||
|
run()
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,14 +3,84 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"device/rp"
|
"device/arm"
|
||||||
|
"machine"
|
||||||
|
"machine/usb/cdc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// machineTicks is provided by package machine.
|
||||||
// On RP2040 each core has a different IRQ number: SIO_IRQ_PROC0 and SIO_IRQ_PROC1.
|
func machineTicks() uint64
|
||||||
// On RP2350 both cores share the same irq number (SIO_IRQ_PROC) just with a
|
|
||||||
// different SIO interrupt output routed to that IRQ input on each core.
|
// machineLightSleep is provided by package machine.
|
||||||
// https://www.raspberrypi.com/documentation/pico-sdk/high_level.html#group_pico_multicore_1ga1413ebfa65114c6f408f4675897ac5ee
|
func machineLightSleep(uint64)
|
||||||
sioIrqFifoProc0 = rp.IRQ_SIO_IRQ_FIFO
|
|
||||||
sioIrqFifoProc1 = rp.IRQ_SIO_IRQ_FIFO
|
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
||||||
)
|
func ticks() timeUnit {
|
||||||
|
t := machineTicks()
|
||||||
|
return timeUnit(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||||
|
return int64(ticks) * 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func nanosecondsToTicks(ns int64) timeUnit {
|
||||||
|
return timeUnit(ns / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sleepTicks(d timeUnit) {
|
||||||
|
if d <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasScheduler {
|
||||||
|
// With scheduler, sleepTicks may return early if an interrupt or
|
||||||
|
// event fires - so scheduler can schedule any go routines now
|
||||||
|
// eligible to run
|
||||||
|
machineLightSleep(uint64(d))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Busy loop
|
||||||
|
sleepUntil := ticks() + d
|
||||||
|
for ticks() < sleepUntil {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func waitForEvents() {
|
||||||
|
arm.Asm("wfe")
|
||||||
|
}
|
||||||
|
|
||||||
|
func putchar(c byte) {
|
||||||
|
machine.Serial.WriteByte(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getchar() byte {
|
||||||
|
for machine.Serial.Buffered() == 0 {
|
||||||
|
Gosched()
|
||||||
|
}
|
||||||
|
v, _ := machine.Serial.ReadByte()
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func buffered() int {
|
||||||
|
return machine.Serial.Buffered()
|
||||||
|
}
|
||||||
|
|
||||||
|
// machineInit is provided by package machine.
|
||||||
|
func machineInit()
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
machineInit()
|
||||||
|
|
||||||
|
cdc.EnableUSBCDC()
|
||||||
|
machine.USBDev.Configure(machine.UARTConfig{})
|
||||||
|
machine.InitSerial()
|
||||||
|
}
|
||||||
|
|
||||||
|
//export Reset_Handler
|
||||||
|
func main() {
|
||||||
|
preinit()
|
||||||
|
run()
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ func addSleepTask(t *task.Task, duration timeUnit) {
|
|||||||
panic("runtime: addSleepTask: expected next task to be nil")
|
panic("runtime: addSleepTask: expected next task to be nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
t.Data = uint64(duration)
|
||||||
now := ticks()
|
now := ticks()
|
||||||
if sleepQueue == nil {
|
if sleepQueue == nil {
|
||||||
scheduleLog(" -> sleep new queue")
|
scheduleLog(" -> sleep new queue")
|
||||||
@@ -84,7 +85,6 @@ func addSleepTask(t *task.Task, duration timeUnit) {
|
|||||||
// set new base time
|
// set new base time
|
||||||
sleepQueueBaseTime = now
|
sleepQueueBaseTime = now
|
||||||
}
|
}
|
||||||
t.Data = uint64(duration + (now - sleepQueueBaseTime))
|
|
||||||
|
|
||||||
// Add to sleep queue.
|
// Add to sleep queue.
|
||||||
q := &sleepQueue
|
q := &sleepQueue
|
||||||
|
|||||||
@@ -46,9 +46,3 @@ func timerCallback(tn *timerNode, delta int64) {
|
|||||||
addTimer(tn)
|
addTimer(tn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:linkname time_runtimeIsBubbled time.runtimeIsBubbled
|
|
||||||
func time_runtimeIsBubbled() bool {
|
|
||||||
// We don't currently support bubbles.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -70,15 +70,3 @@ func (m *Map) Range(f func(key, value interface{}) bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap replaces the value for the given key, and returns the old value if any.
|
|
||||||
func (m *Map) Swap(key, value any) (previous any, loaded bool) {
|
|
||||||
m.lock.Lock()
|
|
||||||
defer m.lock.Unlock()
|
|
||||||
if m.m == nil {
|
|
||||||
m.m = make(map[interface{}]interface{})
|
|
||||||
}
|
|
||||||
previous, loaded = m.m[key]
|
|
||||||
m.m[key] = value
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,22 +17,3 @@ func TestMapLoadAndDelete(t *testing.T) {
|
|||||||
t.Errorf("LoadAndDelete returned %v, %v, want nil, false", v, ok)
|
t.Errorf("LoadAndDelete returned %v, %v, want nil, false", v, ok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMapSwap(t *testing.T) {
|
|
||||||
var sm sync.Map
|
|
||||||
sm.Store("present", "value")
|
|
||||||
|
|
||||||
if v, ok := sm.Swap("present", "value2"); !ok || v != "value" {
|
|
||||||
t.Errorf("Swap returned %v, %v, want value, true", v, ok)
|
|
||||||
}
|
|
||||||
if v, ok := sm.Load("present"); !ok || v != "value2" {
|
|
||||||
t.Errorf("Load after Swap returned %v, %v, want value2, true", v, ok)
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := sm.Swap("new", "foo"); ok || v != nil {
|
|
||||||
t.Errorf("Swap returned %v, %v, want nil, false", v, ok)
|
|
||||||
}
|
|
||||||
if v, ok := sm.Load("present"); !ok || v != "value2" {
|
|
||||||
t.Errorf("Load after Swap returned %v, %v, want foo, true", v, ok)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ type RWMutex struct {
|
|||||||
|
|
||||||
const rwMutexMaxReaders = 1 << 30
|
const rwMutexMaxReaders = 1 << 30
|
||||||
|
|
||||||
// Lock locks rw for writing.
|
|
||||||
// If the lock is already locked for reading or writing,
|
|
||||||
// Lock blocks until the lock is available.
|
|
||||||
func (rw *RWMutex) Lock() {
|
func (rw *RWMutex) Lock() {
|
||||||
// Exclusive lock for writers.
|
// Exclusive lock for writers.
|
||||||
rw.writerLock.Lock()
|
rw.writerLock.Lock()
|
||||||
@@ -59,12 +56,6 @@ func (rw *RWMutex) Lock() {
|
|||||||
rw.writer.Store(0)
|
rw.writer.Store(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock unlocks rw for writing. It is a run-time error if rw is
|
|
||||||
// not locked for writing on entry to Unlock.
|
|
||||||
//
|
|
||||||
// As with Mutexes, a locked [RWMutex] is not associated with a particular
|
|
||||||
// goroutine. One goroutine may [RWMutex.RLock] ([RWMutex.Lock]) a RWMutex and then
|
|
||||||
// arrange for another goroutine to [RWMutex.RUnlock] ([RWMutex.Unlock]) it.
|
|
||||||
func (rw *RWMutex) Unlock() {
|
func (rw *RWMutex) Unlock() {
|
||||||
// Signal that new readers can lock this mutex.
|
// Signal that new readers can lock this mutex.
|
||||||
waiting := rw.readers.Add(rwMutexMaxReaders)
|
waiting := rw.readers.Add(rwMutexMaxReaders)
|
||||||
@@ -77,31 +68,6 @@ func (rw *RWMutex) Unlock() {
|
|||||||
rw.writerLock.Unlock()
|
rw.writerLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryLock tries to lock m and reports whether it succeeded.
|
|
||||||
//
|
|
||||||
// Note that while correct uses of TryLock do exist, they are rare,
|
|
||||||
// and use of TryLock is often a sign of a deeper problem
|
|
||||||
// in a particular use of mutexes.
|
|
||||||
func (rw *RWMutex) TryLock() bool {
|
|
||||||
// Check for active writers
|
|
||||||
if !rw.writerLock.TryLock() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// Have write lock, now check for active readers
|
|
||||||
n := uint32(rwMutexMaxReaders)
|
|
||||||
if !rw.readers.CompareAndSwap(0, -n) {
|
|
||||||
// Active readers, give up write lock
|
|
||||||
rw.writerLock.Unlock()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// RLock locks rw for reading.
|
|
||||||
//
|
|
||||||
// It should not be used for recursive read locking; a blocked Lock
|
|
||||||
// call excludes new readers from acquiring the lock. See the
|
|
||||||
// documentation on the [RWMutex] type.
|
|
||||||
func (rw *RWMutex) RLock() {
|
func (rw *RWMutex) RLock() {
|
||||||
// Add us as a reader.
|
// Add us as a reader.
|
||||||
newVal := rw.readers.Add(1)
|
newVal := rw.readers.Add(1)
|
||||||
@@ -113,10 +79,6 @@ func (rw *RWMutex) RLock() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RUnlock undoes a single [RWMutex.RLock] call;
|
|
||||||
// it does not affect other simultaneous readers.
|
|
||||||
// It is a run-time error if rw is not locked for reading
|
|
||||||
// on entry to RUnlock.
|
|
||||||
func (rw *RWMutex) RUnlock() {
|
func (rw *RWMutex) RUnlock() {
|
||||||
// Remove us as a reader.
|
// Remove us as a reader.
|
||||||
one := uint32(1)
|
one := uint32(1)
|
||||||
@@ -136,25 +98,6 @@ func (rw *RWMutex) RUnlock() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryRLock tries to lock rw for reading and reports whether it succeeded.
|
|
||||||
//
|
|
||||||
// Note that while correct uses of TryRLock do exist, they are rare,
|
|
||||||
// and use of TryRLock is often a sign of a deeper problem
|
|
||||||
// in a particular use of mutexes.
|
|
||||||
func (rw *RWMutex) TryRLock() bool {
|
|
||||||
for {
|
|
||||||
c := rw.readers.Load()
|
|
||||||
if c < 0 {
|
|
||||||
// There is a writer waiting or writing.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if rw.readers.CompareAndSwap(c, c+1) {
|
|
||||||
// Read lock obtained.
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Locker interface {
|
type Locker interface {
|
||||||
Lock()
|
Lock()
|
||||||
Unlock()
|
Unlock()
|
||||||
|
|||||||
+1
-29
@@ -7,13 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mutex interface {
|
func HammerMutex(m *sync.Mutex, loops int, cdone chan bool) {
|
||||||
Lock()
|
|
||||||
Unlock()
|
|
||||||
TryLock() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func HammerMutex(m mutex, loops int, cdone chan bool) {
|
|
||||||
for i := 0; i < loops; i++ {
|
for i := 0; i < loops; i++ {
|
||||||
if i%3 == 0 {
|
if i%3 == 0 {
|
||||||
if m.TryLock() {
|
if m.TryLock() {
|
||||||
@@ -246,25 +240,3 @@ func TestRWMutexReadToWrite(t *testing.T) {
|
|||||||
t.Errorf("write lock acquired while %d readers were active", res)
|
t.Errorf("write lock acquired while %d readers were active", res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRWMutex(t *testing.T) {
|
|
||||||
m := new(sync.RWMutex)
|
|
||||||
|
|
||||||
m.Lock()
|
|
||||||
if m.TryLock() {
|
|
||||||
t.Fatalf("TryLock succeeded with mutex locked")
|
|
||||||
}
|
|
||||||
m.Unlock()
|
|
||||||
if !m.TryLock() {
|
|
||||||
t.Fatalf("TryLock failed with mutex unlocked")
|
|
||||||
}
|
|
||||||
m.Unlock()
|
|
||||||
|
|
||||||
c := make(chan bool)
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
go HammerMutex(m, 1000, c)
|
|
||||||
}
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
<-c
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,517 @@
|
|||||||
|
// Copyright 2009 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.
|
||||||
|
//
|
||||||
|
// This file has been modified for use by the TinyGo compiler.
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func initBenchmarkFlags() {
|
||||||
|
matchBenchmarks = flag.String("test.bench", "", "run only benchmarks matching `regexp`")
|
||||||
|
benchmarkMemory = flag.Bool("test.benchmem", false, "print memory allocations for benchmarks")
|
||||||
|
flag.Var(&benchTime, "test.benchtime", "run each benchmark for duration `d`")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
matchBenchmarks *string
|
||||||
|
benchmarkMemory *bool
|
||||||
|
benchTime = benchTimeFlag{d: 1 * time.Second} // changed during test of testing package
|
||||||
|
)
|
||||||
|
|
||||||
|
type benchTimeFlag struct {
|
||||||
|
d time.Duration
|
||||||
|
n int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *benchTimeFlag) String() string {
|
||||||
|
if f.n > 0 {
|
||||||
|
return fmt.Sprintf("%dx", f.n)
|
||||||
|
}
|
||||||
|
return time.Duration(f.d).String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *benchTimeFlag) Set(s string) error {
|
||||||
|
if strings.HasSuffix(s, "x") {
|
||||||
|
n, err := strconv.ParseInt(s[:len(s)-1], 10, 0)
|
||||||
|
if err != nil || n <= 0 {
|
||||||
|
return fmt.Errorf("invalid count")
|
||||||
|
}
|
||||||
|
*f = benchTimeFlag{n: int(n)}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
d, err := time.ParseDuration(s)
|
||||||
|
if err != nil || d <= 0 {
|
||||||
|
return fmt.Errorf("invalid duration")
|
||||||
|
}
|
||||||
|
*f = benchTimeFlag{d: d}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// InternalBenchmark is an internal type but exported because it is cross-package;
|
||||||
|
// it is part of the implementation of the "go test" command.
|
||||||
|
type InternalBenchmark struct {
|
||||||
|
Name string
|
||||||
|
F func(b *B)
|
||||||
|
}
|
||||||
|
|
||||||
|
// B is a type passed to Benchmark functions to manage benchmark
|
||||||
|
// timing and to specify the number of iterations to run.
|
||||||
|
//
|
||||||
|
// A benchmark ends when its Benchmark function returns or calls any of the methods
|
||||||
|
// FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods must be called
|
||||||
|
// only from the goroutine running the Benchmark function.
|
||||||
|
// The other reporting methods, such as the variations of Log and Error,
|
||||||
|
// may be called simultaneously from multiple goroutines.
|
||||||
|
//
|
||||||
|
// Like in tests, benchmark logs are accumulated during execution
|
||||||
|
// and dumped to standard output when done. Unlike in tests, benchmark logs
|
||||||
|
// are always printed, so as not to hide output whose existence may be
|
||||||
|
// affecting benchmark results.
|
||||||
|
type B struct {
|
||||||
|
common
|
||||||
|
context *benchContext
|
||||||
|
N int
|
||||||
|
benchFunc func(b *B)
|
||||||
|
bytes int64
|
||||||
|
missingBytes bool // one of the subbenchmarks does not have bytes set.
|
||||||
|
benchTime benchTimeFlag
|
||||||
|
timerOn bool
|
||||||
|
result BenchmarkResult
|
||||||
|
|
||||||
|
// report memory statistics
|
||||||
|
showAllocResult bool
|
||||||
|
// initial state of MemStats.Mallocs and MemStats.TotalAlloc
|
||||||
|
startAllocs uint64
|
||||||
|
startBytes uint64
|
||||||
|
// net total after running benchmar
|
||||||
|
netAllocs uint64
|
||||||
|
netBytes uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartTimer starts timing a test. This function is called automatically
|
||||||
|
// before a benchmark starts, but it can also be used to resume timing after
|
||||||
|
// a call to StopTimer.
|
||||||
|
func (b *B) StartTimer() {
|
||||||
|
if !b.timerOn {
|
||||||
|
b.start = time.Now()
|
||||||
|
b.timerOn = true
|
||||||
|
|
||||||
|
var mstats runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&mstats)
|
||||||
|
b.startAllocs = mstats.Mallocs
|
||||||
|
b.startBytes = mstats.TotalAlloc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopTimer stops timing a test. This can be used to pause the timer
|
||||||
|
// while performing complex initialization that you don't
|
||||||
|
// want to measure.
|
||||||
|
func (b *B) StopTimer() {
|
||||||
|
if b.timerOn {
|
||||||
|
b.duration += time.Since(b.start)
|
||||||
|
b.timerOn = false
|
||||||
|
|
||||||
|
var mstats runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&mstats)
|
||||||
|
b.netAllocs += mstats.Mallocs - b.startAllocs
|
||||||
|
b.netBytes += mstats.TotalAlloc - b.startBytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetTimer zeroes the elapsed benchmark time and memory allocation counters
|
||||||
|
// and deletes user-reported metrics.
|
||||||
|
func (b *B) ResetTimer() {
|
||||||
|
if b.timerOn {
|
||||||
|
b.start = time.Now()
|
||||||
|
|
||||||
|
var mstats runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&mstats)
|
||||||
|
b.startAllocs = mstats.Mallocs
|
||||||
|
b.startBytes = mstats.TotalAlloc
|
||||||
|
}
|
||||||
|
b.duration = 0
|
||||||
|
b.netAllocs = 0
|
||||||
|
b.netBytes = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBytes records the number of bytes processed in a single operation.
|
||||||
|
// If this is called, the benchmark will report ns/op and MB/s.
|
||||||
|
func (b *B) SetBytes(n int64) { b.bytes = n }
|
||||||
|
|
||||||
|
// ReportAllocs enables malloc statistics for this benchmark.
|
||||||
|
// It is equivalent to setting -test.benchmem, but it only affects the
|
||||||
|
// benchmark function that calls ReportAllocs.
|
||||||
|
func (b *B) ReportAllocs() {
|
||||||
|
b.showAllocResult = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// runN runs a single benchmark for the specified number of iterations.
|
||||||
|
func (b *B) runN(n int) {
|
||||||
|
b.N = n
|
||||||
|
runtime.GC()
|
||||||
|
b.ResetTimer()
|
||||||
|
b.StartTimer()
|
||||||
|
b.benchFunc(b)
|
||||||
|
b.StopTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func min(x, y int64) int64 {
|
||||||
|
if x > y {
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func max(x, y int64) int64 {
|
||||||
|
if x < y {
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
// run1 runs the first iteration of benchFunc. It reports whether more
|
||||||
|
// iterations of this benchmarks should be run.
|
||||||
|
func (b *B) run1() bool {
|
||||||
|
if ctx := b.context; ctx != nil {
|
||||||
|
// Extend maxLen, if needed.
|
||||||
|
if n := len(b.name); n > ctx.maxLen {
|
||||||
|
ctx.maxLen = n + 8 // Add additional slack to avoid too many jumps in size.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.runN(1)
|
||||||
|
return !b.hasSub
|
||||||
|
}
|
||||||
|
|
||||||
|
// run executes the benchmark.
|
||||||
|
func (b *B) run() {
|
||||||
|
if b.context != nil {
|
||||||
|
// Running go test --test.bench
|
||||||
|
b.processBench(b.context) // calls doBench and prints results
|
||||||
|
} else {
|
||||||
|
// Running func Benchmark.
|
||||||
|
b.doBench()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *B) doBench() BenchmarkResult {
|
||||||
|
// in upstream, this uses a goroutine
|
||||||
|
b.launch()
|
||||||
|
return b.result
|
||||||
|
}
|
||||||
|
|
||||||
|
// launch launches the benchmark function. It gradually increases the number
|
||||||
|
// of benchmark iterations until the benchmark runs for the requested benchtime.
|
||||||
|
// run1 must have been called on b.
|
||||||
|
func (b *B) launch() {
|
||||||
|
// Run the benchmark for at least the specified amount of time.
|
||||||
|
if b.benchTime.n > 0 {
|
||||||
|
b.runN(b.benchTime.n)
|
||||||
|
} else {
|
||||||
|
d := b.benchTime.d
|
||||||
|
b.failed = false
|
||||||
|
b.duration = 0
|
||||||
|
for n := int64(1); !b.failed && b.duration < d && n < 1e9; {
|
||||||
|
last := n
|
||||||
|
// Predict required iterations.
|
||||||
|
goalns := d.Nanoseconds()
|
||||||
|
prevIters := int64(b.N)
|
||||||
|
prevns := b.duration.Nanoseconds()
|
||||||
|
if prevns <= 0 {
|
||||||
|
// Round up, to avoid div by zero.
|
||||||
|
prevns = 1
|
||||||
|
}
|
||||||
|
// Order of operations matters.
|
||||||
|
// For very fast benchmarks, prevIters ~= prevns.
|
||||||
|
// If you divide first, you get 0 or 1,
|
||||||
|
// which can hide an order of magnitude in execution time.
|
||||||
|
// So multiply first, then divide.
|
||||||
|
n = goalns * prevIters / prevns
|
||||||
|
// Run more iterations than we think we'll need (1.2x).
|
||||||
|
n += n / 5
|
||||||
|
// Don't grow too fast in case we had timing errors previously.
|
||||||
|
n = min(n, 100*last)
|
||||||
|
// Be sure to run at least one more than last time.
|
||||||
|
n = max(n, last+1)
|
||||||
|
// Don't run more than 1e9 times. (This also keeps n in int range on 32 bit platforms.)
|
||||||
|
n = min(n, 1e9)
|
||||||
|
b.runN(int(n))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.result = BenchmarkResult{b.N, b.duration, b.bytes, b.netAllocs, b.netBytes}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BenchmarkResult contains the results of a benchmark run.
|
||||||
|
type BenchmarkResult struct {
|
||||||
|
N int // The number of iterations.
|
||||||
|
T time.Duration // The total time taken.
|
||||||
|
Bytes int64 // Bytes processed in one iteration.
|
||||||
|
|
||||||
|
MemAllocs uint64 // The total number of memory allocations.
|
||||||
|
MemBytes uint64 // The total number of bytes allocated.
|
||||||
|
}
|
||||||
|
|
||||||
|
// NsPerOp returns the "ns/op" metric.
|
||||||
|
func (r BenchmarkResult) NsPerOp() int64 {
|
||||||
|
if r.N <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return r.T.Nanoseconds() / int64(r.N)
|
||||||
|
}
|
||||||
|
|
||||||
|
// mbPerSec returns the "MB/s" metric.
|
||||||
|
func (r BenchmarkResult) mbPerSec() float64 {
|
||||||
|
if r.Bytes <= 0 || r.T <= 0 || r.N <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return (float64(r.Bytes) * float64(r.N) / 1e6) / r.T.Seconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllocsPerOp returns the "allocs/op" metric,
|
||||||
|
// which is calculated as r.MemAllocs / r.N.
|
||||||
|
func (r BenchmarkResult) AllocsPerOp() int64 {
|
||||||
|
if r.N <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int64(r.MemAllocs) / int64(r.N)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllocedBytesPerOp returns the "B/op" metric,
|
||||||
|
// which is calculated as r.MemBytes / r.N.
|
||||||
|
func (r BenchmarkResult) AllocedBytesPerOp() int64 {
|
||||||
|
if r.N <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int64(r.MemBytes) / int64(r.N)
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a summary of the benchmark results.
|
||||||
|
// It follows the benchmark result line format from
|
||||||
|
// https://golang.org/design/14313-benchmark-format, not including the
|
||||||
|
// benchmark name.
|
||||||
|
// Extra metrics override built-in metrics of the same name.
|
||||||
|
// String does not include allocs/op or B/op, since those are reported
|
||||||
|
// by MemString.
|
||||||
|
func (r BenchmarkResult) String() string {
|
||||||
|
buf := new(strings.Builder)
|
||||||
|
fmt.Fprintf(buf, "%8d", r.N)
|
||||||
|
|
||||||
|
// Get ns/op as a float.
|
||||||
|
ns := float64(r.T.Nanoseconds()) / float64(r.N)
|
||||||
|
if ns != 0 {
|
||||||
|
buf.WriteByte('\t')
|
||||||
|
prettyPrint(buf, ns, "ns/op")
|
||||||
|
}
|
||||||
|
|
||||||
|
if mbs := r.mbPerSec(); mbs != 0 {
|
||||||
|
fmt.Fprintf(buf, "\t%7.2f MB/s", mbs)
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MemString returns r.AllocedBytesPerOp and r.AllocsPerOp in the same format as 'go test'.
|
||||||
|
func (r BenchmarkResult) MemString() string {
|
||||||
|
return fmt.Sprintf("%8d B/op\t%8d allocs/op",
|
||||||
|
r.AllocedBytesPerOp(), r.AllocsPerOp())
|
||||||
|
}
|
||||||
|
|
||||||
|
func prettyPrint(w io.Writer, x float64, unit string) {
|
||||||
|
// Print all numbers with 10 places before the decimal point
|
||||||
|
// and small numbers with four sig figs. Field widths are
|
||||||
|
// chosen to fit the whole part in 10 places while aligning
|
||||||
|
// the decimal point of all fractional formats.
|
||||||
|
var format string
|
||||||
|
switch y := math.Abs(x); {
|
||||||
|
case y == 0 || y >= 999.95:
|
||||||
|
format = "%10.0f %s"
|
||||||
|
case y >= 99.995:
|
||||||
|
format = "%12.1f %s"
|
||||||
|
case y >= 9.9995:
|
||||||
|
format = "%13.2f %s"
|
||||||
|
case y >= 0.99995:
|
||||||
|
format = "%14.3f %s"
|
||||||
|
case y >= 0.099995:
|
||||||
|
format = "%15.4f %s"
|
||||||
|
case y >= 0.0099995:
|
||||||
|
format = "%16.5f %s"
|
||||||
|
case y >= 0.00099995:
|
||||||
|
format = "%17.6f %s"
|
||||||
|
default:
|
||||||
|
format = "%18.7f %s"
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, format, x, unit)
|
||||||
|
}
|
||||||
|
|
||||||
|
type benchContext struct {
|
||||||
|
match *matcher
|
||||||
|
|
||||||
|
maxLen int // The largest recorded benchmark name.
|
||||||
|
}
|
||||||
|
|
||||||
|
func runBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) bool {
|
||||||
|
// If no flag was specified, don't run benchmarks.
|
||||||
|
if len(*matchBenchmarks) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
ctx := &benchContext{
|
||||||
|
match: newMatcher(matchString, *matchBenchmarks, "-test.bench", flagSkipRegexp),
|
||||||
|
}
|
||||||
|
var bs []InternalBenchmark
|
||||||
|
for _, Benchmark := range benchmarks {
|
||||||
|
if _, matched, _ := ctx.match.fullName(nil, Benchmark.Name); matched {
|
||||||
|
bs = append(bs, Benchmark)
|
||||||
|
benchName := Benchmark.Name
|
||||||
|
if l := len(benchName); l > ctx.maxLen {
|
||||||
|
ctx.maxLen = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
main := &B{
|
||||||
|
common: common{
|
||||||
|
output: &logger{},
|
||||||
|
name: "Main",
|
||||||
|
},
|
||||||
|
benchTime: benchTime,
|
||||||
|
benchFunc: func(b *B) {
|
||||||
|
for _, Benchmark := range bs {
|
||||||
|
b.Run(Benchmark.Name, Benchmark.F)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
context: ctx,
|
||||||
|
}
|
||||||
|
|
||||||
|
main.runN(1)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// processBench runs bench b and prints the results.
|
||||||
|
func (b *B) processBench(ctx *benchContext) {
|
||||||
|
benchName := b.name
|
||||||
|
|
||||||
|
for i := 0; i < flagCount; i++ {
|
||||||
|
if ctx != nil {
|
||||||
|
fmt.Printf("%-*s\t", ctx.maxLen, benchName)
|
||||||
|
}
|
||||||
|
r := b.doBench()
|
||||||
|
if b.failed {
|
||||||
|
// The output could be very long here, but probably isn't.
|
||||||
|
// We print it all, regardless, because we don't want to trim the reason
|
||||||
|
// the benchmark failed.
|
||||||
|
fmt.Printf("--- FAIL: %s\n%s", benchName, "") // b.output)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ctx != nil {
|
||||||
|
results := r.String()
|
||||||
|
|
||||||
|
if *benchmarkMemory || b.showAllocResult {
|
||||||
|
results += "\t" + r.MemString()
|
||||||
|
}
|
||||||
|
fmt.Println(results)
|
||||||
|
|
||||||
|
// Print any benchmark output
|
||||||
|
if b.output.Len() > 0 {
|
||||||
|
fmt.Printf("--- BENCH: %s\n", benchName)
|
||||||
|
b.output.WriteTo(os.Stdout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run benchmarks f as a subbenchmark with the given name. It reports
|
||||||
|
// true if the subbenchmark succeeded.
|
||||||
|
//
|
||||||
|
// A subbenchmark is like any other benchmark. A benchmark that calls Run at
|
||||||
|
// least once will not be measured itself and will be called once with N=1.
|
||||||
|
func (b *B) Run(name string, f func(b *B)) bool {
|
||||||
|
benchName, ok, partial := b.name, true, false
|
||||||
|
if b.context != nil {
|
||||||
|
benchName, ok, partial = b.context.match.fullName(&b.common, name)
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
b.hasSub = true
|
||||||
|
sub := &B{
|
||||||
|
common: common{
|
||||||
|
output: &logger{},
|
||||||
|
name: benchName,
|
||||||
|
level: b.level + 1,
|
||||||
|
},
|
||||||
|
benchFunc: f,
|
||||||
|
benchTime: b.benchTime,
|
||||||
|
context: b.context,
|
||||||
|
}
|
||||||
|
if partial {
|
||||||
|
// Partial name match, like -bench=X/Y matching BenchmarkX.
|
||||||
|
// Only process sub-benchmarks, if any.
|
||||||
|
sub.hasSub = true
|
||||||
|
}
|
||||||
|
if sub.run1() {
|
||||||
|
sub.run()
|
||||||
|
}
|
||||||
|
b.add(sub.result)
|
||||||
|
return !sub.failed
|
||||||
|
}
|
||||||
|
|
||||||
|
// add simulates running benchmarks in sequence in a single iteration. It is
|
||||||
|
// used to give some meaningful results in case func Benchmark is used in
|
||||||
|
// combination with Run.
|
||||||
|
func (b *B) add(other BenchmarkResult) {
|
||||||
|
r := &b.result
|
||||||
|
// The aggregated BenchmarkResults resemble running all subbenchmarks as
|
||||||
|
// in sequence in a single benchmark.
|
||||||
|
r.N = 1
|
||||||
|
r.T += time.Duration(other.NsPerOp())
|
||||||
|
if other.Bytes == 0 {
|
||||||
|
// Summing Bytes is meaningless in aggregate if not all subbenchmarks
|
||||||
|
// set it.
|
||||||
|
b.missingBytes = true
|
||||||
|
r.Bytes = 0
|
||||||
|
}
|
||||||
|
if !b.missingBytes {
|
||||||
|
r.Bytes += other.Bytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A PB is used by RunParallel for running parallel benchmarks.
|
||||||
|
type PB struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next reports whether there are more iterations to execute.
|
||||||
|
func (pb *PB) Next() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunParallel runs a benchmark in parallel.
|
||||||
|
//
|
||||||
|
// Not implemented
|
||||||
|
func (b *B) RunParallel(body func(*PB)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Benchmark benchmarks a single function. It is useful for creating
|
||||||
|
// custom benchmarks that do not use the "go test" command.
|
||||||
|
//
|
||||||
|
// If f calls Run, the result will be an estimate of running all its
|
||||||
|
// subbenchmarks that don't call Run in sequence in a single benchmark.
|
||||||
|
func Benchmark(f func(b *B)) BenchmarkResult {
|
||||||
|
b := &B{
|
||||||
|
benchFunc: f,
|
||||||
|
benchTime: benchTime,
|
||||||
|
}
|
||||||
|
if b.run1() {
|
||||||
|
b.run()
|
||||||
|
}
|
||||||
|
return b.result
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Copyright 2011 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.
|
||||||
|
|
||||||
|
package testing_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buf = make([]byte, 13579)
|
||||||
|
|
||||||
|
func NonASCII(b []byte, i int, offset int) int {
|
||||||
|
for i = offset; i < len(b)+offset; i++ {
|
||||||
|
if b[i%len(b)] >= 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkFastNonASCII(b *testing.B) {
|
||||||
|
var val int
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
val += NonASCII(buf, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSlowNonASCII(b *testing.B) {
|
||||||
|
var val int
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
val += NonASCII(buf, 0, 0)
|
||||||
|
val += NonASCII(buf, 0, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestBenchmark simply uses Benchmark twice and makes sure it does not crash.
|
||||||
|
func TestBenchmark(t *testing.T) {
|
||||||
|
// FIXME: reduce runtime from the current 3 seconds.
|
||||||
|
rslow := testing.Benchmark(BenchmarkSlowNonASCII)
|
||||||
|
rfast := testing.Benchmark(BenchmarkFastNonASCII)
|
||||||
|
tslow := rslow.NsPerOp()
|
||||||
|
tfast := rfast.NsPerOp()
|
||||||
|
|
||||||
|
// Be exceedingly forgiving; do not fail even if system gets busy.
|
||||||
|
speedup := float64(tslow) / float64(tfast)
|
||||||
|
if speedup < 0.3 {
|
||||||
|
t.Errorf("Expected speedup >= 0.3, got %f", speedup)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSub(b *testing.B) {
|
||||||
|
b.Run("Fast", func(b *testing.B) { BenchmarkFastNonASCII(b) })
|
||||||
|
b.Run("Slow", func(b *testing.B) { BenchmarkSlowNonASCII(b) })
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package testing
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is a sad stub of the upstream testing package because it doesn't compile
|
||||||
|
with tinygo right now.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InternalFuzzTarget is an internal type but exported because it is
|
||||||
|
// cross-package; it is part of the implementation of the "go test" command.
|
||||||
|
type InternalFuzzTarget struct {
|
||||||
|
Name string
|
||||||
|
Fn func(f *F)
|
||||||
|
}
|
||||||
|
|
||||||
|
// F is a type passed to fuzz tests.
|
||||||
|
//
|
||||||
|
// Fuzz tests run generated inputs against a provided fuzz target, which can
|
||||||
|
// find and report potential bugs in the code being tested.
|
||||||
|
//
|
||||||
|
// A fuzz test runs the seed corpus by default, which includes entries provided
|
||||||
|
// by (*F).Add and entries in the testdata/fuzz/<FuzzTestName> directory. After
|
||||||
|
// any necessary setup and calls to (*F).Add, the fuzz test must then call
|
||||||
|
// (*F).Fuzz to provide the fuzz target. See the testing package documentation
|
||||||
|
// for an example, and see the F.Fuzz and F.Add method documentation for
|
||||||
|
// details.
|
||||||
|
//
|
||||||
|
// *F methods can only be called before (*F).Fuzz. Once the test is
|
||||||
|
// executing the fuzz target, only (*T) methods can be used. The only *F methods
|
||||||
|
// that are allowed in the (*F).Fuzz function are (*F).Failed and (*F).Name.
|
||||||
|
type F struct {
|
||||||
|
common
|
||||||
|
fuzzContext *fuzzContext
|
||||||
|
testContext *testContext
|
||||||
|
|
||||||
|
// inFuzzFn is true when the fuzz function is running. Most F methods cannot
|
||||||
|
// be called when inFuzzFn is true.
|
||||||
|
inFuzzFn bool
|
||||||
|
|
||||||
|
// corpus is a set of seed corpus entries, added with F.Add and loaded
|
||||||
|
// from testdata.
|
||||||
|
corpus []corpusEntry
|
||||||
|
|
||||||
|
result fuzzResult
|
||||||
|
fuzzCalled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// corpusEntry is an alias to the same type as internal/fuzz.CorpusEntry.
|
||||||
|
// We use a type alias because we don't want to export this type, and we can't
|
||||||
|
// import internal/fuzz from testing.
|
||||||
|
type corpusEntry = struct {
|
||||||
|
Parent string
|
||||||
|
Path string
|
||||||
|
Data []byte
|
||||||
|
Values []interface{}
|
||||||
|
Generation int
|
||||||
|
IsSeed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add will add the arguments to the seed corpus for the fuzz test. This will be
|
||||||
|
// a no-op if called after or within the fuzz target, and args must match the
|
||||||
|
// arguments for the fuzz target.
|
||||||
|
func (f *F) Add(args ...interface{}) {
|
||||||
|
var values []interface{}
|
||||||
|
for i := range args {
|
||||||
|
if t := reflect.TypeOf(args[i]); !supportedTypes[t] {
|
||||||
|
panic(fmt.Sprintf("testing: unsupported type to Add %v", t))
|
||||||
|
}
|
||||||
|
values = append(values, args[i])
|
||||||
|
}
|
||||||
|
f.corpus = append(f.corpus, corpusEntry{Values: values, IsSeed: true, Path: fmt.Sprintf("seed#%d", len(f.corpus))})
|
||||||
|
}
|
||||||
|
|
||||||
|
// supportedTypes represents all of the supported types which can be fuzzed.
|
||||||
|
var supportedTypes = map[reflect.Type]bool{
|
||||||
|
reflect.TypeOf(([]byte)("")): true,
|
||||||
|
reflect.TypeOf((string)("")): true,
|
||||||
|
reflect.TypeOf((bool)(false)): true,
|
||||||
|
reflect.TypeOf((byte)(0)): true,
|
||||||
|
reflect.TypeOf((rune)(0)): true,
|
||||||
|
reflect.TypeOf((float32)(0)): true,
|
||||||
|
reflect.TypeOf((float64)(0)): true,
|
||||||
|
reflect.TypeOf((int)(0)): true,
|
||||||
|
reflect.TypeOf((int8)(0)): true,
|
||||||
|
reflect.TypeOf((int16)(0)): true,
|
||||||
|
reflect.TypeOf((int32)(0)): true,
|
||||||
|
reflect.TypeOf((int64)(0)): true,
|
||||||
|
reflect.TypeOf((uint)(0)): true,
|
||||||
|
reflect.TypeOf((uint8)(0)): true,
|
||||||
|
reflect.TypeOf((uint16)(0)): true,
|
||||||
|
reflect.TypeOf((uint32)(0)): true,
|
||||||
|
reflect.TypeOf((uint64)(0)): true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fuzz runs the fuzz function, ff, for fuzz testing. If ff fails for a set of
|
||||||
|
// arguments, those arguments will be added to the seed corpus.
|
||||||
|
//
|
||||||
|
// ff must be a function with no return value whose first argument is *T and
|
||||||
|
// whose remaining arguments are the types to be fuzzed.
|
||||||
|
// For example:
|
||||||
|
//
|
||||||
|
// f.Fuzz(func(t *testing.T, b []byte, i int) { ... })
|
||||||
|
//
|
||||||
|
// The following types are allowed: []byte, string, bool, byte, rune, float32,
|
||||||
|
// float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64.
|
||||||
|
// More types may be supported in the future.
|
||||||
|
//
|
||||||
|
// ff must not call any *F methods, e.g. (*F).Log, (*F).Error, (*F).Skip. Use
|
||||||
|
// the corresponding *T method instead. The only *F methods that are allowed in
|
||||||
|
// the (*F).Fuzz function are (*F).Failed and (*F).Name.
|
||||||
|
//
|
||||||
|
// This function should be fast and deterministic, and its behavior should not
|
||||||
|
// depend on shared state. No mutatable input arguments, or pointers to them,
|
||||||
|
// should be retained between executions of the fuzz function, as the memory
|
||||||
|
// backing them may be mutated during a subsequent invocation. ff must not
|
||||||
|
// modify the underlying data of the arguments provided by the fuzzing engine.
|
||||||
|
//
|
||||||
|
// When fuzzing, F.Fuzz does not return until a problem is found, time runs out
|
||||||
|
// (set with -fuzztime), or the test process is interrupted by a signal. F.Fuzz
|
||||||
|
// should be called exactly once, unless F.Skip or F.Fail is called beforehand.
|
||||||
|
func (f *F) Fuzz(ff interface{}) {
|
||||||
|
f.failed = true
|
||||||
|
f.result.N = 0
|
||||||
|
f.result.T = 0
|
||||||
|
f.result.Error = errors.New("operation not implemented")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// fuzzContext holds fields common to all fuzz tests.
|
||||||
|
type fuzzContext struct {
|
||||||
|
deps testDeps
|
||||||
|
mode fuzzMode
|
||||||
|
}
|
||||||
|
|
||||||
|
type fuzzMode uint8
|
||||||
|
|
||||||
|
// fuzzResult contains the results of a fuzz run.
|
||||||
|
type fuzzResult struct {
|
||||||
|
N int // The number of iterations.
|
||||||
|
T time.Duration // The total time taken.
|
||||||
|
Error error // Error is the error from the failing input
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2016 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 baremetal
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
const isBaremetal = true
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2016 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 !baremetal
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
const isBaremetal = false
|
||||||
@@ -0,0 +1,323 @@
|
|||||||
|
// Copyright 2015 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.
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// matcher sanitizes, uniques, and filters names of subtests and subbenchmarks.
|
||||||
|
type matcher struct {
|
||||||
|
filter filterMatch
|
||||||
|
skip filterMatch
|
||||||
|
matchFunc func(pat, str string) (bool, error)
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
|
|
||||||
|
// subNames is used to deduplicate subtest names.
|
||||||
|
// Each key is the subtest name joined to the deduplicated name of the parent test.
|
||||||
|
// Each value is the count of the number of occurrences of the given subtest name
|
||||||
|
// already seen.
|
||||||
|
subNames map[string]int32
|
||||||
|
}
|
||||||
|
|
||||||
|
type filterMatch interface {
|
||||||
|
// matches checks the name against the receiver's pattern strings using the
|
||||||
|
// given match function.
|
||||||
|
matches(name []string, matchString func(pat, str string) (bool, error)) (ok, partial bool)
|
||||||
|
|
||||||
|
// verify checks that the receiver's pattern strings are valid filters by
|
||||||
|
// calling the given match function.
|
||||||
|
verify(name string, matchString func(pat, str string) (bool, error)) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// simpleMatch matches a test name if all of the pattern strings match in
|
||||||
|
// sequence.
|
||||||
|
type simpleMatch []string
|
||||||
|
|
||||||
|
// alternationMatch matches a test name if one of the alternations match.
|
||||||
|
type alternationMatch []filterMatch
|
||||||
|
|
||||||
|
// TODO: fix test_main to avoid race and improve caching, also allowing to
|
||||||
|
// eliminate this Mutex.
|
||||||
|
var matchMutex sync.Mutex
|
||||||
|
|
||||||
|
func allMatcher() *matcher {
|
||||||
|
return newMatcher(nil, "", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMatcher(matchString func(pat, str string) (bool, error), patterns, name, skips string) *matcher {
|
||||||
|
if isBaremetal {
|
||||||
|
matchString = fakeMatchString
|
||||||
|
}
|
||||||
|
|
||||||
|
var filter, skip filterMatch
|
||||||
|
if patterns == "" {
|
||||||
|
filter = simpleMatch{} // always partial true
|
||||||
|
} else {
|
||||||
|
filter = splitRegexp(patterns)
|
||||||
|
if err := filter.verify(name, matchString); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "testing: invalid regexp for %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if skips == "" {
|
||||||
|
skip = alternationMatch{} // always false
|
||||||
|
} else {
|
||||||
|
skip = splitRegexp(skips)
|
||||||
|
if err := skip.verify("-test.skip", matchString); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "testing: invalid regexp for %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &matcher{
|
||||||
|
filter: filter,
|
||||||
|
skip: skip,
|
||||||
|
matchFunc: matchString,
|
||||||
|
subNames: map[string]int32{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *matcher) fullName(c *common, subname string) (name string, ok, partial bool) {
|
||||||
|
name = subname
|
||||||
|
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
if c != nil && c.level > 0 {
|
||||||
|
name = m.unique(c.name, rewrite(subname))
|
||||||
|
}
|
||||||
|
|
||||||
|
matchMutex.Lock()
|
||||||
|
defer matchMutex.Unlock()
|
||||||
|
|
||||||
|
// We check the full array of paths each time to allow for the case that a pattern contains a '/'.
|
||||||
|
elem := strings.Split(name, "/")
|
||||||
|
|
||||||
|
// filter must match.
|
||||||
|
// accept partial match that may produce full match later.
|
||||||
|
ok, partial = m.filter.matches(elem, m.matchFunc)
|
||||||
|
if !ok {
|
||||||
|
return name, false, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip must not match.
|
||||||
|
// ignore partial match so we can get to more precise match later.
|
||||||
|
skip, partialSkip := m.skip.matches(elem, m.matchFunc)
|
||||||
|
if skip && !partialSkip {
|
||||||
|
return name, false, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return name, ok, partial
|
||||||
|
}
|
||||||
|
|
||||||
|
// clearSubNames clears the matcher's internal state, potentially freeing
|
||||||
|
// memory. After this is called, T.Name may return the same strings as it did
|
||||||
|
// for earlier subtests.
|
||||||
|
func (m *matcher) clearSubNames() {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
for key := range m.subNames {
|
||||||
|
delete(m.subNames, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m simpleMatch) matches(name []string, matchString func(pat, str string) (bool, error)) (ok, partial bool) {
|
||||||
|
for i, s := range name {
|
||||||
|
if i >= len(m) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if ok, _ := matchString(m[i], s); !ok {
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, len(name) < len(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m simpleMatch) verify(name string, matchString func(pat, str string) (bool, error)) error {
|
||||||
|
for i, s := range m {
|
||||||
|
m[i] = rewrite(s)
|
||||||
|
}
|
||||||
|
// Verify filters before doing any processing.
|
||||||
|
for i, s := range m {
|
||||||
|
if _, err := matchString(s, "non-empty"); err != nil {
|
||||||
|
return fmt.Errorf("element %d of %s (%q): %s", i, name, s, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m alternationMatch) matches(name []string, matchString func(pat, str string) (bool, error)) (ok, partial bool) {
|
||||||
|
for _, m := range m {
|
||||||
|
if ok, partial = m.matches(name, matchString); ok {
|
||||||
|
return ok, partial
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m alternationMatch) verify(name string, matchString func(pat, str string) (bool, error)) error {
|
||||||
|
for i, m := range m {
|
||||||
|
if err := m.verify(name, matchString); err != nil {
|
||||||
|
return fmt.Errorf("alternation %d of %s", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func splitRegexp(s string) filterMatch {
|
||||||
|
a := make(simpleMatch, 0, strings.Count(s, "/"))
|
||||||
|
b := make(alternationMatch, 0, strings.Count(s, "|"))
|
||||||
|
cs := 0
|
||||||
|
cp := 0
|
||||||
|
for i := 0; i < len(s); {
|
||||||
|
switch s[i] {
|
||||||
|
case '[':
|
||||||
|
cs++
|
||||||
|
case ']':
|
||||||
|
if cs--; cs < 0 { // An unmatched ']' is legal.
|
||||||
|
cs = 0
|
||||||
|
}
|
||||||
|
case '(':
|
||||||
|
if cs == 0 {
|
||||||
|
cp++
|
||||||
|
}
|
||||||
|
case ')':
|
||||||
|
if cs == 0 {
|
||||||
|
cp--
|
||||||
|
}
|
||||||
|
case '\\':
|
||||||
|
i++
|
||||||
|
case '/':
|
||||||
|
if cs == 0 && cp == 0 {
|
||||||
|
a = append(a, s[:i])
|
||||||
|
s = s[i+1:]
|
||||||
|
i = 0
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
case '|':
|
||||||
|
if cs == 0 && cp == 0 {
|
||||||
|
a = append(a, s[:i])
|
||||||
|
s = s[i+1:]
|
||||||
|
i = 0
|
||||||
|
b = append(b, a)
|
||||||
|
a = make(simpleMatch, 0, len(a))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
a = append(a, s)
|
||||||
|
if len(b) == 0 {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return append(b, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// unique creates a unique name for the given parent and subname by affixing it
|
||||||
|
// with one or more counts, if necessary.
|
||||||
|
func (m *matcher) unique(parent, subname string) string {
|
||||||
|
base := parent + "/" + subname
|
||||||
|
|
||||||
|
for {
|
||||||
|
n := m.subNames[base]
|
||||||
|
if n < 0 {
|
||||||
|
panic("subtest count overflow")
|
||||||
|
}
|
||||||
|
m.subNames[base] = n + 1
|
||||||
|
|
||||||
|
if n == 0 && subname != "" {
|
||||||
|
prefix, nn := parseSubtestNumber(base)
|
||||||
|
if len(prefix) < len(base) && nn < m.subNames[prefix] {
|
||||||
|
// This test is explicitly named like "parent/subname#NN",
|
||||||
|
// and #NN was already used for the NNth occurrence of "parent/subname".
|
||||||
|
// Loop to add a disambiguating suffix.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return base
|
||||||
|
}
|
||||||
|
|
||||||
|
name := fmt.Sprintf("%s#%02d", base, n)
|
||||||
|
if m.subNames[name] != 0 {
|
||||||
|
// This is the nth occurrence of base, but the name "parent/subname#NN"
|
||||||
|
// collides with the first occurrence of a subtest *explicitly* named
|
||||||
|
// "parent/subname#NN". Try the next number.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseSubtestNumber splits a subtest name into a "#%02d"-formatted int32
|
||||||
|
// suffix (if present), and a prefix preceding that suffix (always).
|
||||||
|
func parseSubtestNumber(s string) (prefix string, nn int32) {
|
||||||
|
i := strings.LastIndex(s, "#")
|
||||||
|
if i < 0 {
|
||||||
|
return s, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix, suffix := s[:i], s[i+1:]
|
||||||
|
if len(suffix) < 2 || (len(suffix) > 2 && suffix[0] == '0') {
|
||||||
|
// Even if suffix is numeric, it is not a possible output of a "%02" format
|
||||||
|
// string: it has either too few digits or too many leading zeroes.
|
||||||
|
return s, 0
|
||||||
|
}
|
||||||
|
if suffix == "00" {
|
||||||
|
if !strings.HasSuffix(prefix, "/") {
|
||||||
|
// We only use "#00" as a suffix for subtests named with the empty
|
||||||
|
// string — it isn't a valid suffix if the subtest name is non-empty.
|
||||||
|
return s, 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := strconv.ParseInt(suffix, 10, 32)
|
||||||
|
if err != nil || n < 0 {
|
||||||
|
return s, 0
|
||||||
|
}
|
||||||
|
return prefix, int32(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// rewrite rewrites a subname to having only printable characters and no white
|
||||||
|
// space.
|
||||||
|
func rewrite(s string) string {
|
||||||
|
b := []byte{}
|
||||||
|
for _, r := range s {
|
||||||
|
switch {
|
||||||
|
case isSpace(r):
|
||||||
|
b = append(b, '_')
|
||||||
|
case !strconv.IsPrint(r):
|
||||||
|
s := strconv.QuoteRune(r)
|
||||||
|
b = append(b, s[1:len(s)-1]...)
|
||||||
|
default:
|
||||||
|
b = append(b, string(r)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSpace(r rune) bool {
|
||||||
|
if r < 0x2000 {
|
||||||
|
switch r {
|
||||||
|
// Note: not the same as Unicode Z class.
|
||||||
|
case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0, 0x1680:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if r <= 0x200a {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
switch r {
|
||||||
|
case 0x2028, 0x2029, 0x202f, 0x205f, 0x3000:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -0,0 +1,259 @@
|
|||||||
|
// Copyright 2015 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.
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Verify that our IsSpace agrees with unicode.IsSpace.
|
||||||
|
func TestIsSpace(t *T) {
|
||||||
|
n := 0
|
||||||
|
for r := rune(0); r <= unicode.MaxRune; r++ {
|
||||||
|
if isSpace(r) != unicode.IsSpace(r) {
|
||||||
|
t.Errorf("IsSpace(%U)=%t incorrect", r, isSpace(r))
|
||||||
|
n++
|
||||||
|
if n > 10 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSplitRegexp(t *T) {
|
||||||
|
res := func(s ...string) filterMatch { return simpleMatch(s) }
|
||||||
|
alt := func(m ...filterMatch) filterMatch { return alternationMatch(m) }
|
||||||
|
testCases := []struct {
|
||||||
|
pattern string
|
||||||
|
result filterMatch
|
||||||
|
}{
|
||||||
|
// Correct patterns
|
||||||
|
// If a regexp pattern is correct, all split regexps need to be correct
|
||||||
|
// as well.
|
||||||
|
{"", res("")},
|
||||||
|
{"/", res("", "")},
|
||||||
|
{"//", res("", "", "")},
|
||||||
|
{"A", res("A")},
|
||||||
|
{"A/B", res("A", "B")},
|
||||||
|
{"A/B/", res("A", "B", "")},
|
||||||
|
{"/A/B/", res("", "A", "B", "")},
|
||||||
|
{"[A]/(B)", res("[A]", "(B)")},
|
||||||
|
{"[/]/[/]", res("[/]", "[/]")},
|
||||||
|
{"[/]/[:/]", res("[/]", "[:/]")},
|
||||||
|
{"/]", res("", "]")},
|
||||||
|
{"]/", res("]", "")},
|
||||||
|
{"]/[/]", res("]", "[/]")},
|
||||||
|
{`([)/][(])`, res(`([)/][(])`)},
|
||||||
|
{"[(]/[)]", res("[(]", "[)]")},
|
||||||
|
|
||||||
|
{"A/B|C/D", alt(res("A", "B"), res("C", "D"))},
|
||||||
|
|
||||||
|
// Faulty patterns
|
||||||
|
// Errors in original should produce at least one faulty regexp in results.
|
||||||
|
{")/", res(")/")},
|
||||||
|
{")/(/)", res(")/(", ")")},
|
||||||
|
{"a[/)b", res("a[/)b")},
|
||||||
|
{"(/]", res("(/]")},
|
||||||
|
{"(/", res("(/")},
|
||||||
|
{"[/]/[/", res("[/]", "[/")},
|
||||||
|
{`\p{/}`, res(`\p{`, "}")},
|
||||||
|
{`\p/`, res(`\p`, "")},
|
||||||
|
{`[[:/:]]`, res(`[[:/:]]`)},
|
||||||
|
}
|
||||||
|
for _, tc := range testCases {
|
||||||
|
a := splitRegexp(tc.pattern)
|
||||||
|
if !reflect.DeepEqual(a, tc.result) {
|
||||||
|
t.Errorf("splitRegexp(%q) = %#v; want %#v", tc.pattern, a, tc.result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is any error in the pattern, one of the returned subpatterns
|
||||||
|
// needs to have an error as well.
|
||||||
|
if _, err := regexp.Compile(tc.pattern); err != nil {
|
||||||
|
ok := true
|
||||||
|
if err := a.verify("", regexp.MatchString); err != nil {
|
||||||
|
ok = false
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
t.Errorf("%s: expected error in any of %q", tc.pattern, a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMatcher(t *T) {
|
||||||
|
testCases := []struct {
|
||||||
|
pattern string
|
||||||
|
skip string
|
||||||
|
parent, sub string
|
||||||
|
ok bool
|
||||||
|
partial bool
|
||||||
|
}{
|
||||||
|
// Behavior without subtests.
|
||||||
|
{"", "", "", "TestFoo", true, false},
|
||||||
|
{"TestFoo", "", "", "TestFoo", true, false},
|
||||||
|
{"TestFoo/", "", "", "TestFoo", true, true},
|
||||||
|
{"TestFoo/bar/baz", "", "", "TestFoo", true, true},
|
||||||
|
{"TestFoo", "", "", "TestBar", false, false},
|
||||||
|
{"TestFoo/", "", "", "TestBar", false, false},
|
||||||
|
{"TestFoo/bar/baz", "", "", "TestBar/bar/baz", false, false},
|
||||||
|
{"", "TestBar", "", "TestFoo", true, false},
|
||||||
|
{"", "TestBar", "", "TestBar", false, false},
|
||||||
|
|
||||||
|
// Skipping a non-existent test doesn't change anything.
|
||||||
|
{"", "TestFoo/skipped", "", "TestFoo", true, false},
|
||||||
|
{"TestFoo", "TestFoo/skipped", "", "TestFoo", true, false},
|
||||||
|
{"TestFoo/", "TestFoo/skipped", "", "TestFoo", true, true},
|
||||||
|
{"TestFoo/bar/baz", "TestFoo/skipped", "", "TestFoo", true, true},
|
||||||
|
{"TestFoo", "TestFoo/skipped", "", "TestBar", false, false},
|
||||||
|
{"TestFoo/", "TestFoo/skipped", "", "TestBar", false, false},
|
||||||
|
{"TestFoo/bar/baz", "TestFoo/skipped", "", "TestBar/bar/baz", false, false},
|
||||||
|
|
||||||
|
// with subtests
|
||||||
|
{"", "", "TestFoo", "x", true, false},
|
||||||
|
{"TestFoo", "", "TestFoo", "x", true, false},
|
||||||
|
{"TestFoo/", "", "TestFoo", "x", true, false},
|
||||||
|
{"TestFoo/bar/baz", "", "TestFoo", "bar", true, true},
|
||||||
|
|
||||||
|
{"", "TestFoo/skipped", "TestFoo", "x", true, false},
|
||||||
|
{"TestFoo", "TestFoo/skipped", "TestFoo", "x", true, false},
|
||||||
|
{"TestFoo", "TestFoo/skipped", "TestFoo", "skipped", false, false},
|
||||||
|
{"TestFoo/", "TestFoo/skipped", "TestFoo", "x", true, false},
|
||||||
|
{"TestFoo/bar/baz", "TestFoo/skipped", "TestFoo", "bar", true, true},
|
||||||
|
|
||||||
|
// Subtest with a '/' in its name still allows for copy and pasted names
|
||||||
|
// to match.
|
||||||
|
{"TestFoo/bar/baz", "", "TestFoo", "bar/baz", true, false},
|
||||||
|
{"TestFoo/bar/baz", "TestFoo/bar/baz", "TestFoo", "bar/baz", false, false},
|
||||||
|
{"TestFoo/bar/baz", "TestFoo/bar/baz/skip", "TestFoo", "bar/baz", true, false},
|
||||||
|
{"TestFoo/bar/baz", "", "TestFoo/bar", "baz", true, false},
|
||||||
|
{"TestFoo/bar/baz", "", "TestFoo", "x", false, false},
|
||||||
|
{"TestFoo", "", "TestBar", "x", false, false},
|
||||||
|
{"TestFoo/", "", "TestBar", "x", false, false},
|
||||||
|
{"TestFoo/bar/baz", "", "TestBar", "x/bar/baz", false, false},
|
||||||
|
|
||||||
|
{"A/B|C/D", "", "TestA", "B", true, false},
|
||||||
|
{"A/B|C/D", "", "TestC", "D", true, false},
|
||||||
|
{"A/B|C/D", "", "TestA", "C", false, false},
|
||||||
|
|
||||||
|
// subtests only
|
||||||
|
{"", "", "TestFoo", "x", true, false},
|
||||||
|
{"/", "", "TestFoo", "x", true, false},
|
||||||
|
{"./", "", "TestFoo", "x", true, false},
|
||||||
|
{"./.", "", "TestFoo", "x", true, false},
|
||||||
|
{"/bar/baz", "", "TestFoo", "bar", true, true},
|
||||||
|
{"/bar/baz", "", "TestFoo", "bar/baz", true, false},
|
||||||
|
{"//baz", "", "TestFoo", "bar/baz", true, false},
|
||||||
|
{"//", "", "TestFoo", "bar/baz", true, false},
|
||||||
|
{"/bar/baz", "", "TestFoo/bar", "baz", true, false},
|
||||||
|
{"//foo", "", "TestFoo", "bar/baz", false, false},
|
||||||
|
{"/bar/baz", "", "TestFoo", "x", false, false},
|
||||||
|
{"/bar/baz", "", "TestBar", "x/bar/baz", false, false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
m := newMatcher(regexp.MatchString, tc.pattern, "-test.run", tc.skip)
|
||||||
|
|
||||||
|
parent := &common{name: tc.parent}
|
||||||
|
if tc.parent != "" {
|
||||||
|
parent.level = 1
|
||||||
|
}
|
||||||
|
if n, ok, partial := m.fullName(parent, tc.sub); ok != tc.ok || partial != tc.partial {
|
||||||
|
t.Errorf("for pattern %q, fullName(parent=%q, sub=%q) = %q, ok %v partial %v; want ok %v partial %v",
|
||||||
|
tc.pattern, tc.parent, tc.sub, n, ok, partial, tc.ok, tc.partial)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var namingTestCases = []struct{ name, want string }{
|
||||||
|
// Uniqueness
|
||||||
|
{"", "x/#00"},
|
||||||
|
{"", "x/#01"},
|
||||||
|
{"#0", "x/#0"}, // Doesn't conflict with #00 because the number of digits differs.
|
||||||
|
{"#00", "x/#00#01"}, // Conflicts with implicit #00 (used above), so add a suffix.
|
||||||
|
{"#", "x/#"},
|
||||||
|
{"#", "x/##01"},
|
||||||
|
|
||||||
|
{"t", "x/t"},
|
||||||
|
{"t", "x/t#01"},
|
||||||
|
{"t", "x/t#02"},
|
||||||
|
{"t#00", "x/t#00"}, // Explicit "#00" doesn't conflict with the unsuffixed first subtest.
|
||||||
|
|
||||||
|
{"a#01", "x/a#01"}, // user has subtest with this name.
|
||||||
|
{"a", "x/a"}, // doesn't conflict with this name.
|
||||||
|
{"a", "x/a#02"}, // This string is claimed now, so resume
|
||||||
|
{"a", "x/a#03"}, // with counting.
|
||||||
|
{"a#02", "x/a#02#01"}, // We already used a#02 once, so add a suffix.
|
||||||
|
|
||||||
|
{"b#00", "x/b#00"},
|
||||||
|
{"b", "x/b"}, // Implicit 0 doesn't conflict with explicit "#00".
|
||||||
|
{"b", "x/b#01"},
|
||||||
|
{"b#9223372036854775807", "x/b#9223372036854775807"}, // MaxInt64
|
||||||
|
{"b", "x/b#02"},
|
||||||
|
{"b", "x/b#03"},
|
||||||
|
|
||||||
|
// Sanitizing
|
||||||
|
{"A:1 B:2", "x/A:1_B:2"},
|
||||||
|
{"s\t\r\u00a0", "x/s___"},
|
||||||
|
{"\x01", `x/\x01`},
|
||||||
|
{"\U0010ffff", `x/\U0010ffff`},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNaming(t *T) {
|
||||||
|
m := newMatcher(regexp.MatchString, "", "", "")
|
||||||
|
parent := &common{name: "x", level: 1} // top-level test.
|
||||||
|
|
||||||
|
for i, tc := range namingTestCases {
|
||||||
|
if got, _, _ := m.fullName(parent, tc.name); got != tc.want {
|
||||||
|
t.Errorf("%d:%s: got %q; want %q", i, tc.name, got, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func FuzzNaming(f *F) {
|
||||||
|
for _, tc := range namingTestCases {
|
||||||
|
f.Add(tc.name)
|
||||||
|
}
|
||||||
|
parent := &common{name: "x", level: 1}
|
||||||
|
var m *matcher
|
||||||
|
var seen map[string]string
|
||||||
|
reset := func() {
|
||||||
|
m = allMatcher()
|
||||||
|
seen = make(map[string]string)
|
||||||
|
}
|
||||||
|
reset()
|
||||||
|
|
||||||
|
f.Fuzz(func(t *T, subname string) {
|
||||||
|
if len(subname) > 10 {
|
||||||
|
// Long names attract the OOM killer.
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
|
name := m.unique(parent.name, subname)
|
||||||
|
if !strings.Contains(name, "/"+subname) {
|
||||||
|
t.Errorf("name %q does not contain subname %q", name, subname)
|
||||||
|
}
|
||||||
|
if prev, ok := seen[name]; ok {
|
||||||
|
t.Errorf("name %q generated by both %q and %q", name, prev, subname)
|
||||||
|
}
|
||||||
|
if len(seen) > 1e6 {
|
||||||
|
// Free up memory.
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
seen[name] = subname
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoString returns a string that is more readable than the default, which makes
|
||||||
|
// it easier to read test errors.
|
||||||
|
func (m alternationMatch) GoString() string {
|
||||||
|
s := make([]string, len(m))
|
||||||
|
for i, m := range m {
|
||||||
|
s[i] = fmt.Sprintf("%#v", m)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("(%s)", strings.Join(s, " | "))
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
// Copyright 2016 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.
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCleanup(t *T) {
|
||||||
|
var cleanups []int
|
||||||
|
t.Run("test", func(t *T) {
|
||||||
|
t.Cleanup(func() { cleanups = append(cleanups, 1) })
|
||||||
|
t.Cleanup(func() { cleanups = append(cleanups, 2) })
|
||||||
|
})
|
||||||
|
if got, want := cleanups, []int{2, 1}; !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("unexpected cleanup record; got %v want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunCleanup(t *T) {
|
||||||
|
outerCleanup := 0
|
||||||
|
innerCleanup := 0
|
||||||
|
t.Run("test", func(t *T) {
|
||||||
|
t.Cleanup(func() { outerCleanup++ })
|
||||||
|
t.Run("x", func(t *T) {
|
||||||
|
t.Cleanup(func() { innerCleanup++ })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if innerCleanup != 1 {
|
||||||
|
t.Errorf("unexpected inner cleanup count; got %d want 1", innerCleanup)
|
||||||
|
}
|
||||||
|
if outerCleanup != 1 {
|
||||||
|
t.Errorf("unexpected outer cleanup count; got %d want 1", outerCleanup) // wrong upstream!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCleanupParallelSubtests(t *T) {
|
||||||
|
ranCleanup := 0
|
||||||
|
t.Run("test", func(t *T) {
|
||||||
|
t.Cleanup(func() { ranCleanup++ })
|
||||||
|
t.Run("x", func(t *T) {
|
||||||
|
t.Parallel()
|
||||||
|
if ranCleanup > 0 {
|
||||||
|
t.Error("outer cleanup ran before parallel subtest")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if ranCleanup != 1 {
|
||||||
|
t.Errorf("unexpected cleanup count; got %d want 1", ranCleanup)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNestedCleanup(t *T) {
|
||||||
|
ranCleanup := 0
|
||||||
|
t.Run("test", func(t *T) {
|
||||||
|
t.Cleanup(func() {
|
||||||
|
if ranCleanup != 2 {
|
||||||
|
t.Errorf("unexpected cleanup count in first cleanup: got %d want 2", ranCleanup)
|
||||||
|
}
|
||||||
|
ranCleanup++
|
||||||
|
})
|
||||||
|
t.Cleanup(func() {
|
||||||
|
if ranCleanup != 0 {
|
||||||
|
t.Errorf("unexpected cleanup count in second cleanup: got %d want 0", ranCleanup)
|
||||||
|
}
|
||||||
|
ranCleanup++
|
||||||
|
t.Cleanup(func() {
|
||||||
|
if ranCleanup != 1 {
|
||||||
|
t.Errorf("unexpected cleanup count in nested cleanup: got %d want 1", ranCleanup)
|
||||||
|
}
|
||||||
|
ranCleanup++
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if ranCleanup != 3 {
|
||||||
|
t.Errorf("unexpected cleanup count: got %d want 3", ranCleanup)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,686 @@
|
|||||||
|
// Copyright 2009 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.
|
||||||
|
//
|
||||||
|
// This file has been modified for use by the TinyGo compiler.
|
||||||
|
// src: https://github.com/golang/go/blob/61bb56ad/src/testing/testing.go
|
||||||
|
|
||||||
|
// Package testing provides support for automated testing of Go packages.
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Testing flags.
|
||||||
|
var (
|
||||||
|
flagVerbose bool
|
||||||
|
flagShort bool
|
||||||
|
flagRunRegexp string
|
||||||
|
flagSkipRegexp string
|
||||||
|
flagShuffle string
|
||||||
|
flagCount int
|
||||||
|
)
|
||||||
|
|
||||||
|
var initRan bool
|
||||||
|
|
||||||
|
// Init registers testing flags. It has no effect if it has already run.
|
||||||
|
func Init() {
|
||||||
|
if initRan {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
initRan = true
|
||||||
|
|
||||||
|
flag.BoolVar(&flagVerbose, "test.v", false, "verbose: print additional output")
|
||||||
|
flag.BoolVar(&flagShort, "test.short", false, "short: run smaller test suite to save time")
|
||||||
|
flag.StringVar(&flagRunRegexp, "test.run", "", "run: regexp of tests to run")
|
||||||
|
flag.StringVar(&flagSkipRegexp, "test.skip", "", "skip: regexp of tests to run")
|
||||||
|
flag.StringVar(&flagShuffle, "test.shuffle", "off", "shuffle: off, on, <numeric-seed>")
|
||||||
|
|
||||||
|
flag.IntVar(&flagCount, "test.count", 1, "run each test or benchmark `count` times")
|
||||||
|
|
||||||
|
initBenchmarkFlags()
|
||||||
|
}
|
||||||
|
|
||||||
|
// common holds the elements common between T and B and
|
||||||
|
// captures common methods such as Errorf.
|
||||||
|
type common struct {
|
||||||
|
output *logger
|
||||||
|
indent string
|
||||||
|
ran bool // Test or benchmark (or one of its subtests) was executed.
|
||||||
|
failed bool // Test or benchmark has failed.
|
||||||
|
skipped bool // Test of benchmark has been skipped.
|
||||||
|
cleanups []func() // optional functions to be called at the end of the test
|
||||||
|
finished bool // Test function has completed.
|
||||||
|
|
||||||
|
hasSub bool // TODO: should be atomic
|
||||||
|
|
||||||
|
parent *common
|
||||||
|
level int // Nesting depth of test or benchmark.
|
||||||
|
name string // Name of test or benchmark.
|
||||||
|
start time.Time // Time test or benchmark started
|
||||||
|
duration time.Duration
|
||||||
|
|
||||||
|
tempDir string
|
||||||
|
tempDirErr error
|
||||||
|
tempDirSeq int32
|
||||||
|
}
|
||||||
|
|
||||||
|
type logger struct {
|
||||||
|
logToStdout bool
|
||||||
|
b bytes.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Write(p []byte) (int, error) {
|
||||||
|
if l.logToStdout {
|
||||||
|
return os.Stdout.Write(p)
|
||||||
|
}
|
||||||
|
return l.b.Write(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) WriteTo(w io.Writer) (int64, error) {
|
||||||
|
if l.logToStdout {
|
||||||
|
// We've already been logging to stdout; nothing to do.
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
return l.b.WriteTo(w)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logger) Len() int {
|
||||||
|
return l.b.Len()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Short reports whether the -test.short flag is set.
|
||||||
|
func Short() bool {
|
||||||
|
return flagShort
|
||||||
|
}
|
||||||
|
|
||||||
|
// CoverMode reports what the test coverage mode is set to.
|
||||||
|
//
|
||||||
|
// Test coverage is not supported; this returns the empty string.
|
||||||
|
func CoverMode() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verbose reports whether the -test.v flag is set.
|
||||||
|
func Verbose() bool {
|
||||||
|
return flagVerbose
|
||||||
|
}
|
||||||
|
|
||||||
|
// String constant that is being set when running a test.
|
||||||
|
var testBinary string
|
||||||
|
|
||||||
|
// Testing returns whether the program was compiled as a test, using "tinygo
|
||||||
|
// test". It returns false when built using "tinygo build", "tinygo flash", etc.
|
||||||
|
func Testing() bool {
|
||||||
|
return testBinary == "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
// flushToParent writes c.output to the parent after first writing the header
|
||||||
|
// with the given format and arguments.
|
||||||
|
func (c *common) flushToParent(testName, format string, args ...interface{}) {
|
||||||
|
if c.parent == nil {
|
||||||
|
// The fake top-level test doesn't want a FAIL or PASS banner.
|
||||||
|
// Not quite sure how this works upstream.
|
||||||
|
c.output.WriteTo(os.Stdout)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(c.parent.output, format, args...)
|
||||||
|
c.output.WriteTo(c.parent.output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fmtDuration returns a string representing d in the form "87.00s".
|
||||||
|
func fmtDuration(d time.Duration) string {
|
||||||
|
return fmt.Sprintf("%.2fs", d.Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
// TB is the interface common to T and B.
|
||||||
|
type TB interface {
|
||||||
|
Cleanup(func())
|
||||||
|
Error(args ...interface{})
|
||||||
|
Errorf(format string, args ...interface{})
|
||||||
|
Fail()
|
||||||
|
FailNow()
|
||||||
|
Failed() bool
|
||||||
|
Fatal(args ...interface{})
|
||||||
|
Fatalf(format string, args ...interface{})
|
||||||
|
Helper()
|
||||||
|
Log(args ...interface{})
|
||||||
|
Logf(format string, args ...interface{})
|
||||||
|
Name() string
|
||||||
|
Setenv(key, value string)
|
||||||
|
Skip(args ...interface{})
|
||||||
|
SkipNow()
|
||||||
|
Skipf(format string, args ...interface{})
|
||||||
|
Skipped() bool
|
||||||
|
TempDir() string
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ TB = (*T)(nil)
|
||||||
|
var _ TB = (*B)(nil)
|
||||||
|
|
||||||
|
// T is a type passed to Test functions to manage test state and support formatted test logs.
|
||||||
|
// Logs are accumulated during execution and dumped to standard output when done.
|
||||||
|
type T struct {
|
||||||
|
common
|
||||||
|
context *testContext // For running tests and subtests.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name returns the name of the running test or benchmark.
|
||||||
|
func (c *common) Name() string {
|
||||||
|
return c.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *common) setRan() {
|
||||||
|
if c.parent != nil {
|
||||||
|
c.parent.setRan()
|
||||||
|
}
|
||||||
|
c.ran = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fail marks the function as having failed but continues execution.
|
||||||
|
func (c *common) Fail() {
|
||||||
|
c.failed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failed reports whether the function has failed.
|
||||||
|
func (c *common) Failed() bool {
|
||||||
|
failed := c.failed
|
||||||
|
return failed
|
||||||
|
}
|
||||||
|
|
||||||
|
// FailNow marks the function as having failed and stops its execution
|
||||||
|
// by calling runtime.Goexit (which then runs all deferred calls in the
|
||||||
|
// current goroutine).
|
||||||
|
func (c *common) FailNow() {
|
||||||
|
c.Fail()
|
||||||
|
|
||||||
|
c.finished = true
|
||||||
|
c.Error("FailNow is incomplete, requires runtime.Goexit()")
|
||||||
|
}
|
||||||
|
|
||||||
|
// log generates the output.
|
||||||
|
func (c *common) log(s string) {
|
||||||
|
// This doesn't print the same as in upstream go, but works for now.
|
||||||
|
if len(s) != 0 && s[len(s)-1] == '\n' {
|
||||||
|
s = s[:len(s)-1]
|
||||||
|
}
|
||||||
|
lines := strings.Split(s, "\n")
|
||||||
|
// First line.
|
||||||
|
fmt.Fprintf(c.output, "%s %s\n", c.indent, lines[0])
|
||||||
|
// More lines.
|
||||||
|
for _, line := range lines[1:] {
|
||||||
|
fmt.Fprintf(c.output, "%s %s\n", c.indent, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log formats its arguments using default formatting, analogous to Println,
|
||||||
|
// and records the text in the error log. For tests, the text will be printed only if
|
||||||
|
// the test fails or the -test.v flag is set. For benchmarks, the text is always
|
||||||
|
// printed to avoid having performance depend on the value of the -test.v flag.
|
||||||
|
func (c *common) Log(args ...interface{}) { c.log(fmt.Sprintln(args...)) }
|
||||||
|
|
||||||
|
// Logf formats its arguments according to the format, analogous to Printf, and
|
||||||
|
// records the text in the error log. A final newline is added if not provided. For
|
||||||
|
// tests, the text will be printed only if the test fails or the -test.v flag is
|
||||||
|
// set. For benchmarks, the text is always printed to avoid having performance
|
||||||
|
// depend on the value of the -test.v flag.
|
||||||
|
func (c *common) Logf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) }
|
||||||
|
|
||||||
|
// Error is equivalent to Log followed by Fail.
|
||||||
|
func (c *common) Error(args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintln(args...))
|
||||||
|
c.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf is equivalent to Logf followed by Fail.
|
||||||
|
func (c *common) Errorf(format string, args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintf(format, args...))
|
||||||
|
c.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal is equivalent to Log followed by FailNow.
|
||||||
|
func (c *common) Fatal(args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintln(args...))
|
||||||
|
c.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf is equivalent to Logf followed by FailNow.
|
||||||
|
func (c *common) Fatalf(format string, args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintf(format, args...))
|
||||||
|
c.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip is equivalent to Log followed by SkipNow.
|
||||||
|
func (c *common) Skip(args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintln(args...))
|
||||||
|
c.SkipNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skipf is equivalent to Logf followed by SkipNow.
|
||||||
|
func (c *common) Skipf(format string, args ...interface{}) {
|
||||||
|
c.log(fmt.Sprintf(format, args...))
|
||||||
|
c.SkipNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SkipNow marks the test as having been skipped and stops its execution
|
||||||
|
// by calling runtime.Goexit.
|
||||||
|
func (c *common) SkipNow() {
|
||||||
|
c.skip()
|
||||||
|
c.finished = true
|
||||||
|
c.Error("SkipNow is incomplete, requires runtime.Goexit()")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *common) skip() {
|
||||||
|
c.skipped = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skipped reports whether the test was skipped.
|
||||||
|
func (c *common) Skipped() bool {
|
||||||
|
return c.skipped
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper is not implemented, it is only provided for compatibility.
|
||||||
|
func (c *common) Helper() {
|
||||||
|
// Unimplemented.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup registers a function to be called when the test (or subtest) and all its
|
||||||
|
// subtests complete. Cleanup functions will be called in last added,
|
||||||
|
// first called order.
|
||||||
|
func (c *common) Cleanup(f func()) {
|
||||||
|
c.cleanups = append(c.cleanups, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TempDir returns a temporary directory for the test to use.
|
||||||
|
// The directory is automatically removed by Cleanup when the test and
|
||||||
|
// all its subtests complete.
|
||||||
|
// Each subsequent call to t.TempDir returns a unique directory;
|
||||||
|
// if the directory creation fails, TempDir terminates the test by calling Fatal.
|
||||||
|
func (c *common) TempDir() string {
|
||||||
|
// Use a single parent directory for all the temporary directories
|
||||||
|
// created by a test, each numbered sequentially.
|
||||||
|
var nonExistent bool
|
||||||
|
if c.tempDir == "" { // Usually the case with js/wasm
|
||||||
|
nonExistent = true
|
||||||
|
} else {
|
||||||
|
_, err := os.Stat(c.tempDir)
|
||||||
|
nonExistent = errors.Is(err, fs.ErrNotExist)
|
||||||
|
if err != nil && !nonExistent {
|
||||||
|
c.Fatalf("TempDir: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if nonExistent {
|
||||||
|
c.Helper()
|
||||||
|
|
||||||
|
// Drop unusual characters (such as path separators or
|
||||||
|
// characters interacting with globs) from the directory name to
|
||||||
|
// avoid surprising os.MkdirTemp behavior.
|
||||||
|
mapper := func(r rune) rune {
|
||||||
|
if r < utf8.RuneSelf {
|
||||||
|
const allowed = "!#$%&()+,-.=@^_{}~ "
|
||||||
|
if '0' <= r && r <= '9' ||
|
||||||
|
'a' <= r && r <= 'z' ||
|
||||||
|
'A' <= r && r <= 'Z' {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
if strings.ContainsRune(allowed, r) {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
} else if unicode.IsLetter(r) || unicode.IsNumber(r) {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
pattern := strings.Map(mapper, c.Name())
|
||||||
|
c.tempDir, c.tempDirErr = os.MkdirTemp("", pattern)
|
||||||
|
if c.tempDirErr == nil {
|
||||||
|
c.Cleanup(func() {
|
||||||
|
if err := os.RemoveAll(c.tempDir); err != nil {
|
||||||
|
c.Errorf("TempDir RemoveAll cleanup: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.tempDirErr != nil {
|
||||||
|
c.Fatalf("TempDir: %v", c.tempDirErr)
|
||||||
|
}
|
||||||
|
seq := c.tempDirSeq
|
||||||
|
c.tempDirSeq++
|
||||||
|
dir := fmt.Sprintf("%s%c%03d", c.tempDir, os.PathSeparator, seq)
|
||||||
|
if err := os.Mkdir(dir, 0777); err != nil {
|
||||||
|
c.Fatalf("TempDir: %v", err)
|
||||||
|
}
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setenv calls os.Setenv(key, value) and uses Cleanup to
|
||||||
|
// restore the environment variable to its original value
|
||||||
|
// after the test.
|
||||||
|
func (c *common) Setenv(key, value string) {
|
||||||
|
prevValue, ok := os.LookupEnv(key)
|
||||||
|
|
||||||
|
if err := os.Setenv(key, value); err != nil {
|
||||||
|
c.Fatalf("cannot set environment variable: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
c.Cleanup(func() {
|
||||||
|
os.Setenv(key, prevValue)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
c.Cleanup(func() {
|
||||||
|
os.Unsetenv(key)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chdir calls os.Chdir(dir) and uses Cleanup to restore the current
|
||||||
|
// working directory to its original value after the test. On Unix, it
|
||||||
|
// also sets PWD environment variable for the duration of the test.
|
||||||
|
//
|
||||||
|
// Because Chdir affects the whole process, it cannot be used
|
||||||
|
// in parallel tests or tests with parallel ancestors.
|
||||||
|
func (c *common) Chdir(dir string) {
|
||||||
|
// Note: function copied from the Go 1.24.0 source tree.
|
||||||
|
|
||||||
|
oldwd, err := os.Open(".")
|
||||||
|
if err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.Chdir(dir); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
// On POSIX platforms, PWD represents “an absolute pathname of the
|
||||||
|
// current working directory.” Since we are changing the working
|
||||||
|
// directory, we should also set or update PWD to reflect that.
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows", "plan9":
|
||||||
|
// Windows and Plan 9 do not use the PWD variable.
|
||||||
|
default:
|
||||||
|
if !filepath.IsAbs(dir) {
|
||||||
|
dir, err = os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.Setenv("PWD", dir)
|
||||||
|
}
|
||||||
|
c.Cleanup(func() {
|
||||||
|
err := oldwd.Chdir()
|
||||||
|
oldwd.Close()
|
||||||
|
if err != nil {
|
||||||
|
// It's not safe to continue with tests if we can't
|
||||||
|
// get back to the original working directory. Since
|
||||||
|
// we are holding a dirfd, this is highly unlikely.
|
||||||
|
panic("testing.Chdir: " + err.Error())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// runCleanup is called at the end of the test.
|
||||||
|
func (c *common) runCleanup() {
|
||||||
|
for {
|
||||||
|
var cleanup func()
|
||||||
|
if len(c.cleanups) > 0 {
|
||||||
|
last := len(c.cleanups) - 1
|
||||||
|
cleanup = c.cleanups[last]
|
||||||
|
c.cleanups = c.cleanups[:last]
|
||||||
|
}
|
||||||
|
if cleanup == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parallel is not implemented, it is only provided for compatibility.
|
||||||
|
func (t *T) Parallel() {
|
||||||
|
// Unimplemented.
|
||||||
|
}
|
||||||
|
|
||||||
|
// InternalTest is a reference to a test that should be called during a test suite run.
|
||||||
|
type InternalTest struct {
|
||||||
|
Name string
|
||||||
|
F func(*T)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tRunner(t *T, fn func(t *T)) {
|
||||||
|
defer func() {
|
||||||
|
t.runCleanup()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Run the test.
|
||||||
|
t.start = time.Now()
|
||||||
|
fn(t)
|
||||||
|
t.duration += time.Since(t.start) // TODO: capture cleanup time, too.
|
||||||
|
|
||||||
|
t.report() // Report after all subtests have finished.
|
||||||
|
if t.parent != nil && !t.hasSub {
|
||||||
|
t.setRan()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run runs f as a subtest of t called name. It waits until the subtest is finished
|
||||||
|
// and returns whether the subtest succeeded.
|
||||||
|
func (t *T) Run(name string, f func(t *T)) bool {
|
||||||
|
t.hasSub = true
|
||||||
|
testName, ok, _ := t.context.match.fullName(&t.common, name)
|
||||||
|
if !ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a subtest.
|
||||||
|
sub := T{
|
||||||
|
common: common{
|
||||||
|
output: &logger{logToStdout: flagVerbose},
|
||||||
|
name: testName,
|
||||||
|
parent: &t.common,
|
||||||
|
level: t.level + 1,
|
||||||
|
},
|
||||||
|
context: t.context,
|
||||||
|
}
|
||||||
|
if t.level > 0 {
|
||||||
|
sub.indent = sub.indent + " "
|
||||||
|
}
|
||||||
|
if flagVerbose {
|
||||||
|
fmt.Fprintf(t.output, "=== RUN %s\n", sub.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
tRunner(&sub, f)
|
||||||
|
return !sub.failed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deadline reports the time at which the test binary will have
|
||||||
|
// exceeded the timeout specified by the -timeout flag.
|
||||||
|
//
|
||||||
|
// The ok result is false if the -timeout flag indicates “no timeout” (0).
|
||||||
|
// For now tinygo always return 0, false.
|
||||||
|
//
|
||||||
|
// Not Implemented.
|
||||||
|
func (t *T) Deadline() (deadline time.Time, ok bool) {
|
||||||
|
deadline = t.context.deadline
|
||||||
|
return deadline, !deadline.IsZero()
|
||||||
|
}
|
||||||
|
|
||||||
|
// testContext holds all fields that are common to all tests. This includes
|
||||||
|
// synchronization primitives to run at most *parallel tests.
|
||||||
|
type testContext struct {
|
||||||
|
match *matcher
|
||||||
|
deadline time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestContext(m *matcher) *testContext {
|
||||||
|
return &testContext{
|
||||||
|
match: m,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// M is a test suite.
|
||||||
|
type M struct {
|
||||||
|
// tests is a list of the test names to execute
|
||||||
|
Tests []InternalTest
|
||||||
|
Benchmarks []InternalBenchmark
|
||||||
|
|
||||||
|
deps testDeps
|
||||||
|
|
||||||
|
// value to pass to os.Exit, the outer test func main
|
||||||
|
// harness calls os.Exit with this code. See #34129.
|
||||||
|
exitCode int
|
||||||
|
}
|
||||||
|
|
||||||
|
type testDeps interface {
|
||||||
|
MatchString(pat, str string) (bool, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *M) shuffle() error {
|
||||||
|
var n int64
|
||||||
|
|
||||||
|
if flagShuffle == "on" {
|
||||||
|
n = time.Now().UnixNano()
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
n, err = strconv.ParseInt(flagShuffle, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
m.exitCode = 2
|
||||||
|
return fmt.Errorf(`testing: -shuffle should be "off", "on", or a valid integer: %v`, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("-test.shuffle", n)
|
||||||
|
rng := rand.New(rand.NewSource(n))
|
||||||
|
rng.Shuffle(len(m.Tests), func(i, j int) { m.Tests[i], m.Tests[j] = m.Tests[j], m.Tests[i] })
|
||||||
|
rng.Shuffle(len(m.Benchmarks), func(i, j int) { m.Benchmarks[i], m.Benchmarks[j] = m.Benchmarks[j], m.Benchmarks[i] })
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run runs the tests. It returns an exit code to pass to os.Exit.
|
||||||
|
func (m *M) Run() (code int) {
|
||||||
|
defer func() {
|
||||||
|
code = m.exitCode
|
||||||
|
}()
|
||||||
|
|
||||||
|
if !flag.Parsed() {
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
if flagShuffle != "off" {
|
||||||
|
if err := m.shuffle(); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testRan, testOk := runTests(m.deps.MatchString, m.Tests)
|
||||||
|
if !testRan && *matchBenchmarks == "" {
|
||||||
|
fmt.Fprintln(os.Stderr, "testing: warning: no tests to run")
|
||||||
|
}
|
||||||
|
if !testOk || !runBenchmarks(m.deps.MatchString, m.Benchmarks) {
|
||||||
|
fmt.Println("FAIL")
|
||||||
|
m.exitCode = 1
|
||||||
|
} else {
|
||||||
|
fmt.Println("PASS")
|
||||||
|
m.exitCode = 0
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func runTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ran, ok bool) {
|
||||||
|
ok = true
|
||||||
|
|
||||||
|
ctx := newTestContext(newMatcher(matchString, flagRunRegexp, "-test.run", flagSkipRegexp))
|
||||||
|
t := &T{
|
||||||
|
common: common{
|
||||||
|
output: &logger{logToStdout: flagVerbose},
|
||||||
|
},
|
||||||
|
context: ctx,
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < flagCount; i++ {
|
||||||
|
tRunner(t, func(t *T) {
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.Name, test.F)
|
||||||
|
ok = ok && !t.Failed()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.ran, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *T) report() {
|
||||||
|
dstr := fmtDuration(t.duration)
|
||||||
|
format := t.indent + "--- %s: %s (%s)\n"
|
||||||
|
if t.Failed() {
|
||||||
|
if t.parent != nil {
|
||||||
|
t.parent.failed = true
|
||||||
|
}
|
||||||
|
t.flushToParent(t.name, format, "FAIL", t.name, dstr)
|
||||||
|
} else if flagVerbose {
|
||||||
|
if t.Skipped() {
|
||||||
|
t.flushToParent(t.name, format, "SKIP", t.name, dstr)
|
||||||
|
} else {
|
||||||
|
t.flushToParent(t.name, format, "PASS", t.name, dstr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllocsPerRun returns the average number of allocations during calls to f.
|
||||||
|
// Although the return value has type float64, it will always be an integral
|
||||||
|
// value.
|
||||||
|
//
|
||||||
|
// Not implemented.
|
||||||
|
func AllocsPerRun(runs int, f func()) (avg float64) {
|
||||||
|
f()
|
||||||
|
for i := 0; i < runs; i++ {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type InternalExample struct {
|
||||||
|
Name string
|
||||||
|
F func()
|
||||||
|
Output string
|
||||||
|
Unordered bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MainStart is meant for use by tests generated by 'go test'.
|
||||||
|
// It is not meant to be called directly and is not subject to the Go 1 compatibility document.
|
||||||
|
// It may change signature from release to release.
|
||||||
|
func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, fuzzTargets []InternalFuzzTarget, examples []InternalExample) *M {
|
||||||
|
Init()
|
||||||
|
return &M{
|
||||||
|
Tests: tests,
|
||||||
|
Benchmarks: benchmarks,
|
||||||
|
deps: deps.(testDeps),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A fake regexp matcher.
|
||||||
|
// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full,
|
||||||
|
// and lets tests pass on cortex-m.
|
||||||
|
func fakeMatchString(pat, str string) (bool, error) {
|
||||||
|
if pat == ".*" {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
matched := strings.Contains(str, pat)
|
||||||
|
return matched, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
// TODO: implement readdir for windows, then enable this file
|
||||||
|
|
||||||
|
// Copyright 2014 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.
|
||||||
|
|
||||||
|
package testing_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is exactly what a test would do without a TestMain.
|
||||||
|
// It's here only so that there is at least one package in the
|
||||||
|
// standard library with a TestMain, so that code is executed.
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Exit(m.Run())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTempDirInCleanup(t *testing.T) {
|
||||||
|
if runtime.GOOS == "wasip1" || runtime.GOOS == "wasip2" {
|
||||||
|
t.Log("Skipping. TODO: implement RemoveAll for wasi")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var dir string
|
||||||
|
|
||||||
|
t.Run("test", func(t *testing.T) {
|
||||||
|
t.Cleanup(func() {
|
||||||
|
dir = t.TempDir()
|
||||||
|
})
|
||||||
|
_ = t.TempDir()
|
||||||
|
})
|
||||||
|
|
||||||
|
fi, err := os.Stat(dir)
|
||||||
|
if fi != nil {
|
||||||
|
t.Fatalf("Directory %q from user Cleanup still exists", dir)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, fs.ErrNotExist) {
|
||||||
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTempDirInBenchmark(t *testing.T) {
|
||||||
|
testing.Benchmark(func(b *testing.B) {
|
||||||
|
if !b.Run("test", func(b *testing.B) {
|
||||||
|
// Add a loop so that the test won't fail. See issue 38677.
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_ = b.TempDir()
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
t.Fatal("Sub test failure in a benchmark")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTempDir(t *testing.T) {
|
||||||
|
if runtime.GOOS == "wasip1" || runtime.GOOS == "wasip2" {
|
||||||
|
t.Log("Skipping. TODO: implement RemoveAll for wasi")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
testTempDir(t)
|
||||||
|
t.Run("InSubtest", testTempDir)
|
||||||
|
t.Run("test/subtest", testTempDir)
|
||||||
|
t.Run("test\\subtest", testTempDir)
|
||||||
|
t.Run("test:subtest", testTempDir)
|
||||||
|
t.Run("test/..", testTempDir)
|
||||||
|
t.Run("../test", testTempDir)
|
||||||
|
t.Run("test[]", testTempDir)
|
||||||
|
t.Run("test*", testTempDir)
|
||||||
|
t.Run("äöüéè", testTempDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTempDir(t *testing.T) {
|
||||||
|
dirCh := make(chan string, 1)
|
||||||
|
t.Cleanup(func() {
|
||||||
|
// Verify directory has been removed.
|
||||||
|
select {
|
||||||
|
case dir := <-dirCh:
|
||||||
|
fi, err := os.Stat(dir)
|
||||||
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
|
// All good
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Errorf("directory %q still exists: %v, isDir=%v", dir, fi, fi.IsDir())
|
||||||
|
default:
|
||||||
|
if !t.Failed() {
|
||||||
|
t.Fatal("never received dir channel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
dir := t.TempDir()
|
||||||
|
if dir == "" {
|
||||||
|
t.Fatal("expected dir")
|
||||||
|
}
|
||||||
|
dir2 := t.TempDir()
|
||||||
|
if dir == dir2 {
|
||||||
|
t.Fatal("subsequent calls to TempDir returned the same directory")
|
||||||
|
}
|
||||||
|
if filepath.Dir(dir) != filepath.Dir(dir2) {
|
||||||
|
t.Fatalf("calls to TempDir do not share a parent; got %q, %q", dir, dir2)
|
||||||
|
}
|
||||||
|
dirCh <- dir
|
||||||
|
fi, err := os.Stat(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !fi.IsDir() {
|
||||||
|
t.Errorf("dir %q is not a dir", dir)
|
||||||
|
}
|
||||||
|
files, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(files) > 0 {
|
||||||
|
t.Errorf("unexpected %d files in TempDir: %v", len(files), files)
|
||||||
|
}
|
||||||
|
|
||||||
|
glob := filepath.Join(dir, "*.txt")
|
||||||
|
if _, err := filepath.Glob(glob); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Remove(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected files in TempDir")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetenv(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
key string
|
||||||
|
initialValueExists bool
|
||||||
|
initialValue string
|
||||||
|
newValue string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "initial value exists",
|
||||||
|
key: "GO_TEST_KEY_1",
|
||||||
|
initialValueExists: true,
|
||||||
|
initialValue: "111",
|
||||||
|
newValue: "222",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "initial value exists but empty",
|
||||||
|
key: "GO_TEST_KEY_2",
|
||||||
|
initialValueExists: true,
|
||||||
|
initialValue: "",
|
||||||
|
newValue: "222",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "initial value is not exists",
|
||||||
|
key: "GO_TEST_KEY_3",
|
||||||
|
initialValueExists: false,
|
||||||
|
initialValue: "",
|
||||||
|
newValue: "222",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
if test.initialValueExists {
|
||||||
|
if err := os.Setenv(test.key, test.initialValue); err != nil {
|
||||||
|
t.Fatalf("unable to set env: got %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
os.Unsetenv(test.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
t.Setenv(test.key, test.newValue)
|
||||||
|
if os.Getenv(test.key) != test.newValue {
|
||||||
|
t.Fatalf("unexpected value after t.Setenv: got %s, want %s", os.Getenv(test.key), test.newValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
got, exists := os.LookupEnv(test.key)
|
||||||
|
if got != test.initialValue {
|
||||||
|
t.Fatalf("unexpected value after t.Setenv cleanup: got %s, want %s", got, test.initialValue)
|
||||||
|
}
|
||||||
|
if exists != test.initialValueExists {
|
||||||
|
t.Fatalf("unexpected value after t.Setenv cleanup: got %t, want %t", exists, test.initialValueExists)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTesting(t *testing.T) {
|
||||||
|
if !testing.Testing() {
|
||||||
|
t.Error("Expected testing.Testing() to return true while in a test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"serial-port": ["2e8a:0003"],
|
"serial-port": ["2e8a:0003"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"build-tags": ["badger2040_w", "cyw43439"],
|
"build-tags": ["badger2040_w", "cyw43439"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=1020K"
|
"--defsym=__flash_size=1020K"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"serial-port": ["2e8a:0003"],
|
"serial-port": ["2e8a:0003"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"build-tags": ["badger2040"],
|
"build-tags": ["badger2040"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=1020K"
|
"--defsym=__flash_size=1020K"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"serial-port": ["2e8a:1023"],
|
"serial-port": ["2e8a:1023"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"build-tags": ["challenger_rp2040"],
|
"build-tags": ["challenger_rp2040"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=8M"
|
"--defsym=__flash_size=8M"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"serial-port": ["239a:80f1"],
|
"serial-port": ["239a:80f1"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"build-tags": ["feather_rp2040"],
|
"build-tags": ["feather_rp2040"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=8192K"
|
"--defsym=__flash_size=8192K"
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"inherits": ["attiny85"],
|
|
||||||
"build-tags": ["gopher_arcade"],
|
|
||||||
"ldflags": [
|
|
||||||
"--defsym=_bootloader_size=2180",
|
|
||||||
"--defsym=_stack_size=128"
|
|
||||||
],
|
|
||||||
"flash-command": "avrdude -c usbasp -p t85 -B 10 -U flash:w:{hex}:i",
|
|
||||||
"emulator": "simavr -m attiny85 -f 16000000 {}"
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"serial-port": ["2e8a:0003"],
|
"serial-port": ["2e8a:0003"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"build-tags": ["gopher_badge"],
|
"build-tags": ["gopher_badge"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=8M"
|
"--defsym=__flash_size=8M"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"build-tags": ["macropad_rp2040"],
|
"build-tags": ["macropad_rp2040"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"serial-port": ["239a:8107"],
|
"serial-port": ["239a:8107"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=8M"
|
"--defsym=__flash_size=8M"
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"inherits": [
|
|
||||||
"rp2350b"
|
|
||||||
],
|
|
||||||
"build-tags": ["metro_rp2350"],
|
|
||||||
"serial-port": ["239a:814e"],
|
|
||||||
"default-stack-size": 8192,
|
|
||||||
"ldflags": [
|
|
||||||
"--defsym=__flash_size=16M"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"serial-port": ["2341:005e"],
|
"serial-port": ["2341:005e"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"build-tags": ["nano_rp2040", "ninafw", "ninafw_machine_init"],
|
"build-tags": ["nano_rp2040", "ninafw", "ninafw_machine_init"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=16M"
|
"--defsym=__flash_size=16M"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
"rp2040"
|
"rp2040"
|
||||||
],
|
],
|
||||||
"serial-port": ["239a:80f7"],
|
"serial-port": ["239a:80f7"],
|
||||||
"default-stack-size": 8192,
|
|
||||||
"build-tags": ["qtpy_rp2040"],
|
"build-tags": ["qtpy_rp2040"],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"--defsym=__flash_size=8192K"
|
"--defsym=__flash_size=8192K"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"qemu"
|
"qemu"
|
||||||
],
|
],
|
||||||
"scheduler": "cores",
|
"scheduler": "cores",
|
||||||
"default-stack-size": 16384,
|
"default-stack-size": 8192,
|
||||||
"cflags": [
|
"cflags": [
|
||||||
"-march=rv32imaczihintpause",
|
"-march=rv32imaczihintpause",
|
||||||
"-DTINYGO_CORES=4"
|
"-DTINYGO_CORES=4"
|
||||||
|
|||||||
@@ -10,8 +10,7 @@
|
|||||||
"-march=rv32imac"
|
"-march=rv32imac"
|
||||||
],
|
],
|
||||||
"ldflags": [
|
"ldflags": [
|
||||||
"-melf32lriscv",
|
"-melf32lriscv"
|
||||||
"-mllvm", "-enable-machine-outliner=never"
|
|
||||||
],
|
],
|
||||||
"gdb": [
|
"gdb": [
|
||||||
"gdb-multiarch",
|
"gdb-multiarch",
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user