bpfix_test.go 18 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. // Copyright 2017 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. // This file implements the logic of bpfix and also provides a programmatic interface
  15. package bpfix
  16. import (
  17. "bytes"
  18. "fmt"
  19. "strings"
  20. "testing"
  21. "reflect"
  22. "github.com/google/blueprint/parser"
  23. )
  24. // TODO(jeffrygaston) remove this when position is removed from ParseNode (in b/38325146) and we can directly do reflect.DeepEqual
  25. func printListOfStrings(items []string) (text string) {
  26. if len(items) == 0 {
  27. return "[]"
  28. }
  29. return fmt.Sprintf("[\"%s\"]", strings.Join(items, "\", \""))
  30. }
  31. func buildTree(local_include_dirs []string, export_include_dirs []string) (file *parser.File, errs []error) {
  32. // TODO(jeffrygaston) use the builder class when b/38325146 is done
  33. input := fmt.Sprintf(`cc_library_shared {
  34. name: "iAmAModule",
  35. local_include_dirs: %s,
  36. export_include_dirs: %s,
  37. }
  38. `,
  39. printListOfStrings(local_include_dirs), printListOfStrings(export_include_dirs))
  40. tree, errs := parser.Parse("", strings.NewReader(input), parser.NewScope(nil))
  41. if len(errs) > 0 {
  42. errs = append([]error{fmt.Errorf("failed to parse:\n%s", input)}, errs...)
  43. }
  44. return tree, errs
  45. }
  46. func implFilterListTest(t *testing.T, local_include_dirs []string, export_include_dirs []string, expectedResult []string) {
  47. // build tree
  48. tree, errs := buildTree(local_include_dirs, export_include_dirs)
  49. if len(errs) > 0 {
  50. t.Error("failed to build tree")
  51. for _, err := range errs {
  52. t.Error(err)
  53. }
  54. t.Fatalf("%d parse errors", len(errs))
  55. }
  56. fixer := NewFixer(tree)
  57. // apply simplifications
  58. err := runPatchListMod(simplifyKnownPropertiesDuplicatingEachOther)(fixer)
  59. if len(errs) > 0 {
  60. t.Fatal(err)
  61. }
  62. // lookup legacy property
  63. mod := fixer.tree.Defs[0].(*parser.Module)
  64. expectedResultString := fmt.Sprintf("%q", expectedResult)
  65. if expectedResult == nil {
  66. expectedResultString = "unset"
  67. }
  68. // check that the value for the legacy property was updated to the correct value
  69. errorHeader := fmt.Sprintf("\nFailed to correctly simplify key 'local_include_dirs' in the presence of 'export_include_dirs.'\n"+
  70. "original local_include_dirs: %q\n"+
  71. "original export_include_dirs: %q\n"+
  72. "expected result: %s\n"+
  73. "actual result: ",
  74. local_include_dirs, export_include_dirs, expectedResultString)
  75. result, found := mod.GetProperty("local_include_dirs")
  76. if !found {
  77. if expectedResult == nil {
  78. return
  79. }
  80. t.Fatal(errorHeader + "property not found")
  81. }
  82. listResult, ok := result.Value.(*parser.List)
  83. if !ok {
  84. t.Fatalf("%sproperty is not a list: %v", errorHeader, listResult)
  85. }
  86. if expectedResult == nil {
  87. t.Fatalf("%sproperty exists: %v", errorHeader, listResult)
  88. }
  89. actualExpressions := listResult.Values
  90. actualValues := make([]string, 0)
  91. for _, expr := range actualExpressions {
  92. str := expr.(*parser.String)
  93. actualValues = append(actualValues, str.Value)
  94. }
  95. if !reflect.DeepEqual(actualValues, expectedResult) {
  96. t.Fatalf("%s%q\nlists are different", errorHeader, actualValues)
  97. }
  98. }
  99. func TestSimplifyKnownVariablesDuplicatingEachOther(t *testing.T) {
  100. // TODO use []Expression{} once buildTree above can support it (which is after b/38325146 is done)
  101. implFilterListTest(t, []string{"include"}, []string{"include"}, nil)
  102. implFilterListTest(t, []string{"include1"}, []string{"include2"}, []string{"include1"})
  103. implFilterListTest(t, []string{"include1", "include2", "include3", "include4"}, []string{"include2"},
  104. []string{"include1", "include3", "include4"})
  105. implFilterListTest(t, []string{}, []string{"include"}, []string{})
  106. implFilterListTest(t, []string{}, []string{}, []string{})
  107. }
  108. func runPass(t *testing.T, in, out string, innerTest func(*Fixer) error) {
  109. expected, err := Reformat(out)
  110. if err != nil {
  111. t.Fatal(err)
  112. }
  113. in, err = Reformat(in)
  114. if err != nil {
  115. t.Fatal(err)
  116. }
  117. tree, errs := parser.Parse("<testcase>", bytes.NewBufferString(in), parser.NewScope(nil))
  118. if errs != nil {
  119. t.Fatal(errs)
  120. }
  121. fixer := NewFixer(tree)
  122. got := ""
  123. prev := "foo"
  124. passes := 0
  125. for got != prev && passes < 10 {
  126. err := innerTest(fixer)
  127. if err != nil {
  128. t.Fatal(err)
  129. }
  130. out, err := parser.Print(fixer.tree)
  131. if err != nil {
  132. t.Fatal(err)
  133. }
  134. prev = got
  135. got = string(out)
  136. passes++
  137. }
  138. if got != expected {
  139. t.Errorf("output didn't match:\ninput:\n%s\n\nexpected:\n%s\ngot:\n%s\n",
  140. in, expected, got)
  141. }
  142. }
  143. func TestMergeMatchingProperties(t *testing.T) {
  144. tests := []struct {
  145. name string
  146. in string
  147. out string
  148. }{
  149. {
  150. name: "empty",
  151. in: `
  152. java_library {
  153. name: "foo",
  154. static_libs: [],
  155. static_libs: [],
  156. }
  157. `,
  158. out: `
  159. java_library {
  160. name: "foo",
  161. static_libs: [],
  162. }
  163. `,
  164. },
  165. {
  166. name: "single line into multiline",
  167. in: `
  168. java_library {
  169. name: "foo",
  170. static_libs: [
  171. "a",
  172. "b",
  173. ],
  174. //c1
  175. static_libs: ["c" /*c2*/],
  176. }
  177. `,
  178. out: `
  179. java_library {
  180. name: "foo",
  181. static_libs: [
  182. "a",
  183. "b",
  184. "c", /*c2*/
  185. ],
  186. //c1
  187. }
  188. `,
  189. },
  190. {
  191. name: "multiline into multiline",
  192. in: `
  193. java_library {
  194. name: "foo",
  195. static_libs: [
  196. "a",
  197. "b",
  198. ],
  199. //c1
  200. static_libs: [
  201. //c2
  202. "c", //c3
  203. "d",
  204. ],
  205. }
  206. `,
  207. out: `
  208. java_library {
  209. name: "foo",
  210. static_libs: [
  211. "a",
  212. "b",
  213. //c2
  214. "c", //c3
  215. "d",
  216. ],
  217. //c1
  218. }
  219. `,
  220. },
  221. }
  222. for _, test := range tests {
  223. t.Run(test.name, func(t *testing.T) {
  224. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  225. return runPatchListMod(mergeMatchingModuleProperties)(fixer)
  226. })
  227. })
  228. }
  229. }
  230. func TestReorderCommonProperties(t *testing.T) {
  231. var tests = []struct {
  232. name string
  233. in string
  234. out string
  235. }{
  236. {
  237. name: "empty",
  238. in: `cc_library {}`,
  239. out: `cc_library {}`,
  240. },
  241. {
  242. name: "only priority",
  243. in: `
  244. cc_library {
  245. name: "foo",
  246. }
  247. `,
  248. out: `
  249. cc_library {
  250. name: "foo",
  251. }
  252. `,
  253. },
  254. {
  255. name: "already in order",
  256. in: `
  257. cc_library {
  258. name: "foo",
  259. defaults: ["bar"],
  260. }
  261. `,
  262. out: `
  263. cc_library {
  264. name: "foo",
  265. defaults: ["bar"],
  266. }
  267. `,
  268. },
  269. {
  270. name: "reorder only priority",
  271. in: `
  272. cc_library {
  273. defaults: ["bar"],
  274. name: "foo",
  275. }
  276. `,
  277. out: `
  278. cc_library {
  279. name: "foo",
  280. defaults: ["bar"],
  281. }
  282. `,
  283. },
  284. {
  285. name: "reorder",
  286. in: `
  287. cc_library {
  288. name: "foo",
  289. srcs: ["a.c"],
  290. host_supported: true,
  291. defaults: ["bar"],
  292. shared_libs: ["baz"],
  293. }
  294. `,
  295. out: `
  296. cc_library {
  297. name: "foo",
  298. defaults: ["bar"],
  299. host_supported: true,
  300. srcs: ["a.c"],
  301. shared_libs: ["baz"],
  302. }
  303. `,
  304. },
  305. }
  306. for _, test := range tests {
  307. t.Run(test.name, func(t *testing.T) {
  308. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  309. return runPatchListMod(reorderCommonProperties)(fixer)
  310. })
  311. })
  312. }
  313. }
  314. func TestRemoveMatchingModuleListProperties(t *testing.T) {
  315. var tests = []struct {
  316. name string
  317. in string
  318. out string
  319. }{
  320. {
  321. name: "simple",
  322. in: `
  323. cc_library {
  324. name: "foo",
  325. foo: ["a"],
  326. bar: ["a"],
  327. }
  328. `,
  329. out: `
  330. cc_library {
  331. name: "foo",
  332. bar: ["a"],
  333. }
  334. `,
  335. },
  336. {
  337. name: "long",
  338. in: `
  339. cc_library {
  340. name: "foo",
  341. foo: [
  342. "a",
  343. "b",
  344. ],
  345. bar: ["a"],
  346. }
  347. `,
  348. out: `
  349. cc_library {
  350. name: "foo",
  351. foo: [
  352. "b",
  353. ],
  354. bar: ["a"],
  355. }
  356. `,
  357. },
  358. {
  359. name: "long fully removed",
  360. in: `
  361. cc_library {
  362. name: "foo",
  363. foo: [
  364. "a",
  365. ],
  366. bar: ["a"],
  367. }
  368. `,
  369. out: `
  370. cc_library {
  371. name: "foo",
  372. bar: ["a"],
  373. }
  374. `,
  375. },
  376. {
  377. name: "comment",
  378. in: `
  379. cc_library {
  380. name: "foo",
  381. // comment
  382. foo: ["a"],
  383. bar: ["a"],
  384. }
  385. `,
  386. out: `
  387. cc_library {
  388. name: "foo",
  389. // comment
  390. bar: ["a"],
  391. }
  392. `,
  393. },
  394. {
  395. name: "inner comment",
  396. in: `
  397. cc_library {
  398. name: "foo",
  399. foo: [
  400. // comment
  401. "a",
  402. ],
  403. bar: ["a"],
  404. }
  405. `,
  406. out: `
  407. cc_library {
  408. name: "foo",
  409. bar: ["a"],
  410. }
  411. `,
  412. },
  413. {
  414. name: "eol comment",
  415. in: `
  416. cc_library {
  417. name: "foo",
  418. foo: ["a"], // comment
  419. bar: ["a"],
  420. }
  421. `,
  422. out: `
  423. cc_library {
  424. name: "foo",
  425. // comment
  426. bar: ["a"],
  427. }
  428. `,
  429. },
  430. {
  431. name: "eol comment with blank lines",
  432. in: `
  433. cc_library {
  434. name: "foo",
  435. foo: ["a"], // comment
  436. // bar
  437. bar: ["a"],
  438. }
  439. `,
  440. out: `
  441. cc_library {
  442. name: "foo",
  443. // comment
  444. // bar
  445. bar: ["a"],
  446. }
  447. `,
  448. },
  449. }
  450. for _, test := range tests {
  451. t.Run(test.name, func(t *testing.T) {
  452. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  453. return runPatchListMod(func(mod *parser.Module, buf []byte, patchList *parser.PatchList) error {
  454. return removeMatchingModuleListProperties(mod, patchList, "bar", "foo")
  455. })(fixer)
  456. })
  457. })
  458. }
  459. }
  460. func TestReplaceJavaStaticLibs(t *testing.T) {
  461. tests := []struct {
  462. name string
  463. in string
  464. out string
  465. }{
  466. {
  467. name: "static lib",
  468. in: `
  469. java_library_static {
  470. name: "foo",
  471. }
  472. `,
  473. out: `
  474. java_library {
  475. name: "foo",
  476. }
  477. `,
  478. },
  479. {
  480. name: "java lib",
  481. in: `
  482. java_library {
  483. name: "foo",
  484. }
  485. `,
  486. out: `
  487. java_library {
  488. name: "foo",
  489. }
  490. `,
  491. },
  492. {
  493. name: "java installable lib",
  494. in: `
  495. java_library {
  496. name: "foo",
  497. installable: true,
  498. }
  499. `,
  500. out: `
  501. java_library {
  502. name: "foo",
  503. installable: true,
  504. }
  505. `,
  506. },
  507. }
  508. for _, test := range tests {
  509. t.Run(test.name, func(t *testing.T) {
  510. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  511. return rewriteJavaStaticLibs(fixer)
  512. })
  513. })
  514. }
  515. }
  516. func TestRewritePrebuilts(t *testing.T) {
  517. tests := []struct {
  518. name string
  519. in string
  520. out string
  521. }{
  522. {
  523. name: "jar srcs",
  524. in: `
  525. java_import {
  526. name: "foo",
  527. srcs: ["foo.jar"],
  528. }
  529. `,
  530. out: `
  531. java_import {
  532. name: "foo",
  533. jars: ["foo.jar"],
  534. }
  535. `,
  536. },
  537. {
  538. name: "aar srcs",
  539. in: `
  540. java_import {
  541. name: "foo",
  542. srcs: ["foo.aar"],
  543. installable: true,
  544. }
  545. `,
  546. out: `
  547. android_library_import {
  548. name: "foo",
  549. aars: ["foo.aar"],
  550. }
  551. `,
  552. },
  553. {
  554. name: "host prebuilt",
  555. in: `
  556. java_import {
  557. name: "foo",
  558. srcs: ["foo.jar"],
  559. host: true,
  560. }
  561. `,
  562. out: `
  563. java_import_host {
  564. name: "foo",
  565. jars: ["foo.jar"],
  566. }
  567. `,
  568. },
  569. }
  570. for _, test := range tests {
  571. t.Run(test.name, func(t *testing.T) {
  572. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  573. return rewriteIncorrectAndroidmkPrebuilts(fixer)
  574. })
  575. })
  576. }
  577. }
  578. func TestRewriteCtsModuleTypes(t *testing.T) {
  579. tests := []struct {
  580. name string
  581. in string
  582. out string
  583. }{
  584. {
  585. name: "cts_support_package",
  586. in: `
  587. cts_support_package {
  588. name: "foo",
  589. }
  590. `,
  591. out: `
  592. android_test {
  593. name: "foo",
  594. defaults: ["cts_support_defaults"],
  595. }
  596. `,
  597. },
  598. {
  599. name: "cts_package",
  600. in: `
  601. cts_package {
  602. name: "foo",
  603. }
  604. `,
  605. out: `
  606. android_test {
  607. name: "foo",
  608. defaults: ["cts_defaults"],
  609. }
  610. `,
  611. },
  612. {
  613. name: "cts_target_java_library",
  614. in: `
  615. cts_target_java_library {
  616. name: "foo",
  617. }
  618. `,
  619. out: `
  620. java_library {
  621. name: "foo",
  622. defaults: ["cts_defaults"],
  623. }
  624. `,
  625. },
  626. {
  627. name: "cts_host_java_library",
  628. in: `
  629. cts_host_java_library {
  630. name: "foo",
  631. }
  632. `,
  633. out: `
  634. java_library_host {
  635. name: "foo",
  636. defaults: ["cts_defaults"],
  637. }
  638. `,
  639. },
  640. }
  641. for _, test := range tests {
  642. t.Run(test.name, func(t *testing.T) {
  643. runPass(t, test.in, test.out, rewriteCtsModuleTypes)
  644. })
  645. }
  646. }
  647. func TestRewritePrebuiltEtc(t *testing.T) {
  648. tests := []struct {
  649. name string
  650. in string
  651. out string
  652. }{
  653. {
  654. name: "prebuilt_etc src",
  655. in: `
  656. prebuilt_etc {
  657. name: "foo",
  658. srcs: ["bar"],
  659. }
  660. `,
  661. out: `prebuilt_etc {
  662. name: "foo",
  663. src: "bar",
  664. }
  665. `,
  666. },
  667. {
  668. name: "prebuilt_etc src",
  669. in: `
  670. prebuilt_etc {
  671. name: "foo",
  672. srcs: FOO,
  673. }
  674. `,
  675. out: `prebuilt_etc {
  676. name: "foo",
  677. src: FOO,
  678. }
  679. `,
  680. },
  681. {
  682. name: "prebuilt_etc src",
  683. in: `
  684. prebuilt_etc {
  685. name: "foo",
  686. srcs: ["bar", "baz"],
  687. }
  688. `,
  689. out: `prebuilt_etc {
  690. name: "foo",
  691. src: "ERROR: LOCAL_SRC_FILES should contain at most one item",
  692. }
  693. `,
  694. },
  695. {
  696. name: "prebuilt_etc sub_dir",
  697. in: `
  698. prebuilt_etc {
  699. name: "foo",
  700. src: "bar",
  701. sub_dir: "baz",
  702. }
  703. `,
  704. out: `prebuilt_etc {
  705. name: "foo",
  706. src: "bar",
  707. relative_install_dir: "baz",
  708. }
  709. `,
  710. },
  711. }
  712. for _, test := range tests {
  713. t.Run(test.name, func(t *testing.T) {
  714. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  715. return rewriteAndroidmkPrebuiltEtc(fixer)
  716. })
  717. })
  718. }
  719. }
  720. func TestRewriteAndroidTest(t *testing.T) {
  721. tests := []struct {
  722. name string
  723. in string
  724. out string
  725. }{
  726. {
  727. name: "android_test valid module path",
  728. in: `
  729. android_test {
  730. name: "foo",
  731. local_module_path: {
  732. var: "TARGET_OUT_DATA_APPS",
  733. },
  734. }
  735. `,
  736. out: `
  737. android_test {
  738. name: "foo",
  739. }
  740. `,
  741. },
  742. }
  743. for _, test := range tests {
  744. t.Run(test.name, func(t *testing.T) {
  745. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  746. return rewriteAndroidTest(fixer)
  747. })
  748. })
  749. }
  750. }
  751. func TestRewriteAndroidAppImport(t *testing.T) {
  752. tests := []struct {
  753. name string
  754. in string
  755. out string
  756. }{
  757. {
  758. name: "android_app_import apk",
  759. in: `
  760. android_app_import {
  761. name: "foo",
  762. srcs: ["package.apk"],
  763. }
  764. `,
  765. out: `
  766. android_app_import {
  767. name: "foo",
  768. apk: "package.apk",
  769. }
  770. `,
  771. },
  772. {
  773. name: "android_app_import presigned",
  774. in: `
  775. android_app_import {
  776. name: "foo",
  777. apk: "package.apk",
  778. certificate: "PRESIGNED",
  779. }
  780. `,
  781. out: `
  782. android_app_import {
  783. name: "foo",
  784. apk: "package.apk",
  785. presigned: true,
  786. }
  787. `,
  788. },
  789. }
  790. for _, test := range tests {
  791. t.Run(test.name, func(t *testing.T) {
  792. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  793. return rewriteAndroidAppImport(fixer)
  794. })
  795. })
  796. }
  797. }
  798. func TestRemoveEmptyLibDependencies(t *testing.T) {
  799. tests := []struct {
  800. name string
  801. in string
  802. out string
  803. }{
  804. {
  805. name: "remove sole shared lib",
  806. in: `
  807. cc_library {
  808. name: "foo",
  809. shared_libs: ["libhwbinder"],
  810. }
  811. `,
  812. out: `
  813. cc_library {
  814. name: "foo",
  815. }
  816. `,
  817. },
  818. {
  819. name: "remove a shared lib",
  820. in: `
  821. cc_library {
  822. name: "foo",
  823. shared_libs: [
  824. "libhwbinder",
  825. "libfoo",
  826. "libhidltransport",
  827. ],
  828. }
  829. `,
  830. out: `
  831. cc_library {
  832. name: "foo",
  833. shared_libs: [
  834. "libfoo",
  835. ],
  836. }
  837. `,
  838. },
  839. }
  840. for _, test := range tests {
  841. t.Run(test.name, func(t *testing.T) {
  842. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  843. return removeEmptyLibDependencies(fixer)
  844. })
  845. })
  846. }
  847. }
  848. func TestRemoveHidlInterfaceTypes(t *testing.T) {
  849. tests := []struct {
  850. name string
  851. in string
  852. out string
  853. }{
  854. {
  855. name: "remove types",
  856. in: `
  857. hidl_interface {
  858. name: "foo@1.0",
  859. types: ["ParcelFooBar"],
  860. }
  861. `,
  862. out: `
  863. hidl_interface {
  864. name: "foo@1.0",
  865. }
  866. `,
  867. },
  868. }
  869. for _, test := range tests {
  870. t.Run(test.name, func(t *testing.T) {
  871. runPass(t, test.in, test.out, func(fixer *Fixer) error {
  872. return removeHidlInterfaceTypes(fixer)
  873. })
  874. })
  875. }
  876. }
  877. func TestRemoveSoongConfigBoolVariable(t *testing.T) {
  878. tests := []struct {
  879. name string
  880. in string
  881. out string
  882. }{
  883. {
  884. name: "remove bool",
  885. in: `
  886. soong_config_module_type {
  887. name: "foo",
  888. variables: ["bar", "baz"],
  889. }
  890. soong_config_bool_variable {
  891. name: "bar",
  892. }
  893. soong_config_string_variable {
  894. name: "baz",
  895. }
  896. `,
  897. out: `
  898. soong_config_module_type {
  899. name: "foo",
  900. variables: [
  901. "baz"
  902. ],
  903. bool_variables: ["bar"],
  904. }
  905. soong_config_string_variable {
  906. name: "baz",
  907. }
  908. `,
  909. },
  910. {
  911. name: "existing bool_variables",
  912. in: `
  913. soong_config_module_type {
  914. name: "foo",
  915. variables: ["baz"],
  916. bool_variables: ["bar"],
  917. }
  918. soong_config_bool_variable {
  919. name: "baz",
  920. }
  921. `,
  922. out: `
  923. soong_config_module_type {
  924. name: "foo",
  925. bool_variables: ["bar", "baz"],
  926. }
  927. `,
  928. },
  929. }
  930. for _, test := range tests {
  931. t.Run(test.name, func(t *testing.T) {
  932. runPass(t, test.in, test.out, removeSoongConfigBoolVariable)
  933. })
  934. }
  935. }
  936. func TestRemovePdkProperty(t *testing.T) {
  937. tests := []struct {
  938. name string
  939. in string
  940. out string
  941. }{
  942. {
  943. name: "remove property",
  944. in: `
  945. cc_library_shared {
  946. name: "foo",
  947. product_variables: {
  948. other: {
  949. bar: true,
  950. },
  951. pdk: {
  952. enabled: false,
  953. },
  954. },
  955. }
  956. `,
  957. out: `
  958. cc_library_shared {
  959. name: "foo",
  960. product_variables: {
  961. other: {
  962. bar: true,
  963. },
  964. },
  965. }
  966. `,
  967. },
  968. {
  969. name: "remove property and empty product_variables",
  970. in: `
  971. cc_library_shared {
  972. name: "foo",
  973. product_variables: {
  974. pdk: {
  975. enabled: false,
  976. },
  977. },
  978. }
  979. `,
  980. out: `
  981. cc_library_shared {
  982. name: "foo",
  983. }
  984. `,
  985. },
  986. }
  987. for _, test := range tests {
  988. t.Run(test.name, func(t *testing.T) {
  989. runPass(t, test.in, test.out, runPatchListMod(removePdkProperty))
  990. })
  991. }
  992. }