aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/cros_host_config_test.go
blob: 4f3b5cb23fb39d7af0b6e85a9cdcf701dbf0d77a (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//  Copyright 2019 The Chromium OS Authors. All rights reserved.
//  Use of this source code is governed by a BSD-style license that can be
//  found in the LICENSE file.

package main

import (
	"path"
	"testing"
)

const crosClangHostGoldenDir = "testdata/cros_clang_host_golden"
const crosGccHostGoldenDir = "testdata/cros_gcc_host_golden"

func TestCrosClangHostConfig(t *testing.T) {
	withGoldenTestContext(t, func(ctx *testContext) {
		useLlvmNext := false
		useCCache := false
		cfg, err := getConfig("cros.host", useCCache, useLlvmNext, "123")
		if err != nil {
			t.Fatal(err)
		}
		ctx.updateConfig(cfg)

		gomaPath := path.Join(ctx.tempDir, "gomacc")
		ctx.writeFile(gomaPath, "")
		gomaEnv := "GOMACC_PATH=" + gomaPath

		goldenFiles := []goldenFile{
			createClangPathGoldenInputs(ctx, gomaEnv),
			createGoldenInputsForAllTargets("clang", mainCc),
			createGoldenInputsForAllTargets("clang", "-ftrapv", mainCc),
			createSanitizerGoldenInputs("clang"),
			createClangArgsGoldenInputs(),
			createBisectGoldenInputs(clangX86_64),
			createForceDisableWErrorGoldenInputs(),
			createClangTidyGoldenInputs(gomaEnv),
			createClangHostWrapperInputs(),
		}

		runGoldenRecords(ctx, crosClangHostGoldenDir, goldenFiles)
	})
}

func TestCrosGccHostConfig(t *testing.T) {
	withGoldenTestContext(t, func(ctx *testContext) {
		useLlvmNext := false
		useCCache := false
		cfg, err := getConfig("cros.host", useCCache, useLlvmNext, "123")
		if err != nil {
			t.Fatal(err)
		}
		ctx.updateConfig(cfg)

		gomaPath := path.Join(ctx.tempDir, "gomacc")
		ctx.writeFile(gomaPath, "")
		gomaEnv := "GOMACC_PATH=" + gomaPath

		// Note: The old gcc host wrapper is very limited and only adds flags.
		// So we only test very few things here.
		goldenFiles := []goldenFile{
			createGccPathGoldenInputs(ctx, gomaEnv),
			createGoldenInputsForAllTargets("gcc", mainCc),
			createGccArgsGoldenInputs(),
			createGccHostWrapperInputs(),
		}

		runGoldenRecords(ctx, crosGccHostGoldenDir, goldenFiles)
	})
}

func createClangHostWrapperInputs() goldenFile {
	return goldenFile{
		Name: "clang_host_wrapper.json",
		Records: []goldenRecord{
			{
				WrapperCmd: newGoldenCmd("./clang", mainCc),
				Cmds:       okResults,
			},
		},
	}
}

func createGccHostWrapperInputs() goldenFile {
	return goldenFile{
		Name: "gcc_host_wrapper.json",
		Records: []goldenRecord{
			{
				WrapperCmd: newGoldenCmd("./gcc", mainCc),
				Cmds:       okResults,
			},
		},
	}
}