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