summaryrefslogtreecommitdiff
path: root/test-cli/test_main.py
diff options
context:
space:
mode:
authorHector Fernandez <hector@iatec.biz>2020-07-07 14:09:59 +0200
committerHector Fernandez <hector@iatec.biz>2020-07-07 14:09:59 +0200
commit9f89f02e7d6e2a3208b0b85d2567ebffd2515e09 (patch)
treebcf4dee36e9413513eb67a1745160668703a2e81 /test-cli/test_main.py
parent43f688b414ea182cd9baf06ee83df072c3f563f5 (diff)
downloadboard-9f89f02e7d6e2a3208b0b85d2567ebffd2515e09.zip
board-9f89f02e7d6e2a3208b0b85d2567ebffd2515e09.tar.gz
board-9f89f02e7d6e2a3208b0b85d2567ebffd2515e09.tar.bz2
New way to check preivous state before changing to a new one. Solved some problems with audio test.
Diffstat (limited to 'test-cli/test_main.py')
-rw-r--r--test-cli/test_main.py160
1 files changed, 82 insertions, 78 deletions
diff --git a/test-cli/test_main.py b/test-cli/test_main.py
index 8f82398..3da79f7 100644
--- a/test-cli/test_main.py
+++ b/test-cli/test_main.py
@@ -45,12 +45,71 @@ def clear():
_ = call('clear' if os.name == 'posix' else 'cls')
+def execute_station_error(text):
+ print("Error: {}".format(text))
+ loggerObj.getlogger().info("Station error: #{}#".format(text))
+ while True:
+ currentstate = psdbObj.read_station_state(globalVar.station)
+ if currentstate == StationStates.STATION_REBOOT.name:
+ os.system("reboot")
+ exit(1)
+ time.sleep(1)
+
+
+def check_first_state():
+ currentstate = psdbObj.read_station_state(globalVar.station)
+ if currentstate == StationStates.STATION_ERROR.name:
+ while True:
+ currentstate = psdbObj.read_station_state(globalVar.station)
+ if currentstate == StationStates.STATION_REBOOT.name:
+ os.system("reboot")
+ exit(1)
+ time.sleep(1)
+ elif currentstate == StationStates.STATION_REBOOT.name:
+ os.system("reboot")
+ exit(1)
+ else:
+ starttime = time.time()
+ while currentstate != StationStates.WAIT_TEST_START.name:
+ if time.time() - starttime >= 30.0:
+ # Error
+ execute_station_error("Timeout while waiting for WAIT_TEST_START state")
+ else:
+ time.sleep(5)
+ currentstate = psdbObj.read_station_state(globalVar.station)
+ if currentstate == StationStates.STATION_ERROR.name:
+ while True:
+ currentstate = psdbObj.read_station_state(globalVar.station)
+ if currentstate == StationStates.STATION_REBOOT.name:
+ os.system("reboot")
+ exit(1)
+ time.sleep(1)
+ elif currentstate == StationStates.STATION_REBOOT.name:
+ os.system("reboot")
+ exit(1)
+
+
+def set_next_state(newstate):
+ statewritten = psdbObj.change_station_state(globalVar.station, newstate)
+ if statewritten == StationStates.STATION_REBOOT.name:
+ os.system("reboot")
+ exit(1)
+ elif statewritten == StationStates.STATION_ERROR.name:
+ while True:
+ currentstate = psdbObj.read_station_state(globalVar.station)
+ if currentstate == StationStates.STATION_REBOOT.name:
+ os.system("reboot")
+ exit(1)
+ time.sleep(1)
+
+
def reboot_if_autotest():
# reset board if AUTOTEST is enabled
autotest = psdbObj.get_setup_variable("AUTOTEST_" + globalVar.station)
if int(autotest) == 1:
os.system('reboot')
+
def create_paramslist(params):
paramlist = {}
for row in params:
@@ -121,7 +180,7 @@ def create_testsuite():
paramlist["xml"] = xmlObj
paramlist["db"] = psdbObj
# add test to TestSuite
- rescode = add_test(suite1, testdefname, paramlist)
+ add_test(suite1, testdefname, paramlist)
return suite1
@@ -132,20 +191,16 @@ def create_board():
variant = cmd.getkvar("bvariant", "none")
if model_id == "none" or variant == "none":
- print("Error: Cannot open DB connection")
- loggerObj.getlogger().info("Station error: #Cannot get model and variant information#")
- reboot_if_autotest()
- exit(0)
+ # Error
+ execute_station_error("Cannot get model and variant information")
# get model id
globalVar.g_mid = model_id + "-" + variant
# get station
if "Station" not in globalVar.station:
- print("Error: Wrong Station name")
- loggerObj.getlogger().info("Station error: #Wrong station name#")
- reboot_if_autotest()
- exit(0)
+ # Error
+ execute_station_error("Wrong station name")
processor_id = get_die_id(globalVar.g_mid)
print(globalVar.g_mid)
@@ -170,13 +225,7 @@ def main():
# create a process
globalVar.testid_ctl = psdbObj.open_test(globalVar.g_uuid)
# Change state to "TESTS_RUNNING"
- if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
- # Abort
- print(
- "Error: Wrong previous station state before changing to TESTS_RUNNING state. STATION_ERROR state unexpected.")
- reboot_if_autotest()
- exit(0)
- psdbObj.change_station_state(globalVar.station, StationStates.TESTS_RUNNING.name)
+ set_next_state(StationStates.TESTS_RUNNING.name)
# generate suits
suite1 = create_testsuite()
@@ -191,21 +240,9 @@ def main():
# execute aditional tasks, only if the test was successful
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 before changing to TESTS_OK state. STATION_ERROR state unexpected.")
- reboot_if_autotest()
- exit(0)
- psdbObj.change_station_state(globalVar.station, StationStates.TESTS_OK.name)
+ set_next_state(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 before changing to EXTRATASKS_RUNNING state. STATION_ERROR state unexpected.")
- reboot_if_autotest()
- exit(0)
- psdbObj.change_station_state(globalVar.station, StationStates.EXTRATASKS_RUNNING.name)
+ set_next_state(StationStates.EXTRATASKS_RUNNING.name)
# create task control
globalVar.taskid_ctl = psdbObj.open_task(globalVar.g_uuid)
# get extra variables
@@ -235,13 +272,7 @@ def main():
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 before changing to WAITING_FOR_SCANNER state. STATION_ERROR state unexpected.")
- reboot_if_autotest()
- exit(0)
- psdbObj.change_station_state(globalVar.station, StationStates.WAITING_FOR_SCANNER.name)
+ set_next_state(StationStates.WAITING_FOR_SCANNER.name)
# get barcode using the scanner, only if autotest is disabled
autotest = psdbObj.get_setup_variable("AUTOTEST_" + globalVar.station)
@@ -271,13 +302,7 @@ def main():
loggerObj.getlogger().info("Station error: #Unable to complete extra tasks#")
else:
# Change state to "TESTS_FAILED"
- if psdbObj.read_station_state(globalVar.station) == StationStates.STATION_ERROR.name:
- # Abort
- print(
- "Error: Wrong previous station state before changing to TESTS_FAILED state. STATION_ERROR state unexpected.")
- reboot_if_autotest()
- exit(0)
- psdbObj.change_station_state(globalVar.station, StationStates.TESTS_FAILED.name)
+ set_next_state(StationStates.TESTS_FAILED.name)
# reset board if AUTOTEST is enabled
reboot_if_autotest()
@@ -295,34 +320,22 @@ if __name__ == "__main__":
try:
xmlObj = XMLSetup(os.path.join(test_abspath, "setup.xml"))
except:
- # Abort
- print("Error: Cannot parse setup.xml file")
- loggerObj.getlogger().info("Station error: #Cannot parse XML configuration file#")
- reboot_if_autotest()
- exit(0)
+ # Error
+ execute_station_error("Cannot parse setup.xml file")
# Try to connect to the DB, according to setup.xml configuration
if not psdbObj.open(xmlObj):
- print("Error: Cannot open DB connection")
- loggerObj.getlogger().info("Station error: #Cannot open DB connection#")
- reboot_if_autotest()
- exit(0)
+ # Error
+ execute_station_error("Cannot open DB connection")
# get station name
globalVar.station = socket.gethostname()
- # Check if current state is "WAIT_TEST_START"
- currentstate = psdbObj.read_station_state(globalVar.station)
- while currentstate != StationStates.WAIT_TEST_START.name:
- currentstate = psdbObj.read_station_state(globalVar.station)
- if currentstate != StationStates.WAIT_TEST_START.name:
- # Wait
- print("Error: Wrong previous station state. WAIT_TEST_START state expected. Current state is: {}".format(currentstate))
- print("Waiting for WAIT_TEST_START state")
- time.sleep(5)
+ # Check if current state is "WAIT_TEST_START". if not, waits here
+ check_first_state()
# Change state to "TESTS_CHECKING_ENV"
- psdbObj.change_station_state(globalVar.station, StationStates.TESTS_CHECKING_ENV.name)
+ set_next_state(StationStates.TESTS_CHECKING_ENV.name)
# Wait before beginning
time.sleep(2)
@@ -332,27 +345,18 @@ if __name__ == "__main__":
if qr.openQR():
qr.closeQR()
else:
- # Abort
- print("Error: Cannot find a barcode scanner.")
- loggerObj.getlogger().info("Station error: #Cannot find a barcode scanner#")
- reboot_if_autotest()
- exit(0)
+ # Error
+ execute_station_error("Cannot find a barcode scanner")
# 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#")
- reboot_if_autotest()
- exit(0)
+ # Error
+ execute_station_error("Cannot open an amperimeter COM port")
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#")
- reboot_if_autotest()
- exit(0)
+ # Error
+ execute_station_error("Cannot open find an amperimeter")
# Execute main
main()