| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 1 | package sh | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 2 |  | 
 | 3 | import ( | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 4 | 	"os" | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 5 | 	"path/filepath" | 
| Dan Shi | b40deac | 2021-05-24 12:04:54 -0700 | [diff] [blame] | 6 | 	"strconv" | 
| Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 7 | 	"strings" | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 8 | 	"testing" | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 9 |  | 
 | 10 | 	"android/soong/android" | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 11 | 	"android/soong/cc" | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 12 | 	"android/soong/java" | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 13 | ) | 
 | 14 |  | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 15 | func TestMain(m *testing.M) { | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 16 | 	os.Exit(m.Run()) | 
| Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 17 | } | 
 | 18 |  | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 19 | var prepareForShTest = android.GroupFixturePreparers( | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 20 | 	cc.PrepareForTestWithCcBuildComponents, | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 21 | 	java.PrepareForTestWithJavaDefaultModules, | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 22 | 	PrepareForTestWithShBuildComponents, | 
 | 23 | 	android.FixtureMergeMockFs(android.MockFS{ | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 24 | 		"test.sh":            nil, | 
 | 25 | 		"testdata/data1":     nil, | 
 | 26 | 		"testdata/sub/data2": nil, | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 27 | 	}), | 
 | 28 | ) | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 29 |  | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 30 | // testShBinary runs tests using the prepareForShTest | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 31 | // | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 32 | // Do not add any new usages of this, instead use the prepareForShTest directly as it makes it much | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 33 | // easier to customize the test behavior. | 
 | 34 | // | 
 | 35 | // If it is necessary to customize the behavior of an existing test that uses this then please first | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 36 | // convert the test to using prepareForShTest first and then in a following change add the | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 37 | // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify | 
 | 38 | // that it did not change the test behavior unexpectedly. | 
 | 39 | // | 
 | 40 | // deprecated | 
 | 41 | func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config) { | 
| Colin Cross | 06c80eb | 2022-02-10 10:34:19 -0800 | [diff] [blame] | 42 | 	bp = bp + cc.GatherRequiredDepsForTest(android.Android) | 
 | 43 |  | 
| Paul Duffin | 89648f9 | 2021-03-20 00:36:55 +0000 | [diff] [blame] | 44 | 	result := prepareForShTest.RunTestWithBp(t, bp) | 
| Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 45 |  | 
| Paul Duffin | 56fb8ee | 2021-03-08 15:05:52 +0000 | [diff] [blame] | 46 | 	return result.TestContext, result.Config | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 47 | } | 
 | 48 |  | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 49 | func TestShTestSubDir(t *testing.T) { | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 50 | 	result := android.GroupFixturePreparers( | 
 | 51 | 		prepareForShTest, | 
 | 52 | 		android.FixtureModifyConfig(android.SetKatiEnabledForTests), | 
 | 53 | 	).RunTestWithBp(t, ` | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 54 | 		sh_test { | 
 | 55 | 			name: "foo", | 
 | 56 | 			src: "test.sh", | 
 | 57 | 			sub_dir: "foo_test" | 
 | 58 | 		} | 
 | 59 | 	`) | 
 | 60 |  | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 61 | 	mod := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 62 |  | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 63 | 	entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0] | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 64 |  | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 65 | 	expectedPath := "out/target/product/test_device/data/nativetest64/foo_test" | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 66 | 	actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 67 | 	android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", result.Config, expectedPath, actualPath) | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 68 | } | 
 | 69 |  | 
 | 70 | func TestShTest(t *testing.T) { | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 71 | 	result := android.GroupFixturePreparers( | 
 | 72 | 		prepareForShTest, | 
 | 73 | 		android.FixtureModifyConfig(android.SetKatiEnabledForTests), | 
 | 74 | 	).RunTestWithBp(t, ` | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 75 | 		sh_test { | 
 | 76 | 			name: "foo", | 
 | 77 | 			src: "test.sh", | 
 | 78 | 			filename: "test.sh", | 
 | 79 | 			data: [ | 
 | 80 | 				"testdata/data1", | 
 | 81 | 				"testdata/sub/data2", | 
 | 82 | 			], | 
 | 83 | 		} | 
 | 84 | 	`) | 
 | 85 |  | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 86 | 	mod := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 87 |  | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 88 | 	entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0] | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 89 |  | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 90 | 	expectedPath := "out/target/product/test_device/data/nativetest64/foo" | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 91 | 	actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 92 | 	android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", result.Config, expectedPath, actualPath) | 
