mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-06 15:04:11 +00:00
Startup and communication bugfixes
- reduce amount of mode switched when starting and loading setups - improve logging for errors during HIL tests - fix small USB communication bugs
This commit is contained in:
parent
733d0ffbf4
commit
ca25969574
14 changed files with 148 additions and 44 deletions
|
|
@ -4,43 +4,72 @@ import tests.definitions as defs
|
|||
import subprocess
|
||||
import time
|
||||
import select
|
||||
import os
|
||||
from signal import SIGINT
|
||||
|
||||
class TestBase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.gui = subprocess.Popen([defs.GUI_PATH, '-p', '19544', '--reset-preferences', '--no-gui', '-platform', 'offscreen'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
f = open("log.txt", "w")
|
||||
self.gui = subprocess.Popen([defs.GUI_PATH, '-p', '19544', '--reset-preferences', '--no-gui', '-platform', 'offscreen'], stdout=f, stderr=subprocess.STDOUT)
|
||||
|
||||
# wait for the SCPI server to become available
|
||||
timeout = time.time() + 3;
|
||||
poll_obj = select.poll()
|
||||
poll_obj.register(self.gui.stdout, select.POLLIN)
|
||||
fread = open("log.txt", "r")
|
||||
while True:
|
||||
poll_result = poll_obj.poll(0)
|
||||
if poll_result:
|
||||
line = self.gui.stdout.readline().decode().strip()
|
||||
if "Listening on port 19544" in line:
|
||||
break
|
||||
text = fread.read()
|
||||
if text and "Listening on port 19544" in text:
|
||||
break
|
||||
if time.time() >= timeout:
|
||||
self.tearDown()
|
||||
raise AssertionError("Timed out waiting for SCPI server")
|
||||
|
||||
self.vna = libreVNA('localhost', 19544, timeout=4)
|
||||
try:
|
||||
self.vna.cmd("*CLS;:DEV:CONN")
|
||||
self.vna.cmd("*CLS")
|
||||
except Exception as e:
|
||||
self.tearDown()
|
||||
raise e
|
||||
if self.vna.query(":DEV:CONN?") == "Not connected":
|
||||
self.tearDown()
|
||||
raise AssertionError("Not connected")
|
||||
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
if hasattr(self._outcome, 'errors'):
|
||||
# Python 3.4 - 3.10 (These two methods have no side effects)
|
||||
result = self.defaultTestResult()
|
||||
self._feedErrorsToResult(result, self._outcome.errors)
|
||||
else:
|
||||
# Python 3.11+
|
||||
result = self._outcome.result
|
||||
ok = all(test != self for test, text in result.errors + result.failures)
|
||||
|
||||
if not ok:
|
||||
try:
|
||||
# Try to grab the packet log and save it
|
||||
packetlog = self.vna.query(":DEV:PACKETLOG?", timeout=5)
|
||||
f = open("packetlog_"+time.strftime("%Y%m%d%H%M%S.vnalog"), "w")
|
||||
f.write(packetlog)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
# make sure the GUI did not crash during the test
|
||||
self.assertEqual(self.gui.poll(), None)
|
||||
crashed = self.gui.poll() is not None
|
||||
self.gui.send_signal(SIGINT)
|
||||
try:
|
||||
self.gui.wait(timeout = 3)
|
||||
except subprocess.TimeoutExpired:
|
||||
self.gui.kill()
|
||||
|
||||
|
||||
if ok and not crashed:
|
||||
# remove log file
|
||||
os.remove("log.txt")
|
||||
else:
|
||||
os.rename("log.txt", "errorlog_"+time.strftime("%Y%m%d%H%M%S.txt"))
|
||||
|
||||
if(crashed):
|
||||
raise Exception("GUI crashed")
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue