| Colin Cross | ef35448 | 2018-10-23 11:27:50 -0700 | [diff] [blame] | 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 |  | 
 | 15 | package cc | 
 | 16 |  | 
 | 17 | import ( | 
 | 18 | 	"reflect" | 
 | 19 | 	"testing" | 
 | 20 |  | 
 | 21 | 	"android/soong/android" | 
 | 22 | ) | 
 | 23 |  | 
 | 24 | func testGenruleContext(config android.Config, bp string, | 
 | 25 | 	fs map[string][]byte) *android.TestContext { | 
 | 26 |  | 
 | 27 | 	ctx := android.NewTestArchContext() | 
 | 28 | 	ctx.RegisterModuleType("cc_genrule", android.ModuleFactoryAdaptor(genRuleFactory)) | 
 | 29 | 	ctx.Register() | 
 | 30 |  | 
 | 31 | 	mockFS := map[string][]byte{ | 
 | 32 | 		"Android.bp": []byte(bp), | 
 | 33 | 		"tool":       nil, | 
 | 34 | 		"foo":        nil, | 
 | 35 | 		"bar":        nil, | 
 | 36 | 	} | 
 | 37 |  | 
 | 38 | 	for k, v := range fs { | 
 | 39 | 		mockFS[k] = v | 
 | 40 | 	} | 
 | 41 |  | 
 | 42 | 	ctx.MockFileSystem(mockFS) | 
 | 43 |  | 
 | 44 | 	return ctx | 
 | 45 | } | 
 | 46 |  | 
 | 47 | func TestArchGenruleCmd(t *testing.T) { | 
 | 48 | 	config := android.TestArchConfig(buildDir, nil) | 
 | 49 | 	bp := ` | 
 | 50 | 				cc_genrule { | 
 | 51 | 					name: "gen", | 
 | 52 | 					tool_files: ["tool"], | 
 | 53 | 					cmd: "$(location tool) $(in) $(out)", | 
 | 54 | 					arch: { | 
 | 55 | 						arm: { | 
 | 56 | 							srcs: ["foo"], | 
 | 57 | 							out: ["out_arm"], | 
 | 58 | 						}, | 
 | 59 | 						arm64: { | 
 | 60 | 							srcs: ["bar"], | 
 | 61 | 							out: ["out_arm64"], | 
 | 62 | 						}, | 
 | 63 | 					}, | 
 | 64 | 				} | 
 | 65 | 			` | 
 | 66 |  | 
 | 67 | 	ctx := testGenruleContext(config, bp, nil) | 
 | 68 |  | 
 | 69 | 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"}) | 
 | 70 | 	if errs == nil { | 
 | 71 | 		_, errs = ctx.PrepareBuildActions(config) | 
 | 72 | 	} | 
 | 73 | 	if errs != nil { | 
 | 74 | 		t.Fatal(errs) | 
 | 75 | 	} | 
 | 76 |  | 
 | 77 | 	gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out_arm") | 
 | 78 | 	expected := []string{"foo"} | 
 | 79 | 	if !reflect.DeepEqual(expected, gen.Inputs.Strings()) { | 
 | 80 | 		t.Errorf(`want arm inputs %v, got %v`, expected, gen.Inputs.Strings()) | 
 | 81 | 	} | 
 | 82 |  | 
 | 83 | 	gen = ctx.ModuleForTests("gen", "android_arm64_armv8-a").Output("out_arm64") | 
 | 84 | 	expected = []string{"bar"} | 
 | 85 | 	if !reflect.DeepEqual(expected, gen.Inputs.Strings()) { | 
 | 86 | 		t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Inputs.Strings()) | 
 | 87 | 	} | 
 | 88 | } |