| Jaewoong Jung | 4aedc86 | 2020-06-10 17:23:46 -0700 | [diff] [blame] | 93 |  | 
 | 94 | 	expectedData := []string{":testdata/data1", ":testdata/sub/data2"} | 
 | 95 | 	actualData := entries.EntryMap["LOCAL_TEST_DATA"] | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 96 | 	android.AssertDeepEquals(t, "LOCAL_TEST_DATA", expectedData, actualData) | 
| Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 97 | } | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 98 |  | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 99 | func TestShTest_dataModules(t *testing.T) { | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 100 | 	ctx, config := testShBinary(t, ` | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 101 | 		sh_test { | 
 | 102 | 			name: "foo", | 
 | 103 | 			src: "test.sh", | 
 | 104 | 			host_supported: true, | 
 | 105 | 			data_bins: ["bar"], | 
 | 106 | 			data_libs: ["libbar"], | 
 | 107 | 		} | 
 | 108 |  | 
 | 109 | 		cc_binary { | 
 | 110 | 			name: "bar", | 
 | 111 | 			host_supported: true, | 
 | 112 | 			shared_libs: ["libbar"], | 
 | 113 | 			no_libcrt: true, | 
 | 114 | 			nocrt: true, | 
 | 115 | 			system_shared_libs: [], | 
 | 116 | 			stl: "none", | 
 | 117 | 		} | 
 | 118 |  | 
 | 119 | 		cc_library { | 
 | 120 | 			name: "libbar", | 
 | 121 | 			host_supported: true, | 
 | 122 | 			no_libcrt: true, | 
 | 123 | 			nocrt: true, | 
 | 124 | 			system_shared_libs: [], | 
 | 125 | 			stl: "none", | 
 | 126 | 		} | 
 | 127 | 	`) | 
 | 128 |  | 
| Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 129 | 	buildOS := config.BuildOS.String() | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 130 | 	arches := []string{"android_arm64_armv8-a", buildOS + "_x86_64"} | 
 | 131 | 	for _, arch := range arches { | 
 | 132 | 		variant := ctx.ModuleForTests("foo", arch) | 
 | 133 |  | 
 | 134 | 		libExt := ".so" | 
 | 135 | 		if arch == "darwin_x86_64" { | 
 | 136 | 			libExt = ".dylib" | 
 | 137 | 		} | 
| Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 138 | 		relocated := variant.Output(filepath.Join("out/soong/.intermediates/foo", arch, "relocated/lib64/libbar"+libExt)) | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 139 | 		expectedInput := "out/soong/.intermediates/libbar/" + arch + "_shared/libbar" + libExt | 
 | 140 | 		android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input) | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 141 |  | 
 | 142 | 		mod := variant.Module().(*ShTest) | 
| Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 143 | 		entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 144 | 		expectedData := []string{ | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 145 | 			filepath.Join("out/soong/.intermediates/bar", arch, ":bar"), | 
 | 146 | 			filepath.Join("out/soong/.intermediates/foo", arch, "relocated/:lib64/libbar"+libExt), | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 147 | 		} | 
 | 148 | 		actualData := entries.EntryMap["LOCAL_TEST_DATA"] | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 149 | 		android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 150 | 	} | 
 | 151 | } | 
 | 152 |  | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 153 | func TestShTestHost(t *testing.T) { | 
 | 154 | 	ctx, _ := testShBinary(t, ` | 
 | 155 | 		sh_test_host { | 
 | 156 | 			name: "foo", | 
 | 157 | 			src: "test.sh", | 
 | 158 | 			filename: "test.sh", | 
 | 159 | 			data: [ | 
 | 160 | 				"testdata/data1", | 
 | 161 | 				"testdata/sub/data2", | 
 | 162 | 			], | 
| Dan Shi | b40deac | 2021-05-24 12:04:54 -0700 | [diff] [blame] | 163 | 			test_options: { | 
 | 164 | 				unit_test: true, | 
 | 165 | 			}, | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 166 | 		} | 
 | 167 | 	`) | 
 | 168 |  | 
| Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 169 | 	buildOS := ctx.Config().BuildOS.String() | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 170 | 	mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest) | 
 | 171 | 	if !mod.Host() { | 
 | 172 | 		t.Errorf("host bit is not set for a sh_test_host module.") | 
 | 173 | 	} | 
