253 строки
4,3 КиБ
Go
253 строки
4,3 КиБ
Go
//go:build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
// mage:import
|
|
. "magefile/docker"
|
|
|
|
"github.com/magefile/mage/mg"
|
|
)
|
|
|
|
var (
|
|
GolangVolume = "golang.my"
|
|
tests_to_run = []string{}
|
|
)
|
|
|
|
func init() {
|
|
AppName = "tinygo"
|
|
ImageName = "my/qtbase.dev"
|
|
|
|
LoadContainerConfig()
|
|
|
|
BuildFn = build
|
|
}
|
|
|
|
func Test() {
|
|
mg.Deps(TestLibs)
|
|
mg.Deps(TestIntegration)
|
|
}
|
|
func TestLibs(ctx context.Context) error {
|
|
paths := []string{
|
|
"pkg",
|
|
"pkg/printer",
|
|
"pkg/scenarios",
|
|
"pkg/link",
|
|
"pkg/link/wifi",
|
|
"pkg/parser",
|
|
"internal",
|
|
}
|
|
|
|
listTests(paths)
|
|
|
|
// err := addTest("test")
|
|
// if err != nil {
|
|
// println("ERROR: " + "test")
|
|
// return err
|
|
// }
|
|
|
|
return runListedTests()
|
|
}
|
|
func TestIntegration(ctx context.Context) error {
|
|
return runTests("./test/int")
|
|
}
|
|
func TestSystem(ctx context.Context) error {
|
|
return runTests("./test")
|
|
}
|
|
|
|
func listTests(paths []string) error {
|
|
for _, p := range paths {
|
|
listAndTest(p)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func listAndTest(p string) error {
|
|
entries, err := os.ReadDir(p)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return testList(p, entries)
|
|
}
|
|
|
|
func testList(p string, entries []os.DirEntry) error {
|
|
for _, e := range entries {
|
|
testOne(p, e)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testOne(p string, e os.DirEntry) error {
|
|
if !e.IsDir() {
|
|
return nil
|
|
}
|
|
if e.Name() == "driver" {
|
|
return nil
|
|
}
|
|
if e.Name() == "lib" {
|
|
return nil
|
|
}
|
|
if e.Name() == "testlib" {
|
|
return nil
|
|
}
|
|
|
|
entries, err := os.ReadDir(p + "/" + e.Name())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
found := false
|
|
for _, e2 := range entries {
|
|
if e2.IsDir() {
|
|
continue
|
|
}
|
|
|
|
if strings.Contains(e2.Name(), "_test.go") {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
testPath := p + "/" + e.Name()
|
|
err = addTest(testPath)
|
|
if err != nil {
|
|
println("ERROR: " + testPath)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func addTest(p string) error {
|
|
tests_to_run = append(tests_to_run, "./"+p)
|
|
return nil
|
|
}
|
|
|
|
func runListedTests() error {
|
|
test_paths := strings.Join(tests_to_run, " ")
|
|
return runTests(test_paths)
|
|
}
|
|
|
|
func runTests(paths string) error {
|
|
Bash(`cp -f $HOME/.Xauthority /tmp/._test_Xauthority`)
|
|
return Bash(`sudo docker run -ti --rm \
|
|
-h host \
|
|
--net=none \
|
|
-v /etc/localtime:/etc/localtime:ro \
|
|
-v ` + GolangVolume + `:/usr/local/go:ro \
|
|
\
|
|
-v /gopath:/gopath:rw \
|
|
-v ${PWD}:/app \
|
|
-v /usr/bin/docker:/usr/bin/docker:ro \
|
|
-v /var/run/docker.sock:/var/run/docker.sock:ro \
|
|
-v /usr/bin/socat:/usr/bin/socat \
|
|
\
|
|
-e GOPATH=/gopath \
|
|
-e GOCACHE=/gopath/gocache \
|
|
-e APPDIR=${PWD} \
|
|
\
|
|
--device=/dev/dri/card0 \
|
|
-e DISPLAY=:0 \
|
|
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
|
|
-v /tmp/._test_Xauthority:/home/user/.Xauthority:ro \
|
|
\
|
|
-w /app \
|
|
-u 0 \
|
|
\
|
|
--entrypoint=/bin/bash \
|
|
\
|
|
` + ImageName + " -c '" + ` \
|
|
for t in ` + paths + `; do \
|
|
go test -v -p 1 -gcflags=-l -count=1 $t || exit 1; \
|
|
done'`)
|
|
}
|
|
|
|
func build() {
|
|
BuildAllWithSync()
|
|
}
|
|
|
|
func BuildAllWithSync() {
|
|
GitSubmoduleUpdateInit()
|
|
BuildLLVM()
|
|
Make()
|
|
LLVMSource()
|
|
GenDevice()
|
|
}
|
|
|
|
func GitSubmoduleUpdateInit() error {
|
|
return Bash(`todirect git submodule update --init --recursive`)
|
|
}
|
|
func BuildLLVM() error {
|
|
return Bash(`todirect make llvm-source \
|
|
&& make llvm-build`)
|
|
}
|
|
func Make() {
|
|
LLVMBuildImageName := "my/qtbase.dev"
|
|
Bash(`sudo docker run --rm \
|
|
-h host \
|
|
--net=bridge \
|
|
-v /etc/localtime:/etc/localtime:ro \
|
|
-v ` + GolangVolume + `:/usr/local/go:ro \
|
|
-e PATH=$PATH:/usr/local/go/bin \
|
|
\
|
|
-v /gopath:/gopath:rw \
|
|
-e GOPATH=/gopath \
|
|
-e GOCACHE=/gopath/gocache \
|
|
` + DockerProxyOptions + ` \
|
|
\
|
|
-v ${PWD}:/app \
|
|
\
|
|
-w /app \
|
|
-u 1000 \
|
|
\
|
|
--entrypoint=/bin/bash \
|
|
\
|
|
` + LLVMBuildImageName + " -c '" + ` \
|
|
make \
|
|
'`)
|
|
}
|
|
func BuildLLVMInDocker() {
|
|
LLVMBuildImageName := "my/qtbase.dev"
|
|
Bash(`sudo docker run --rm \
|
|
-h host \
|
|
--net=none \
|
|
-v /etc/localtime:/etc/localtime:ro \
|
|
-v ` + GolangVolume + `:/usr/local/go:ro \
|
|
-e PATH=$PATH:/usr/local/go/bin \
|
|
\
|
|
-v /gopath:/gopath:rw \
|
|
-e GOPATH=/gopath \
|
|
-e GOCACHE=/gopath/gocache \
|
|
\
|
|
-v ${PWD}:/app \
|
|
\
|
|
-w /app \
|
|
-u 1000 \
|
|
\
|
|
--entrypoint=/bin/bash \
|
|
\
|
|
` + LLVMBuildImageName + " -c '" + ` \
|
|
make llvm-build
|
|
'`)
|
|
}
|
|
func LLVMSource() error {
|
|
return Bash(`make llvm-source`)
|
|
}
|
|
func GenDevice() {
|
|
Bash(`:\
|
|
&& cd lib/cmsis-svd && git checkout && cd - \
|
|
&& cd lib/stm32-svd && git checkout && cd - \
|
|
&& make gen-device \
|
|
`)
|
|
}
|