• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 The Chromium OS Authors. All rights reserved.
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	"path/filepath"
10	"testing"
11)
12
13const androidGoldenDir = "testdata/android_golden"
14
15func TestAndroidConfig(t *testing.T) {
16	withTestContext(t, func(ctx *testContext) {
17		useLlvmNext := false
18		useCCache := false
19		cfg, err := getConfig("android", useCCache, useLlvmNext, "123")
20		if err != nil {
21			t.Fatal(err)
22		}
23		ctx.updateConfig(cfg)
24
25		runGoldenRecords(ctx, androidGoldenDir, []goldenFile{
26			createAndroidClangPathGoldenInputs(ctx),
27			createBisectGoldenInputs(filepath.Join(ctx.tempDir, "clang")),
28			createAndroidCompileWithFallbackGoldenInputs(ctx),
29		})
30	})
31}
32
33func createAndroidClangPathGoldenInputs(ctx *testContext) goldenFile {
34	gomaPath := path.Join(ctx.tempDir, "gomacc")
35	ctx.writeFile(gomaPath, "")
36	defaultPath := filepath.Join(ctx.tempDir, "clang")
37	clangTidyPath := filepath.Join(ctx.tempDir, "clang-tidy")
38
39	deepPath := "a/b/c/d/e/f/g/clang"
40	linkedDeepPath := "symlinked/clang_other"
41	ctx.writeFile(filepath.Join(ctx.tempDir, "/pathenv/clang"), "")
42	ctx.symlink(deepPath, linkedDeepPath)
43	return goldenFile{
44		Name: "clang_path.json",
45		Records: []goldenRecord{
46			{
47				WrapperCmd: newGoldenCmd(defaultPath, mainCc),
48				Cmds:       okResults,
49			},
50			{
51				WrapperCmd: newGoldenCmd(defaultPath, mainCc),
52				Cmds:       errorResults,
53			},
54			{
55				Env:        []string{"WITH_TIDY=1"},
56				WrapperCmd: newGoldenCmd(defaultPath, mainCc),
57				Cmds:       okResults,
58			},
59			{
60				WrapperCmd: newGoldenCmd(filepath.Join(ctx.tempDir, "clang++"), mainCc),
61				Cmds:       okResults,
62			},
63			{
64				WrapperCmd: newGoldenCmd(clangTidyPath, mainCc),
65				Cmds:       okResults,
66			},
67			{
68				Env:        []string{"WITH_TIDY=1"},
69				WrapperCmd: newGoldenCmd(clangTidyPath, mainCc),
70				Cmds:       okResults,
71			},
72			{
73				WrapperCmd: newGoldenCmd(deepPath, mainCc),
74				Cmds:       okResults,
75			},
76			{
77				WrapperCmd: newGoldenCmd(linkedDeepPath, mainCc),
78				Cmds:       okResults,
79			},
80			{
81				Env:        []string{"PATH=" + filepath.Join(ctx.tempDir, "/pathenv")},
82				WrapperCmd: newGoldenCmd("clang", mainCc),
83				Cmds:       okResults,
84			},
85			{
86				WrapperCmd: newGoldenCmd(defaultPath, mainCc, "--gomacc-path", gomaPath),
87				Cmds:       okResults,
88			},
89		},
90	}
91}
92
93func createAndroidCompileWithFallbackGoldenInputs(ctx *testContext) goldenFile {
94	env := []string{
95		"ANDROID_LLVM_PREBUILT_COMPILER_PATH=fallback_compiler",
96		"ANDROID_LLVM_STDERR_REDIRECT=" + filepath.Join(ctx.tempDir, "fallback_stderr"),
97		"ANDROID_LLVM_FALLBACK_DISABLED_WARNINGS=-a -b",
98	}
99	defaultPath := filepath.Join(ctx.tempDir, "clang")
100	return goldenFile{
101		Name: "compile_with_fallback.json",
102		Records: []goldenRecord{
103			{
104				WrapperCmd: newGoldenCmd(defaultPath, mainCc),
105				Env:        env,
106				Cmds:       okResults,
107			},
108			{
109				WrapperCmd: newGoldenCmd(defaultPath, mainCc),
110				Env:        env,
111				Cmds: []commandResult{
112					{
113						ExitCode: 1,
114					},
115					okResult,
116				},
117			},
118			{
119				WrapperCmd: newGoldenCmd(defaultPath, mainCc),
120				Env:        env,
121				Cmds: []commandResult{
122					{
123						ExitCode: 1,
124					},
125					{
126						ExitCode: 1,
127					},
128				},
129			},
130		},
131	}
132}
133