aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/rusage_flag_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'compiler_wrapper/rusage_flag_test.go')
-rw-r--r--compiler_wrapper/rusage_flag_test.go45
1 files changed, 24 insertions, 21 deletions
diff --git a/compiler_wrapper/rusage_flag_test.go b/compiler_wrapper/rusage_flag_test.go
index 439cfd15..bd0f980c 100644
--- a/compiler_wrapper/rusage_flag_test.go
+++ b/compiler_wrapper/rusage_flag_test.go
@@ -5,7 +5,6 @@
package main
import (
- "encoding/json"
"errors"
"fmt"
"io"
@@ -13,6 +12,7 @@ import (
"os"
"path/filepath"
"regexp"
+ "strconv"
"strings"
"testing"
)
@@ -73,7 +73,7 @@ func TestReportGeneralErrorsFromLogRusage(t *testing.T) {
func TestCreateDirAndFileForLogRusage(t *testing.T) {
withLogRusageTestContext(t, func(ctx *testContext) {
logFileName := filepath.Join(ctx.tempDir, "somedir", "rusage.log")
- ctx.env = []string{"TOOLCHAIN_RUSAGE_OUTPUT=" + logFileName}
+ ctx.env = []string{"GETRUSAGE=" + logFileName}
ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
if _, err := os.Stat(logFileName); err != nil {
@@ -85,32 +85,37 @@ func TestCreateDirAndFileForLogRusage(t *testing.T) {
func TestLogRusageFileContent(t *testing.T) {
withLogRusageTestContext(t, func(ctx *testContext) {
logFileName := filepath.Join(ctx.tempDir, "rusage.log")
- ctx.env = []string{"TOOLCHAIN_RUSAGE_OUTPUT=" + logFileName}
+ ctx.env = []string{"GETRUSAGE=" + logFileName}
ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
data, err := ioutil.ReadFile(logFileName)
if err != nil {
t.Errorf("could not read the rusage log file. Error: %s", err)
}
-
- rlog := rusageLog{}
-
- if err := json.Unmarshal(data, &rlog); err != nil {
- t.Fatalf("rusage log could not be unmarshalled. Got: %s", data)
+ // Example output:
+ // 0.100318 : 0.103412 : 0.096386 : 6508 : /tmp/compiler_wrapper036306868/x86_64-cros-linux-gnu-gcc.real : x86_64-cros-linux-gnu-gcc.real --sysroot=/tmp/compiler_wrapper036306868/usr/x86_64-cros-linux-gnu main.cc -mno-movbe
+ logParts := strings.Split(string(data), " : ")
+ if len(logParts) != 6 {
+ t.Errorf("unexpected number of rusage log parts. Got: %s", logParts)
}
- if rlog.Compiler != filepath.Join(ctx.tempDir, gccX86_64+".real") {
- t.Errorf("unexpected compiler path. Got: %s", rlog.Compiler)
+ // First 3 numbers are times in seconds.
+ for i := 0; i < 3; i++ {
+ if _, err := strconv.ParseFloat(logParts[i], 64); err != nil {
+ t.Errorf("unexpected value for index %d. Got: %s", i, logParts[i])
+ }
}
- if matched, _ := regexp.MatchString("--sysroot=.*", rlog.CompilerArgs[0]); !matched {
- t.Errorf("unexpected compiler args. Got: %s", rlog.CompilerArgs)
+ // Then an int for the memory usage
+ if _, err := strconv.ParseInt(logParts[3], 10, 64); err != nil {
+ t.Errorf("unexpected mem usage. Got: %s", logParts[3])
}
- cwd, err := os.Getwd()
- if err != nil {
- t.Fatalf("Failed to get current working directory: %v", err)
+ // Then the full path of the compiler
+ if logParts[4] != filepath.Join(ctx.tempDir, gccX86_64+".real") {
+ t.Errorf("unexpected compiler path. Got: %s", logParts[4])
}
- if rlog.WorkingDirectory != cwd {
- t.Errorf("Unexpected working directory. Got: %q, Want: %q", rlog.WorkingDirectory, cwd)
+ // Then the arguments, prefixes with the compiler basename
+ if matched, _ := regexp.MatchString("x86_64-cros-linux-gnu-gcc.real --sysroot=.* main.cc", logParts[5]); !matched {
+ t.Errorf("unexpected compiler args. Got: %s", logParts[5])
}
})
}
@@ -118,7 +123,7 @@ func TestLogRusageFileContent(t *testing.T) {
func TestLogRusageAppendsToFile(t *testing.T) {
withLogRusageTestContext(t, func(ctx *testContext) {
logFileName := filepath.Join(ctx.tempDir, "rusage.log")
- ctx.env = []string{"TOOLCHAIN_RUSAGE_OUTPUT=" + logFileName}
+ ctx.env = []string{"GETRUSAGE=" + logFileName}
ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
data, err := ioutil.ReadFile(logFileName)
@@ -159,9 +164,7 @@ func TestLogRusageAppendsToFile(t *testing.T) {
func withLogRusageTestContext(t *testing.T, work func(ctx *testContext)) {
withTestContext(t, func(ctx *testContext) {
- ctx.NoteTestWritesToUmask()
-
- ctx.env = []string{"TOOLCHAIN_RUSAGE_OUTPUT=" + filepath.Join(ctx.tempDir, "rusage.log")}
+ ctx.env = []string{"GETRUSAGE=" + filepath.Join(ctx.tempDir, "rusage.log")}
work(ctx)
})
}