arch_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. // Copyright 2019 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. package android
  15. import (
  16. "reflect"
  17. "runtime"
  18. "testing"
  19. "github.com/google/blueprint/proptools"
  20. )
  21. type Named struct {
  22. A *string `android:"arch_variant"`
  23. B *string
  24. }
  25. type NamedAllFiltered struct {
  26. A *string
  27. }
  28. type NamedNoneFiltered struct {
  29. A *string `android:"arch_variant"`
  30. }
  31. func TestFilterArchStruct(t *testing.T) {
  32. tests := []struct {
  33. name string
  34. in interface{}
  35. out interface{}
  36. filtered bool
  37. }{
  38. // Property tests
  39. {
  40. name: "basic",
  41. in: &struct {
  42. A *string `android:"arch_variant"`
  43. B *string
  44. }{},
  45. out: &struct {
  46. A *string
  47. }{},
  48. filtered: true,
  49. },
  50. {
  51. name: "tags",
  52. in: &struct {
  53. A *string `android:"arch_variant"`
  54. B *string `android:"arch_variant,path"`
  55. C *string `android:"arch_variant,path,variant_prepend"`
  56. D *string `android:"path,variant_prepend,arch_variant"`
  57. E *string `android:"path"`
  58. F *string
  59. }{},
  60. out: &struct {
  61. A *string
  62. B *string
  63. C *string
  64. D *string
  65. }{},
  66. filtered: true,
  67. },
  68. {
  69. name: "all filtered",
  70. in: &struct {
  71. A *string
  72. }{},
  73. out: nil,
  74. filtered: true,
  75. },
  76. {
  77. name: "none filtered",
  78. in: &struct {
  79. A *string `android:"arch_variant"`
  80. }{},
  81. out: &struct {
  82. A *string `android:"arch_variant"`
  83. }{},
  84. filtered: false,
  85. },
  86. // Sub-struct tests
  87. {
  88. name: "substruct",
  89. in: &struct {
  90. A struct {
  91. A *string `android:"arch_variant"`
  92. B *string
  93. } `android:"arch_variant"`
  94. }{},
  95. out: &struct {
  96. A struct {
  97. A *string
  98. }
  99. }{},
  100. filtered: true,
  101. },
  102. {
  103. name: "substruct all filtered",
  104. in: &struct {
  105. A struct {
  106. A *string
  107. } `android:"arch_variant"`
  108. }{},
  109. out: nil,
  110. filtered: true,
  111. },
  112. {
  113. name: "substruct none filtered",
  114. in: &struct {
  115. A struct {
  116. A *string `android:"arch_variant"`
  117. } `android:"arch_variant"`
  118. }{},
  119. out: &struct {
  120. A struct {
  121. A *string `android:"arch_variant"`
  122. } `android:"arch_variant"`
  123. }{},
  124. filtered: false,
  125. },
  126. // Named sub-struct tests
  127. {
  128. name: "named substruct",
  129. in: &struct {
  130. A Named `android:"arch_variant"`
  131. }{},
  132. out: &struct {
  133. A struct {
  134. A *string
  135. }
  136. }{},
  137. filtered: true,
  138. },
  139. {
  140. name: "substruct all filtered",
  141. in: &struct {
  142. A NamedAllFiltered `android:"arch_variant"`
  143. }{},
  144. out: nil,
  145. filtered: true,
  146. },
  147. {
  148. name: "substruct none filtered",
  149. in: &struct {
  150. A NamedNoneFiltered `android:"arch_variant"`
  151. }{},
  152. out: &struct {
  153. A NamedNoneFiltered `android:"arch_variant"`
  154. }{},
  155. filtered: false,
  156. },
  157. // Pointer to sub-struct tests
  158. {
  159. name: "pointer substruct",
  160. in: &struct {
  161. A *struct {
  162. A *string `android:"arch_variant"`
  163. B *string
  164. } `android:"arch_variant"`
  165. }{},
  166. out: &struct {
  167. A *struct {
  168. A *string
  169. }
  170. }{},
  171. filtered: true,
  172. },
  173. {
  174. name: "pointer substruct all filtered",
  175. in: &struct {
  176. A *struct {
  177. A *string
  178. } `android:"arch_variant"`
  179. }{},
  180. out: nil,
  181. filtered: true,
  182. },
  183. {
  184. name: "pointer substruct none filtered",
  185. in: &struct {
  186. A *struct {
  187. A *string `android:"arch_variant"`
  188. } `android:"arch_variant"`
  189. }{},
  190. out: &struct {
  191. A *struct {
  192. A *string `android:"arch_variant"`
  193. } `android:"arch_variant"`
  194. }{},
  195. filtered: false,
  196. },
  197. // Pointer to named sub-struct tests
  198. {
  199. name: "pointer named substruct",
  200. in: &struct {
  201. A *Named `android:"arch_variant"`
  202. }{},
  203. out: &struct {
  204. A *struct {
  205. A *string
  206. }
  207. }{},
  208. filtered: true,
  209. },
  210. {
  211. name: "pointer substruct all filtered",
  212. in: &struct {
  213. A *NamedAllFiltered `android:"arch_variant"`
  214. }{},
  215. out: nil,
  216. filtered: true,
  217. },
  218. {
  219. name: "pointer substruct none filtered",
  220. in: &struct {
  221. A *NamedNoneFiltered `android:"arch_variant"`
  222. }{},
  223. out: &struct {
  224. A *NamedNoneFiltered `android:"arch_variant"`
  225. }{},
  226. filtered: false,
  227. },
  228. }
  229. for _, test := range tests {
  230. t.Run(test.name, func(t *testing.T) {
  231. out, filtered := proptools.FilterPropertyStruct(reflect.TypeOf(test.in), filterArchStruct)
  232. if filtered != test.filtered {
  233. t.Errorf("expected filtered %v, got %v", test.filtered, filtered)
  234. }
  235. expected := reflect.TypeOf(test.out)
  236. if out != expected {
  237. t.Errorf("expected type %v, got %v", expected, out)
  238. }
  239. })
  240. }
  241. }
  242. type archTestModule struct {
  243. ModuleBase
  244. props struct {
  245. Deps []string
  246. }
  247. }
  248. func (m *archTestMultiTargetsModule) GenerateAndroidBuildActions(ctx ModuleContext) {
  249. }
  250. func (m *archTestMultiTargetsModule) DepsMutator(ctx BottomUpMutatorContext) {
  251. ctx.AddDependency(ctx.Module(), nil, m.props.Deps...)
  252. }
  253. func archTestMultiTargetsModuleFactory() Module {
  254. m := &archTestMultiTargetsModule{}
  255. m.AddProperties(&m.props)
  256. InitAndroidMultiTargetsArchModule(m, HostAndDeviceSupported, MultilibCommon)
  257. return m
  258. }
  259. type archTestMultiTargetsModule struct {
  260. ModuleBase
  261. props struct {
  262. Deps []string
  263. }
  264. }
  265. func (m *archTestModule) GenerateAndroidBuildActions(ctx ModuleContext) {
  266. }
  267. func (m *archTestModule) DepsMutator(ctx BottomUpMutatorContext) {
  268. ctx.AddDependency(ctx.Module(), nil, m.props.Deps...)
  269. }
  270. func archTestModuleFactory() Module {
  271. m := &archTestModule{}
  272. m.AddProperties(&m.props)
  273. InitAndroidArchModule(m, HostAndDeviceSupported, MultilibBoth)
  274. return m
  275. }
  276. var prepareForArchTest = GroupFixturePreparers(
  277. PrepareForTestWithArchMutator,
  278. FixtureRegisterWithContext(func(ctx RegistrationContext) {
  279. ctx.RegisterModuleType("module", archTestModuleFactory)
  280. ctx.RegisterModuleType("multi_targets_module", archTestMultiTargetsModuleFactory)
  281. }),
  282. )
  283. func TestArchMutator(t *testing.T) {
  284. var buildOSVariants []string
  285. var buildOS64Variants []string
  286. var buildOS32Variants []string
  287. var buildOSCommonVariant string
  288. switch runtime.GOOS {
  289. case "linux":
  290. buildOSVariants = []string{"linux_glibc_x86_64", "linux_glibc_x86"}
  291. buildOS64Variants = []string{"linux_glibc_x86_64"}
  292. buildOS32Variants = []string{"linux_glibc_x86"}
  293. buildOSCommonVariant = "linux_glibc_common"
  294. case "darwin":
  295. buildOSVariants = []string{"darwin_x86_64"}
  296. buildOS64Variants = []string{"darwin_x86_64"}
  297. buildOS32Variants = nil
  298. buildOSCommonVariant = "darwin_common"
  299. }
  300. bp := `
  301. module {
  302. name: "foo",
  303. }
  304. module {
  305. name: "bar",
  306. host_supported: true,
  307. }
  308. module {
  309. name: "baz",
  310. device_supported: false,
  311. }
  312. module {
  313. name: "qux",
  314. host_supported: true,
  315. compile_multilib: "32",
  316. }
  317. module {
  318. name: "first",
  319. host_supported: true,
  320. compile_multilib: "first",
  321. }
  322. multi_targets_module {
  323. name: "multi_targets",
  324. host_supported: true,
  325. }
  326. `
  327. testCases := []struct {
  328. name string
  329. preparer FixturePreparer
  330. fooVariants []string
  331. barVariants []string
  332. bazVariants []string
  333. quxVariants []string
  334. firstVariants []string
  335. multiTargetVariants []string
  336. multiTargetVariantsMap map[string][]string
  337. goOS string
  338. }{
  339. {
  340. name: "normal",
  341. preparer: nil,
  342. fooVariants: []string{"android_arm64_armv8-a", "android_arm_armv7-a-neon"},
  343. barVariants: append(buildOSVariants, "android_arm64_armv8-a", "android_arm_armv7-a-neon"),
  344. bazVariants: nil,
  345. quxVariants: append(buildOS32Variants, "android_arm_armv7-a-neon"),
  346. firstVariants: append(buildOS64Variants, "android_arm64_armv8-a"),
  347. multiTargetVariants: []string{buildOSCommonVariant, "android_common"},
  348. multiTargetVariantsMap: map[string][]string{
  349. buildOSCommonVariant: buildOS64Variants,
  350. "android_common": {"android_arm64_armv8-a"},
  351. }},
  352. {
  353. name: "host-only",
  354. preparer: FixtureModifyConfig(func(config Config) {
  355. config.BuildOSTarget = Target{}
  356. config.BuildOSCommonTarget = Target{}
  357. config.Targets[Android] = nil
  358. }),
  359. fooVariants: nil,
  360. barVariants: buildOSVariants,
  361. bazVariants: nil,
  362. quxVariants: buildOS32Variants,
  363. firstVariants: buildOS64Variants,
  364. multiTargetVariants: []string{buildOSCommonVariant},
  365. multiTargetVariantsMap: map[string][]string{
  366. buildOSCommonVariant: buildOS64Variants,
  367. },
  368. },
  369. {
  370. name: "same arch host and host cross",
  371. preparer: FixtureModifyConfig(func(config Config) {
  372. ModifyTestConfigForMusl(config)
  373. modifyTestConfigForMuslArm64HostCross(config)
  374. }),
  375. fooVariants: []string{"android_arm64_armv8-a", "android_arm_armv7-a-neon"},
  376. barVariants: []string{"linux_musl_x86_64", "linux_musl_arm64", "linux_musl_x86", "android_arm64_armv8-a", "android_arm_armv7-a-neon"},
  377. bazVariants: nil,
  378. quxVariants: []string{"linux_musl_x86", "android_arm_armv7-a-neon"},
  379. firstVariants: []string{"linux_musl_x86_64", "linux_musl_arm64", "android_arm64_armv8-a"},
  380. multiTargetVariants: []string{"linux_musl_common", "android_common"},
  381. multiTargetVariantsMap: map[string][]string{
  382. "linux_musl_common": {"linux_musl_x86_64"},
  383. "android_common": {"android_arm64_armv8-a"},
  384. },
  385. goOS: "linux",
  386. },
  387. }
  388. enabledVariants := func(ctx *TestContext, name string) []string {
  389. var ret []string
  390. variants := ctx.ModuleVariantsForTests(name)
  391. for _, variant := range variants {
  392. m := ctx.ModuleForTests(name, variant)
  393. if m.Module().Enabled() {
  394. ret = append(ret, variant)
  395. }
  396. }
  397. return ret
  398. }
  399. moduleMultiTargets := func(ctx *TestContext, name string, variant string) []string {
  400. var ret []string
  401. targets := ctx.ModuleForTests(name, variant).Module().MultiTargets()
  402. for _, t := range targets {
  403. ret = append(ret, t.String())
  404. }
  405. return ret
  406. }
  407. for _, tt := range testCases {
  408. t.Run(tt.name, func(t *testing.T) {
  409. if tt.goOS != runtime.GOOS {
  410. t.Skipf("requries runtime.GOOS %s", tt.goOS)
  411. }
  412. result := GroupFixturePreparers(
  413. prepareForArchTest,
  414. // Test specific preparer
  415. OptionalFixturePreparer(tt.preparer),
  416. FixtureWithRootAndroidBp(bp),
  417. ).RunTest(t)
  418. ctx := result.TestContext
  419. if g, w := enabledVariants(ctx, "foo"), tt.fooVariants; !reflect.DeepEqual(w, g) {
  420. t.Errorf("want foo variants:\n%q\ngot:\n%q\n", w, g)
  421. }
  422. if g, w := enabledVariants(ctx, "bar"), tt.barVariants; !reflect.DeepEqual(w, g) {
  423. t.Errorf("want bar variants:\n%q\ngot:\n%q\n", w, g)
  424. }
  425. if g, w := enabledVariants(ctx, "baz"), tt.bazVariants; !reflect.DeepEqual(w, g) {
  426. t.Errorf("want baz variants:\n%q\ngot:\n%q\n", w, g)
  427. }
  428. if g, w := enabledVariants(ctx, "qux"), tt.quxVariants; !reflect.DeepEqual(w, g) {
  429. t.Errorf("want qux variants:\n%q\ngot:\n%q\n", w, g)
  430. }
  431. if g, w := enabledVariants(ctx, "first"), tt.firstVariants; !reflect.DeepEqual(w, g) {
  432. t.Errorf("want first variants:\n%q\ngot:\n%q\n", w, g)
  433. }
  434. if g, w := enabledVariants(ctx, "multi_targets"), tt.multiTargetVariants; !reflect.DeepEqual(w, g) {
  435. t.Fatalf("want multi_target variants:\n%q\ngot:\n%q\n", w, g)
  436. }
  437. for _, variant := range tt.multiTargetVariants {
  438. targets := moduleMultiTargets(ctx, "multi_targets", variant)
  439. if g, w := targets, tt.multiTargetVariantsMap[variant]; !reflect.DeepEqual(w, g) {
  440. t.Errorf("want ctx.MultiTarget() for %q:\n%q\ngot:\n%q\n", variant, w, g)
  441. }
  442. }
  443. })
  444. }
  445. }
  446. func TestArchMutatorNativeBridge(t *testing.T) {
  447. bp := `
  448. // This module is only enabled for x86.
  449. module {
  450. name: "foo",
  451. }
  452. // This module is enabled for x86 and arm (via native bridge).
  453. module {
  454. name: "bar",
  455. native_bridge_supported: true,
  456. }
  457. // This module is enabled for arm (native_bridge) only.
  458. module {
  459. name: "baz",
  460. native_bridge_supported: true,
  461. enabled: false,
  462. target: {
  463. native_bridge: {
  464. enabled: true,
  465. }
  466. }
  467. }
  468. `
  469. testCases := []struct {
  470. name string
  471. preparer FixturePreparer
  472. fooVariants []string
  473. barVariants []string
  474. bazVariants []string
  475. }{
  476. {
  477. name: "normal",
  478. preparer: nil,
  479. fooVariants: []string{"android_x86_64_silvermont", "android_x86_silvermont"},
  480. barVariants: []string{"android_x86_64_silvermont", "android_native_bridge_arm64_armv8-a", "android_x86_silvermont", "android_native_bridge_arm_armv7-a-neon"},
  481. bazVariants: []string{"android_native_bridge_arm64_armv8-a", "android_native_bridge_arm_armv7-a-neon"},
  482. },
  483. }
  484. enabledVariants := func(ctx *TestContext, name string) []string {
  485. var ret []string
  486. variants := ctx.ModuleVariantsForTests(name)
  487. for _, variant := range variants {
  488. m := ctx.ModuleForTests(name, variant)
  489. if m.Module().Enabled() {
  490. ret = append(ret, variant)
  491. }
  492. }
  493. return ret
  494. }
  495. for _, tt := range testCases {
  496. t.Run(tt.name, func(t *testing.T) {
  497. result := GroupFixturePreparers(
  498. prepareForArchTest,
  499. // Test specific preparer
  500. OptionalFixturePreparer(tt.preparer),
  501. // Prepare for native bridge test
  502. FixtureModifyConfig(func(config Config) {
  503. config.Targets[Android] = []Target{
  504. {Android, Arch{ArchType: X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, NativeBridgeDisabled, "", "", false},
  505. {Android, Arch{ArchType: X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, NativeBridgeDisabled, "", "", false},
  506. {Android, Arch{ArchType: Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridgeEnabled, "x86_64", "arm64", false},
  507. {Android, Arch{ArchType: Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, NativeBridgeEnabled, "x86", "arm", false},
  508. }
  509. }),
  510. FixtureWithRootAndroidBp(bp),
  511. ).RunTest(t)
  512. ctx := result.TestContext
  513. if g, w := enabledVariants(ctx, "foo"), tt.fooVariants; !reflect.DeepEqual(w, g) {
  514. t.Errorf("want foo variants:\n%q\ngot:\n%q\n", w, g)
  515. }
  516. if g, w := enabledVariants(ctx, "bar"), tt.barVariants; !reflect.DeepEqual(w, g) {
  517. t.Errorf("want bar variants:\n%q\ngot:\n%q\n", w, g)
  518. }
  519. if g, w := enabledVariants(ctx, "baz"), tt.bazVariants; !reflect.DeepEqual(w, g) {
  520. t.Errorf("want qux variants:\n%q\ngot:\n%q\n", w, g)
  521. }
  522. })
  523. }
  524. }
  525. type testArchPropertiesModule struct {
  526. ModuleBase
  527. properties struct {
  528. A []string `android:"arch_variant"`
  529. }
  530. }
  531. func (testArchPropertiesModule) GenerateAndroidBuildActions(ctx ModuleContext) {}
  532. // Module property "a" does not have "variant_prepend" tag.
  533. // Expected variant property orders are based on this fact.
  534. func TestArchProperties(t *testing.T) {
  535. bp := `
  536. module {
  537. name: "foo",
  538. a: ["root"],
  539. arch: {
  540. arm: {
  541. a: ["arm"],
  542. },
  543. arm64: {
  544. a: ["arm64"],
  545. },
  546. riscv64: { a: ["riscv64"] },
  547. x86: { a: ["x86"] },
  548. x86_64: { a: ["x86_64"] },
  549. },
  550. multilib: {
  551. lib32: { a: ["lib32"] },
  552. lib64: { a: ["lib64"] },
  553. },
  554. target: {
  555. bionic: { a: ["bionic"] },
  556. host: { a: ["host"] },
  557. android: { a: ["android"] },
  558. glibc: { a: ["glibc"] },
  559. musl: { a: ["musl"] },
  560. linux_bionic: { a: ["linux_bionic"] },
  561. linux: { a: ["linux"] },
  562. host_linux: { a: ["host_linux"] },
  563. linux_glibc: { a: ["linux_glibc"] },
  564. linux_musl: { a: ["linux_musl"] },
  565. windows: { a: ["windows"], enabled: true },
  566. darwin: { a: ["darwin"] },
  567. not_windows: { a: ["not_windows"] },
  568. android32: { a: ["android32"] },
  569. android64: { a: ["android64"] },
  570. android_arm: { a: ["android_arm"] },
  571. android_arm64: { a: ["android_arm64"] },
  572. linux_x86: { a: ["linux_x86"] },
  573. linux_x86_64: { a: ["linux_x86_64"] },
  574. linux_glibc_x86: { a: ["linux_glibc_x86"] },
  575. linux_glibc_x86_64: { a: ["linux_glibc_x86_64"] },
  576. linux_musl_x86: { a: ["linux_musl_x86"] },
  577. linux_musl_x86_64: { a: ["linux_musl_x86_64"] },
  578. darwin_x86_64: { a: ["darwin_x86_64"] },
  579. windows_x86: { a: ["windows_x86"] },
  580. windows_x86_64: { a: ["windows_x86_64"] },
  581. },
  582. }
  583. `
  584. type result struct {
  585. module string
  586. variant string
  587. property []string
  588. }
  589. testCases := []struct {
  590. name string
  591. goOS string
  592. preparer FixturePreparer
  593. results []result
  594. }{
  595. {
  596. name: "default",
  597. results: []result{
  598. {
  599. module: "foo",
  600. variant: "android_arm64_armv8-a",
  601. property: []string{"root", "linux", "bionic", "android", "android64", "arm64", "lib64", "android_arm64"},
  602. },
  603. {
  604. module: "foo",
  605. variant: "android_arm_armv7-a-neon",
  606. property: []string{"root", "linux", "bionic", "android", "android64", "arm", "lib32", "android_arm"},
  607. },
  608. },
  609. },
  610. {
  611. name: "linux",
  612. goOS: "linux",
  613. results: []result{
  614. {
  615. module: "foo",
  616. variant: "linux_glibc_x86_64",
  617. property: []string{"root", "host", "linux", "host_linux", "glibc", "linux_glibc", "not_windows", "x86_64", "lib64", "linux_x86_64", "linux_glibc_x86_64"},
  618. },
  619. {
  620. module: "foo",
  621. variant: "linux_glibc_x86",
  622. property: []string{"root", "host", "linux", "host_linux", "glibc", "linux_glibc", "not_windows", "x86", "lib32", "linux_x86", "linux_glibc_x86"},
  623. },
  624. },
  625. },
  626. {
  627. name: "windows",
  628. goOS: "linux",
  629. preparer: FixtureModifyConfig(func(config Config) {
  630. config.Targets[Windows] = []Target{
  631. {Windows, Arch{ArchType: X86_64}, NativeBridgeDisabled, "", "", true},
  632. {Windows, Arch{ArchType: X86}, NativeBridgeDisabled, "", "", true},
  633. }
  634. }),
  635. results: []result{
  636. {
  637. module: "foo",
  638. variant: "windows_x86_64",
  639. property: []string{"root", "host", "windows", "x86_64", "lib64", "windows_x86_64"},
  640. },
  641. {
  642. module: "foo",
  643. variant: "windows_x86",
  644. property: []string{"root", "host", "windows", "x86", "lib32", "windows_x86"},
  645. },
  646. },
  647. },
  648. {
  649. name: "linux_musl",
  650. goOS: "linux",
  651. preparer: FixtureModifyConfig(ModifyTestConfigForMusl),
  652. results: []result{
  653. {
  654. module: "foo",
  655. variant: "linux_musl_x86_64",
  656. property: []string{"root", "host", "linux", "host_linux", "musl", "linux_musl", "not_windows", "x86_64", "lib64", "linux_x86_64", "linux_musl_x86_64"},
  657. },
  658. {
  659. module: "foo",
  660. variant: "linux_musl_x86",
  661. property: []string{"root", "host", "linux", "host_linux", "musl", "linux_musl", "not_windows", "x86", "lib32", "linux_x86", "linux_musl_x86"},
  662. },
  663. },
  664. },
  665. {
  666. name: "darwin",
  667. goOS: "darwin",
  668. results: []result{
  669. {
  670. module: "foo",
  671. variant: "darwin_x86_64",
  672. property: []string{"root", "host", "darwin", "not_windows", "x86_64", "lib64", "darwin_x86_64"},
  673. },
  674. },
  675. },
  676. }
  677. for _, tt := range testCases {
  678. t.Run(tt.name, func(t *testing.T) {
  679. if tt.goOS != "" && tt.goOS != runtime.GOOS {
  680. t.Skipf("test requires runtime.GOOS==%s, got %s", tt.goOS, runtime.GOOS)
  681. }
  682. result := GroupFixturePreparers(
  683. PrepareForTestWithArchMutator,
  684. OptionalFixturePreparer(tt.preparer),
  685. FixtureRegisterWithContext(func(ctx RegistrationContext) {
  686. ctx.RegisterModuleType("module", func() Module {
  687. module := &testArchPropertiesModule{}
  688. module.AddProperties(&module.properties)
  689. InitAndroidArchModule(module, HostAndDeviceDefault, MultilibBoth)
  690. return module
  691. })
  692. }),
  693. ).RunTestWithBp(t, bp)
  694. for _, want := range tt.results {
  695. t.Run(want.module+"_"+want.variant, func(t *testing.T) {
  696. got := result.ModuleForTests(want.module, want.variant).Module().(*testArchPropertiesModule).properties.A
  697. AssertArrayString(t, "arch mutator property", want.property, got)
  698. })
  699. }
  700. })
  701. }
  702. }