1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#!/usr/bin/env python
import unittest
import os
import subprocess
import shutil
import tempfile
import sys
import stat
import imp
class RunBitbakeTestBase(unittest.TestCase):
def setUp(self):
self.tempdir = tempfile.mkdtemp(prefix="runbitbaketest-tmpdir")
self.pokydir = os.path.join(self.tempdir, "poky")
os.mkdir(self.pokydir)
# runbitbake.py requires --pokydir with a "oe-init-build-env" script
self.setupscript = os.path.join(self.pokydir, "oe-init-build-env")
with open(self.setupscript, "w"):
pass
# Create a builddir and confdir as if oe-init-build-env had ran
self.builddir = os.path.join(self.tempdir, "build")
self.confdir = os.path.join(self.builddir, "conf")
os.mkdir(self.builddir)
os.mkdir(self.confdir)
# Create an executable bitbake that does nothing
self.bindir = os.path.join(self.tempdir, "bin")
os.mkdir(self.bindir)
self.bitbake = os.path.join(self.bindir, "bitbake")
with open(self.bitbake, "w") as f:
f.write("#!/bin/sh\n")
os.chmod(self.bitbake, stat.S_IRWXU)
# Make sure runbitbake.py can run our fake bitbake
os.environ["PATH"] = "{}:{}".format(self.bindir, os.environ["PATH"])
# We will have one line local.conf and bblayers.conf.
self.local_conf = os.path.join(self.confdir, "local.conf")
with open(self.local_conf, "w") as f:
f.write("Some data\n")
self.bblayers_conf = os.path.join(self.confdir, "bblayers.conf")
with open(self.bblayers_conf, "w") as f:
f.write("Other data\n")
# Create the files that contain extra data to be added to the original
# configuration files
self.extraconf = os.path.join(self.tempdir, "extra.conf")
with open(self.extraconf, "w") as f:
f.write("MOAR STUFF\nEVEN MOAR!!!!\n")
self.extralayers = os.path.join(self.tempdir, "bblayers_extra.conf")
with open(self.extralayers, "w") as f:
f.write("BBLAYERS MOAR STUFF\nEVEN MOAR BBLAYERS!!!!\n")
def tearDown(self):
shutil.rmtree(self.tempdir, ignore_errors=True)
class ConfFilesTest(RunBitbakeTestBase):
def setUp(self):
super(ConfFilesTest, self).setUp()
# These ".orig" files are for checking that the file is restored back
# to the original state
self.local_conf_orig = os.path.join(self.tempdir, "local.conf.orig")
self.bblayers_conf_orig = os.path.join(self.tempdir,
"bblayers.conf.orig")
shutil.copyfile(self.local_conf, self.local_conf_orig)
shutil.copyfile(self.bblayers_conf, self.bblayers_conf_orig)
def test_files_are_restored(self):
cmd = """python helpers/runbitbake.py --pokydir={} """ \
"""-t junk -b {} """ \
"""--extraconf={} """ \
"""--extralayers={}""".format(self.pokydir, self.builddir,
self.extraconf, self.extralayers)
subprocess.call(cmd.split(), stderr=sys.stderr, stdout=sys.stdout,
shell=False)
with open(self.local_conf_orig, "r") as f:
origlines = f.readlines()
with open(self.local_conf, "r") as f:
newlines = f.readlines()
self.assertListEqual(origlines, newlines)
with open(self.bblayers_conf_orig, "r") as f:
origlines = f.readlines()
with open(self.bblayers_conf, "r") as f:
newlines = f.readlines()
self.assertListEqual(origlines, newlines)
class AddExtraTest(RunBitbakeTestBase):
def setUp(self):
super(AddExtraTest, self).setUp()
# Since we are importing a file in the source directory, this prevents
# cluttering the directory with a .pyc file.
sys.dont_write_bytecode = True
self.runbitbake = os.path.join("helpers", "runbitbake.py")
self.module = imp.load_source("", self.runbitbake)
self.addextra_tempdir = os.path.join(self.tempdir, "addextratmp")
os.mkdir(self.addextra_tempdir)
def test_addextra_changed_files(self):
addextra = self.module.addextra
addextra(self.addextra_tempdir, self.builddir, "local.conf",
[self.extraconf])
with open(self.extraconf, "r") as f:
extraconflines = set(f.readlines())
with open(self.local_conf, "r") as f:
localconflines = set(f.readlines())
intersection = extraconflines & localconflines
self.assertListEqual(list(intersection), list(extraconflines))
if __name__ == '__main__':
unittest.main()
|