Skip to content

os: add stubs for Readlink and File.Seek for baremetal targets #2565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ jobs:
path: build/tinygo.darwin-amd64.tar.gz
- name: Smoke tests
shell: bash
run: make smoketest TINYGO=build/tinygo AVR=0
run: make smoketest TINYGO=$(PWD)/build/tinygo AVR=0
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ jobs:
path: build/release/release.zip
- name: Smoke tests
shell: bash
run: make smoketest TINYGO=build/tinygo AVR=0 XTENSA=0
run: make smoketest TINYGO=$(PWD)/build/tinygo AVR=0 XTENSA=0
- name: Test stdlib packages
run: make tinygo-test
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ GOTESTFLAGS ?= -v
MD5SUM = md5sum

# tinygo binary for tests
TINYGO ?= $(call detect,tinygo,tinygo build/tinygo)
TINYGO ?= $(call detect,tinygo,tinygo $(CURDIR)/build/tinygo)

# Use CCACHE for LLVM if possible
ifneq (, $(shell command -v ccache 2> /dev/null))
Expand Down Expand Up @@ -298,6 +298,8 @@ tinygo-bench-wasi-fast:
.PHONY: smoketest
smoketest:
$(TINYGO) version
# regression test for #2563
cd tests/os/smoke && $(TINYGO) test -c -target=pybadge && rm smoke.test
# test all examples (except pwm)
$(TINYGO) build -size short -o test.hex -target=pca10040 examples/blinky1
@$(MD5SUM) test.hex
Expand Down
8 changes: 8 additions & 0 deletions src/os/file_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func Pipe() (r *File, w *File, err error) {
return nil, nil, ErrNotImplemented
}

func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
return 0, ErrNotImplemented
}

func Readlink(name string) (string, error) {
return "", ErrNotImplemented
}

func tempDir() string {
return "/tmp"
}
27 changes: 27 additions & 0 deletions tests/os/smoke/smoke_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package os_smoke_test

// Simple smoke tests for the os package or things that depend on it.
// Intended to catch build tag mistakes affecting bare metal targets.

import (
"fmt"
"path/filepath"
"testing"
)

// Regression test for https://github.com/tinygo-org/tinygo/issues/2563
func TestFilepath(t *testing.T) {
if filepath.Base("foo/bar") != "bar" {
t.Errorf("filepath.Base is very confused")
}
}

// Regression test for https://github.com/tinygo-org/tinygo/issues/2530
func TestFmt(t *testing.T) {
n, err := fmt.Printf("Hello, world!\n")
if err != nil {
t.Errorf("printf returned error %s", err)
} else if n != 14 {
t.Errorf("printf returned %d, expected 14", n)
}
}