summaryrefslogtreecommitdiff
path: root/test-cli
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli')
-rw-r--r--test-cli/.idea/workspace.xml4
-rw-r--r--test-cli/test/enums/StationStates.py1
-rw-r--r--test-cli/test/helpers/testsrv_db.py4
-rw-r--r--test-cli/test/tests/qaudio.py5
-rw-r--r--test-cli/test_main.py160
5 files changed, 93 insertions, 81 deletions
diff --git a/test-cli/.idea/workspace.xml b/test-cli/.idea/workspace.xml
index 1d513ac..31b0cdc 100644
--- a/test-cli/.idea/workspace.xml
+++ b/test-cli/.idea/workspace.xml
@@ -3,7 +3,9 @@
<component name="ChangeListManager">
<list default="true" id="4991a6e0-1b9d-4824-9b6e-5ac031eb4816" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/test/tests/qusbdual.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qusbdual.py" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/test/enums/StationStates.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/enums/StationStates.py" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/test/helpers/testsrv_db.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/helpers/testsrv_db.py" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/test/tests/qaudio.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/tests/qaudio.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test_main.py" beforeDir="false" afterPath="$PROJECT_DIR$/test_main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
diff --git a/test-cli/test/enums/StationStates.py b/test-cli/test/enums/StationStates.py
index 9de5e15..040e6bc 100644
--- a/test-cli/test/enums/StationStates.py
+++ b/test-cli/test/enums/StationStates.py
@@ -17,4 +17,5 @@ class StationStates(Enum):
EXTRATASKS_RUNNING = 100
WAITING_FOR_SCANNER = 50
FINISHED = 60
+ STATION_REBOOT = 2001
diff --git a/test-cli/test/helpers/testsrv_db.py b/test-cli/test/helpers/testsrv_db.py
index 7eeefb3..9579e7e 100644
--- a/test-cli/test/helpers/testsrv_db.py
+++ b/test-cli/test/helpers/testsrv_db.py
@@ -197,7 +197,9 @@ class TestSrv_Database(object):
sql = "SELECT station.setmystate('{}', '{}', NULL)".format(newstate, station)
# print('>>>' + sql)
try:
- self.__sqlObject.db_execute_query(sql)
+ res = self.__sqlObject.db_execute_query(sql)
+ # print(res)
+ return res[0][0]
except Exception as err:
r = find_between(str(err), '#', '#')
# print(r)
diff --git a/test-cli/test/tests/qaudio.py b/test-cli/test/tests/qaudio.py
index 364d8b2..3d2113a 100644
--- a/test-cli/test/tests/qaudio.py
+++ b/test-cli/test/tests/qaudio.py
@@ -28,7 +28,10 @@ class Qaudio(unittest.TestCase):
# analize audio file
recordtime = calc_audio_duration("/var/lib/hwtest-files/dtmf-13579.wav") + 0.15
# previous play to estabilise audio lines
- sh.aplay("/var/lib/hwtest-files/dtmf-13579.wav")
+ p1 = sh.aplay("/var/lib/hwtest-files/dtmf-13579.wav", _bg=True)
+ p2 = sh.arecord("-r", 8000, "-d", recordtime, "/mnt/station_ramdisk/recorded.wav", _bg=True)
+ p1.wait()
+ p2.wait()
# play and record
p1 = sh.aplay("/var/lib/hwtest-files/dtmf-13579.wav", _bg=True)
p2 = sh.arecord("-r", 8000, "-d", recordtime, "/mnt/station_ramdisk/recorded.wav", _bg=True)
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()