summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib')
-rwxr-xr-xmeta/lib/oeqa/runexported.py140
1 files changed, 140 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runexported.py b/meta/lib/oeqa/runexported.py
new file mode 100755
index 0000000000..e1b6642ec2
--- /dev/null
+++ b/meta/lib/oeqa/runexported.py
@@ -0,0 +1,140 @@
1#!/usr/bin/env python
2
3
4# Copyright (C) 2013 Intel Corporation
5#
6# Released under the MIT license (see COPYING.MIT)
7
8# This script should be used outside of the build system to run image tests.
9# It needs a json file as input as exported by the build.
10# E.g for an already built image:
11#- export the tests:
12# TEST_EXPORT_ONLY = "1"
13# TEST_TARGET = "simpleremote"
14# TEST_TARGET_IP = "192.168.7.2"
15# TEST_SERVER_IP = "192.168.7.1"
16# bitbake core-image-sato -c testimage
17# Setup your target, e.g for qemu: runqemu core-image-sato
18# cd build/tmp/testimage/core-image-sato
19# ./runexported.py testdata.json
20
21import sys
22import os
23import time
24from optparse import OptionParser
25
26try:
27 import simplejson as json
28except ImportError:
29 import json
30
31sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "oeqa")))
32
33from oeqa.oetest import runTests
34from oeqa.utils.sshcontrol import SSHControl
35
36# this isn't pretty but we need a fake target object
37# for running the tests externally as we don't care
38# about deploy/start we only care about the connection methods (run, copy)
39class FakeTarget(object):
40 def __init__(self, d):
41 self.connection = None
42 self.ip = None
43 self.server_ip = None
44 self.datetime = time.strftime('%Y%m%d%H%M%S',time.gmtime())
45 self.testdir = d.getVar("TEST_LOG_DIR", True)
46 self.pn = d.getVar("PN", True)
47
48 def exportStart(self):
49 self.sshlog = os.path.join(self.testdir, "ssh_target_log.%s" % self.datetime)
50 sshloglink = os.path.join(self.testdir, "ssh_target_log")
51 if os.path.islink(sshloglink):
52 os.unlink(sshloglink)
53 os.symlink(self.sshlog, sshloglink)
54 print("SSH log file: %s" % self.sshlog)
55 self.connection = SSHControl(self.ip, logfile=self.sshlog)
56
57 def run(self, cmd, timeout=None):
58 return self.connection.run(cmd, timeout)
59
60 def copy_to(self, localpath, remotepath):
61 return self.connection.copy_to(localpath, remotepath)
62
63 def copy_from(self, remotepath, localpath):
64 return self.connection.copy_from(remotepath, localpath)
65
66
67class MyDataDict(dict):
68 def getVar(self, key, unused = None):
69 return self.get(key, "")
70
71class TestContext(object):
72 def __init__(self):
73 self.d = None
74 self.target = None
75
76def main():
77
78 usage = "usage: %prog [options] <json file>"
79 parser = OptionParser(usage=usage)
80 parser.add_option("-t", "--target-ip", dest="ip", help="The IP address of the target machine. Use this to \
81 overwrite the value determined from TEST_TARGET_IP at build time")
82 parser.add_option("-s", "--server-ip", dest="server_ip", help="The IP address of this machine. Use this to \
83 overwrite the value determined from TEST_SERVER_IP at build time.")
84 parser.add_option("-d", "--deploy-dir", dest="deploy_dir", help="Full path to the package feeds, that this \
85 the contents of what used to be DEPLOY_DIR on the build machine. If not specified it will use the value \
86 specified in the json if that directory actually exists or it will error out.")
87 parser.add_option("-l", "--log-dir", dest="log_dir", help="This sets the path for TEST_LOG_DIR. If not specified \
88 the current dir is used. This is used for usually creating a ssh log file and a scp test file.")
89
90 (options, args) = parser.parse_args()
91 if len(args) != 1:
92 parser.error("Incorrect number of arguments. The one and only argument should be a json file exported by the build system")
93
94 with open(args[0], "r") as f:
95 loaded = json.load(f)
96
97 if options.ip:
98 loaded["target"]["ip"] = options.ip
99 if options.server_ip:
100 loaded["target"]["server_ip"] = options.server_ip
101
102 d = MyDataDict()
103 for key in loaded["d"].keys():
104 d[key] = loaded["d"][key]
105
106 if options.log_dir:
107 d["TEST_LOG_DIR"] = options.log_dir
108 else:
109 d["TEST_LOG_DIR"] = os.path.abspath(os.path.dirname(__file__))
110 if options.deploy_dir:
111 d["DEPLOY_DIR"] = options.deploy_dir
112 else:
113 if not os.path.isdir(d["DEPLOY_DIR"]):
114 raise Exception("The path to DEPLOY_DIR does not exists: %s" % d["DEPLOY_DIR"])
115
116
117 target = FakeTarget(d)
118 for key in loaded["target"].keys():
119 setattr(target, key, loaded["target"][key])
120
121 tc = TestContext()
122 setattr(tc, "d", d)
123 setattr(tc, "target", target)
124 for key in loaded.keys():
125 if key != "d" and key != "target":
126 setattr(tc, key, loaded[key])
127
128 target.exportStart()
129 runTests(tc)
130
131 return 0
132
133if __name__ == "__main__":
134 try:
135 ret = main()
136 except Exception:
137 ret = 1
138 import traceback
139 traceback.print_exc(5)
140 sys.exit(ret)