diff options
author | Tobias Bosch <tbosch@google.com> | 2019-06-10 15:50:33 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-06-20 15:41:37 +0000 |
commit | ef8f969c8ea2498c2a8aa701cb2e83833339f9a8 (patch) | |
tree | a3c988999263f4e43ec561908b452093ad169b53 /compiler_wrapper/sanitizer_flags_test.go | |
parent | 87d457dfc5ae0a7631917523eb3c62751453e4bb (diff) | |
download | toolchain-utils-ef8f969c8ea2498c2a8aa701cb2e83833339f9a8.tar.gz |
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 <manojgupta@chromium.org>
Reviewed-by: Tobias Bosch <tbosch@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Tobias Bosch <tbosch@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Diffstat (limited to 'compiler_wrapper/sanitizer_flags_test.go')
-rw-r--r-- | compiler_wrapper/sanitizer_flags_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/compiler_wrapper/sanitizer_flags_test.go b/compiler_wrapper/sanitizer_flags_test.go new file mode 100644 index 00000000..b54398a6 --- /dev/null +++ b/compiler_wrapper/sanitizer_flags_test.go @@ -0,0 +1,73 @@ +package main + +import ( + "testing" +) + +func TestFilterUnsupportedSanitizerFlagsIfSanitizeGiven(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=kernel-address", "-Wl,--no-undefined", mainCc))) + if err := verifyArgCount(cmd, 0, "-Wl,--no-undefined"); err != nil { + t.Error(err) + } + + cmd = ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=kernel-address", + "-Wl,-z,defs", mainCc))) + if err := verifyArgCount(cmd, 0, "-Wl,-z,defs"); err != nil { + t.Error(err) + } + + cmd = ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=kernel-address", "-D_FORTIFY_SOURCE=1", mainCc))) + if err := verifyArgCount(cmd, 0, "-D_FORTIFY_SOURCE=1"); err != nil { + t.Error(err) + } + + cmd = ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-fsanitize=kernel-address", "-D_FORTIFY_SOURCE=2", mainCc))) + if err := verifyArgCount(cmd, 0, "-D_FORTIFY_SOURCE=2"); err != nil { + t.Error(err) + } + }) +} + +func TestKeepSanitizerFlagsIfNoSanitizeGiven(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-Wl,--no-undefined", mainCc))) + if err := verifyArgCount(cmd, 1, "-Wl,--no-undefined"); err != nil { + t.Error(err) + } + + cmd = ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-Wl,-z,defs", mainCc))) + if err := verifyArgCount(cmd, 1, "-Wl,-z,defs"); err != nil { + t.Error(err) + } + + cmd = ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-D_FORTIFY_SOURCE=1", mainCc))) + if err := verifyArgCount(cmd, 1, "-D_FORTIFY_SOURCE=1"); err != nil { + t.Error(err) + } + + cmd = ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-D_FORTIFY_SOURCE=2", mainCc))) + if err := verifyArgCount(cmd, 1, "-D_FORTIFY_SOURCE=2"); err != nil { + t.Error(err) + } + }) +} + +func TestKeepSanitizerFlagsIfSanitizeGivenInCommonFlags(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + ctx.cfg.commonFlags = []string{"-fsanitize=kernel-address"} + cmd := ctx.must(calcCompilerCommandAndCompareToOld(ctx, ctx.cfg, + ctx.newCommand(gccX86_64, "-Wl,--no-undefined", mainCc))) + if err := verifyArgCount(cmd, 1, "-Wl,--no-undefined"); err != nil { + t.Error(err) + } + }) +} |