1// 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
24func testGenruleContext(config android.Config) *android.TestContext {
25	ctx := android.NewTestArchContext()
26	ctx.RegisterModuleType("cc_genrule", genRuleFactory)
27	ctx.Register(config)
28
29	return ctx
30}
31
32func TestArchGenruleCmd(t *testing.T) {
33	fs := map[string][]byte{
34		"tool": nil,
35		"foo":  nil,
36		"bar":  nil,
37	}
38	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			`
55	config := android.TestArchConfig(buildDir, nil, bp, fs)
56
57	ctx := testGenruleContext(config)
58
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
67	gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out_arm")
68	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
73	gen = ctx.ModuleForTests("gen", "android_arm64_armv8-a").Output("out_arm64")
74	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}
79