blob: d38cf27f042174f815848131a1fb43770dec97c2 [file] [log] [blame]
Colin Crossef354482018-10-23 11:27:50 -07001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "reflect"
19 "testing"
20
21 "android/soong/android"
22)
23
Colin Cross98be1bb2019-12-13 20:41:13 -080024func testGenruleContext(config android.Config) *android.TestContext {
Colin Crossef354482018-10-23 11:27:50 -070025 ctx := android.NewTestArchContext()
Colin Cross4b49b762019-11-22 15:25:03 -080026 ctx.RegisterModuleType("cc_genrule", genRuleFactory)
Colin Cross98be1bb2019-12-13 20:41:13 -080027 ctx.Register(config)
Colin Crossef354482018-10-23 11:27:50 -070028
29 return ctx
30}
31
32func TestArchGenruleCmd(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -080033 fs := map[string][]byte{
34 "tool": nil,
35 "foo": nil,
36 "bar": nil,
37 }
Colin Crossef354482018-10-23 11:27:50 -070038 bp := `
39 cc_genrule {
40 name: "gen",
41 tool_files: ["tool"],
42 cmd: "$(location tool) $(in) $(out)",
43 arch: {
44 arm: {
45 srcs: ["foo"],
46 out: ["out_arm"],
47 },
48 arm64: {
49 srcs: ["bar"],
50 out: ["out_arm64"],
51 },
52 },
53 }
54 `
Colin Cross98be1bb2019-12-13 20:41:13 -080055 config := android.TestArchConfig(buildDir, nil, bp, fs)
Colin Crossef354482018-10-23 11:27:50 -070056
Colin Cross98be1bb2019-12-13 20:41:13 -080057 ctx := testGenruleContext(config)
Colin Crossef354482018-10-23 11:27:50 -070058
59 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
60 if errs == nil {
61 _, errs = ctx.PrepareBuildActions(config)
62 }
63 if errs != nil {
64 t.Fatal(errs)
65 }
66
Colin Cross7113d202019-11-20 16:39:12 -080067 gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out_arm")
Colin Crossef354482018-10-23 11:27:50 -070068 expected := []string{"foo"}
69 if !reflect.DeepEqual(expected, gen.Inputs.Strings()) {
70 t.Errorf(`want arm inputs %v, got %v`, expected, gen.Inputs.Strings())
71 }
72
Colin Cross7113d202019-11-20 16:39:12 -080073 gen = ctx.ModuleForTests("gen", "android_arm64_armv8-a").Output("out_arm64")
Colin Crossef354482018-10-23 11:27:50 -070074 expected = []string{"bar"}
75 if !reflect.DeepEqual(expected, gen.Inputs.Strings()) {
76 t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Inputs.Strings())
77 }
78}