blob: 27736ba58f8aa9db5d661d3aca4e04206437e960 [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}
Jiyong Park139a2e62018-10-26 21:49:39 +090094
95func TestPrebuiltEtcOutputPath(t *testing.T) {
96 ctx := testPrebuiltEtc(t, `
97 prebuilt_etc {
98 name: "foo.conf",
99 src: "foo.conf",
100 filename: "foo.installed.conf",
101 }
102 `)
103
104 p := ctx.ModuleForTests("foo.conf", "android_common_core").Module().(*PrebuiltEtc)
105 if p.outputFilePath.Base() != "foo.installed.conf" {
106 t.Errorf("expected foo.installed.conf, got %q", p.outputFilePath.Base())
107 }
108}
Jiyong Park1a7cf082018-11-13 11:59:12 +0900109
110func TestPrebuiltEtcGlob(t *testing.T) {
111 ctx := testPrebuiltEtc(t, `
112 prebuilt_etc {
113 name: "my_foo",
114 src: "foo.*",
115 }
116 prebuilt_etc {
117 name: "my_bar",
118 src: "bar.*",
119 filename_from_src: true,
120 }
121 `)
122
123 p := ctx.ModuleForTests("my_foo", "android_common_core").Module().(*PrebuiltEtc)
124 if p.outputFilePath.Base() != "my_foo" {
125 t.Errorf("expected my_foo, got %q", p.outputFilePath.Base())
126 }
127
128 p = ctx.ModuleForTests("my_bar", "android_common_core").Module().(*PrebuiltEtc)
129 if p.outputFilePath.Base() != "bar.conf" {
130 t.Errorf("expected bar.conf, got %q", p.outputFilePath.Base())
131 }
132}