Home | History | Annotate | Download | only in patch
      1 runtime, crypto/x509: add -target flag.
      2 
      3 --- src/crypto/x509/x509_test.go
      4 +++ src/crypto/x509/x509_test.go
      5 @@ -13,29 +13,32 @@ import (
      6  	"crypto/rsa"
      7  	_ "crypto/sha256"
      8  	_ "crypto/sha512"
      9  	"crypto/x509/pkix"
     10  	"encoding/asn1"
     11  	"encoding/base64"
     12  	"encoding/hex"
     13  	"encoding/pem"
     14 +	"flag"
     15  	"fmt"
     16  	"internal/testenv"
     17  	"math/big"
     18  	"net"
     19  	"net/url"
     20  	"os/exec"
     21  	"reflect"
     22  	"runtime"
     23  	"strings"
     24  	"testing"
     25  	"time"
     26  )
     27  
     28 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
     29 +
     30  func TestParsePKCS1PrivateKey(t *testing.T) {
     31  	block, _ := pem.Decode([]byte(pemPrivateKey))
     32  	priv, err := ParsePKCS1PrivateKey(block.Bytes)
     33  	if err != nil {
     34  		t.Errorf("Failed to parse private key: %s", err)
     35  		return
     36  	}
     37  	if priv.PublicKey.N.Cmp(rsaPrivateKey.PublicKey.N) != 0 ||
     38 @@ -1089,17 +1092,23 @@ func TestParsePEMCRL(t *testing.T) {
     39  	}
     40  
     41  	// Can't check the signature here without a package cycle.
     42  }
     43  
     44  func TestImports(t *testing.T) {
     45  	testenv.MustHaveGoRun(t)
     46  
     47 -	if err := exec.Command(testenv.GoToolPath(t), "run", "x509_test_import.go").Run(); err != nil {
     48 +	var cmd *exec.Cmd
     49 +	if *target == "" {
     50 +		cmd = exec.Command(testenv.GoToolPath(t), "run", "x509_test_import.go")
     51 +	} else {
     52 +		cmd = exec.Command("go_"+*target, "run", "-exec", "go_"+*target+"_exec", "x509_test_import.go")
     53 +	}
     54 +	if err := cmd.Run(); err != nil {
     55  		t.Errorf("failed to run x509_test_import.go: %s", err)
     56  	}
     57  }
     58  
     59  const derCRLBase64 = "MIINqzCCDJMCAQEwDQYJKoZIhvcNAQEF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QUlRd0RRWUpLb1pJaHZjTkFRRUZCUUFEZ1lFQUZVNUFzNk16DQpxNVBSc2lmYW9iUVBHaDFhSkx5QytNczVBZ2MwYld5QTNHQWR4dXI1U3BQWmVSV0NCamlQL01FSEJXSkNsQkhQDQpHUmNxNXlJZDNFakRrYUV5eFJhK2k2N0x6dmhJNmMyOUVlNks5cFNZd2ppLzdSVWhtbW5Qclh0VHhsTDBsckxyDQptUVFKNnhoRFJhNUczUUE0Q21VZHNITnZicnpnbUNZcHZWRT0NCi0tLS0tRU5EIFg1MDkgQ1JMLS0tLS0NCg0K"
     62  
     63 --- src/runtime/crash_cgo_test.go
     64 +++ src/runtime/crash_cgo_test.go
     65 @@ -279,17 +279,17 @@ func testCgoPprof(t *testing.T, buildArg, runArg string) {
     66  	}
     67  	testenv.MustHaveGoRun(t)
     68  
     69  	exe, err := buildTestProg(t, "testprogcgo", buildArg)
     70  	if err != nil {
     71  		t.Fatal(err)
     72  	}
     73  
     74 -	got, err := testenv.CleanCmdEnv(exec.Command(exe, runArg)).CombinedOutput()
     75 +	got, err := testenv.CleanCmdEnv(goExecCmd(exe, runArg)).CombinedOutput()
     76  	if err != nil {
     77  		if testenv.Builder() == "linux-amd64-alpine" {
     78  			// See Issue 18243 and Issue 19938.
     79  			t.Skipf("Skipping failing test on Alpine (golang.org/issue/18243). Ignoring error: %v", err)
     80  		}
     81  		t.Fatal(err)
     82  	}
     83  	fn := strings.TrimSpace(string(got))
     84 --- src/runtime/crash_test.go
     85 +++ src/runtime/crash_test.go
     86 @@ -17,16 +17,35 @@ import (
     87  	"runtime"
     88  	"strconv"
     89  	"strings"
     90  	"sync"
     91  	"testing"
     92  	"time"
     93  )
     94  
     95 +var target = flag.String("target", "", "if non empty, use 'go_target' to compile test files and 'go_target_exec' to run the binaries")
     96 +
     97 +func goCmd(t *testing.T) string {
     98 +	if *target != "" {
     99 +		return "go_" + *target
    100 +	}
    101 +	return testenv.GoToolPath(t)
    102 +}
    103 +
    104 +func goExecCmd(name string, arg ...string) *exec.Cmd {
    105 +	var cmd []string
    106 +	if *target != "" {
    107 +		cmd = append(cmd, "go_"+*target+"_exec")
    108 +	}
    109 +	cmd = append(cmd, name)
    110 +	cmd = append(cmd, arg...)
    111 +	return exec.Command(cmd[0], cmd[1:]...)
    112 +}
    113 +
    114  var toRemove []string
    115  
    116  func TestMain(m *testing.M) {
    117  	status := m.Run()
    118  	for _, file := range toRemove {
    119  		os.RemoveAll(file)
    120  	}
    121  	os.Exit(status)
    122 @@ -50,17 +69,17 @@ func runTestProg(t *testing.T, binary, name string, env ...string) string {
    123  
    124  	testenv.MustHaveGoBuild(t)
    125  
    126  	exe, err := buildTestProg(t, binary)
    127  	if err != nil {
    128  		t.Fatal(err)
    129  	}
    130  
    131 -	cmd := testenv.CleanCmdEnv(exec.Command(exe, name))
    132 +	cmd := testenv.CleanCmdEnv(goExecCmd(exe, name))
    133  	cmd.Env = append(cmd.Env, env...)
    134  	if testing.Short() {
    135  		cmd.Env = append(cmd.Env, "RUNTIME_TEST_SHORT=1")
    136  	}
    137  	var b bytes.Buffer
    138  	cmd.Stdout = &b
    139  	cmd.Stderr = &b
    140  	if err := cmd.Start(); err != nil {
    141 @@ -125,17 +144,17 @@ func buildTestProg(t *testing.T, binary string, flags ...string) (string, error)
    142  		name += "_" + strings.Join(flags, "_")
    143  	}
    144  	target, ok := testprog.target[name]
    145  	if ok {
    146  		return target.exe, target.err
    147  	}
    148  
    149  	exe := filepath.Join(testprog.dir, name+".exe")
    150 -	cmd := exec.Command(testenv.GoToolPath(t), append([]string{"build", "-o", exe}, flags...)...)
    151 +	cmd := exec.Command(goCmd(t), append([]string{"build", "-o", exe}, flags...)...)
    152  	cmd.Dir = "testdata/" + binary
    153  	out, err := testenv.CleanCmdEnv(cmd).CombinedOutput()
    154  	if err != nil {
    155  		target.err = fmt.Errorf("building %s %v: %v\n%s", binary, flags, err, out)
    156  		testprog.target[name] = target
    157  		return "", target.err
    158  	}
    159  	target.exe = exe
    160 @@ -456,17 +475,17 @@ func TestPanicLoop(t *testing.T) {
    161  func TestMemPprof(t *testing.T) {
    162  	testenv.MustHaveGoRun(t)
    163  
    164  	exe, err := buildTestProg(t, "testprog")
    165  	if err != nil {
    166  		t.Fatal(err)
    167  	}
    168  
    169 -	got, err := testenv.CleanCmdEnv(exec.Command(exe, "MemProf")).CombinedOutput()
    170 +	got, err := testenv.CleanCmdEnv(goExecCmd(exe, "MemProf")).CombinedOutput()
    171  	if err != nil {
    172  		t.Fatal(err)
    173  	}
    174  	fn := strings.TrimSpace(string(got))
    175  	defer os.Remove(fn)
    176  
    177  	for try := 0; try < 2; try++ {
    178  		cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-alloc_space", "-top"))
    179 --- src/runtime/crash_unix_test.go
    180 +++ src/runtime/crash_unix_test.go
    181 @@ -244,17 +244,17 @@ func testPanicSystemstackInternal() {
    182  }
    183  
    184  func TestSignalExitStatus(t *testing.T) {
    185  	testenv.MustHaveGoBuild(t)
    186  	exe, err := buildTestProg(t, "testprog")
    187  	if err != nil {
    188  		t.Fatal(err)
    189  	}
    190 -	err = testenv.CleanCmdEnv(exec.Command(exe, "SignalExitStatus")).Run()
    191 +	err = testenv.CleanCmdEnv(goExecCmd(exe, "SignalExitStatus")).Run()
    192  	if err == nil {
    193  		t.Error("test program succeeded unexpectedly")
    194  	} else if ee, ok := err.(*exec.ExitError); !ok {
    195  		t.Errorf("error (%v) has type %T; expected exec.ExitError", err, err)
    196  	} else if ws, ok := ee.Sys().(syscall.WaitStatus); !ok {
    197  		t.Errorf("error.Sys (%v) has type %T; expected syscall.WaitStatus", ee.Sys(), ee.Sys())
    198  	} else if !ws.Signaled() || ws.Signal() != syscall.SIGTERM {
    199  		t.Errorf("got %v; expected SIGTERM", ee)
    200