| Dan Shi | b40deac | 2021-05-24 12:04:54 -0700 | [diff] [blame] | 174 | 	entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] | 
 | 175 | 	actualData, _ := strconv.ParseBool(entries.EntryMap["LOCAL_IS_UNIT_TEST"][0]) | 
 | 176 | 	android.AssertBoolEquals(t, "LOCAL_IS_UNIT_TEST", true, actualData) | 
| Jaewoong Jung | 61a8368 | 2019-07-01 09:08:50 -0700 | [diff] [blame] | 177 | } | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 178 |  | 
| Ronald Braunstein | f424c9a | 2024-10-22 01:41:20 +0000 | [diff] [blame] | 179 | func TestShTestExtraTestConfig(t *testing.T) { | 
 | 180 | 	result, _ := testShBinary(t, ` | 
 | 181 | 		sh_test { | 
 | 182 | 			name: "foo", | 
 | 183 | 			src: "test.sh", | 
 | 184 | 			filename: "test.sh", | 
 | 185 |                         extra_test_configs: ["config1.xml", "config2.xml"], | 
 | 186 | 		} | 
 | 187 | 	`) | 
 | 188 |  | 
 | 189 | 	mod := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) | 
 | 190 | 	entries := android.AndroidMkEntriesForTest(t, result, mod)[0] | 
 | 191 | 	actualData := entries.EntryMap["LOCAL_EXTRA_FULL_TEST_CONFIGS"] | 
 | 192 | 	android.AssertStringPathsRelativeToTopEquals(t, "extra_configs", result.Config(), []string{"config1.xml", "config2.xml"}, actualData) | 
 | 193 | } | 
 | 194 |  | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 195 | func TestShTestHost_dataDeviceModules(t *testing.T) { | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 196 | 	ctx, config := testShBinary(t, ` | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 197 | 		sh_test_host { | 
 | 198 | 			name: "foo", | 
 | 199 | 			src: "test.sh", | 
 | 200 | 			data_device_bins: ["bar"], | 
 | 201 | 			data_device_libs: ["libbar"], | 
 | 202 | 		} | 
 | 203 |  | 
 | 204 | 		cc_binary { | 
 | 205 | 			name: "bar", | 
 | 206 | 			shared_libs: ["libbar"], | 
 | 207 | 			no_libcrt: true, | 
 | 208 | 			nocrt: true, | 
 | 209 | 			system_shared_libs: [], | 
 | 210 | 			stl: "none", | 
 | 211 | 		} | 
 | 212 |  | 
 | 213 | 		cc_library { | 
 | 214 | 			name: "libbar", | 
 | 215 | 			no_libcrt: true, | 
 | 216 | 			nocrt: true, | 
 | 217 | 			system_shared_libs: [], | 
 | 218 | 			stl: "none", | 
 | 219 | 		} | 
 | 220 | 	`) | 
 | 221 |  | 
| Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 222 | 	buildOS := config.BuildOS.String() | 
| Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 223 | 	variant := buildOS + "_x86_64" | 
 | 224 | 	foo := ctx.ModuleForTests("foo", variant) | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 225 |  | 
| Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 226 | 	relocated := foo.Output(filepath.Join("out/soong/.intermediates/foo", variant, "relocated/lib64/libbar.so")) | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 227 | 	expectedInput := "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so" | 
 | 228 | 	android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input) | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 229 |  | 
| Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 230 | 	mod := foo.Module().(*ShTest) | 
| Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 231 | 	entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 232 | 	expectedData := []string{ | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 233 | 		"out/soong/.intermediates/bar/android_arm64_armv8-a/:bar", | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 234 | 		// libbar has been relocated, and so has a variant that matches the host arch. | 
| Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 235 | 		"out/soong/.intermediates/foo/" + variant + "/relocated/:lib64/libbar.so", | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 236 | 	} | 
 | 237 | 	actualData := entries.EntryMap["LOCAL_TEST_DATA"] | 
