Skip to content

Commit

Permalink
Clean up existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Oct 15, 2024
1 parent 7bcfcb2 commit 346696b
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 83 deletions.
35 changes: 19 additions & 16 deletions run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,41 @@
'basic_record.py',
'get_set_recording_info.py',
'config_audio_device.py',
#'round_trip_record.py',
'round_trip_record.py',
)

#TODO: Add more plugin tests
plugin_tests = (
'channel_map.py',
)

GHA = os.getenv("GITHUB_ACTIONS") == "true"

LOCAL_MAC_PATH = '/Volumes/T7/test-suite/'

RECORD_PATH = ''
if platform.system() == 'Windows':
if GHA: RECORD_PATH = 'C:\\open-ephys\\data'
else:
pass #define local path here
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_WINDOWS_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_WINDOWS_LOCAL_RECORD_PATH')
elif platform.system() == 'Linux':
if GHA: pass #RECORD_PATH = '<path/to/linux/runner>' # TODO
else:
pass #define local path here
else: #macos
if GHA: pass #RECORD_PATH = '<path/to/Mac/runner>' # TODO
else: RECORD_PATH = LOCAL_MAC_PATH
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_LINUX_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_LINUX_LOCAL_RECORD_PATH')
else:
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_MAC_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_MAC_LOCAL_RECORD_PATH')

