aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/gcc_flags_test.go
blob: adf720180147e6279488d3a04b7a25ce6785da7f (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
// 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 (
	"testing"
)

func TestCallRealGcc(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
			ctx.newCommand(gccX86_64, mainCc)))
		if err := verifyPath(cmd, gccX86_64+".real"); err != nil {
			t.Error(err)
		}
	})
}

func TestCallRealGccForOtherNames(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
			ctx.newCommand("./x86_64-cros-linux-gnu-somename", mainCc)))
		if err := verifyPath(cmd, "\\./x86_64-cros-linux-gnu-somename.real"); err != nil {
			t.Error(err)
		}
	})
}

func TestConvertClangToGccFlags(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		var tests = []struct {
			in  string
			out string
		}{
			{"-march=alderlake", "-march=skylake"},
		}

		for _, tt := range tests {
			cmd := ctx.must(callCompiler(ctx, ctx.cfg,
				ctx.newCommand(gccX86_64, tt.in, mainCc)))
			if err := verifyArgCount(cmd, 0, tt.in); err != nil {
				t.Error(err)
			}
			if err := verifyArgOrder(cmd, tt.out, mainCc); err != nil {
				t.Error(err)
			}
		}
	})
}

func TestFilterUnsupportedGccFlags(t *testing.T) {
	withTestContext(t, func(ctx *testContext) {
		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
			ctx.newCommand(gccX86_64, "-Xcompiler", mainCc)))
		if err := verifyArgCount(cmd, 0, "-Xcompiler"); err != nil {
			t.Error(err)
		}
	})
}