Writing a test wrapper for HLA

I’d like to write a test wrapper for my ReSearch HLA that can run stand alone to test ReSearch’s behavior with different LLAs, without needing to actually generate suitable test data with each LLA!

I’ve tried:

import sys

sys.path.append("C:\\Program Files\\Logic\\resources\\windows-x64\\pythonlibs\\lib\\site-packages")

from saleae.analyzers import HighLevelAnalyzer, AnalyzerFrame

to get HighLevelAnalyzer and particularly AnalyzerFrame available to the test script, but that comes unstuck with:

Traceback (most recent call last):
File “D:\Projects\Logic2Extensions\ReSearch\testReSearch.py”, line 5, in
from saleae.analyzers import HighLevelAnalyzer, AnalyzerFrame
File “C:\Program Files\Logic\resources\windows-x64\pythonlibs\lib\site-packages\saleae\analyzers_init_.py”, line 1, in
from .high_level_analyzer import HighLevelAnalyzer, AnalyzerFrame
File “C:\Program Files\Logic\resources\windows-x64\pythonlibs\lib\site-packages\saleae\analyzers\high_level_analyzer.py”, line 3, in
from saleae.data import SaleaeTime
File “C:\Program Files\Logic\resources\windows-x64\pythonlibs\lib\site-packages\saleae\data_init_.py”, line 1, in
from .timing import SaleaeTime, SaleaeTimeDelta, SaleaeTimeInterval, GraphTime, GraphTimeDelta, GraphTimeInterval
ModuleNotFoundError: No module named ‘saleae.data.timing’

I see that salaea.data includes timing.pxd which is a cython file - something I know next to nothing about, but I presume means there is a compiled timing module tucked away somewhere that provides the Saleae time related classes.

Is there a way forward for me that allows me to make use of the modules used by Logic to support HLAs in a stand alone test script? If it is important (and not already clear from file paths) I’m working on a Windows system. For test purposes execution speed is not greatly important.

Hi Peter,

I’m not sure you will be able to test your HLA through that route - even if you are able to get the necessary Saleae Python native modules to load (which will likely require using exactly the same version of Python we use), it’s possible that they will require some initialization that is only done by the Logic software to work. That said, this development flow is very attractive and it’s on our list of ideas for V2.

Instead, I recommend running your unit tests from inside of the Logic 2 software. You can simply just run your tests either when your HLA module is loaded, or when your HLA class is constructed. HLA construction occurs each time a HLA is created. I can’t remember exactly how often we load modules.

we connect the built-in print() function to the analyzer terminal inside of the Logic 2 software, so you can just print your test results and find them there.

Hi Mark,

I’ve used “print debugging” in the past with HLAs, but it’s not my preferred software development methodology! :smiley:

This isn’t a big issue. I was doing a little work on my ReSearch HLA while I had a couple of uncommitted work days before heading off on leave and realized that there was scope for breaking existing code in the work I was doing. When I get a few toits available maybe I’ll have a go at mocking up enough of the API described in the API documentation to write a stand alone test suite. Ideally I don’t want to pollute the HLA with test code!

So, I have a “solution” to the testing issue. I mock up the Saleae modules in a MockSaleae folder. The mocked modules are fundamentally copies of the real modules with the option of subverting them as needed for testing and to allow them to run without the infrastructure they expect to see. I can then write a test script like:

import sys


from saleae.analyzers import HighLevelAnalyzer, AnalyzerFrame
import ReSearch

def RunSearch(searcher, frames):
    for frame in frames:
        result = searcher.decode(frame)

        if result != None:
            print("Match ('" + result.data["Matched"] + "') found starting at " \
                  + str(result.start_time))

frames = []
frames.append(AnalyzerFrame("data", 0.0, 100e-6))
frames[-1].data = {'data': bytearray("The quick brown", "ascii")}
frames.append(AnalyzerFrame("data", 200.0e-6, 300e-6))
frames[-1].data = {'data': bytearray(" fox jumps over the l", "ascii")}
frames.append(AnalyzerFrame("data", 400.0e-6, 500e-6))
frames[-1].data = {'data': bytearray("azy dog", "ascii")}
frames.append(AnalyzerFrame("data", 1500.0e-6, 1550e-6))
frames[-1].data = {'data': bytearray(" 358281.2", "ascii")}
frames.append(AnalyzerFrame("data", 1560.0e-6, 1570e-6))
frames[-1].data = {'data': bytearray("1", "ascii")}
frames.append(AnalyzerFrame("data", 1570.0e-6, 1600e-6))
frames[-1].data = {'data': bytearray("5543", "ascii")}
frames.append(AnalyzerFrame("data", 2000.0e-6, 2010e-6))
frames[-1].data = {'data': bytearray(" ", "ascii")}

searcher = ReSearch.ReSearch({'kMatchStr': '1\.2\d+', "kMatchTime": '0.1'})
RunSearch(searcher, frames)

and debug it using whatever tools I usually use for debugging Python scripts. For interest I’ve attached the MockSaleae folder structure and contents I’ve been using for debugging my ReSearch HLA. The folder for TeSearch lives in the same folder that contains the MockSaleae folder.

MockSaleae.zip (6.9 KB)

1 Like