summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Vacek <patrickvacek@gmail.com>2017-11-16 16:57:57 +0100
committerPatrick Vacek <patrickvacek@gmail.com>2017-11-16 17:40:48 +0100
commitc687237422dc7f22b85d9718d112fe0b674007c3 (patch)
tree43f6833ef354bb3579043f4229023a7e8653aef3
parent7a3258934b2c53f7c29c212c695805da1893ba3f (diff)
downloadmeta-updater-c687237422dc7f22b85d9718d112fe0b674007c3.tar.gz
Make launching qemu part of setUpClass.
And terminating part of tearDownClass. This cleans things up nicely and means we only have to boot once for multiple tests. If we do want to boot multiple times (e.g. with different configs), we can move most of the qemu code to non-class functions and use multiple classes that each call those functions in setUpClass and tearDownClass.
-rw-r--r--lib/oeqa/selftest/updater.py85
1 files changed, 44 insertions, 41 deletions
diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py
index 8ee3c69..ad99964 100644
--- a/lib/oeqa/selftest/updater.py
+++ b/lib/oeqa/selftest/updater.py
@@ -121,56 +121,59 @@ class QemuTests(oeSelfTest):
121 logger = logging.getLogger("selftest") 121 logger = logging.getLogger("selftest")
122 logger.info('Running bitbake to build core-image-minimal') 122 logger.info('Running bitbake to build core-image-minimal')
123 bitbake('core-image-minimal') 123 bitbake('core-image-minimal')
124 # Create empty object.
125 args = type('', (), {})()
126 args.imagename = 'core-image-minimal'
127 args.mac = None
128 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
129 # subdirectory.
130 args.dir = 'tmp/deploy/images'
131 args.efi = False
132 args.machine = None
133 args.kvm = None # Autodetect
134 args.no_gui = True
135 args.gdb = False
136 args.pcap = None
137 args.overlay = None
138 args.dry_run = False
139
140 cls.qemu = QemuCommand(args)
141 cmdline = cls.qemu.command_line()
142 print('Booting image with run-qemu-ota...')
143 cls.s = subprocess.Popen(cmdline)
144 time.sleep(10)
145
146 @classmethod
147 def tearDownClass(cls):
148 try:
149 cls.s.terminate()
150 except KeyboardInterrupt:
151 pass
152
153 def run_test_qemu(self, command):
154 command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
155 str(self.qemu.ssh_port) + ' "' + command + '"']
156 s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
157 value, err = s2.communicate()
158 return value, err
124 159
125 def test_hostname(self): 160 def test_hostname(self):
126 value, err = run_test_qemu('hostname', False, 'Checking machine name (hostname) of device:') 161 print('')
162 print('Checking machine name (hostname) of device:')
163 value, err = self.run_test_qemu('hostname')
127 machine = get_bb_var('MACHINE', 'core-image-minimal') 164 machine = get_bb_var('MACHINE', 'core-image-minimal')
128 self.assertEqual(err, b'', 'Error: ' + err.decode()) 165 self.assertEqual(err, b'', 'Error: ' + err.decode())
129 # Strip off line ending. 166 # Strip off line ending.
130 value_str = value.decode()[:-1] 167 value_str = value.decode()[:-1]
131 self.assertEqual(value_str, machine, 'MACHINE does not match hostname: ' + machine + ', ' + value_str) 168 self.assertEqual(value_str, machine,
132 print('hostname: ' + value_str) 169 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
170 print(value_str)
133 171
134 def test_var_sota(self): 172 def test_var_sota(self):
135 value, err = run_test_qemu('ls /var/sota', True, 'Checking contents of /var/sota:') 173 print('')
174 print('Checking contents of /var/sota:')
175 value, err = self.run_test_qemu('ls /var/sota')
136 self.assertEqual(err, b'', 'Error: ' + err.decode()) 176 self.assertEqual(err, b'', 'Error: ' + err.decode())
137 print(value.decode()) 177 print(value.decode())
138 178
139 179
140def run_test_qemu(command, use_shell, message):
141 print('')
142 # Create empty object.
143 args = type('', (), {})()
144 args.imagename = 'core-image-minimal'
145 args.mac = None
146 # Could use DEPLOY_DIR_IMAGE here but it's already in the machine
147 # subdirectory.
148 args.dir = 'tmp/deploy/images'
149 args.efi = False
150 args.machine = None
151 args.kvm = None # Autodetect
152 args.no_gui = True
153 args.gdb = False
154 args.pcap = None
155 args.overlay = None
156 args.dry_run = False
157
158 qemu_command = QemuCommand(args)
159 cmdline = qemu_command.command_line()
160 print('Booting image with run-qemu-ota...')
161 s = subprocess.Popen(cmdline)
162 time.sleep(10)
163 print(message)
164 if not use_shell:
165 command = ['ssh', '-q', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'root@localhost', '-p', str(qemu_command.ssh_port), '"' + command + '"']
166 else:
167 command = 'ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + str(qemu_command.ssh_port) + ' "' + command + '"'
168 s2 = subprocess.Popen(command, shell=use_shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
169 value, err = s2.communicate()
170 time.sleep(5)
171 try:
172 s.terminate()
173 except KeyboardInterrupt:
174 pass
175 return value, err
176