xref: /aosp_15_r20/external/toolchain-utils/compiler_wrapper/crash_dump_test.go (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1// Copyright 2024 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package main
6
7import (
8	"path/filepath"
9	"testing"
10)
11
12func TestHardenedConfigDoesNotSpecifyCrashDirWhenNotInEnv(t *testing.T) {
13	withTestContext(t, func(ctx *testContext) {
14		cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
15		if err := verifyArgCount(cmd, 0, "-fcrash-diagnostics-dir=.*"); err != nil {
16			t.Error(err)
17		}
18	})
19}
20
21func TestHardenedConfigSpecifiesCrashDirWhenInEnv(t *testing.T) {
22	withTestContext(t, func(ctx *testContext) {
23		artifactsDir := ctx.setArbitraryClangArtifactsDir()
24		crashDir := filepath.Join(artifactsDir, clangCrashArtifactsSubdir)
25
26		cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
27		if err := verifyArgCount(cmd, 1, "-fcrash-diagnostics-dir="+crashDir); err != nil {
28			t.Error(err)
29		}
30	})
31}
32
33func TestHardenedConfigDoesNotSpecifyCrashDirForGCC(t *testing.T) {
34	withTestContext(t, func(ctx *testContext) {
35		ctx.setArbitraryClangArtifactsDir()
36
37		cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
38		if err := verifyArgCount(cmd, 0, "-fcrash-diagnostics-dir=.*"); err != nil {
39			t.Error(err)
40		}
41	})
42}
43