Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # ex:ts=4:sw=4:sts=4:et |
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 3 | # |
| 4 | # BitBake Test for lib/bb/parse/ |
| 5 | # |
| 6 | # Copyright (C) 2015 Richard Purdie |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License version 2 as |
| 10 | # published by the Free Software Foundation. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License along |
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | # |
| 21 | |
| 22 | import unittest |
| 23 | import tempfile |
| 24 | import logging |
| 25 | import bb |
| 26 | import os |
| 27 | |
| 28 | logger = logging.getLogger('BitBake.TestParse') |
| 29 | |
| 30 | import bb.parse |
| 31 | import bb.data |
| 32 | import bb.siggen |
| 33 | |
| 34 | class ParseTest(unittest.TestCase): |
| 35 | |
| 36 | testfile = """ |
| 37 | A = "1" |
| 38 | B = "2" |
| 39 | do_install() { |
| 40 | echo "hello" |
| 41 | } |
| 42 | |
| 43 | C = "3" |
| 44 | """ |
| 45 | |
| 46 | def setUp(self): |
| 47 | self.d = bb.data.init() |
| 48 | bb.parse.siggen = bb.siggen.init(self.d) |
| 49 | |
| 50 | def parsehelper(self, content, suffix = ".bb"): |
| 51 | |
| 52 | f = tempfile.NamedTemporaryFile(suffix = suffix) |
| 53 | f.write(content) |
| 54 | f.flush() |
| 55 | os.chdir(os.path.dirname(f.name)) |
| 56 | return f |
| 57 | |
| 58 | def test_parse_simple(self): |
| 59 | f = self.parsehelper(self.testfile) |
| 60 | d = bb.parse.handle(f.name, self.d)[''] |
| 61 | self.assertEqual(d.getVar("A", True), "1") |
| 62 | self.assertEqual(d.getVar("B", True), "2") |
| 63 | self.assertEqual(d.getVar("C", True), "3") |
| 64 | |
| 65 | def test_parse_incomplete_function(self): |
| 66 | testfileB = self.testfile.replace("}", "") |
| 67 | f = self.parsehelper(testfileB) |
| 68 | with self.assertRaises(bb.parse.ParseError): |
| 69 | d = bb.parse.handle(f.name, self.d)[''] |
| 70 | |
| 71 | overridetest = """ |
| 72 | RRECOMMENDS_${PN} = "a" |
| 73 | RRECOMMENDS_${PN}_libc = "b" |
| 74 | OVERRIDES = "libc:${PN}" |
| 75 | PN = "gtk+" |
| 76 | """ |
| 77 | |
| 78 | def test_parse_overrides(self): |
| 79 | f = self.parsehelper(self.overridetest) |
| 80 | d = bb.parse.handle(f.name, self.d)[''] |
| 81 | self.assertEqual(d.getVar("RRECOMMENDS", True), "b") |
| 82 | bb.data.expandKeys(d) |
| 83 | self.assertEqual(d.getVar("RRECOMMENDS", True), "b") |
| 84 | d.setVar("RRECOMMENDS_gtk+", "c") |
| 85 | self.assertEqual(d.getVar("RRECOMMENDS", True), "c") |
| 86 | |
| 87 | overridetest2 = """ |
| 88 | EXTRA_OECONF = "" |
| 89 | EXTRA_OECONF_class-target = "b" |
| 90 | EXTRA_OECONF_append = " c" |
| 91 | """ |
| 92 | |
| 93 | def test_parse_overrides(self): |
| 94 | f = self.parsehelper(self.overridetest2) |
| 95 | d = bb.parse.handle(f.name, self.d)[''] |
| 96 | d.appendVar("EXTRA_OECONF", " d") |
| 97 | d.setVar("OVERRIDES", "class-target") |
| 98 | self.assertEqual(d.getVar("EXTRA_OECONF", True), "b c d") |
| 99 | |
| 100 | overridetest3 = """ |
| 101 | DESCRIPTION = "A" |
| 102 | DESCRIPTION_${PN}-dev = "${DESCRIPTION} B" |
| 103 | PN = "bc" |
| 104 | """ |
| 105 | |
| 106 | def test_parse_combinations(self): |
| 107 | f = self.parsehelper(self.overridetest3) |
| 108 | d = bb.parse.handle(f.name, self.d)[''] |
| 109 | bb.data.expandKeys(d) |
| 110 | self.assertEqual(d.getVar("DESCRIPTION_bc-dev", True), "A B") |
| 111 | d.setVar("DESCRIPTION", "E") |
| 112 | d.setVar("DESCRIPTION_bc-dev", "C D") |
| 113 | d.setVar("OVERRIDES", "bc-dev") |
| 114 | self.assertEqual(d.getVar("DESCRIPTION", True), "C D") |
| 115 | |
| 116 | |
| 117 | classextend = """ |
| 118 | VAR_var_override1 = "B" |
| 119 | EXTRA = ":override1" |
| 120 | OVERRIDES = "nothing${EXTRA}" |
| 121 | |
| 122 | BBCLASSEXTEND = "###CLASS###" |
| 123 | """ |
| 124 | classextend_bbclass = """ |
| 125 | EXTRA = "" |
| 126 | python () { |
| 127 | d.renameVar("VAR_var", "VAR_var2") |
| 128 | } |
| 129 | """ |
| 130 | |
| 131 | # |
| 132 | # Test based upon a real world data corruption issue. One |
| 133 | # data store changing a variable poked through into a different data |
| 134 | # store. This test case replicates that issue where the value 'B' would |
| 135 | # become unset/disappear. |
| 136 | # |
| 137 | def test_parse_classextend_contamination(self): |
| 138 | cls = self.parsehelper(self.classextend_bbclass, suffix=".bbclass") |
| 139 | #clsname = os.path.basename(cls.name).replace(".bbclass", "") |
| 140 | self.classextend = self.classextend.replace("###CLASS###", cls.name) |
| 141 | f = self.parsehelper(self.classextend) |
| 142 | alldata = bb.parse.handle(f.name, self.d) |
| 143 | d1 = alldata[''] |
| 144 | d2 = alldata[cls.name] |
| 145 | self.assertEqual(d1.getVar("VAR_var", True), "B") |
| 146 | self.assertEqual(d2.getVar("VAR_var", True), None) |
| 147 | |