From patchwork Tue Oct 23 20:53:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Terceiro X-Patchwork-Id: 12451 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3502423FB6 for ; Tue, 23 Oct 2012 20:53:16 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id BC7D2A18BD6 for ; Tue, 23 Oct 2012 20:53:15 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so5783474iej.11 for ; Tue, 23 Oct 2012 13:53:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=GZ+PSPAeVXGuUflnpC3DwCHaMSxApX2tPYrHUdON64Y=; b=ouhe6Md4a5E08HEaIoMz/3FuHm6ut6ldk6P8NUP/8q43RABVr3e9CgGGX9qHX6itK8 j7brdx9s1J95GglEpNHIZyPiyQqR466xmwS5VA2RjfBCrKA0wnFZbIBG8swjEOtBgJM9 8N9ksnS+rPx20CN+P/WDI6EJyWpnJI1K6V5vnC954E6FT6DqGCGJ/EYitXf5y6d2vQKb sdtphzw3TKjdbkCz+skIXlpvYSU6gtWcdVveaAbo/1DiLOsC0BJd61Ug+vuZ5+OsMhpr U0A7Hgxt6oFNRK7LMirmBYXaQ0Y9P7+ilyVV+oKjc8sG1+uFQlAotRfvNgrEu7zgq9l7 G02g== Received: by 10.50.46.226 with SMTP id y2mr307177igm.62.1351025595085; Tue, 23 Oct 2012 13:53:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp502520igt; Tue, 23 Oct 2012 13:53:14 -0700 (PDT) Received: by 10.180.77.38 with SMTP id p6mr723880wiw.1.1351025593409; Tue, 23 Oct 2012 13:53:13 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id l64si140927wej.161.2012.10.23.13.53.12 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 13:53:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1TQlTM-0002nE-KJ for ; Tue, 23 Oct 2012 20:53:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 88929E04D8 for ; Tue, 23 Oct 2012 20:53:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-dispatcher X-Launchpad-Branch: ~linaro-validation/lava-dispatcher/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 418 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-dispatcher/trunk] Rev 418: Device version support Message-Id: <20121023205312.11486.52143.launchpad@ackee.canonical.com> Date: Tue, 23 Oct 2012 20:53:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="16179"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 82271dc14c444931d53d2cf11bc4256d5c4fc9b1 X-Gm-Message-State: ALoCoQnD1FPBXdszXcldUE/tM2Ly+oxM3DgxjwdGmZ2qeSrYuxc2VnH6bM8aDwP3DdDEuc/G6oEV Merge authors: Antonio Terceiro (terceiro) Related merge proposals: https://code.launchpad.net/~terceiro/lava-dispatcher/device-version/+merge/130404 proposed by: Antonio Terceiro (terceiro) review: Approve - Michael Hudson-Doyle (mwhudson) ------------------------------------------------------------ revno: 418 [merge] committer: Antonio Terceiro branch nick: lava-dispatcher timestamp: Tue 2012-10-23 17:51:34 -0300 message: Device version support added: lava_dispatcher/tests/helper.py lava_dispatcher/tests/test_device_version.py modified: lava_dispatcher/context.py lava_dispatcher/device/fastmodel.py lava_dispatcher/device/qemu.py lava_dispatcher/device/target.py lava_dispatcher/job.py lava_dispatcher/tests/__init__.py lava_dispatcher/tests/test_config.py --- lp:lava-dispatcher https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk You are subscribed to branch lp:lava-dispatcher. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription === modified file 'lava_dispatcher/context.py' --- lava_dispatcher/context.py 2012-09-30 17:01:44 +0000 +++ lava_dispatcher/context.py 2012-10-08 22:19:31 +0000 @@ -55,3 +55,6 @@ self._host_result_dir = tempfile.mkdtemp() atexit.register(shutil.rmtree, self._host_result_dir) return self._host_result_dir + + def get_device_version(self): + return self.client.target_device.get_device_version() === modified file 'lava_dispatcher/device/fastmodel.py' --- lava_dispatcher/device/fastmodel.py 2012-10-19 05:16:51 +0000 +++ lava_dispatcher/device/fastmodel.py 2012-10-23 17:45:15 +0000 @@ -26,6 +26,8 @@ import shutil import stat import threading +import re +import subprocess from lava_dispatcher.device.target import ( Target @@ -263,6 +265,20 @@ return [create_attachment('rtsm.log', content)] return [] + def get_device_version(self): + cmd = '%s --version' % self._sim_binary + try: + banner = subprocess.check_output(cmd, shell = True) + return self._parse_fastmodel_version(banner) + except subprocess.CalledProcessError: + return "unknown" + + def _parse_fastmodel_version(self, banner): + match = re.search('Fast Models \[([0-9.]+)', banner) + if match: + return match.group(1) + else: + return "unknown" class _pexpect_drain(threading.Thread): ''' The simulator process can dump a lot of information to its console. If === modified file 'lava_dispatcher/device/qemu.py' --- lava_dispatcher/device/qemu.py 2012-10-17 16:52:05 +0000 +++ lava_dispatcher/device/qemu.py 2012-10-22 17:56:18 +0000 @@ -20,6 +20,8 @@ import contextlib import logging +import subprocess +import re from lava_dispatcher.device.target import ( Target @@ -76,4 +78,12 @@ proc = logging_spawn(qemu_cmd, logfile=self.sio, timeout=1200) return proc + def get_device_version(self): + try: + output = subprocess.check_output([self.context.config.default_qemu_binary, '--version']) + matches = re.findall('[0-9]+\.[0-9a-z.+\-:~]+', output) + return matches[-1] + except subprocess.CalledProcessError: + return "unknown" + target_class = QEMUTarget === modified file 'lava_dispatcher/device/target.py' --- lava_dispatcher/device/target.py 2012-10-19 04:38:47 +0000 +++ lava_dispatcher/device/target.py 2012-10-23 17:45:15 +0000 @@ -71,9 +71,15 @@ self.sio = SerialIO(sys.stdout) self.boot_options = [] - self.scratch_dir = utils.mkdtemp(context.config.lava_image_tmpdir) + self._scratch_dir = None self.deployment_data = {} + @property + def scratch_dir(self): + if self._scratch_dir is None: + self._scratch_dir = utils.mkdtemp(context.config.lava_image_tmpdir) + return self._scratch_dir + def power_on(self): """ responsible for powering on the target device and returning an instance of a pexpect session @@ -147,6 +153,13 @@ def get_test_data_attachments(self): return [] + def get_device_version(self): + """ Returns the device version associated with the device, i.e. version + of emulation software, or version of master image. Must be overriden in + subclasses. + """ + return 'unknown' + def _customize_ubuntu(self, rootdir): self.deployment_data = Target.ubuntu_deployment_data with open('%s/root/.bashrc' % rootdir, 'a') as f: @@ -168,7 +181,6 @@ # just no upstart or dash assumptions self._customize_oe(mnt) - class SerialIO(file): def __init__(self, logfile): self.serialio = StringIO() === modified file 'lava_dispatcher/job.py' --- lava_dispatcher/job.py 2012-08-30 04:22:50 +0000 +++ lava_dispatcher/job.py 2012-10-08 22:19:31 +0000 @@ -142,6 +142,7 @@ metadata = { 'target.hostname': self.target, + 'target.device_version': self.context.get_device_version(), } if 'device_type' in self.job_data: === modified file 'lava_dispatcher/tests/__init__.py' --- lava_dispatcher/tests/__init__.py 2011-06-27 04:55:08 +0000 +++ lava_dispatcher/tests/__init__.py 2012-10-08 22:19:31 +0000 @@ -1,6 +1,9 @@ import unittest def test_suite(): - module_names = ['lava_dispatcher.tests.test_config',] + module_names = [ + 'lava_dispatcher.tests.test_config', + 'lava_dispatcher.tests.test_device_version', + ] loader = unittest.TestLoader() return loader.loadTestsFromNames(module_names) === added file 'lava_dispatcher/tests/helper.py' --- lava_dispatcher/tests/helper.py 1970-01-01 00:00:00 +0000 +++ lava_dispatcher/tests/helper.py 2012-10-20 19:45:13 +0000 @@ -0,0 +1,52 @@ +# Copyright (C) 2012 Linaro Limited +# +# Author: Antonio Terceiro +# +# This file is part of LAVA Dispatcher. +# +# LAVA Dispatcher is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LAVA Dispatcher is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +import os +from lava_dispatcher.config import get_config, get_device_config + +__tmp_dir = os.getenv("TMPDIR") or '/tmp' +__tmp_config_dir = os.path.join(__tmp_dir, 'lava-dispatcher-config') + +def create_config(name, data): + filename = os.path.join(__tmp_config_dir, name) + if not os.path.exists(os.path.dirname(filename)): + os.mkdir(os.path.dirname(filename)) + with open(filename, 'w') as f: + for key in data.keys(): + f.write("%s = %s\n" % (key, data[key])) + +def create_device_config(name, data): + create_config("devices/%s.conf" % name, data) + return get_device_config(name, __tmp_config_dir) + +def setup_config_dir(): + os.mkdir(__tmp_config_dir) + +def cleanup_config_dir(): + os.system('rm -rf %s' % __tmp_config_dir) + +from unittest import TestCase + +class LavaDispatcherTestCase(TestCase): + + def setUp(self): + setup_config_dir() + + def tearDown(self): + cleanup_config_dir() === modified file 'lava_dispatcher/tests/test_config.py' --- lava_dispatcher/tests/test_config.py 2012-10-16 02:26:18 +0000 +++ lava_dispatcher/tests/test_config.py 2012-10-18 17:37:08 +0000 @@ -17,33 +17,23 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, see . -import os from unittest import TestCase from lava_dispatcher.config import get_config, get_device_config from lava_dispatcher.utils import string_to_list from lava_dispatcher.client.base import LavaClient +from lava_dispatcher.tests.helper import * + test_config_dir = os.path.join(os.path.dirname(__file__), 'test-config') -print test_config_dir - -tmp_dir = os.getenv("TMPDIR") or '/tmp' -tmp_config_dir = os.path.join(tmp_dir, 'lava-dispatcher-config') - -def create_config(name, data): - filename = os.path.join(tmp_config_dir, name) - os.mkdir(os.path.dirname(filename)) - with open(filename, 'w') as f: - for key in data.keys(): - f.write("%s = %s\n" % (key, data[key])) class TestConfigData(TestCase): def setUp(self): - os.mkdir(tmp_config_dir) + setup_config_dir() def tearDown(self): - os.system('rm -rf %s' % tmp_config_dir) + cleanup_config_dir() def test_beagle01_uboot_cmds(self): beagle01_config = get_device_config("beaglexm01", test_config_dir) === added file 'lava_dispatcher/tests/test_device_version.py' --- lava_dispatcher/tests/test_device_version.py 1970-01-01 00:00:00 +0000 +++ lava_dispatcher/tests/test_device_version.py 2012-10-20 19:48:31 +0000 @@ -0,0 +1,69 @@ +# Copyright (C) 2012 Linaro Limited +# +# Author: Antonio Terceiro +# +# This file is part of LAVA Dispatcher. +# +# LAVA Dispatcher is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LAVA Dispatcher is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +from unittest import TestCase +import re +from lava_dispatcher.tests.helper import LavaDispatcherTestCase, create_device_config, create_config, __tmp_config_dir + +from lava_dispatcher.device.target import Target +from lava_dispatcher.device.qemu import QEMUTarget +from lava_dispatcher.device.fastmodel import FastModelTarget +from lava_dispatcher.context import LavaContext +from lava_dispatcher.config import get_config + +def _create_fastmodel_target(): + config = create_device_config('fastmodel01', { 'device_type': 'fastmodel', 'simulator_binary': '/path/to/fastmodel', 'license_server': 'foo.local' }) + target = FastModelTarget(None, config) + return target + +def _create_qemu_target(): + create_config('lava-dispatcher.conf', {'default_qemu_binary': 'qemu-system-arm'}) + device_config = create_device_config('qemu01', { 'device_type': 'qemu' }) + dispatcher_config = get_config(__tmp_config_dir) + + context = LavaContext('qemu01', dispatcher_config, None, None) + return QEMUTarget(context, device_config) + +class TestDeviceVersion(LavaDispatcherTestCase): + + def test_base(self): + target = Target(None, None) + self.assertIsInstance(target.get_device_version(), str) + + def test_qemu(self): + target = _create_qemu_target() + device_version = target.get_device_version() + assert(re.search('^[0-9.]+', device_version)) + + def test_fastmodel(self): + banner = "\n".join([ + "Fast Models [7.1.36 (May 17 2012)]", + "Copyright 2000-2012 ARM Limited.", + "All Rights Reserved.", + "Top component name: RTSM_VE_Cortex_A15x1_A7x1" + ]) + target = _create_fastmodel_target() + version = target._parse_fastmodel_version(banner) + self.assertEqual('7.1.36', version) + + def test_fastmodel_wrong_format(self): + client = _create_fastmodel_target() + version = client._parse_fastmodel_version('random string') + self.assertEqual('unknown', version) +