aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py30
-rw-r--r--tests/fixtures.py37
-rw-r--r--tests/imposters.py83
-rwxr-xr-xtests/test_hwprofile.py180
-rw-r--r--tests/test_lavaandroidtest_commands.py106
-rw-r--r--tests/test_lavaandroidtest_test.py96
-rw-r--r--tests/test_lavaandroidtest_testinstaller.py58
-rw-r--r--tests/test_lavaandroidtest_testparser.py57
-rw-r--r--tests/test_lavaandroidtest_testrunner.py65
-rw-r--r--tests/test_swprofile.py87
-rwxr-xr-xtests/tests_util.py88
11 files changed, 887 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..b898536
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1,30 @@
+# Copyright (c) 2010, 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import unittest
+
+
+def test_suite():
+ module_names = [
+ 'tests.test_lavaandroidtest_commands',
+ 'tests.test_lavaandroidtest_test',
+ 'tests.test_lavaandroidtest_testinstaller',
+ 'tests.test_lavaandroidtest_testparser',
+ 'tests.test_lavaandroidtest_testrunner',
+ 'tests.test_swprofile',
+ 'tests.test_hwprofile']
+ loader = unittest.TestLoader()
+ suite = loader.loadTestsFromNames(module_names)
+ return suite
diff --git a/tests/fixtures.py b/tests/fixtures.py
new file mode 100644
index 0000000..ba75b61
--- /dev/null
+++ b/tests/fixtures.py
@@ -0,0 +1,37 @@
+# Copyright (c) 2010, 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import unittest
+
+
+class TestCaseWithFixtures(unittest.TestCase):
+ """TestCase extended to allow adding fixtures
+
+ Fixtures added should contain at least a setUp() method, and
+ optionally a tearDown method as well
+ """
+
+ def add_fixture(self, fixture):
+ if not hasattr(self, "_fixtures"):
+ self._fixtures = []
+ fixture.setUp()
+ if hasattr(self, "tearDown"):
+ self._fixtures.append(fixture)
+ return fixture
+
+ def tearDown(self):
+ for fixture in self._fixtures:
+ fixture.tearDown()
+ self._fixtures = []
diff --git a/tests/imposters.py b/tests/imposters.py
new file mode 100644
index 0000000..ef28ad3
--- /dev/null
+++ b/tests/imposters.py
@@ -0,0 +1,83 @@
+# Copyright (c) 2010, 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import os
+import shutil
+import sys
+import tempfile
+import StringIO
+
+
+class OutputImposter(object):
+ def setUp(self):
+ self.origstdout = sys.stdout
+ self.origstderr = sys.stderr
+ sys.stdout = sys.stderr = self.fakestdout = StringIO.StringIO()
+
+ def tearDown(self):
+ sys.stdout = self.origstdout
+ sys.stderr = self.origstderr
+
+ def getvalue(self):
+ return self.fakestdout.getvalue()
+
+
+class ConfigImposter(object):
+ def setUp(self):
+ class fakeconfig:
+ def __init__(self, basedir):
+ self.configdir = os.path.join(basedir, "config")
+ self.installdir = os.path.join(basedir, "install")
+ self.resultsdir = os.path.join(basedir, "results")
+ self.registry = {
+ "format": "LAVA Test Test Registry 1.0",
+ "providers": [
+ {
+ "entry_point":
+ "lava_test.core.providers:BuiltInProvider"
+ },
+ {
+ "entry_point":
+ "lava_test.core.providers:PkgResourcesProvider",
+ "config":
+ {"namespace": "lava_test.test_definitions"}
+ },
+ {
+ "entry_point":
+ "lava_test.core.providers:RegistryProvider",
+ "config": {
+ "entries": []
+ }
+ }
+ ]
+ }
+
+ self.tmpdir = tempfile.mkdtemp()
+ self.config = fakeconfig(self.tmpdir)
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ @property
+ def configdir(self):
+ return self.config.configdir
+
+ @property
+ def installdir(self):
+ return self.config.installdir
+
+ @property
+ def resultsdir(self):
+ return self.config.resultsdir
diff --git a/tests/test_hwprofile.py b/tests/test_hwprofile.py
new file mode 100755
index 0000000..fc5ee15
--- /dev/null
+++ b/tests/test_hwprofile.py
@@ -0,0 +1,180 @@
+#!/usr/bin/env python
+# Copyright (c) 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import unittest
+
+import lava_android_test.hwprofile
+from tests.tests_util import fake_adb, clear_fake
+
+from tests.imposters import OutputImposter
+from tests.fixtures import TestCaseWithFixtures
+
+FAKE_BOARDNAME_FILE = "XXXXXXX"
+FAKE_BOARDVENDOR_FILE = "YYYYYYY"
+FAKE_BOARDVERSION_FILE = "ZZZZZZZ"
+
+panda_cpu_info = '''Processor : ARMv7 Processor rev 2 (v7l)
+processor : 0
+BogoMIPS : 1576.53
+
+processor : 1
+BogoMIPS : 1539.77
+
+Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls
+CPU implementer : 0x41
+CPU architecture: 7
+CPU variant : 0x1
+CPU part : 0xc09
+CPU revision : 2
+
+Hardware : OMAP4 Panda board
+Revision : 0020
+Serial : 0000000000000000
+'''
+
+panda_mem_info = '''MemTotal: 921832 kB
+MemFree: 545032 kB
+Buffers: 488 kB
+Cached: 183964 kB
+SwapCached: 0 kB
+Active: 212628 kB
+Inactive: 125480 kB
+Active(anon): 153680 kB
+Inactive(anon): 60744 kB
+Active(file): 58948 kB
+Inactive(file): 64736 kB
+Unevictable: 0 kB
+Mlocked: 0 kB
+HighTotal: 211968 kB
+HighFree: 408 kB
+LowTotal: 709864 kB
+LowFree: 544624 kB
+SwapTotal: 0 kB
+SwapFree: 0 kB
+Dirty: 0 kB
+Writeback: 0 kB
+AnonPages: 153640 kB
+Mapped: 105236 kB
+Shmem: 60768 kB
+Slab: 10728 kB
+SReclaimable: 4760 kB
+SUnreclaim: 5968 kB
+KernelStack: 3272 kB
+PageTables: 5528 kB
+NFS_Unstable: 0 kB
+Bounce: 0 kB
+WritebackTmp: 0 kB
+CommitLimit: 460916 kB
+Committed_AS: 4237400 kB
+VmallocTotal: 122880 kB
+VmallocUsed: 75536 kB
+VmallocChunk: 36868 kB
+'''
+
+
+class HwprofileTests(unittest.TestCase):
+ maxDiff = None
+
+ def test_get_cpu_devs(self):
+ fake_adb(output_str=panda_cpu_info)
+ devs = lava_android_test.hwprofile.get_cpu_devs()
+ clear_fake()
+ cpuinfo = {
+ 'attributes': {
+ 'processor': '1',
+ 'cpu_features':
+ 'swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls',
+ 'cpu_variant': 1,
+ 'cpu_architecture': 7,
+ 'BogoMIPS': '1539.77',
+ 'Hardware': 'OMAP4 Panda board',
+ 'cpu_implementer': 65,
+ 'cpu_part': 3081,
+ 'cpu_revision': 2,
+ 'Serial': '0000000000000000',
+ 'Revision': '0020'},
+ 'description': 'Processor #1',
+ 'device_type': 'device.cpu'}
+ self.assertEqual(cpuinfo, devs[1])
+ cpuinfo = {
+ 'attributes': {
+ 'processor': '0',
+ 'cpu_model_name': 'ARMv7 Processor rev 2 (v7l)',
+ 'BogoMIPS': '1576.53'},
+ 'description': 'Processor #0',
+ 'device_type': 'device.cpu'}
+ self.assertEqual(cpuinfo, devs[0])
+
+ def test_get_board_devs(self):
+ fake_adb(output_str=panda_cpu_info)
+ devs = lava_android_test.hwprofile.get_board_devs()
+ clear_fake()
+ boardinfo = {
+ 'description': 'OMAP4 Panda board',
+ 'device_type': 'device.board'}
+ self.assertEqual(boardinfo, devs[0])
+
+ def test_get_mem_devs(self):
+ fake_adb(output_str=panda_mem_info)
+ devs = lava_android_test.hwprofile.get_mem_devs()
+ clear_fake()
+
+ meminfo = {
+ 'attributes': {
+ 'kind': 'RAM',
+ 'capacity': '943955968'},
+ 'description': '900MiB of RAM',
+ 'device_type': 'device.mem'}
+ self.assertEqual(meminfo, devs[0])
+
+
+class MissingFiles(TestCaseWithFixtures):
+ """
+ These are tests for situations where certain files used for gathering
+ hardware profile information may be missing
+ """
+ def setUp(self):
+ super(MissingFiles, self).setUp()
+ clear_fake()
+ self.out = self.add_fixture(OutputImposter())
+
+ def test_bad_cpuinfo(self):
+ errmsg = 'WARNING: Could not read cpu information\n'
+ fake_adb(output_str='', ret_code=255)
+ devs = lava_android_test.hwprofile.get_cpu_devs()
+ clear_fake()
+ self.assertEqual([], devs)
+ self.assertEqual(errmsg, self.out.getvalue())
+
+ def test_bad_boardinfo(self):
+ errmsg = 'WARNING: Could not read board information\n'
+ fake_adb(output_str='', ret_code=255)
+ devs = lava_android_test.hwprofile.get_board_devs()
+ clear_fake()
+ self.assertEqual([], devs)
+ self.assertEqual(errmsg, self.out.getvalue())
+
+ def test_bad_meminfo(self):
+ errmsg = 'WARNING: Could not read memory information\n'
+ fake_adb(output_str='', ret_code=255)
+ devs = lava_android_test.hwprofile.get_mem_devs()
+ clear_fake()
+ self.assertEqual([], devs)
+ self.assertEqual(errmsg, self.out.getvalue())
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_lavaandroidtest_commands.py b/tests/test_lavaandroidtest_commands.py
new file mode 100644
index 0000000..83e1615
--- /dev/null
+++ b/tests/test_lavaandroidtest_commands.py
@@ -0,0 +1,106 @@
+# Copyright (c) 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import re
+from tests.tests_util import fake_adb, clear_fake
+
+from tests.imposters import ConfigImposter, OutputImposter
+from tests.fixtures import TestCaseWithFixtures
+from lava_android_test.main import LAVAAndroidTestDispatcher
+
+
+class LavaTestCommandTestCase(TestCaseWithFixtures):
+ def setUp(self):
+ self.config = self.add_fixture(ConfigImposter())
+ self.out = self.add_fixture(OutputImposter())
+ clear_fake()
+
+ def tearDown(self):
+ clear_fake()
+
+ def _runLavaTest(self, cmds):
+ LAVAAndroidTestDispatcher().dispatch(cmds)
+
+
+class BadCommand(LavaTestCommandTestCase):
+ def test_bad_cmd(self):
+ # Running an unknown command that does not exist of a command that does
+ # gives a nice error message.
+ errmsg = "invalid choice: 'results'"
+
+ self.assertRaises(SystemExit, LAVAAndroidTestDispatcher().dispatch,
+ ['results', 'foo'])
+ self.assertNotEqual(None, re.search(errmsg, self.out.getvalue()),
+ re.MULTILINE)
+ self.assertTrue(errmsg in self.out.getvalue())
+
+
+class ListKnown(LavaTestCommandTestCase):
+ def test_list_tests(self):
+ self._runLavaTest(['list-tests'])
+ self.assertTrue("monkey" in self.out.getvalue())
+
+dir_list_info = '''monkey
+0xbench
+RET_CODE=0'''
+
+
+class ListInstalled(LavaTestCommandTestCase):
+ def test_list_installed(self):
+ # test_name must be in the BuiltInProvider._builtin_tests
+ fake_adb(output_str=dir_list_info)
+ test_name = "monkey"
+ self._runLavaTest(['list-installed'])
+ self.assertTrue(test_name in self.out.getvalue())
+ clear_fake()
+
+devices_list_info = '''List of devices attached
+192.168.1.109:5555 device
+'''
+
+
+class ListDevices(LavaTestCommandTestCase):
+ def test_list_devices(self):
+ # test_name must be in the BuiltInProvider._builtin_tests
+ fake_adb(output_str=devices_list_info)
+ self._runLavaTest(['list-devices'])
+ self.assertTrue('192.168.1.109:5555 device' in self.out.getvalue())
+ clear_fake()
+
+
+class RunTest(LavaTestCommandTestCase):
+ def test_run_command_test_not_install(self):
+ errmsg = 'ERROR: The test (monkey) has not been installed yet.'
+ fake_adb(output_str='RET_CODE=1')
+ ret_code = LAVAAndroidTestDispatcher().dispatch(['run', 'monkey'])
+ self.assertEqual(1, ret_code)
+ self.assertTrue(errmsg in self.out.getvalue())
+ clear_fake()
+
+ def test_run_command_test_not_exist(self):
+ errmsg = "unknown test 'abc'"
+ fake_adb(output_str='RET_CODE=0')
+ self.assertRaises(SystemExit, LAVAAndroidTestDispatcher().dispatch,
+ ['run', 'abc'])
+ self.assertNotEqual(None, re.search(errmsg, self.out.getvalue()),
+ re.MULTILINE)
+ self.assertTrue(errmsg in self.out.getvalue())
+
+
+class TestHelp(LavaTestCommandTestCase):
+ def test_command_help(self):
+ self.assertRaises(SystemExit, LAVAAndroidTestDispatcher().dispatch,
+ ['--help'])
+ self.assertTrue("--help" in self.out.getvalue())
diff --git a/tests/test_lavaandroidtest_test.py b/tests/test_lavaandroidtest_test.py
new file mode 100644
index 0000000..a7d6575
--- /dev/null
+++ b/tests/test_lavaandroidtest_test.py
@@ -0,0 +1,96 @@
+# Copyright (c) 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import re
+import os
+import subprocess
+from lava_android_test.config import get_config
+from lava_android_test.adb import ADB
+from tests.imposters import ConfigImposter, OutputImposter
+from tests.fixtures import TestCaseWithFixtures
+from tests.tests_util import maketest, makerunner, test_tmp, clear_fake, \
+ fake_adb
+
+
+class FakeAdb(ADB):
+ def __init__(self):
+ super(FakeAdb, self).__init__()
+ self.tmp_dir = test_tmp
+ if not os.path.exists(test_tmp):
+ os.makedirs(test_tmp)
+
+ def shell(self, command=None, stdout=None, stderr=None):
+ if command.startswith('mkdir'):
+ dir_path = command[len('mkdir '):]
+ try:
+ os.mkdir('%s/%s' % (test_tmp, dir_path))
+ except:
+ return 1
+ return 0
+ elif command.startswith('ls'):
+ dir_path = command[len('ls '):]
+ real_path = '%s/%s' % (test_tmp, dir_path)
+ if os.path.exists(real_path):
+ return 0
+ else:
+ return 1
+ elif command.startswith('rm -r'):
+ dir_path = command[len('rm -r '):]
+ proc = subprocess.Popen('rm -fr %s/%s' % (test_tmp, dir_path),
+ shell=True)
+ return proc.wait()
+ else:
+ return 0
+
+fake_output_str = \
+'''[ro.build.display.id]: [sdk-eng 4.0.1 ICS_MR0 202595 test-keys]
+RET_CODE=0'''
+
+
+class TestAndroidTest(TestCaseWithFixtures):
+ def setUp(self):
+ super(TestAndroidTest, self).setUp()
+ self.config = self.add_fixture(ConfigImposter())
+ self.out = self.add_fixture(OutputImposter())
+ clear_fake()
+
+ def tearDown(self):
+ clear_fake()
+
+ def test_run(self):
+ config = get_config()
+ test_name = 'foo'
+ clear_fake()
+ testrunner = makerunner(steps_host_pre=["echo foo"])
+ test = maketest(name=test_name, runner=testrunner)
+ real_installed_path = '%s/%s/%s' % (test_tmp,
+ config.installdir_android,
+ test_name)
+ test.setadb(FakeAdb())
+ self.assertFalse(os.path.exists(real_installed_path))
+ test.install()
+ self.assertTrue(os.path.exists(real_installed_path))
+
+ fake_adb(output_str=fake_output_str)
+ result_id = test.run()
+ self.assertTrue("LAVA: (stdout) foo" in self.out.getvalue())
+
+ result_id_pattern = "foo\d+\.\d+"
+ self.assertTrue(re.match(result_id_pattern, result_id))
+ self.assertTrue("LAVA: (stdout) foo" in self.out.getvalue())
+
+ test.uninstall()
+
+ self.assertFalse(os.path.exists(real_installed_path))
diff --git a/tests/test_lavaandroidtest_testinstaller.py b/tests/test_lavaandroidtest_testinstaller.py
new file mode 100644
index 0000000..7111868
--- /dev/null
+++ b/tests/test_lavaandroidtest_testinstaller.py
@@ -0,0 +1,58 @@
+# Copyright (c) 2010, 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import hashlib
+import os
+import shutil
+import tempfile
+import unittest
+from tests.tests_util import makeinstaller
+
+
+class testTestInstaller(unittest.TestCase):
+ def setUp(self):
+ self.origdir = os.path.abspath(os.curdir)
+ self.tmpdir = tempfile.mkdtemp()
+ self.filename = os.path.abspath(__file__)
+ os.chdir(self.tmpdir)
+
+ def tearDown(self):
+ os.chdir(self.origdir)
+ shutil.rmtree(self.tmpdir)
+
+ def test_bad_download(self):
+ url = "file:///xxxyyyzzz"
+ installer = makeinstaller(url=url)
+ self.assertRaises(RuntimeError, installer._download)
+
+ def test_bad_md5(self):
+ url = "file://%s" % self.filename
+ installer = makeinstaller(url=url, md5='foo')
+ self.assertRaises(RuntimeError, installer._download)
+
+ def test_good_md5(self):
+ url = "file://%s" % self.filename
+ md5 = hashlib.md5(file(self.filename).read()).hexdigest()
+ installer = makeinstaller(url=url, md5=md5)
+ location = installer._download()
+ self.assertTrue(os.path.exists(location))
+
+ def test_steps_host_pre(self):
+ self.assertFalse(os.path.exists("./foo"))
+ steps_host_pre = ["echo test > foo"]
+ installer = makeinstaller(steps_host_pre=steps_host_pre)
+ installer.install('./')
+ self.assertTrue(os.path.exists("./foo"))
+ self.assertTrue("test" in open("./foo").read())
diff --git a/tests/test_lavaandroidtest_testparser.py b/tests/test_lavaandroidtest_testparser.py
new file mode 100644
index 0000000..f08f9d5
--- /dev/null
+++ b/tests/test_lavaandroidtest_testparser.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2010, 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import os
+
+from tests.fixtures import TestCaseWithFixtures
+from tests.tests_util import makeparser
+
+
+class testTestParser(TestCaseWithFixtures):
+
+ def setUp(self):
+ self.test_id = "ABC"
+
+ def tearDown(self):
+ os.unlink('stdout.log')
+
+ def writeoutputlog(self, output_str):
+ with open("stdout.log", "w") as fd:
+ fd.write(output_str)
+
+ def test_parse(self):
+ pattern = "^(?P<testid>\w+):\W+(?P<result>\w+)"
+ self.writeoutputlog("test001: pass")
+ parser = makeparser(pattern)
+ parser.parse()
+ self.assertTrue(
+ parser.results["test_results"][0]["testid"] == "test001" and
+ parser.results["test_results"][0]["result"] == "pass")
+
+ def test_fixupdict(self):
+ pattern = "^(?P<testid>\w+):\W+(?P<result>\w+)"
+ fixup = {"pass": "PASS"}
+ self.writeoutputlog("test001: pass")
+ parser = makeparser(pattern, fixupdict=fixup)
+ parser.parse()
+ self.assertEquals("PASS", parser.results["test_results"][0]["result"])
+
+ def test_appendall(self):
+ pattern = "^(?P<testid>\w+):\W+(?P<result>\w+)"
+ append = {"units": "foo/s"}
+ self.writeoutputlog("test001: pass")
+ parser = makeparser(pattern, appendall=append)
+ parser.parse()
+ self.assertEqual("foo/s", parser.results["test_results"][0]["units"])
diff --git a/tests/test_lavaandroidtest_testrunner.py b/tests/test_lavaandroidtest_testrunner.py
new file mode 100644
index 0000000..0d0cd7d
--- /dev/null
+++ b/tests/test_lavaandroidtest_testrunner.py
@@ -0,0 +1,65 @@
+# Copyright (c) 2010, 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import os
+import shutil
+import tempfile
+from datetime import datetime
+from tests.tests_util import makerunner
+from tests.imposters import OutputImposter, ConfigImposter
+from tests.fixtures import TestCaseWithFixtures
+
+
+class testTestRunner(TestCaseWithFixtures):
+ def setUp(self):
+ self.config = self.add_fixture(ConfigImposter())
+ self.out = self.add_fixture(OutputImposter())
+ self.origdir = os.path.abspath(os.curdir)
+ self.tmpdir = tempfile.mkdtemp()
+ self.filename = os.path.abspath(__file__)
+ os.chdir(self.tmpdir)
+ self.test_id = "ABC"
+
+ def tearDown(self):
+ os.chdir(self.origdir)
+ shutil.rmtree(self.tmpdir)
+
+ def test_starttime(self):
+ runner = makerunner()
+ runner.run('./')
+ self.assertTrue(isinstance(runner.starttime, datetime))
+
+ def test_endtime(self):
+ runner = makerunner()
+ runner.run('./')
+ self.assertTrue(isinstance(runner.endtime, datetime))
+
+ def test_timediff(self):
+ steps = ['sleep 2']
+ runner = makerunner(steps_host_pre=steps)
+ runner.run('./')
+ self.assertNotEqual(runner.starttime, runner.endtime)
+
+ def test_runsteps(self):
+ steps = ["echo test > foo"]
+ runner = makerunner(steps_host_pre=steps)
+ runner.run('./')
+ self.assertTrue(os.path.exists("./foo"))
+
+ def test_logoutput(self):
+ steps = ["echo test"]
+ runner = makerunner(steps_host_pre=steps)
+ runner.run('./')
+ self.assertTrue('test' in self.out.getvalue())
diff --git a/tests/test_swprofile.py b/tests/test_swprofile.py
new file mode 100644
index 0000000..4e937be
--- /dev/null
+++ b/tests/test_swprofile.py
@@ -0,0 +1,87 @@
+# Copyright (c) 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+
+import unittest
+
+from lava_android_test import swprofile
+from tests.tests_util import fake_adb, clear_fake
+
+package_list_info = '''package:android:4.0.1.2.3.4.5.6.7.8.9-3 (#14)
+package:com.android.musicvis:4.0.1.2.3.4.5.6.7.8.9-3 (#14)
+package:com.android.videoeditor:1.1 (#11)
+package:com.android.vpndialogs:4.0.1.2.3.4.5.6.7.8.9-3 (#14)
+package:com.android.wallpaper:4.0.1.2.3.4.5.6.7.8.9-3 (#14)
+package:com.android.wallpaper.livepicker:4.0.1.2.3.4.5.6.7.8.9-3 (#14)
+package:com.svox.pico:1.0 (#1)'''
+
+getprop_info = '''[dalvik.vm.heapsize]: [24m]
+[dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
+[dev.bootcomplete]: [1]
+[gsm.current.phone-type]: [1]
+[ro.build.date]: [Wed Oct 12 12:35:47 PDT 2011]
+[ro.build.description]: [sdk-eng 4.0.1 ICS_MR0 202595 test-keys]
+[ro.build.display.id]: [sdk-eng 4.0.1 ICS_MR0 202595 test-keys]
+[ro.build.host]: [android-test-37.mtv.corp.google.com]
+[ro.build.id]: [ICS_MR0]
+[ro.build.product]: [generic]
+[ro.build.tags]: [test-keys]
+[ro.build.type]: [eng]
+[ro.build.version.sdk]: [14]'''
+
+
+class SwprofileTests(unittest.TestCase):
+ maxDiff = None
+
+ def test_getimage_name_from_properties(self):
+ fake_adb(output_str=getprop_info)
+ image_name = swprofile.get_image_name_from_properties()
+ clear_fake()
+ self.assertEqual('sdk-eng 4.0.1 ICS_MR0 202595 test-keys', image_name)
+
+ def test_get_properties(self):
+ fake_adb(output_str=getprop_info)
+ result = swprofile.get_properties()
+ clear_fake()
+ properties = {'dalvik.vm.heapsize': '24m',
+ 'dalvik.vm.stack-trace-file': '/data/anr/traces.txt',
+ 'dev.bootcomplete': '1',
+ 'gsm.current.phone-type': '1',
+ 'ro.build.date': 'Wed Oct 12 12:35:47 PDT 2011',
+ 'ro.build.description': 'sdk-eng 4.0.1 ICS_MR0 202595 test-keys',
+ 'ro.build.display.id': 'sdk-eng 4.0.1 ICS_MR0 202595 test-keys',
+ 'ro.build.host': 'android-test-37.mtv.corp.google.com',
+ 'ro.build.id': 'ICS_MR0',
+ 'ro.build.product': 'generic',
+ 'ro.build.tags': 'test-keys',
+ 'ro.build.type': 'eng',
+ 'ro.build.version.sdk': '14'}
+ self.assertEqual(properties, result)
+
+ def test_get_package_info(self):
+ fake_adb(output_str=package_list_info)
+ result = swprofile.get_package_info()
+ clear_fake()
+ packages = {'android': '4.0.1.2.3.4.5.6.7.8.9-3 (#14)',
+ 'com.android.musicvis': '4.0.1.2.3.4.5.6.7.8.9-3 (#14)',
+ 'com.android.videoeditor': '1.1 (#11)',
+ 'com.android.vpndialogs': '4.0.1.2.3.4.5.6.7.8.9-3 (#14)',
+ 'com.android.wallpaper': '4.0.1.2.3.4.5.6.7.8.9-3 (#14)',
+ 'com.android.wallpaper.livepicker': '4.0.1.2.3.4.5.6.7.8.9-3 (#14)',
+ 'com.svox.pico': '1.0 (#1)'}
+ result_hash = {}
+ for package in result:
+ result_hash[package.get('name')] = package.get('version')
+
+ self.assertEqual(packages, result_hash)
diff --git a/tests/tests_util.py b/tests/tests_util.py
new file mode 100755
index 0000000..0876b9b
--- /dev/null
+++ b/tests/tests_util.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2011 Linaro
+#
+# This program 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 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 <http://www.gnu.org/licenses/>.
+import os
+import stat
+import subprocess
+from lava_android_test.testdef import AndroidTest, \
+ AndroidTestInstaller, \
+ AndroidTestRunner, \
+ AndroidTestParser
+
+
+def maketest(name="foo", version="", installer=None, runner=None, parser=None):
+ if installer is None:
+ installer = makeinstaller()
+ return AndroidTest(name, version, installer, runner, parser)
+
+
+def makerunner(**kwargs):
+ return AndroidTestRunner(**kwargs)
+
+
+def makeinstaller(**kwargs):
+ return AndroidTestInstaller(**kwargs)
+
+
+def makeparser(*args, **kwargs):
+ return AndroidTestParser(*args, **kwargs)
+
+test_tmp = '/tmp/lava-android-test-tmp'
+
+
+def fake_adb(output_str='', target_path=test_tmp, ret_code=0):
+ if not os.path.exists(target_path):
+ os.makedirs(target_path)
+ fake_adb_path = os.path.join(target_path, 'adb')
+ adb_file = open(fake_adb_path, 'w')
+ adb_file.write('#!/bin/bash\n')
+ adb_file.write('if [ "$2" == "chmod" ]; then\n')
+ adb_file.write('\texit 0\n')
+ adb_file.write('fi\n')
+ if output_str is None or output_str == '':
+ pass
+ else:
+ adb_file.write('echo \'\n')
+ adb_file.write(output_str)
+ adb_file.write('\'\n')
+ adb_file.write('exit %s\n' % ret_code)
+ adb_file.close()
+ os.chmod(fake_adb_path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
+ os.chmod(target_path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
+ os.environ['PATH'] = target_path + ':' + os.environ['PATH']
+
+
+def clear_fake(target_path=test_tmp):
+ if not os.path.exists(target_path):
+ return
+ if os.path.isdir(target_path):
+ for sub_path in os.listdir(target_path):
+ clear_fake(os.path.join(target_path, sub_path))
+ os.rmdir(target_path)
+ else:
+ os.unlink(target_path)
+
+
+def main():
+ fake_adb('hello, \ntest')
+ cmd = 'adb shell ls'
+ p = subprocess.Popen(cmd, shell=True)
+ p.wait()
+ clear_fake()
+
+
+if __name__ == '__main__':
+ main()