aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/crash_dump_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'compiler_wrapper/crash_dump_test.go')
-rw-r--r--compiler_wrapper/crash_dump_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/compiler_wrapper/crash_dump_test.go b/compiler_wrapper/crash_dump_test.go
new file mode 100644
index 00000000..f6bacb60
--- /dev/null
+++ b/compiler_wrapper/crash_dump_test.go
@@ -0,0 +1,42 @@
+// Copyright 2024 The ChromiumOS Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package main
+
+import (
+ "path/filepath"
+ "testing"
+)
+
+func TestHardenedConfigDoesNotSpecifyCrashDirWhenNotInEnv(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
+ if err := verifyArgCount(cmd, 0, "-fcrash-diagnostics-dir=.*"); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
+func TestHardenedConfigSpecifiesCrashDirWhenInEnv(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ artifactsDir := ctx.setArbitraryClangArtifactsDir()
+ crashDir := filepath.Join(artifactsDir, clangCrashArtifactsSubdir)
+
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
+ if err := verifyArgCount(cmd, 1, "-fcrash-diagnostics-dir="+crashDir); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
+func TestHardenedConfigDoesNotSpecifyCrashDirForGCC(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.setArbitraryClangArtifactsDir()
+
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
+ if err := verifyArgCount(cmd, 0, "-fcrash-diagnostics-dir=.*"); err != nil {
+ t.Error(err)
+ }
+ })
+}