summaryrefslogtreecommitdiff
path: root/test-cli/test_main.py
blob: b3433bc2a99f4886d94915e7543b35e32ca975b8 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from test.helpers.get_dieid import genDieid
import xml.etree.ElementTree as XMLParser
import errno
import sys
import os
import unittest
from test.helpers.testsrv_db import TestSrv_Database
from test.helpers.testsrv_db import testServerDb
from test.runners.simple import SimpleTestRunner
from test.helpers.setup_xml import XMLSetup
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.finisher import Finisher
from test.helpers.globalVariables import globalVar

# Database global object
pgdbcli = testServerDb()
# Configuration file amd Parse it
xmlsetup = XMLSetup("setup.xml")

# define clear function
def clear():
    # check and make call for specific operating system
    # _ = call('clear' if os.name =='posix' else 'cls')
    if os.name == 'posix':
        os.system('clear')
    else:
        os.system('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")
    auxs = psdb.close_testbatch(globalVar.g_uuid, globalVar.testid_ctl)
    globalVar.fstatus = auxs[0][0]
    # Burn eeprom struct
    psdb = TestSrv_Database()
    psdb.open("setup.xml")
    # We should call getboard_eeprom only if test was ok
    if globalVar.fstatus:
        aux = psdb.getboard_eeprom(globalVar.g_uuid)
        finish = Finisher(aux)
        finish.end_ok()
    else:
        finish = Finisher(globalVar.g_uuid)
        finish.end_fail()
    # Update set_test current_test with 'END' so that it finally gets painted in green
    psdb = TestSrv_Database()
    psdb.open("setup.xml")
    psdb.update_set_test_row(globalVar.station, globalVar.testid_ctl, globalVar.g_uuid, "END","FINISH")


def dbconnection():
    if pgdbcli.open(xmlsetup) is False:
        sys.exit("Database connection error")
    print("value:", xmlsetup.getBoard('model', 'none'))


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 python console
    clear()
    # database connection
    dbconnection()
    # Execute main
    # main()