~gmdduf/lava-dispatcher/gauss-support

« back to all changes in this revision

Viewing changes to lava_dispatcher/signals/armprobe.py

Update l-m-c cmdline options

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import logging
2
 
import os
3
 
import subprocess
4
 
import urlparse
5
 
 
6
 
from lava_dispatcher.downloader import download_image
7
 
from lava_dispatcher.signals import SignalHandler
8
 
 
9
 
 
10
 
class ArmProbe(SignalHandler):
11
 
 
12
 
    def __init__(self, testdef_obj, post_process_script, probe_args=None):
13
 
        SignalHandler.__init__(self, testdef_obj)
14
 
 
15
 
        self.scratch_dir = testdef_obj.context.client.target_device.scratch_dir
16
 
 
17
 
        # post_process_script can be local to the repo or a URL
18
 
        if not urlparse.urlparse(post_process_script).scheme:
19
 
            self.post_process_script = os.path.join(
20
 
                testdef_obj.repo, post_process_script)
21
 
        else:
22
 
            self.post_process_script = download_image(
23
 
                post_process_script, testdef_obj.context, self.scratch_dir)
24
 
        os.chmod(self.post_process_script, 755)  # make sure we can execute it
25
 
 
26
 
        # build up the command we'll use for running the probe
27
 
        config = testdef_obj.context.client.config
28
 
        self.aep_channels = config.arm_probe_channels
29
 
        self.aep_args = [
30
 
            config.arm_probe_binary, '-C', config.arm_probe_config]
31
 
        for c in self.aep_channels:
32
 
            self.aep_args.append('-c')
33
 
            self.aep_args.append(c)
34
 
 
35
 
        for arg in probe_args:
36
 
            self.aep_args.append(arg)
37
 
 
38
 
    def start_testcase(self, test_case_id):
39
 
        ofile = os.path.join(self.scratch_dir, '%s.out' % test_case_id)
40
 
        efile = os.path.join(self.scratch_dir, '%s.err' % test_case_id)
41
 
        ofile = open(ofile, 'w')
42
 
        efile = open(efile, 'w')
43
 
 
44
 
        proc = subprocess.Popen(
45
 
            self.aep_args, stdout=ofile, stderr=efile, stdin=subprocess.PIPE)
46
 
        # The arm-probe-binary allows you to write to stdin via a pipe and
47
 
        # includes the content as comments in the header of its output
48
 
        proc.stdin.write(
49
 
            '# run from lava-test-shell with args: %r' % self.aep_args)
50
 
        proc.stdin.close()
51
 
 
52
 
        return {
53
 
            'process': proc,
54
 
            'logfile': ofile,
55
 
            'errfile': efile,
56
 
        }
57
 
 
58
 
    def end_testcase(self, test_case_id, data):
59
 
        proc = data['process']
60
 
        proc.terminate()
61
 
 
62
 
    def postprocess_test_result(self, test_result, data):
63
 
        tcid = test_result['test_case_id']
64
 
        logging.info('analyzing aep data for %s ...', tcid)
65
 
 
66
 
        lfile = data['logfile']
67
 
        efile = data['errfile']
68
 
 
69
 
        lfile.close()
70
 
        efile.close()
71
 
 
72
 
        with self._result_as_dir(test_result) as result_dir:
73
 
            args = [self.post_process_script, tcid, lfile.name, efile.name]
74
 
            args.extend(self.aep_channels)
75
 
 
76
 
            if subprocess.call(args, cwd=result_dir) != 0:
77
 
                logging.warn('error calling post_process_script')