blob: 9244647c6005cafc57f674dc811bbbdac1b83571 [file] [log] [blame]
Tao Bao0ba5c942018-08-14 22:20:22 -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 android
16
17import (
18 "io/ioutil"
19 "os"
20 "testing"
21)
22
23func testPrebuiltEtc(t *testing.T, bp string) *TestContext {
24 config, buildDir := setUp(t)
25 defer tearDown(buildDir)
26 ctx := NewTestArchContext()
27 ctx.RegisterModuleType("prebuilt_etc", ModuleFactoryAdaptor(PrebuiltEtcFactory))
28 ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
29 ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
30 })
31 ctx.Register()
32 mockFiles := map[string][]byte{
33 "Android.bp": []byte(bp),
34 "foo.conf": nil,
35 "bar.conf": nil,
36 "baz.conf": nil,
37 }
38 ctx.MockFileSystem(mockFiles)
39 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
40 FailIfErrored(t, errs)
41 _, errs = ctx.PrepareBuildActions(config)
42 FailIfErrored(t, errs)
43
44 return ctx
45}
46
47func setUp(t *testing.T) (config Config, buildDir string) {
48 buildDir, err := ioutil.TempDir("", "soong_prebuilt_etc_test")
49 if err != nil {
50 t.Fatal(err)
51 }
52
53 config = TestArchConfig(buildDir, nil)
54 return
55}
56
57func tearDown(buildDir string) {
58 os.RemoveAll(buildDir)
59}
60
61func TestPrebuiltEtcVariants(t *testing.T) {
62 ctx := testPrebuiltEtc(t, `
63 prebuilt_etc {
64 name: "foo.conf",
65 src: "foo.conf",
66 }
67 prebuilt_etc {
68 name: "bar.conf",
69 src: "bar.conf",
70 recovery_available: true,
71 }
72 prebuilt_etc {
73 name: "baz.conf",
74 src: "baz.conf",
75 recovery: true,
76 }
77 `)
78
79 foo_variants := ctx.ModuleVariantsForTests("foo.conf")
80 if len(foo_variants) != 1 {
81 t.Errorf("expected 1, got %#v", foo_variants)
82 }
83
84 bar_variants := ctx.ModuleVariantsForTests("bar.conf")
85 if len(bar_variants) != 2 {
86 t.Errorf("expected 2, got %#v", bar_variants)
87 }
88
89 baz_variants := ctx.ModuleVariantsForTests("baz.conf")
90 if len(baz_variants) != 1 {
91 t.Errorf("expected 1, got %#v", bar_variants)
92 }
93}