| Paul Duffin | 32b06c2 | 2021-03-16 07:50:37 +0000 | [diff] [blame] | 238 | 	android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) | 
| Jaewoong Jung | 6e0eee5 | 2020-05-29 16:15:32 -0700 | [diff] [blame] | 239 | } | 
| Sam Delmerico | b3342ce | 2022-01-20 21:10:28 +0000 | [diff] [blame] | 240 |  | 
 | 241 | func TestShTestHost_dataDeviceModulesAutogenTradefedConfig(t *testing.T) { | 
 | 242 | 	ctx, config := testShBinary(t, ` | 
 | 243 | 		sh_test_host { | 
 | 244 | 			name: "foo", | 
 | 245 | 			src: "test.sh", | 
 | 246 | 			data_device_bins: ["bar"], | 
 | 247 | 			data_device_libs: ["libbar"], | 
 | 248 | 		} | 
 | 249 |  | 
 | 250 | 		cc_binary { | 
 | 251 | 			name: "bar", | 
 | 252 | 			shared_libs: ["libbar"], | 
 | 253 | 			no_libcrt: true, | 
 | 254 | 			nocrt: true, | 
 | 255 | 			system_shared_libs: [], | 
 | 256 | 			stl: "none", | 
 | 257 | 		} | 
 | 258 |  | 
 | 259 | 		cc_library { | 
 | 260 | 			name: "libbar", | 
 | 261 | 			no_libcrt: true, | 
 | 262 | 			nocrt: true, | 
 | 263 | 			system_shared_libs: [], | 
 | 264 | 			stl: "none", | 
 | 265 | 		} | 
 | 266 | 	`) | 
 | 267 |  | 
 | 268 | 	buildOS := config.BuildOS.String() | 
 | 269 | 	fooModule := ctx.ModuleForTests("foo", buildOS+"_x86_64") | 
 | 270 |  | 
 | 271 | 	expectedBinAutogenConfig := `<option name="push-file" key="bar" value="/data/local/tests/unrestricted/foo/bar" />` | 
 | 272 | 	autogen := fooModule.Rule("autogen") | 
 | 273 | 	if !strings.Contains(autogen.Args["extraConfigs"], expectedBinAutogenConfig) { | 
 | 274 | 		t.Errorf("foo extraConfings %v does not contain %q", autogen.Args["extraConfigs"], expectedBinAutogenConfig) | 
 | 275 | 	} | 
 | 276 | } | 
| Makoto Onuki | 1725b20 | 2023-08-24 22:17:56 +0000 | [diff] [blame] | 277 |  | 
 | 278 | func TestShTestHost_javaData(t *testing.T) { | 
 | 279 | 	ctx, config := testShBinary(t, ` | 
 | 280 | 		sh_test_host { | 
 | 281 | 			name: "foo", | 
 | 282 | 			src: "test.sh", | 
 | 283 | 			filename: "test.sh", | 
 | 284 | 			data: [ | 
 | 285 | 				"testdata/data1", | 
 | 286 | 				"testdata/sub/data2", | 
 | 287 | 			], | 
 | 288 | 			java_data: [ | 
 | 289 | 				"javalib", | 
 | 290 | 			], | 
 | 291 | 		} | 
 | 292 |  | 
 | 293 | 		java_library_host { | 
 | 294 | 			name: "javalib", | 
 | 295 | 			srcs: [], | 
 | 296 | 		} | 
 | 297 | 	`) | 
 | 298 | 	buildOS := ctx.Config().BuildOS.String() | 
 | 299 | 	mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest) | 
 | 300 | 	if !mod.Host() { | 
 | 301 | 		t.Errorf("host bit is not set for a sh_test_host module.") | 
 | 302 | 	} | 
 | 303 | 	expectedData := []string{ | 
 | 304 | 		":testdata/data1", | 
 | 305 | 		":testdata/sub/data2", | 
 | 306 | 		"out/soong/.intermediates/javalib/" + buildOS + "_common/combined/:javalib.jar", | 
 | 307 | 	} | 
 | 308 |  | 
 | 309 | 	entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] | 
 | 310 | 	actualData := entries.EntryMap["LOCAL_TEST_DATA"] | 
 | 311 | 	android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) | 
 | 312 | } | 
