• 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	"testing"
9)
10
11func TestAddThumbFlagForArm(t *testing.T) {
12	withTestContext(t, func(ctx *testContext) {
13		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
14			ctx.newCommand(gccArmV7, mainCc)))
15		if err := verifyArgOrder(cmd, "-mthumb", mainCc); err != nil {
16			t.Error(err)
17		}
18
19		cmd = ctx.must(callCompiler(ctx, ctx.cfg,
20			ctx.newCommand(gccArmV8, mainCc)))
21		if err := verifyArgOrder(cmd, "-mthumb", mainCc); err != nil {
22			t.Error(err)
23		}
24	})
25}
26
27func TestOmitThumbFlagForNonArm(t *testing.T) {
28	withTestContext(t, func(ctx *testContext) {
29		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
30			ctx.newCommand(gccX86_64, mainCc)))
31		if err := verifyArgCount(cmd, 0, "-mthumb"); err != nil {
32			t.Error(err)
33		}
34	})
35}
36
37func TestOmitThumbFlagForEabiArm(t *testing.T) {
38	withTestContext(t, func(ctx *testContext) {
39		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
40			ctx.newCommand(gccArmV7Eabi, mainCc)))
41		if err := verifyArgCount(cmd, 0, "-mthumb"); err != nil {
42			t.Error(err)
43		}
44
45		cmd = ctx.must(callCompiler(ctx, ctx.cfg,
46			ctx.newCommand(gccArmV8Eabi, mainCc)))
47		if err := verifyArgCount(cmd, 0, "-mthumb"); err != nil {
48			t.Error(err)
49		}
50	})
51}
52
53func TestRemoveNoOmitFramePointerFlagForArm(t *testing.T) {
54	withTestContext(t, func(ctx *testContext) {
55		initNoOmitFramePointerConfig(ctx.cfg)
56
57		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
58			ctx.newCommand(gccArmV7, mainCc)))
59		if err := verifyArgCount(cmd, 0, "-fno-omit-frame-pointer"); err != nil {
60			t.Error(err)
61		}
62
63		cmd = ctx.must(callCompiler(ctx, ctx.cfg,
64			ctx.newCommand(gccArmV8, mainCc)))
65		if err := verifyArgCount(cmd, 0, "-fno-omit-frame-pointer"); err != nil {
66			t.Error(err)
67		}
68	})
69}
70
71func TestKeepNoOmitFramePointerFlagForNonArm(t *testing.T) {
72	withTestContext(t, func(ctx *testContext) {
73		initNoOmitFramePointerConfig(ctx.cfg)
74
75		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
76			ctx.newCommand(gccX86_64, mainCc)))
77		if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil {
78			t.Error(err)
79		}
80	})
81}
82
83func TestKeepNoOmitFramePointerFlagForEabiArm(t *testing.T) {
84	withTestContext(t, func(ctx *testContext) {
85		initNoOmitFramePointerConfig(ctx.cfg)
86
87		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
88			ctx.newCommand(gccArmV7Eabi, mainCc)))
89		if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil {
90			t.Error(err)
91		}
92
93		cmd = ctx.must(callCompiler(ctx, ctx.cfg,
94			ctx.newCommand(gccArmV8Eabi, mainCc)))
95		if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil {
96			t.Error(err)
97		}
98	})
99}
100
101func TestKeepNoOmitFramePointIfGivenByUser(t *testing.T) {
102	withTestContext(t, func(ctx *testContext) {
103		cmd := ctx.must(callCompiler(ctx, ctx.cfg,
104			ctx.newCommand(gccArmV7, "-fno-omit-frame-pointer", mainCc)))
105		if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil {
106			t.Error(err)
107		}
108	})
109}
110
111func initNoOmitFramePointerConfig(cfg *config) {
112	cfg.commonFlags = []string{"-fno-omit-frame-pointer"}
113}
114