xref: /aosp_15_r20/external/toolchain-utils/compiler_wrapper/cros_host_config_test.go (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1//  Copyright 2019 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"
9	"testing"
10)
11
12const crosClangHostGoldenDir = "testdata/cros_clang_host_golden"
13const crosGccHostGoldenDir = "testdata/cros_gcc_host_golden"
14
15func TestCrosClangHostConfig(t *testing.T) {
16	withGoldenTestContext(t, func(ctx *testContext) {
17		useLlvmNext := false
18		useCCache := false
19		cfg, err := getConfig("cros.host", useCCache, useLlvmNext, "123")
20		if err != nil {
21			t.Fatal(err)
22		}
23		ctx.updateConfig(cfg)
24
25		gomaPath := path.Join(ctx.tempDir, "gomacc")
26		ctx.writeFile(gomaPath, "")
27		gomaEnv := "GOMACC_PATH=" + gomaPath
28
29		goldenFiles := []goldenFile{
30			createClangPathGoldenInputs(ctx, gomaEnv),
31			createGoldenInputsForAllTargets("clang", mainCc),
32			createGoldenInputsForAllTargets("clang", "-ftrapv", mainCc),
33			createSanitizerGoldenInputs("clang"),
34			createClangArgsGoldenInputs(),
35			createBisectGoldenInputs(clangX86_64),
36			createForceDisableWErrorGoldenInputs(),
37			createClangTidyGoldenInputs(gomaEnv),
38			createClangHostWrapperInputs(),
39		}
40
41		runGoldenRecords(ctx, crosClangHostGoldenDir, goldenFiles)
42	})
43}
44
45func TestCrosGccHostConfig(t *testing.T) {
46	withGoldenTestContext(t, func(ctx *testContext) {
47		useLlvmNext := false
48		useCCache := false
49		cfg, err := getConfig("cros.host", useCCache, useLlvmNext, "123")
50		if err != nil {
51			t.Fatal(err)
52		}
53		ctx.updateConfig(cfg)
54
55		gomaPath := path.Join(ctx.tempDir, "gomacc")
56		ctx.writeFile(gomaPath, "")
57		gomaEnv := "GOMACC_PATH=" + gomaPath
58
59		// Note: The old gcc host wrapper is very limited and only adds flags.
60		// So we only test very few things here.
61		goldenFiles := []goldenFile{
62			createGccPathGoldenInputs(ctx, gomaEnv),
63			createGoldenInputsForAllTargets("gcc", mainCc),
64			createGccArgsGoldenInputs(),
65			createGccHostWrapperInputs(),
66		}
67
68		runGoldenRecords(ctx, crosGccHostGoldenDir, goldenFiles)
69	})
70}
71
72func createClangHostWrapperInputs() goldenFile {
73	return goldenFile{
74		Name: "clang_host_wrapper.json",
75		Records: []goldenRecord{
76			{
77				WrapperCmd: newGoldenCmd("./clang", mainCc),
78				Cmds:       okResults,
79			},
80		},
81	}
82}
83
84func createGccHostWrapperInputs() goldenFile {
85	return goldenFile{
86		Name: "gcc_host_wrapper.json",
87		Records: []goldenRecord{
88			{
89				WrapperCmd: newGoldenCmd("./gcc", mainCc),
90				Cmds:       okResults,
91			},
92		},
93	}
94}
95