blob: 925cc3ea22081d681a8d06c3732a2459f868d1a0 [file] [log] [blame]
Jingwen Chen12b4c272021-03-10 02:05:59 -05001// Copyright 2021 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.
14package android
15
Sam Delmerico24c56032022-03-28 19:53:03 +000016import (
17 "android/soong/android/allowlists"
18 "testing"
19)
Jingwen Chen12b4c272021-03-10 02:05:59 -050020
21func TestConvertAllModulesInPackage(t *testing.T) {
22 testCases := []struct {
Sam Delmerico24c56032022-03-28 19:53:03 +000023 prefixes allowlists.Bp2BuildConfig
Jingwen Chen12b4c272021-03-10 02:05:59 -050024 packageDir string
25 }{
26 {
Sam Delmerico24c56032022-03-28 19:53:03 +000027 prefixes: allowlists.Bp2BuildConfig{
28 "a": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050029 },
30 packageDir: "a",
31 },
32 {
Sam Delmerico24c56032022-03-28 19:53:03 +000033 prefixes: allowlists.Bp2BuildConfig{
34 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050035 },
36 packageDir: "a/b",
37 },
38 {
Sam Delmerico24c56032022-03-28 19:53:03 +000039 prefixes: allowlists.Bp2BuildConfig{
40 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
41 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050042 },
43 packageDir: "a/b",
44 },
45 {
Sam Delmerico24c56032022-03-28 19:53:03 +000046 prefixes: allowlists.Bp2BuildConfig{
47 "a": allowlists.Bp2BuildDefaultTrueRecursively,
48 "d/e/f": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050049 },
50 packageDir: "a/b",
51 },
52 {
Sam Delmerico24c56032022-03-28 19:53:03 +000053 prefixes: allowlists.Bp2BuildConfig{
54 "a": allowlists.Bp2BuildDefaultFalse,
55 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
56 "a/b/c": allowlists.Bp2BuildDefaultFalse,
Jingwen Chen12b4c272021-03-10 02:05:59 -050057 },
58 packageDir: "a/b",
59 },
60 {
Sam Delmerico24c56032022-03-28 19:53:03 +000061 prefixes: allowlists.Bp2BuildConfig{
62 "a": allowlists.Bp2BuildDefaultTrueRecursively,
63 "a/b": allowlists.Bp2BuildDefaultFalse,
64 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050065 },
66 packageDir: "a",
67 },
68 }
69
70 for _, test := range testCases {
Sam Delmerico24c56032022-03-28 19:53:03 +000071 if ok, _ := bp2buildDefaultTrueRecursively(test.packageDir, test.prefixes); !ok {
Jingwen Chen12b4c272021-03-10 02:05:59 -050072 t.Errorf("Expected to convert all modules in %s based on %v, but failed.", test.packageDir, test.prefixes)
73 }
74 }
75}
76
77func TestModuleOptIn(t *testing.T) {
78 testCases := []struct {
Sam Delmerico24c56032022-03-28 19:53:03 +000079 prefixes allowlists.Bp2BuildConfig
Jingwen Chen12b4c272021-03-10 02:05:59 -050080 packageDir string
81 }{
82 {
Sam Delmerico24c56032022-03-28 19:53:03 +000083 prefixes: allowlists.Bp2BuildConfig{
84 "a/b": allowlists.Bp2BuildDefaultFalse,
Jingwen Chen12b4c272021-03-10 02:05:59 -050085 },
86 packageDir: "a/b",
87 },
88 {
Sam Delmerico24c56032022-03-28 19:53:03 +000089 prefixes: allowlists.Bp2BuildConfig{
90 "a": allowlists.Bp2BuildDefaultFalse,
91 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050092 },
93 packageDir: "a",
94 },
95 {
Sam Delmerico24c56032022-03-28 19:53:03 +000096 prefixes: allowlists.Bp2BuildConfig{
97 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -050098 },
99 packageDir: "a", // opt-in by default
100 },
101 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000102 prefixes: allowlists.Bp2BuildConfig{
103 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500104 },
105 packageDir: "a/b",
106 },
107 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000108 prefixes: allowlists.Bp2BuildConfig{
109 "a": allowlists.Bp2BuildDefaultTrueRecursively,
110 "d/e/f": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500111 },
112 packageDir: "foo/bar",
113 },
114 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000115 prefixes: allowlists.Bp2BuildConfig{
116 "a": allowlists.Bp2BuildDefaultTrueRecursively,
117 "a/b": allowlists.Bp2BuildDefaultFalse,
118 "a/b/c": allowlists.Bp2BuildDefaultTrueRecursively,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500119 },
120 packageDir: "a/b",
121 },
122 {
Sam Delmerico24c56032022-03-28 19:53:03 +0000123 prefixes: allowlists.Bp2BuildConfig{
124 "a": allowlists.Bp2BuildDefaultFalse,
125 "a/b": allowlists.Bp2BuildDefaultTrueRecursively,
126 "a/b/c": allowlists.Bp2BuildDefaultFalse,
Jingwen Chen12b4c272021-03-10 02:05:59 -0500127 },
128 packageDir: "a",
129 },
130 }
131
132 for _, test := range testCases {
Sam Delmerico24c56032022-03-28 19:53:03 +0000133 if ok, _ := bp2buildDefaultTrueRecursively(test.packageDir, test.prefixes); ok {
Jingwen Chen12b4c272021-03-10 02:05:59 -0500134 t.Errorf("Expected to allow module opt-in in %s based on %v, but failed.", test.packageDir, test.prefixes)
135 }
136 }
137}