summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qdmesg.py
blob: 8117deb2a70b9913976a33b177dd96dade0bf0d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sh
import os.path
from os import path


class Qdmesg:
    params = None
    __resultlist = None  # resultlist is a python list of python dictionaries

    def __init__(self, testname, testfunc, varlist):
        self.params = varlist
        self._testMethodDoc = testname
        self.__resultlist = []
        self.pgObj = varlist["db"]

    def execute(self):
        print("running dmesg test")
        self.pgObj.run_test(self.params["testidctl"], self.params["testid"])
        # delete previous file
        if path.exists("/tmp/station/dmesg.txt"):
            os.remove("/tmp/station/dmesg.txt")
        # generate file
        p = sh.dmesg("--color=never", _out="/tmp/station/dmesg.txt")
        if p.exit_code == 0:
            # save result
            # with open('/tmp/station/dmesg.txt', 'w') as outfile:
            #     n = outfile.write(p.stdout.decode('ascii'))
            # outfile.close()

            # save dmesg result in DB
            self.pgObj.upload_result_file(self.params["testidctl"], self.params["testid"], "dmesg output",
                                          "/tmp/station/dmesg.txt", "text/plain")
            self.pgObj.finish_test(self.params["testidctl"], self.params["testid"], "TEST_COMPLETE", "")
            print("success dmesg test")
        else:
            self.pgObj.finish_test(self.params["testidctl"], self.params["testid"], "TEST_FAILED", "")
            print("fail dmesg test")