summaryrefslogtreecommitdiff
path: root/test-cli/test_main.py
diff options
context:
space:
mode:
authorHector Fernandez <hector@iatec.biz>2020-06-25 11:45:31 +0200
committerHector Fernandez <hector@iatec.biz>2020-06-25 11:45:31 +0200
commitdb3b1e45c47a1ef23c1ad67114a09cbec0976681 (patch)
tree6833ba2e59be77f9e818823068570ca3d51959cc /test-cli/test_main.py
parent278b5729a44837e37fe13611518c1babc8de00df (diff)
downloadboard-db3b1e45c47a1ef23c1ad67114a09cbec0976681.zip
board-db3b1e45c47a1ef23c1ad67114a09cbec0976681.tar.gz
board-db3b1e45c47a1ef23c1ad67114a09cbec0976681.tar.bz2
Solved bugs. Adapted to DB changes.
Diffstat (limited to 'test-cli/test_main.py')
-rw-r--r--test-cli/test_main.py226
1 files changed, 155 insertions, 71 deletions
diff --git a/test-cli/test_main.py b/test-cli/test_main.py
index 3345f53..0df9bd4 100644
--- a/test-cli/test_main.py
+++ b/test-cli/test_main.py
@@ -6,7 +6,6 @@ import unittest
from test.helpers.testsrv_db import TestSrv_Database
from test.helpers.setup_xml import XMLSetup
from test.runners.simple import SimpleTestRunner
-from test.helpers.syscmd import TestSysCommand
from test.tests.qethernet import Qethernet
from test.tests.qram import Qram
from test.tests.qusb import Qusb
@@ -27,6 +26,8 @@ from test.tasks.flashmemory import flash_memory
from test.helpers.qrreader import QRReader
from test.tasks.generatedmesg import generate_dmesg
from test.helpers.cmdline import LinuxKernel
+from test.helpers.amper import Amper
+from test.enums.StationStates import StationStates
# global variables
psdbObj = TestSrv_Database()
@@ -103,13 +104,18 @@ def create_board():
variant = cmd.getkvar("bvariant", "none")
if model_id == "none" or variant == "none":
- return 1
+ print("Error: Cannot open DB connection")
+ loggerObj.getlogger().info("Station error: #Cannot get model and variant information#")
+ exit(0)
# get model id
globalVar.g_mid = model_id + "-" + variant
# get station
- globalVar.station = socket.gethostname()
+ if "Station" not in globalVar.station:
+ print("Error: Wrong Station name")
+ loggerObj.getlogger().info("Station error: #Wrong station name#")
+ exit(0)
processor_id = get_die_id(globalVar.g_mid)
print(globalVar.g_mid)
@@ -117,8 +123,6 @@ def create_board():
globalVar.g_uuid = psdbObj.create_board(processor_id, model_id, variant, globalVar.station,
get_mac(globalVar.g_mid))
print(globalVar.g_uuid)
- psdbObj.bond_to_station(globalVar.g_uuid, globalVar.station)
- return 0
def get_taskvars_list(uuid):
@@ -131,67 +135,97 @@ def get_taskvars_list(uuid):
def main():
# initialize the board
- res = create_board()
- if res:
- loggerObj.getlogger().info("Python program error")
+ create_board()
+
+ # create a process
+ globalVar.testid_ctl = psdbObj.open_test(globalVar.g_uuid)
+ # create and run tests according to the board type
+ runner = SimpleTestRunner(psdbObj)
+ # Change state to "TESTS_RUNNING"
+ if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
+ # Abort
+ print("Error: Wrong previous station state.")
+ exit(0)
+ psdbObj.change_station_state(globalVar.station, StationStates.TESTS_RUNNING.name)
+ # Execute tests
+ testresult = runner.run(create_testsuite())
+ # save dmesg at the end of the tests
+ generate_dmesg(globalVar.testid_ctl, psdbObj)
+
+ # execute aditional tasks, only if the test was succesfull
+ if testresult.wasSuccessful():
+ # Change state to "TESTS_OK"
+ if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
+ # Abort
+ print("Error: Wrong previous station state.")
+ exit(0)
+ psdbObj.change_station_state(globalVar.station, StationStates.TESTS_OK.name)
+ # Change state to "EXTRATASKS_RUNNING"
+ if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
+ # Abort
+ print("Error: Wrong previous station state.")
+ exit(0)
+ psdbObj.change_station_state(globalVar.station, StationStates.EXTRATASKS_RUNNING.name)
+ # create task control
+ globalVar.taskid_ctl = psdbObj.open_task(globalVar.g_uuid)
+ # get extra variables
+ varlist = get_taskvars_list(globalVar.g_uuid)
+
+ alltasksok = False
+
+ # flash eeprom
+ resulteeprom = 0
+ if "eeprompath" in varlist and len(varlist["eeprompath"]) > 0:
+ mac0 = psdbObj.get_board_macaddr(globalVar.g_uuid)
+ resulteeprom, eepromdata = flash_eeprom(varlist["eeprompath"], globalVar.g_uuid, mac0)
+ psdbObj.create_task_result(globalVar.taskid_ctl, "FLASHEEPROM",
+ "TASK_OK" if resulteeprom == 0 else "TASK_FAIL", eepromdata)
+
+ # flash non-volatile memory
+ resultmemory = 0
+ if "flashimagepath" in varlist and len(varlist["flashimagepath"]) > 0:
+ resultmemory = flash_memory(varlist["flashimagepath"])
+ psdbObj.create_task_result(globalVar.taskid_ctl, "FLASHMEMORY",
+ "TASK_OK" if resultmemory == 0 else "TASK_FAIL",
+ varlist["flashimagepath"])
+
+ # update status with the result
+ if resulteeprom == 0 and resultmemory == 0:
+ psdbObj.update_taskctl_status(globalVar.taskid_ctl, "TASK_BOARD_OK")
+ # Change state to "WAITING_FOR_SCANNER"
+ if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
+ # Abort
+ print("Error: Wrong previous station state.")
+ exit(0)
+ psdbObj.change_station_state(globalVar.station, StationStates.WAITING_FOR_SCANNER.name)
+ # get barcode using the scanner
+ qrreceived = False
+ while not qrreceived:
+ qr = QRReader()
+ if qr.openQR():
+ # waits 5s to receive a valid code
+ if qr.readQRasync(5):
+ qrreceived = True
+ factorycode = qr.getQRNumber()
+ psdbObj.set_factorycode(globalVar.g_uuid, factorycode)
+ qr.closeQR()
+ # Change state to "FINISHED"
+ if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
+ # Abort
+ print("Error: Wrong previous station state.")
+ exit(0)
+ psdbObj.change_station_state(globalVar.station, StationStates.FINISHED.name)
+ else:
+ psdbObj.update_taskctl_status(globalVar.taskid_ctl, "TASK_BOARD_FAIL")
+ loggerObj.getlogger().info("Station error: #Unable to complete extra tasks#")
+
else:
- # create a process
- globalVar.testid_ctl = psdbObj.open_test(globalVar.g_uuid)
- # create and run tests according to the board type
- runner = SimpleTestRunner(psdbObj)
- loggerObj.getlogger().info("Tests running")
- testresult = runner.run(create_testsuite())
- # save dmesg
- generate_dmesg(globalVar.testid_ctl, psdbObj)
-
- # execute aditional tasks, only if the test was succesfull
- if testresult.wasSuccessful():
- loggerObj.getlogger().info("Extra tasks running")
- # create task control
- globalVar.taskid_ctl = psdbObj.open_task(globalVar.g_uuid)
- # get extra variables
- varlist = get_taskvars_list(globalVar.g_uuid)
-
- alltasksok = False
-
- # flash eeprom
- resulteeprom = 0
- if "eeprompath" in varlist and len(varlist["eeprompath"]) > 0:
- mac0 = psdbObj.get_board_macaddr(globalVar.g_uuid)
- resulteeprom, eepromdata = flash_eeprom(varlist["eeprompath"], globalVar.g_uuid, mac0)
- psdbObj.create_task_result(globalVar.taskid_ctl, "FLASHEEPROM",
- "TASK_OK" if resulteeprom == 0 else "TASK_FAIL", eepromdata)
-
- # flash non-volatile memory
- resultmemory = 0
- if "flashimagepath" in varlist and len(varlist["flashimagepath"]) > 0:
- resultmemory = flash_memory(varlist["flashimagepath"])
- psdbObj.create_task_result(globalVar.taskid_ctl, "FLASHMEMORY",
- "TASK_OK" if resultmemory == 0 else "TASK_FAIL",
- varlist["flashimagepath"])
-
- # update status with the result
- if resulteeprom == 0 and resultmemory == 0:
- alltasksok = True
- psdbObj.update_taskctl_status(globalVar.taskid_ctl, "TASK_BOARD_OK")
- else:
- psdbObj.update_taskctl_status(globalVar.taskid_ctl, "TASK_BOARD_FAIL")
-
- if alltasksok:
- # get barcode using the scanner
- loggerObj.getlogger().info("Waiting for barcode scanner")
- qrreceived = False
- while not qrreceived:
- qr = QRReader()
- if qr.openQR():
- # waits 5s to receive a valid code
- if qr.readQRasync(5):
- qrreceived = True
- factorycode = qr.getQRNumber()
- psdbObj.set_factorycode(globalVar.g_uuid, factorycode)
- qr.closeQR()
-
- loggerObj.getlogger().info("Python program finished")
+ # Change state to "TESTS_FAILED"
+ if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
+ # Abort
+ print("Error: Wrong previous station state.")
+ exit(0)
+ psdbObj.change_station_state(globalVar.station, StationStates.TESTS_FAILED.name)
if __name__ == "__main__":
@@ -202,18 +236,68 @@ if __name__ == "__main__":
# create logger
loggerObj = ISEE_Logger(logging.INFO)
- loggerObj.getlogger().info("Python program started")
# Try to parse the setup.xml file
try:
xmlObj = XMLSetup(os.path.join(test_abspath, "setup.xml"))
except:
+ # Abort
print("Error: Cannot parse setup.xml file")
- exit(1)
+ loggerObj.getlogger().info("Station error: #Cannot parse XML configuration file#")
+ exit(0)
# Try to connect to the DB, according to setup.xml configuration
- if psdbObj.open(xmlObj):
- main()
- else:
+ if not psdbObj.open(xmlObj):
print("Error: Cannot open DB connection")
- exit(2)
+ loggerObj.getlogger().info("Station error: #Cannot open DB connection#")
+ exit(0)
+
+ # get station name
+ globalVar.station = socket.gethostname()
+
+ # Check if current state is "WAIT_TEST_START"
+ currentstate = psdbObj.read_station_state(globalVar.station)
+ if currentstate != StationStates.WAIT_TEST_START.name:
+ # Abort
+ print("Error: Wrong previous station state.")
+ exit(0)
+
+ # Change state to "TESTS_CHECKING_ENV"
+ psdbObj.change_station_state(globalVar.station, StationStates.TESTS_CHECKING_ENV.name)
+
+ # Look for a sd or pendrive
+ # TODO
+ #if not disk_exists("/dev/mmcblk0") and not :
+ # abort
+ #print("error: cannot find a barcode scanner.")
+ #loggerObj.getlogger().info("station error: #cannot find a sd card or memory usb to load the test environment.#")
+ #exit(0)
+
+ # Look for a barcode scanner
+ qr = QRReader()
+ if qr.openQR():
+ qr.closeQR()
+ else:
+ # Abort
+ print("Error: Cannot find a barcode scanner.")
+ loggerObj.getlogger().info("Station error: #Cannot find a barcode scanner#")
+ exit(0)
+
+ # Look for an amperimeter
+ amp = Amper()
+ if not amp.open():
+ # Abort
+ print("Error: Cannot open an amperimeter COM port.")
+ loggerObj.getlogger().info("Station error: #Cannot open an amperimeter COM port#")
+ exit(0)
+ if not amp.hello():
+ if not amp.hello():
+ # Abort
+ print("Error: Cannot open find an amperimeter.")
+ loggerObj.getlogger().info("Station error: #Cannot open find an amperimeter#")
+ exit(0)
+
+ # Execute main
+ main()
+
+ exit(0)