-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1404 from keyboardio/bugfix/eeprom-settings-loadi…
…ng-regression It turns out that our templated storage().get() method silently fails
- Loading branch information
Showing
16 changed files
with
168 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
68 changes: 68 additions & 0 deletions
68
testing/device-testing/spacecadet-off/space_cadet_off_after_reboot_and_reset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
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_spacecadet_mode_persistence(self): | ||
_, _ = run_focus_command("version") | ||
|
||
# Initially try to erase eeprom and expect an error | ||
_, returncode = run_focus_command("eeprom.erase", hide_stderr=True) | ||
self.assertNotEqual(returncode, 0, "Eeprom erase should fail but did not.") | ||
|
||
#erasing eeprom takes a moment | ||
time.sleep(5) | ||
|
||
# Verify initial spacecadet mode is '1' | ||
initial_mode, _ = run_focus_command("spacecadet.mode") | ||
self.assertEqual(initial_mode, '1', "Initial spacecadet.mode should be '1'") | ||
|
||
# Change spacecadet mode to 0 and verify | ||
run_focus_command("spacecadet.mode 0") | ||
mode_after_setting_to_0, _ = run_focus_command("spacecadet.mode") | ||
self.assertEqual(mode_after_setting_to_0, '0', "spacecadet.mode should be '0' after setting to 0") | ||
|
||
# Reset device and expect an error | ||
_, returncode = run_focus_command("device.reset", hide_stderr=True) | ||
self.assertNotEqual(returncode, 0, "Device reset should fail but did not.") | ||
time.sleep(5) # Wait for the device to potentially reset | ||
|
||
# Verify spacecadet mode is still 0 after reset | ||
mode_after_reset, _ = run_focus_command("spacecadet.mode") | ||
self.assertEqual(mode_after_reset, '0', "spacecadet.mode should remain '0' after reset") | ||
|
||
# Change spacecadet mode to 1 and verify | ||
run_focus_command("spacecadet.mode 1") | ||
mode_after_setting_to_1, _ = run_focus_command("spacecadet.mode") | ||
self.assertEqual(mode_after_setting_to_1, '1', "spacecadet.mode should be '1' after setting to 1") | ||
|
||
# Reset device again and expect an error | ||
_, returncode = run_focus_command("device.reset", hide_stderr=True) | ||
self.assertNotEqual(returncode, 0, "Device reset should fail but did not.") | ||
time.sleep(5) # Wait for the device to potentially reset | ||
|
||
# Verify spacecadet mode is still 1 after reset | ||
mode_final, _ = run_focus_command("spacecadet.mode") | ||
self.assertEqual(mode_final, '1', "spacecadet.mode should remain '1' after final reset") | ||
|
||
# Try to erase eeprom again and expect an error | ||
_, returncode = run_focus_command("eeprom.erase", hide_stderr=True) | ||
self.assertNotEqual(returncode, 0, "Eeprom erase should fail but did not.") | ||
|
||
time.sleep(5) # Wait for the device to potentially reset | ||
|
||
# Verify spacecadet mode is still 1 after attempting to erase eeprom | ||
mode_after_erase, _ = run_focus_command("spacecadet.mode") | ||
self.assertEqual(mode_after_erase, '1', "spacecadet.mode should remain '1' after attempting to erase eeprom") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |