Skip to content

Commit

Permalink
Add a basic eeprom persistence test script a developer can use to verify
Browse files Browse the repository at this point in the history
eeprom persistence
  • Loading branch information
obra committed Mar 7, 2024
1 parent 7294516 commit 258963f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions testing/device-testing/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Things inside this directory are tools and scripts intended for interactive testing with a specific device attached. At this time, they're not intended for automated testing under CI.

Things that might be here include tests of the focus protocol or tests of on-device EEPROM/Storage.

These tests may require locally installed tools.

(There are dragons in this directory and we deemed it better to keep this stuff around in the hopes of eventually getting it automated than throwing it away.)
1 change: 1 addition & 0 deletions testing/device-testing/eeprom-persistence/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This test script does basic tests to ensure eeprom persistence across a reboot
55 changes: 55 additions & 0 deletions testing/device-testing/eeprom-persistence/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import subprocess
import unittest
import time

def run_focus_command(command, hide_stderr=False):
"""Execute a focus send command, print the command and its output, and return its output."""
stderr_setting = subprocess.DEVNULL if hide_stderr else subprocess.PIPE
print(f"Running command: {command}")
completed_process = subprocess.run(f"focus send {command}", shell=True, stdout=subprocess.PIPE, stderr=stderr_setting, text=True)
print(f"Result: {completed_process.stdout.strip()}")
if completed_process.returncode != 0 and not hide_stderr:
print(f"Error: {completed_process.stderr.strip()}" if completed_process.stderr else "Command failed with no error output.")
return completed_process.stdout.strip(), completed_process.returncode


class TestFocusCommands(unittest.TestCase):
def test_focus_commands(self):
# Test 'focus send version', log the result, and store as initial version
initial_version, _ = run_focus_command("version")

# Test 'focus send escape_oneshot.cancel_key' and log the result
cancel_key_result_initial, _ = run_focus_command("escape_oneshot.cancel_key")

run_focus_command("escape_oneshot.cancel_key 45")

new_version, _ = run_focus_command("escape_oneshot.cancel_key")
self.assertEqual(new_version, '45', "New version should be '45'")

# Expect 'focus send device.reset' to error
reset_result, returncode = run_focus_command("device.reset", hide_stderr=True)
self.assertNotEqual(returncode, 0, "Expected non-zero exit code for device.reset")
time.sleep(2) # Add a 5-second delay here

new_version, _ = run_focus_command("escape_oneshot.cancel_key")
self.assertEqual(new_version, '45', "New version should be '45'")


# Set new value for escape_oneshot.cancel_key and verify no action needed
run_focus_command("escape_oneshot.cancel_key 30")

# Fetch new version and ensure it's '30'
new_version, _ = run_focus_command("escape_oneshot.cancel_key")
self.assertEqual(new_version, '30', "New version should be '30'")

# Expect 'focus send device.reset' to error
reset_result, returncode = run_focus_command("device.reset", hide_stderr=True)
self.assertNotEqual(returncode, 0, "Expected non-zero exit code for device.reset")
time.sleep(2) # Add a 5-second delay here

# Test 'focus send escape_oneshot.cancel_key' again and ensure it matches new version
final_version, _ = run_focus_command("escape_oneshot.cancel_key")
self.assertEqual(final_version, new_version, "Final version should match new version after reset")

if __name__ == '__main__':
unittest.main()

0 comments on commit 258963f

Please sign in to comment.