1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
18 // TestLarge generates a very large file to verify that large
19 // program builds successfully, in particular, too-far
20 // conditional branches are fixed.
21 func TestLarge(t *testing.T) {
23 t.Skip("Skip in short mode")
25 testenv.MustHaveGoBuild(t)
27 dir, err := ioutil.TempDir("", "testlarge")
29 t.Fatalf("could not create directory: %v", err)
31 defer os.RemoveAll(dir)
33 // Generate a very large function.
34 buf := bytes.NewBuffer(make([]byte, 0, 7000000))
37 tmpfile := filepath.Join(dir, "x.s")
38 err = ioutil.WriteFile(tmpfile, buf.Bytes(), 0644)
40 t.Fatalf("can't write output: %v\n", err)
43 // Build generated file.
44 cmd := exec.Command(testenv.GoToolPath(t), "tool", "asm", "-o", filepath.Join(dir, "x.o"), tmpfile)
45 cmd.Env = append(os.Environ(), "GOARCH=riscv64", "GOOS=linux")
46 out, err := cmd.CombinedOutput()
48 t.Errorf("Build failed: %v, output: %s", err, out)
52 // gen generates a very large program, with a very far conditional branch.
53 func gen(buf *bytes.Buffer) {
54 fmt.Fprintln(buf, "TEXT f(SB),0,$0-0")
55 fmt.Fprintln(buf, "BEQ X0, X0, label")
56 for i := 0; i < 1<<19; i++ {
57 fmt.Fprintln(buf, "ADD $0, X0, X0")
59 fmt.Fprintln(buf, "label:")
60 fmt.Fprintln(buf, "ADD $0, X0, X0")
64 func TestNoRet(t *testing.T) {
65 dir, err := ioutil.TempDir("", "testnoret")
69 defer os.RemoveAll(dir)
70 tmpfile := filepath.Join(dir, "x.s")
71 if err := ioutil.WriteFile(tmpfile, []byte("TEXT ·stub(SB),$0-0\nNOP\n"), 0644); err != nil {
74 cmd := exec.Command(testenv.GoToolPath(t), "tool", "asm", "-o", filepath.Join(dir, "x.o"), tmpfile)
75 cmd.Env = append(os.Environ(), "GOARCH=riscv64", "GOOS=linux")
76 if out, err := cmd.CombinedOutput(); err != nil {
77 t.Errorf("%v\n%s", err, out)