for test in gui_tests + plugin_tests:
print("--------------------------------")
print("Running: ", test[:-3])
print("Start time: ", datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
print("--------------------------------")
rc = os.system(f"python3 ./tests/{test} --parent_directory {RECORD_PATH}")
rc = os.system(f"python3 ./tests/{test}")
if rc != 0:
print("TEST FAILED: ", test)
break

#remove any files that were created during the current test
os.system("rm -rf " + RECORD_PATH + "/*")

time.sleep(1)
18 changes: 8 additions & 10 deletions tests/basic_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ def test(gui, params):

for _, stream in enumerate(recording.continuous):

SAMPLE_RATE = stream.metadata['sample_rate']
SAMPLE_NUM_TOLERANCE = 0.1 * SAMPLE_RATE

# Validate amount of continuous data recorded is within range
testName = "Recording %d length" % (rec_idx+1)
condition = np.absolute(len(stream.timestamps) - params['rec_time']*SAMPLE_RATE) < SAMPLE_NUM_TOLERANCE
testName = f"Recording {rec_idx+1} data size"
expected_samples = params['rec_time'] * stream.metadata['sample_rate']
condition = np.isclose(len(stream.timestamps), expected_samples, atol=0.05 * expected_samples)
if condition: results[testName] = "PASSED"
else: results[testName] = "FAILED\nExpected: %d\nActual: %d" % (params['rec_time']*stream.metadata['sample_rate'], len(stream.timestamps))
else: results[testName] = "FAILED\nExpected: %d\nActual: %d" % (expected_samples, len(stream.timestamps))

# Validate spikes were written in the second record node
testName = "Spikes recorded"
testName = f"Recording {rec_idx+1} spike count"
condition = node_idx == 1 and len(recording.spikes) > 0
if condition: results[testName] = "PASSED"
else: results[testName] = "FAILED\nExpected: >0\nActual: %d" % len(recording.spikes)
Expand Down Expand Up @@ -108,8 +106,8 @@ def test(gui, params):
parser.add_argument('--cfg_path', required=False, type=str, default=os.path.join(Path(__file__).resolve().parent, '../configs/file_reader_config.xml'))
parser.add_argument('--acq_time', required=False, type=int, default=2)
parser.add_argument('--rec_time', required=False, type=int, default=5)
parser.add_argument('--num_rec', required=False, type=int, default=1)
parser.add_argument('--num_exp', required=False, type=int, default=1)
parser.add_argument('--num_rec', required=False, type=int, default=2)
parser.add_argument('--num_exp', required=False, type=int, default=2)
parser.add_argument('--prepend_text', required=False, type=str, default='')
parser.add_argument('--base_text', required=False, type=str, default='')
parser.add_argument('--append_text', required=False, type=str, default='')
Expand All @@ -120,4 +118,4 @@ def test(gui, params):
results = test(OpenEphysHTTPServer(), params)

for test, result in results.items():
print(test, '-'*(80-len(test)), result)
print(test, '-'*(80-len(test)), result)
27 changes: 17 additions & 10 deletions tests/channel_map.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import time

import numpy as np

from open_ephys.control import OpenEphysHTTPServer
from open_ephys.analysis import Session

import numpy as np

"""
Test Name: Channel Map Recording
Test Description: Verify mapped channels are re-ordered/disabled as expected.
"""

def test(gui, params):

results = {}
Expand All @@ -26,8 +25,8 @@ def test(gui, params):
gui.acquire()
time.sleep(params['acq_time'])
gui.record()
time.sleep(params['rec_time'])

time.sleep(params['rec_time'])
gui.idle()

# Validate results
Expand Down Expand Up @@ -67,17 +66,26 @@ def test(gui, params):
from pathlib import Path

if platform.system() == 'Windows':
RECORD_PATH = 'C:\\open-ephys\\data'
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_WINDOWS_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_WINDOWS_LOCAL_RECORD_PATH')
elif platform.system() == 'Linux':
RECORD_PATH = '<path/to/linux/runner>' #TODO
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_LINUX_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_LINUX_LOCAL_RECORD_PATH')
else:
RECORD_PATH = '/Users/pavelkulik/Projects/Allen/OpenEphys/data/test-suite'
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_MAC_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_MAC_LOCAL_RECORD_PATH')

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Process some integers.')
parser = argparse.ArgumentParser(description='Test Channel Map Functionality')
parser.add_argument('--fetch', required=False, type=int, default=1)
parser.add_argument('--address', required=False, type=str, default='http://127.0.0.1')
parser.add_argument('--parent_directory', required=False, type=str, default=RECORD_PATH)
parser.add_argument('--cfg_path', required=False, type=str, default=os.path.join(Path(__file__).resolve().parent, '../configs/channel_map.xml'))
parser.add_argument('--acq_time', required=False, type=int, default=2)
parser.add_argument('--rec_time', required=False, type=int, default=5)
Expand All @@ -86,7 +94,6 @@ def test(gui, params):
parser.add_argument('--prepend_text', required=False, type=str, default='')
parser.add_argument('--base_text', required=False, type=str, default='')
parser.add_argument('--append_text', required=False, type=str, default='')
parser.add_argument('--parent_directory', required=False, type=str, default=RECORD_PATH)
parser.add_argument('--engine', required=False, type=str, default='engine=0')

params = vars(parser.parse_args(sys.argv[1:]))
Expand Down
46 changes: 26 additions & 20 deletions tests/config_audio_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,23 @@ def test(gui, params):

SAMPLE_NUM_TOLERANCE = 0.025 * SAMPLE_RATE*params['rec_time']

testName = '----------------------------------------------------------------------------------------------------------------\n'
testName += f"Recording w/ buffer size {buffer_size} sample rate {sample_rate}\n"
testName += '----------------------------------------------------------------------------------------------------------------\n'
testName += f"% GUI CPU: Acquire {100 * float(gui_acquire_cpu['usage']):.1f} Record {100 * float(gui_record_cpu['usage']):.1f}\n"
testName += f"% PS CPU: Acquire {ps_acquire_cpu:.1f} Record {ps_record_cpu:.1f}\n"
testName += f"Latency: Acquire\n"
testName = f"Recording w/ buffer size {buffer_size} sample rate {sample_rate}"
stats = f"% GUI CPU: Acquire {100 * float(gui_acquire_cpu['usage']):.1f} Record {100 * float(gui_record_cpu['usage']):.1f}\n"
stats += f"% PS CPU: Acquire {ps_acquire_cpu:.1f} Record {ps_record_cpu:.1f}\n"
stats += f"Latency: Acquire\n"
for processor in latency_acquire['processors']:
testName += f"\t{processor['name']}: {processor['id']}\n"
stats += f"\t{processor['name']}: {processor['id']}\n"
for data_stream in processor['streams']:
testName += f"\t\t{data_stream['name']}: {1000*data_stream['latency']:.1f} us\n"
testName += f"Latency: Record\n"
stats += f"\t\t{data_stream['name']}: {1000*data_stream['latency']:.1f} us\n"
stats += f"Latency: Record\n"
for processor in latency_record['processors']:
testName += f"\t{processor['name']}: {processor['id']}\n"
stats += f"\t{processor['name']}: {processor['id']}\n"
for data_stream in processor['streams']:
testName += f"\t\t{data_stream['name']}: {1000*data_stream['latency']:.1f} us\n"
stats += f"\t\t{data_stream['name']}: {1000*data_stream['latency']:.1f} us\n"

condition = abs(stream.samples.shape[0] - SAMPLE_RATE * params['rec_time']) < SAMPLE_NUM_TOLERANCE
if condition: results[testName] = "PASSED"
else: results[testName] = "FAILED\n\tExpected: %d\n\tActual: %d" % (SAMPLE_RATE * params['rec_time'], stream.samples.shape[0])
if condition: results[testName] = "PASSED\n" + stats
else: results[testName] = "FAILED\n\tExpected: %d\n\tActual: %d" % (SAMPLE_RATE * params['rec_time'], stream.samples.shape[0]) + "\n" + stats

record_count += 1

Expand All @@ -159,17 +157,26 @@ def test(gui, params):
from pathlib import Path

if platform.system() == 'Windows':
RECORD_PATH = 'C:\\open-ephys\\data'
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_WINDOWS_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_WINDOWS_LOCAL_RECORD_PATH')
elif platform.system() == 'Linux':
RECORD_PATH = '<path/to/linux/runner>' #TODO
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_LINUX_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_LINUX_LOCAL_RECORD_PATH')
else:
RECORD_PATH = '<path/to/mac/runner>' #TODO
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_MAC_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_MAC_LOCAL_RECORD_PATH')

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Process some integers.')
parser = argparse.ArgumentParser(description='Test Audio Device Configuration')
parser.add_argument('--fetch', required=False, type=int, default=1)
parser.add_argument('--address', required=False, type=str, default='http://127.0.0.1')
parser.add_argument('--parent_directory', required=False, type=str, default=RECORD_PATH)
parser.add_argument('--cfg_path', required=False, type=str, default=os.path.join(Path(__file__).resolve().parent, '../configs/file_reader_config.xml'))
parser.add_argument('--acq_time', required=False, type=int, default=2)
parser.add_argument('--rec_time', required=False, type=int, default=5)
Expand All @@ -178,12 +185,11 @@ def test(gui, params):
parser.add_argument('--prepend_text', required=False, type=str, default='')
parser.add_argument('--base_text', required=False, type=str, default='')
parser.add_argument('--append_text', required=False, type=str, default='')
parser.add_argument('--parent_directory', required=False, type=str, default=RECORD_PATH)
parser.add_argument('--engine', required=False, type=str, default='engine=0')

params = vars(parser.parse_args(sys.argv[1:]))

results = test(OpenEphysHTTPServer(), params)

for test, result in results.items():
print(test, '-'*(100-len(test)), result)
print(test, '-'*(80-len(test)), result)
62 changes: 43 additions & 19 deletions tests/get_set_recording_info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from open_ephys.control import OpenEphysHTTPServer
from open_ephys.analysis import Session

import time
import os
import time

"""
Test Name: Set recording info
Test Description: Set recording names and locations for Record Nodes
"""
def test(gui, params):

# Fetch fresh data if needed
Expand All @@ -18,30 +23,31 @@ def test(gui, params):

time.sleep(3)

# Set the parent directory
gui.set_parent_dir(params['parent_directory'])
# Set a new parent directory to get applied to new RecordNodes
os.makedirs(os.path.join(params['parent_directory'], 'test'), exist_ok=True)
gui.set_parent_dir(os.path.join(params['parent_directory'], 'test'))

# Set all record node engines
# Set all record node paths and engines
for node in gui.get_processors("Record Node"):
gui.set_record_path(node['id'], params['parent_directory'])
gui.set_record_engine(node['id'], params['engine'])

# Add record node after Spike Viewer
gui.add_processor("Record Node")
gui.add_processor("Record Node") # (should use new parent dir)

# Check only the latest RecordNode has the new parent directory
nodeDirectories = {}
for node in gui.get_recording_info()['record_nodes']:
nodeDirectories[node['node_id']] = node['parent_directory']
print("%d : %s" % (node['node_id'], node['parent_directory']))
print(f"Set path for Record Node {node['node_id']} to {node['parent_directory']}")

# Only latest RecordNode will have the newly set parent directory
testName = 'Set recording names and locations'

# Run some actions and record data
for n in range(params['num_exp']):

#Start a new directory only for the third experiment
if n == 2:
gui.set_start_new_dir()
if n == 2: gui.set_start_new_dir()

for _ in range(params['num_rec']):

Expand All @@ -52,11 +58,13 @@ def test(gui, params):

gui.idle()

root_folder = params['prepend_text'] + params['base_text'] + params['append_text']

#Find the expected recordings
for node, dir in nodeDirectories.items():
condition = len(gui.get_latest_recordings(dir, count=2)) == 2
if condition: results["Recording write path for node %d" % node] = "PASSED"
else: results["Recording write path for node %d" % node] = f"FAILED"
condition = len(gui.get_latest_recordings(os.path.join(dir, root_folder))) == 1
if condition: results[f"Recording write path for Record Node {node}"] = "PASSED"
else: results[f"Recording write path for Record Node {node}"] = "FAILED"

# reset to default settings
gui.set_prepend_text('')
Expand All @@ -73,23 +81,39 @@ def test(gui, params):
import os
import sys
import argparse
import platform

from pathlib import Path

if platform.system() == 'Windows':
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_WINDOWS_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_WINDOWS_LOCAL_RECORD_PATH')
elif platform.system() == 'Linux':
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_LINUX_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_LINUX_LOCAL_RECORD_PATH')
else:
if os.getenv("GITHUB_ACTIONS"):
RECORD_PATH = os.getenv('OE_MAC_GITHUB_RECORD_PATH')
else: # custom local path
RECORD_PATH = os.getenv('OE_MAC_LOCAL_RECORD_PATH')

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Process some integers.')
parser = argparse.ArgumentParser(description='Test Processor Graph Actions')
parser.add_argument('--fetch', required=False, type=int, default=1)
parser.add_argument('--address', required=False, type=str, default='http://127.0.0.1')
parser.add_argument('--parent_directory', required=False, type=str, default=RECORD_PATH)
parser.add_argument('--cfg_path', required=False, type=str, default=os.path.join(Path(__file__).resolve().parent, '../configs/file_reader_config.xml'))
parser.add_argument('--acq_time', required=False, type=int, default=2)
parser.add_argument('--rec_time', required=False, type=int, default=5)
parser.add_argument('--num_rec', required=False, type=int, default=1)
parser.add_argument('--num_exp', required=False, type=int, default=3)
parser.add_argument('--prepend_text', required=False, type=str, default='alice')
parser.add_argument('--base_text', required=False, type=str, default='test')
parser.add_argument('--append_text', required=False, type=str, default='auto')
parser.add_argument('--parent_directory', required=False, type=str, default='C:\\open-ephys\\data')
parser.add_argument('--num_exp', required=False, type=int, default=1)
parser.add_argument('--prepend_text', required=False, type=str, default='abc')
parser.add_argument('--base_text', required=False, type=str, default='main')
parser.add_argument('--append_text', required=False, type=str, default='xyz')
parser.add_argument('--engine', required=False, type=str, default='engine=0')

params = vars(parser.parse_args(sys.argv[1:]))
Expand Down
Loading

0 comments on commit 346696b

Please sign in to comment.