0
0
mirror of https://gitlab.com/cznic/sqlite.git synced 2025-06-11 23:41:48 +00:00
Files
go-sqlite/tcl_test.go
2020-12-30 11:45:05 +01:00

165 lines
3.7 KiB
Go

// Copyright 2020 The Sqlite 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 sqlite // import "modernc.org/sqlite"
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"modernc.org/tcl"
)
var (
oMaxError = flag.Uint("maxerror", 0, "argument of -maxerror passed to the Tcl test suite")
oStart = flag.String("start", "", "argument of -start passed to the Tcl test suite (-start=[$permutation:]$testfile)")
oTclSuite = flag.String("suite", "full", "Tcl test suite [test-file] to run")
oVerbose = flag.String("verbose", "0", "argument of -verbose passed to the Tcl test suite, must be set to a boolean (0, 1) or to \"file\"")
)
func TestTclTest(t *testing.T) {
blacklist := map[string]struct{}{}
switch runtime.GOARCH {
case "386", "arm":
// # This test causes thrashing on machines with smaller amounts of
// # memory. Make sure the host has at least 8GB available before running
// # this test.
blacklist["bigsort.test"] = struct{}{}
}
switch runtime.GOOS {
case "darwin":
for _, v := range []string{
"avtrans.test",
"busy2.test",
"crash5.test",
"exists.test",
"lock2.test",
"mmap1.test",
"mmap4.test",
"multiplex2.test",
"pager1.test",
"pagerfault.test",
"pragma3.test",
"rowallock.test",
"rtree.test",
"savepoint.test",
"schema3.test",
"shared2.test",
"shared9.test",
"superlock.test",
"symlink.test",
"syscall.test",
"tkt-5d863f876e.test",
"tkt-fc62af4523.test",
"tkt4018.test",
"unixexcl.test",
"wal.test",
"wal3.test",
"wal5.test",
"walcrash2.test",
"walro.test",
"walro2.test",
"walsetlk.test",
"walslow.test",
"writecrash.test",
} {
blacklist[v] = struct{}{}
t.Errorf("%v: crashes, disabled", v)
}
}
m, err := filepath.Glob(filepath.FromSlash("testdata/tcl/*"))
if err != nil {
t.Fatal(err)
}
dir, err := ioutil.TempDir("", "sqlite-test-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
bin := "testfixture"
if runtime.GOOS == "windows" {
bin += ".exe"
}
testfixture := filepath.Join(dir, bin)
args0 := []string{"build", "-o", testfixture}
tags := "-tags=libc.nofsync"
if s := *oXTags; s != "" {
tags += "," + s
}
args0 = append(args0, tags, "modernc.org/sqlite/internal/testfixture")
cmd := exec.Command("go", args0...)
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%s\n%v", out, err)
}
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
defer os.Chdir(wd)
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
for _, v := range m {
if _, ok := blacklist[filepath.Base(v)]; ok {
continue
}
s := filepath.Join(wd, v)
d := filepath.Join(dir, filepath.Base(v))
f, err := ioutil.ReadFile(s)
if err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(d, f, 0660); err != nil {
t.Fatal(err)
}
}
library := filepath.Join(dir, "library")
if err := tcl.Library(library); err != nil {
t.Fatal(err)
}
os.Setenv("TCL_LIBRARY", library)
var args []string
switch s := *oTclSuite; s {
case "":
args = []string{"all.test"}
default:
a := strings.Split(s, " ")
args = append([]string{"permutations.test"}, a...)
}
if *oVerbose != "" {
args = append(args, fmt.Sprintf("-verbose=%s", *oVerbose))
}
if *oMaxError != 0 {
args = append(args, fmt.Sprintf("-maxerror=%d", *oMaxError))
}
if *oStart != "" {
args = append(args, fmt.Sprintf("-start=%s", *oStart))
}
os.Setenv("PATH", fmt.Sprintf("%s%c%s", dir, os.PathListSeparator, os.Getenv("PATH")))
cmd = exec.Command(bin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
t.Fatal(err)
}
}