1*760c253cSXin Li// Copyright 2019 The ChromiumOS Authors 2*760c253cSXin Li// Use of this source code is governed by a BSD-style license that can be 3*760c253cSXin Li// found in the LICENSE file. 4*760c253cSXin Li 5*760c253cSXin Lipackage main 6*760c253cSXin Li 7*760c253cSXin Liimport ( 8*760c253cSXin Li "testing" 9*760c253cSXin Li) 10*760c253cSXin Li 11*760c253cSXin Lifunc TestAddThumbFlagForArm(t *testing.T) { 12*760c253cSXin Li withTestContext(t, func(ctx *testContext) { 13*760c253cSXin Li cmd := ctx.must(callCompiler(ctx, ctx.cfg, 14*760c253cSXin Li ctx.newCommand(gccArmV7, mainCc))) 15*760c253cSXin Li if err := verifyArgOrder(cmd, "-mthumb", mainCc); err != nil { 16*760c253cSXin Li t.Error(err) 17*760c253cSXin Li } 18*760c253cSXin Li 19*760c253cSXin Li cmd = ctx.must(callCompiler(ctx, ctx.cfg, 20*760c253cSXin Li ctx.newCommand(gccArmV8, mainCc))) 21*760c253cSXin Li if err := verifyArgOrder(cmd, "-mthumb", mainCc); err != nil { 22*760c253cSXin Li t.Error(err) 23*760c253cSXin Li } 24*760c253cSXin Li }) 25*760c253cSXin Li} 26*760c253cSXin Li 27*760c253cSXin Lifunc TestOmitThumbFlagForNonArm(t *testing.T) { 28*760c253cSXin Li withTestContext(t, func(ctx *testContext) { 29*760c253cSXin Li cmd := ctx.must(callCompiler(ctx, ctx.cfg, 30*760c253cSXin Li ctx.newCommand(gccX86_64, mainCc))) 31*760c253cSXin Li if err := verifyArgCount(cmd, 0, "-mthumb"); err != nil { 32*760c253cSXin Li t.Error(err) 33*760c253cSXin Li } 34*760c253cSXin Li }) 35*760c253cSXin Li} 36*760c253cSXin Li 37*760c253cSXin Lifunc TestOmitThumbFlagForEabiArm(t *testing.T) { 38*760c253cSXin Li withTestContext(t, func(ctx *testContext) { 39*760c253cSXin Li cmd := ctx.must(callCompiler(ctx, ctx.cfg, 40*760c253cSXin Li ctx.newCommand(gccArmV7Eabi, mainCc))) 41*760c253cSXin Li if err := verifyArgCount(cmd, 0, "-mthumb"); err != nil { 42*760c253cSXin Li t.Error(err) 43*760c253cSXin Li } 44*760c253cSXin Li 45*760c253cSXin Li cmd = ctx.must(callCompiler(ctx, ctx.cfg, 46*760c253cSXin Li ctx.newCommand(gccArmV8Eabi, mainCc))) 47*760c253cSXin Li if err := verifyArgCount(cmd, 0, "-mthumb"); err != nil { 48*760c253cSXin Li t.Error(err) 49*760c253cSXin Li } 50*760c253cSXin Li }) 51*760c253cSXin Li} 52*760c253cSXin Li 53*760c253cSXin Lifunc TestRemoveNoOmitFramePointerFlagForArm(t *testing.T) { 54*760c253cSXin Li withTestContext(t, func(ctx *testContext) { 55*760c253cSXin Li initNoOmitFramePointerConfig(ctx.cfg) 56*760c253cSXin Li 57*760c253cSXin Li cmd := ctx.must(callCompiler(ctx, ctx.cfg, 58*760c253cSXin Li ctx.newCommand(gccArmV7, mainCc))) 59*760c253cSXin Li if err := verifyArgCount(cmd, 0, "-fno-omit-frame-pointer"); err != nil { 60*760c253cSXin Li t.Error(err) 61*760c253cSXin Li } 62*760c253cSXin Li 63*760c253cSXin Li cmd = ctx.must(callCompiler(ctx, ctx.cfg, 64*760c253cSXin Li ctx.newCommand(gccArmV8, mainCc))) 65*760c253cSXin Li if err := verifyArgCount(cmd, 0, "-fno-omit-frame-pointer"); err != nil { 66*760c253cSXin Li t.Error(err) 67*760c253cSXin Li } 68*760c253cSXin Li }) 69*760c253cSXin Li} 70*760c253cSXin Li 71*760c253cSXin Lifunc TestKeepNoOmitFramePointerFlagForNonArm(t *testing.T) { 72*760c253cSXin Li withTestContext(t, func(ctx *testContext) { 73*760c253cSXin Li initNoOmitFramePointerConfig(ctx.cfg) 74*760c253cSXin Li 75*760c253cSXin Li cmd := ctx.must(callCompiler(ctx, ctx.cfg, 76*760c253cSXin Li ctx.newCommand(gccX86_64, mainCc))) 77*760c253cSXin Li if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil { 78*760c253cSXin Li t.Error(err) 79*760c253cSXin Li } 80*760c253cSXin Li }) 81*760c253cSXin Li} 82*760c253cSXin Li 83*760c253cSXin Lifunc TestKeepNoOmitFramePointerFlagForEabiArm(t *testing.T) { 84*760c253cSXin Li withTestContext(t, func(ctx *testContext) { 85*760c253cSXin Li initNoOmitFramePointerConfig(ctx.cfg) 86*760c253cSXin Li 87*760c253cSXin Li cmd := ctx.must(callCompiler(ctx, ctx.cfg, 88*760c253cSXin Li ctx.newCommand(gccArmV7Eabi, mainCc))) 89*760c253cSXin Li if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil { 90*760c253cSXin Li t.Error(err) 91*760c253cSXin Li } 92*760c253cSXin Li 93*760c253cSXin Li cmd = ctx.must(callCompiler(ctx, ctx.cfg, 94*760c253cSXin Li ctx.newCommand(gccArmV8Eabi, mainCc))) 95*760c253cSXin Li if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil { 96*760c253cSXin Li t.Error(err) 97*760c253cSXin Li } 98*760c253cSXin Li }) 99*760c253cSXin Li} 100*760c253cSXin Li 101*760c253cSXin Lifunc TestKeepNoOmitFramePointIfGivenByUser(t *testing.T) { 102*760c253cSXin Li withTestContext(t, func(ctx *testContext) { 103*760c253cSXin Li cmd := ctx.must(callCompiler(ctx, ctx.cfg, 104*760c253cSXin Li ctx.newCommand(gccArmV7, "-fno-omit-frame-pointer", mainCc))) 105*760c253cSXin Li if err := verifyArgCount(cmd, 1, "-fno-omit-frame-pointer"); err != nil { 106*760c253cSXin Li t.Error(err) 107*760c253cSXin Li } 108*760c253cSXin Li }) 109*760c253cSXin Li} 110*760c253cSXin Li 111*760c253cSXin Lifunc initNoOmitFramePointerConfig(cfg *config) { 112*760c253cSXin Li cfg.commonFlags = []string{"-fno-omit-frame-pointer"} 113*760c253cSXin Li} 114