summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/_ptest.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2016-10-27 16:39:47 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-23 12:05:19 +0000
commitb61326efb1bc66202831f9710716b5171a722039 (patch)
tree31e229ee225f0a816eb60a5fb721b021f8eab3e2 /meta/lib/oeqa/runtime/_ptest.py
parentba1aec3407e38f4dc4141e4d6300b3d538dc9dd3 (diff)
downloadpoky-b61326efb1bc66202831f9710716b5171a722039.tar.gz
oeqa/runtime: Move to runtime_cases
The new oeqa core framework will modify the structure of the runtime folder the new runtime folder will have python code inside to support runtime test cases. (From OE-Core rev: 637b712096e9d230e15b1a432a561e4118db34c8) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/runtime/_ptest.py')
-rw-r--r--meta/lib/oeqa/runtime/_ptest.py125
1 files changed, 0 insertions, 125 deletions
diff --git a/meta/lib/oeqa/runtime/_ptest.py b/meta/lib/oeqa/runtime/_ptest.py
deleted file mode 100644
index a2432517e3..0000000000
--- a/meta/lib/oeqa/runtime/_ptest.py
+++ /dev/null
@@ -1,125 +0,0 @@
1import unittest, os, shutil
2from oeqa.oetest import oeRuntimeTest, skipModule
3from oeqa.utils.decorators import *
4from oeqa.utils.logparser import *
5from oeqa.utils.httpserver import HTTPService
6import bb
7import glob
8from oe.package_manager import RpmPkgsList
9import subprocess
10
11def setUpModule():
12 if not oeRuntimeTest.hasFeature("package-management"):
13 skipModule("Image doesn't have package management feature")
14 if not oeRuntimeTest.hasPackage("smartpm"):
15 skipModule("Image doesn't have smart installed")
16 if "package_rpm" != oeRuntimeTest.tc.d.getVar("PACKAGE_CLASSES").split()[0]:
17 skipModule("Rpm is not the primary package manager")
18
19class PtestRunnerTest(oeRuntimeTest):
20
21 # a ptest log parser
22 def parse_ptest(self, logfile):
23 parser = Lparser(test_0_pass_regex="^PASS:(.+)", test_0_fail_regex="^FAIL:(.+)", section_0_begin_regex="^BEGIN: .*/(.+)/ptest", section_0_end_regex="^END: .*/(.+)/ptest")
24 parser.init()
25 result = Result()
26
27 with open(logfile) as f:
28 for line in f:
29 result_tuple = parser.parse_line(line)
30 if not result_tuple:
31 continue
32 result_tuple = line_type, category, status, name = parser.parse_line(line)
33
34 if line_type == 'section' and status == 'begin':
35 current_section = name
36 continue
37
38 if line_type == 'section' and status == 'end':
39 current_section = None
40 continue
41
42 if line_type == 'test' and status == 'pass':
43 result.store(current_section, name, status)
44 continue
45
46 if line_type == 'test' and status == 'fail':
47 result.store(current_section, name, status)
48 continue
49
50 result.sort_tests()
51 return result
52
53 @classmethod
54 def setUpClass(self):
55 #note the existing channels that are on the board before creating new ones
56# self.existingchannels = set()
57# (status, result) = oeRuntimeTest.tc.target.run('smart channel --show | grep "\["', 0)
58# for x in result.split("\n"):
59# self.existingchannels.add(x)
60 self.repo_server = HTTPService(oeRuntimeTest.tc.d.getVar('DEPLOY_DIR'), oeRuntimeTest.tc.target.server_ip)
61 self.repo_server.start()
62
63 @classmethod
64 def tearDownClass(self):
65 self.repo_server.stop()
66 #remove created channels to be able to repeat the tests on same image
67# (status, result) = oeRuntimeTest.tc.target.run('smart channel --show | grep "\["', 0)
68# for x in result.split("\n"):
69# if x not in self.existingchannels:
70# oeRuntimeTest.tc.target.run('smart channel --remove '+x[1:-1]+' -y', 0)
71
72 def add_smart_channel(self):
73 image_pkgtype = self.tc.d.getVar('IMAGE_PKGTYPE')
74 deploy_url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, image_pkgtype)
75 pkgarchs = self.tc.d.getVar('PACKAGE_ARCHS').replace("-","_").split()
76 for arch in os.listdir('%s/%s' % (self.repo_server.root_dir, image_pkgtype)):
77 if arch in pkgarchs:
78 self.target.run('smart channel -y --add {a} type=rpm-md baseurl={u}/{a}'.format(a=arch, u=deploy_url), 0)
79 self.target.run('smart update', 0)
80
81 def install_complementary(self, globs=None):
82 installed_pkgs_file = os.path.join(oeRuntimeTest.tc.d.getVar('WORKDIR'),
83 "installed_pkgs.txt")
84 self.pkgs_list = RpmPkgsList(oeRuntimeTest.tc.d, oeRuntimeTest.tc.d.getVar('IMAGE_ROOTFS'), oeRuntimeTest.tc.d.getVar('arch_var'), oeRuntimeTest.tc.d.getVar('os_var'))
85 with open(installed_pkgs_file, "w+") as installed_pkgs:
86 installed_pkgs.write(self.pkgs_list.list("arch"))
87
88 cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"),
89 "-p", oeRuntimeTest.tc.d.getVar('PKGDATA_DIR'), "glob", installed_pkgs_file,
90 globs]
91 try:
92 bb.note("Installing complementary packages ...")
93 complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
94 except subprocess.CalledProcessError as e:
95 bb.fatal("Could not compute complementary packages list. Command "
96 "'%s' returned %d:\n%s" %
97 (' '.join(cmd), e.returncode, e.output))
98
99 return complementary_pkgs.split()
100
101 def setUpLocal(self):
102 self.ptest_log = os.path.join(oeRuntimeTest.tc.d.getVar("TEST_LOG_DIR"), "ptest-%s.log" % oeRuntimeTest.tc.d.getVar('DATETIME'))
103
104 @skipUnlessPassed('test_ssh')
105 def test_ptestrunner(self):
106 self.add_smart_channel()
107 (runnerstatus, result) = self.target.run('which ptest-runner', 0)
108 cond = oeRuntimeTest.hasPackage("ptest-runner") and oeRuntimeTest.hasFeature("ptest") and oeRuntimeTest.hasPackageMatch("-ptest") and (runnerstatus != 0)
109 if cond:
110 self.install_packages(self.install_complementary("*-ptest"))
111 self.install_packages(['ptest-runner'])
112
113 (runnerstatus, result) = self.target.run('/usr/bin/ptest-runner > /tmp/ptest.log 2>&1', 0)
114 #exit code is !=0 even if ptest-runner executes because some ptest tests fail.
115 self.assertTrue(runnerstatus != 127, msg="Cannot execute ptest-runner!")
116 self.target.copy_from('/tmp/ptest.log', self.ptest_log)
117 shutil.copyfile(self.ptest_log, "ptest.log")
118
119 result = self.parse_ptest("ptest.log")
120 log_results_to_location = "./results"
121 if os.path.exists(log_results_to_location):
122 shutil.rmtree(log_results_to_location)
123 os.makedirs(log_results_to_location)
124
125 result.log_as_files(log_results_to_location, test_status = ['pass','fail'])