aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/compiler_wrapper_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'compiler_wrapper/compiler_wrapper_test.go')
-rw-r--r--compiler_wrapper/compiler_wrapper_test.go70
1 files changed, 62 insertions, 8 deletions
diff --git a/compiler_wrapper/compiler_wrapper_test.go b/compiler_wrapper/compiler_wrapper_test.go
index 52b92f56..74fe3f58 100644
--- a/compiler_wrapper/compiler_wrapper_test.go
+++ b/compiler_wrapper/compiler_wrapper_test.go
@@ -9,6 +9,9 @@ import (
"errors"
"fmt"
"io"
+ "os"
+ "path"
+ "path/filepath"
"strings"
"syscall"
"testing"
@@ -94,27 +97,76 @@ func TestLogMissingCCacheExecError(t *testing.T) {
})
}
-func TestErrorOnLogRusageAndForceDisableWError(t *testing.T) {
+func TestGomaDisablesRusage(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
+ gomaPath := path.Join(ctx.tempDir, "gomacc")
+ ctx.writeFile(gomaPath, "")
+ ctx.env = []string{"GOMACC_PATH=" + gomaPath}
+ logFileName := filepath.Join(ctx.tempDir, "rusage.log")
ctx.env = []string{
- "FORCE_DISABLE_WERROR=1",
- "GETRUSAGE=rusage.log",
+ "TOOLCHAIN_RUSAGE_OUTPUT=" + logFileName,
+ "GOMACC_PATH=" + gomaPath,
}
- stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
- if err := verifyNonInternalError(stderr, "GETRUSAGE is meaningless with FORCE_DISABLE_WERROR"); err != nil {
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
+ // Ensure Goma was used
+ if err := verifyPath(cmd, gomaPath); err != nil {
+ t.Fatal(err)
+ }
+ if err := verifyArgOrder(cmd, gccX86_64+".real", mainCc); err != nil {
t.Error(err)
}
+ // Ensure rusage log was not created
+ if _, err := os.Stat(logFileName); err == nil {
+ t.Errorf("Logfile shouldn't have been created at TOOLCHAIN_RUSAGE_OUTPUT path %q but was", logFileName)
+ } else if !os.IsNotExist(err) {
+ t.Fatalf("error checking for rusage logfile at %q: %v", logFileName, err)
+ }
+ })
+}
+
+func TestLogRusageAndForceDisableWError(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.NoteTestWritesToUmask()
+
+ logFileName := filepath.Join(ctx.tempDir, "rusage.log")
+ ctx.env = []string{
+ "FORCE_DISABLE_WERROR=1",
+ "TOOLCHAIN_RUSAGE_OUTPUT=" + logFileName,
+ }
+ ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
+ switch ctx.cmdCount {
+ case 1:
+ io.WriteString(stderr, "-Werror originalerror")
+ return newExitCodeError(1)
+ case 2:
+ return nil
+ default:
+ t.Fatalf("unexpected command: %#v", cmd)
+ return nil
+ }
+ }
+ ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
+ if _, err := os.Stat(logFileName); os.IsNotExist(err) {
+ t.Errorf("no logfile created at TOOLCHAIN_RUSAGE_OUTPUT path %q", logFileName)
+ } else if err != nil {
+ t.Fatalf("error checking for rusage logfile at %q: %v", logFileName, err)
+ }
+ if ctx.cmdCount != 2 {
+ t.Errorf("expected 2 calls. Got: %d", ctx.cmdCount)
+ }
})
}
func TestErrorOnLogRusageAndBisect(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
+ ctx.NoteTestWritesToUmask()
+
ctx.env = []string{
"BISECT_STAGE=xyz",
- "GETRUSAGE=rusage.log",
+ "TOOLCHAIN_RUSAGE_OUTPUT=rusage.log",
}
stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
- if err := verifyNonInternalError(stderr, "BISECT_STAGE is meaningless with GETRUSAGE"); err != nil {
+ if err := verifyNonInternalError(stderr, "TOOLCHAIN_RUSAGE_OUTPUT is meaningless with BISECT_STAGE"); err != nil {
t.Error(err)
}
})
@@ -122,11 +174,13 @@ func TestErrorOnLogRusageAndBisect(t *testing.T) {
func TestErrorOnBisectAndForceDisableWError(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
+ ctx.NoteTestWritesToUmask()
+
ctx.env = []string{
"BISECT_STAGE=xyz",
"FORCE_DISABLE_WERROR=1",
}
- stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
+ stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
if err := verifyNonInternalError(stderr, "BISECT_STAGE is meaningless with FORCE_DISABLE_WERROR"); err != nil {
t.Error(err)
}