3 //go:build !nacl && !js && !wasip1 && gc
5 // Copyright 2011 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
9 // Test that compiling with optimization turned on produces faster code.
22 err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
25 tmpDir, err := ioutil.TempDir("", "bug369")
27 defer os.RemoveAll(tmpDir)
29 tmp := func(name string) string {
30 return filepath.Join(tmpDir, name)
33 check(os.Mkdir(tmp("test"), 0777))
35 stdlibimportcfg, err := os.ReadFile(os.Getenv("STDLIB_IMPORTCFG"))
37 importcfg := string(stdlibimportcfg) + "\npackagefile test/slow=" + tmp("test/slow.o") + "\npackagefile test/fast=" + tmp("test/fast.o")
38 os.WriteFile(tmp("importcfg"), []byte(importcfg), 0644)
40 run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=test/slow", "-N", "-o", tmp("test/slow.o"), "pkg.go")
41 run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=test/fast", "-o", tmp("test/fast.o"), "pkg.go")
42 run("go", "tool", "compile", "-importcfg="+tmp("importcfg"), "-p=main", "-D", "test", "-o", tmp("main.o"), "main.go")
43 run("go", "tool", "link", "-importcfg="+tmp("importcfg"), "-o", tmp("a.exe"), tmp("main.o"))
47 func run(name string, args ...string) {
48 cmd := exec.Command(name, args...)
49 out, err := cmd.CombinedOutput()
51 fmt.Println(string(out))
57 func check(err error) {