From ef8f969c8ea2498c2a8aa701cb2e83833339f9a8 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Mon, 10 Jun 2019 15:50:33 -0700 Subject: Initial version of a go version of the compiler wrapper. Still calls the old wrapper if one of the following flags is given: - Xclang-path - clang-syntax - env WITH_TIDY - env FORCE_DISABLE_WERROR - env GETRUSAGE - env BISECT_STAGE BUG=chromium:773875 TEST=Unit tests that also verify the produced command against the TEST=existing compiler wrapper. Change-Id: I1e0a720ce9f485d8015deefb2682f2cb760d82e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1652057 Reviewed-by: Manoj Gupta Reviewed-by: Tobias Bosch Reviewed-by: George Burgess Tested-by: Tobias Bosch Legacy-Commit-Queue: Commit Bot --- compiler_wrapper/gcc_flags_test.go | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 compiler_wrapper/gcc_flags_test.go (limited to 'compiler_wrapper/gcc_flags_test.go') diff --git a/compiler_wrapper/gcc_flags_test.go b/compiler_wrapper/gcc_flags_test.go new file mode 100644 index 00000000..12119f0b --- /dev/null +++ b/compiler_wrapper/gcc_flags_test.go @@ -0,0 +1,59 @@ +package main + +import ( + "testing" +) + +func TestCallRealGcc(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + wrapperCmd := ctx.newCommand(gccX86_64, "-noccache", mainCc) + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, wrapperCmd)) + if err := verifyPath(cmd, wrapperCmd.path+".real"); err != nil { + t.Error(err) + } + }) +} + +func TestCallRealGPlusPlus(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + wrapperCmd := ctx.newCommand("./x86_64-cros-linux-gnu-g++", "-noccache", mainCc) + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, wrapperCmd)) + if err := verifyPath(cmd, "\\./x86_64-cros-linux-gnu-g\\+\\+\\.real"); err != nil { + t.Error(err) + } + }) +} + +func TestConvertClangToGccFlags(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + var tests = []struct { + in string + out string + }{ + {"-march=goldmont", "-march=silvermont"}, + {"-march=goldmont-plus", "-march=silvermont"}, + {"-march=skylake", "-march=corei7"}, + } + + for _, tt := range tests { + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, tt.in, mainCc))) + if err := verifyArgCount(cmd, 0, tt.in); err != nil { + t.Error(err) + } + if err := verifyArgOrder(cmd, tt.out, mainCc); err != nil { + t.Error(err) + } + } + }) +} + +func TestFilterUnsupportedGccFlags(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-Xcompiler", mainCc))) + if err := verifyArgCount(cmd, 0, "-Xcompiler"); err != nil { + t.Error(err) + } + }) +} -- cgit v1.2.3