aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/crash_dump_test.go
blob: f6bacb6029162db333b732a7c26743b39e14c5b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)
		}
	})
}