summaryrefslogtreecommitdiff
path: root/scripts/PYTHON_SOFTWARE/test_main.py
blob: 6a8ed7eeb9b81ce6680b6ef496787f4f9c740206 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from test.helpers.get_dieid import genDieid
from subprocess import call
import xml.etree.ElementTree as XMLParser
import errno
import sys
import os
import unittest
from test.helpers.testsrv_db import TestSrv_Database
from test.runners.simple import SimpleTestRunner
from test.tests.qbutton import Qbutton
from test.helpers.syscmd import TestSysCommand
from test.helpers.syscmd import SysCommand
from test.tests.qiperf import QIperf
from test.tests.qethernet import Qethernet
from test.tests.qaudio import Qaudio
from test.tests.qram import Qram
from test.tests.qusb import Qusb
from test.tests.qi2c import Qi2c
from test.tests.qeeprom import Qeeprom
from test.tests.qserial import Qserial
from test.tests.qscreen import Qscreen
from test.tests.qwifi import Qwifi
from test.tests.qrtc import Qrtc
from test.tests.qduplex_ser import Qduplex
from test.tests.qamp import Qamp
from test.tests.qflash import Qflasher
from test.helpers.globalVariables import globalVar

# define clear function
def clear():
    # check and make call for specific operating system
    _ = call('clear' if os.name =='posix' else 'cls')


def create_board():
    psdb = TestSrv_Database()
    psdb.open("setup.xml")
    tree = XMLParser.parse('setup.xml')
    root = tree.getroot()
    suite = unittest.TestSuite()
    for element in root.iter('board'):
        # print(str(element.tag) + str(element.attrib))
        model_id = element.attrib['model']
        variant = element.attrib['variant']
        nstation = element.attrib['station']
    globalVar.g_mid=model_id + "-" + variant
    globalVar.station=nstation
    processor_id=genDieid(globalVar.g_mid)
    print(globalVar.g_mid)
    print(processor_id)
    globalVar.g_uuid = psdb.create_board(processor_id, model_id, variant, bmac = None)

def testsuite():
    psdb=TestSrv_Database()
    psdb.open("setup.xml")
    suite = unittest.TestSuite()
    tests=psdb.getboard_comp_test_list(globalVar.g_uuid)
    for i in range(len(tests)):
        #newstr = oldstr.replace("M", "")
        variables=str(tests[i][0]).split(",")
        testname=variables[0].replace('(', '')
        testdes=variables[1]
        testfunc=variables[2]
        if len(tests)>2:
            testparam=variables[3].replace(')', '')
            testparam = testparam.replace('"', '')
            testparam = testparam.replace(';', "','")
            if testparam == "":
                command = "suite.addTest({}('{}','execute'))".format(testfunc, testname)
            else:
                command="suite.addTest({}('{}','execute','{}'))".format(testfunc,testname,testparam)
        else:
            print(testname)
            command = "suite.addTest({}('{}','execute'))".format(testfunc, testname)
        exec(command)
    globalVar.testid_ctl=psdb.open_testbatch(globalVar.g_uuid)
    return suite


def finish_test():
    psdb = TestSrv_Database()
    psdb.open("setup.xml")
    psdb.close_testbatch(globalVar.g_uuid, globalVar.testid_ctl)

def main():
    #addtesttomodel()
    #addtestdef()
    create_board()
    #globalVar.g_uuid = "1f59c654-0cc6-11e8-8d51-e644f56b8edd"
    try:
        os.remove("test_results.dat")
    except:
        pass
    runner = SimpleTestRunner()
    runner.run(testsuite())
    finish_test()


if __name__ == "__main__":
    clear()
    main()