| Ronald Braunstein | 9820408 | 2024-10-29 11:09:00 -0700 | [diff] [blame] | 313 |  | 
 | 314 | func TestDefaultsForTests(t *testing.T) { | 
 | 315 | 	ctx, config := testShBinary(t, ` | 
 | 316 | 		sh_defaults { | 
 | 317 | 			name: "defaults", | 
 | 318 | 			src: "test.sh", | 
 | 319 | 			filename: "test.sh", | 
 | 320 | 			data: [ | 
 | 321 | 				"testdata/data1", | 
 | 322 | 				"testdata/sub/data2", | 
 | 323 | 			], | 
 | 324 | 		} | 
 | 325 | 		sh_test_host { | 
 | 326 | 			name: "foo", | 
 | 327 | 			defaults: ["defaults"], | 
 | 328 | 			data: [ | 
 | 329 | 				"testdata/more_data", | 
 | 330 | 			], | 
 | 331 | 			java_data: [ | 
 | 332 | 				"javalib", | 
 | 333 | 			], | 
 | 334 | 		} | 
 | 335 |  | 
 | 336 | 		java_library_host { | 
 | 337 | 			name: "javalib", | 
 | 338 | 			srcs: [], | 
 | 339 | 		} | 
 | 340 |  | 
 | 341 | 		sh_test { | 
 | 342 | 			name: "sh-test", | 
 | 343 | 			defaults: ["defaults"], | 
 | 344 | 		} | 
 | 345 |  | 
 | 346 | 	`) | 
 | 347 | 	buildOS := ctx.Config().BuildOS.String() | 
 | 348 | 	mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest) | 
 | 349 | 	if !mod.Host() { | 
 | 350 | 		t.Errorf("host bit is not set for a sh_test_host module.") | 
 | 351 | 	} | 
 | 352 | 	expectedData := []string{ | 
 | 353 | 		":testdata/data1", | 
 | 354 | 		":testdata/sub/data2", | 
 | 355 | 		":testdata/more_data", | 
 | 356 | 		"out/soong/.intermediates/javalib/" + buildOS + "_common/combined/:javalib.jar", | 
 | 357 | 	} | 
 | 358 |  | 
 | 359 | 	entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] | 
 | 360 | 	actualData := entries.EntryMap["LOCAL_TEST_DATA"] | 
 | 361 | 	android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) | 
 | 362 |  | 
 | 363 | 	// Just the defaults | 
 | 364 | 	expectedData = []string{ | 
 | 365 | 		":testdata/data1", | 
 | 366 | 		":testdata/sub/data2", | 
 | 367 | 	} | 
 | 368 | 	mod = ctx.ModuleForTests("sh-test", "android_arm64_armv8-a").Module().(*ShTest) | 
 | 369 | 	entries = android.AndroidMkEntriesForTest(t, ctx, mod)[0] | 
 | 370 | 	actualData = entries.EntryMap["LOCAL_TEST_DATA"] | 
 | 371 | 	android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData) | 
 | 372 | } | 
 | 373 |  | 
 | 374 | func TestDefaultsForBinaries(t *testing.T) { | 
 | 375 | 	ctx, _ := testShBinary(t, ` | 
 | 376 | 		sh_defaults { | 
 | 377 | 			name: "defaults", | 
 | 378 | 			src: "test.sh", | 
 | 379 | 			filename: "test.sh", | 
 | 380 | 		} | 
 | 381 | 		sh_binary_host { | 
 | 382 | 			name: "the-host-binary", | 
 | 383 | 			defaults: ["defaults"], | 
 | 384 | 		} | 
 | 385 | 		sh_binary{ | 
 | 386 | 			name: "the-binary", | 
 | 387 | 			defaults: ["defaults"], | 
 | 388 | 		} | 
 | 389 | 	`) | 
 | 390 | 	buildOS := ctx.Config().BuildOS.String() | 
 | 391 | 	mod := ctx.ModuleForTests("the-host-binary", buildOS+"_x86_64").Module().(*ShBinary) | 
 | 392 | 	if !mod.Host() { | 
 | 393 | 		t.Errorf("host bit is not set for a sh_binary_host module.") | 
 | 394 | 	} | 
 | 395 |  | 
 | 396 | 	expectedFilename := "test.sh" | 
 | 397 | 	android.AssertStringEquals(t, "Filename", expectedFilename, *mod.properties.Filename) | 
 | 398 |  | 
 | 399 | 	mod = ctx.ModuleForTests("the-binary", "android_arm64_armv8-a").Module().(*ShBinary) | 
 | 400 | 	android.AssertStringEquals(t, "Filename", expectedFilename, *mod.properties.Filename) | 
 | 401 | } |