test with 0.7.5 files, which has an expanded config section

This commit is contained in:
Brian S. Stephan 2023-11-06 23:55:01 -06:00
parent a681a8e6a0
commit fcb1297139
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
15 changed files with 529 additions and 173 deletions

View File

@ -11,9 +11,9 @@ from gp2040ce_bintools.pico import get_bootsel_endpoints, read
logger = logging.getLogger(__name__)
STORAGE_BINARY_LOCATION = 0x1FE000
STORAGE_MEMORY_ADDRESS = 0x101FE000
STORAGE_SIZE = 8192
STORAGE_BINARY_LOCATION = 0x1FC000
STORAGE_MEMORY_ADDRESS = 0x101FC000
STORAGE_SIZE = 16384
FOOTER_SIZE = 12
FOOTER_MAGIC = b'\x65\xe3\xf1\xd2'
@ -232,7 +232,7 @@ def visualize():
group.add_argument('--usb', action='store_true', help="retrieve the config from a Pico board connected over USB "
"and in BOOTSEL mode")
group.add_argument('--filename', help=".bin file of a GP2040-CE board's storage section, bytes "
"101FE000-10200000, or of a GP2040-CE's whole board dump "
"101FC000-10200000, or of a GP2040-CE's whole board dump "
"if --whole-board is specified")
args, _ = parser.parse_known_args()

View File

@ -28,7 +28,7 @@ def firmware_binary():
@pytest.fixture
def storage_dump():
"""Read in a test storage dump file (101FE000-10200000) of a GP2040-CE board."""
"""Read in a test storage dump file (101FC000-10200000) of a GP2040-CE board."""
filename = os.path.join(HERE, 'test-files', 'test-storage-area.bin')
with open(filename, 'rb') as file:
content = file.read()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,7 @@ message GamepadOptions
optional bool lockHotkeys = 7;
optional bool fourWayMode = 8;
optional uint32 profileNumber = 9;
optional PS4ControllerType ps4ControllerType = 10;
}
message KeyboardMapping
@ -116,6 +117,40 @@ message PinMappings
optional int32 pinButtonFn = 19;
}
message GpioMappings
{
optional GpioAction pin00 = 1;
optional GpioAction pin01 = 2;
optional GpioAction pin02 = 3;
optional GpioAction pin03 = 4;
optional GpioAction pin04 = 5;
optional GpioAction pin05 = 6;
optional GpioAction pin06 = 7;
optional GpioAction pin07 = 8;
optional GpioAction pin08 = 9;
optional GpioAction pin09 = 10;
optional GpioAction pin10 = 11;
optional GpioAction pin11 = 12;
optional GpioAction pin12 = 13;
optional GpioAction pin13 = 14;
optional GpioAction pin14 = 15;
optional GpioAction pin15 = 16;
optional GpioAction pin16 = 17;
optional GpioAction pin17 = 18;
optional GpioAction pin18 = 19;
optional GpioAction pin19 = 20;
optional GpioAction pin20 = 21;
optional GpioAction pin21 = 22;
optional GpioAction pin22 = 23;
optional GpioAction pin23 = 24;
optional GpioAction pin24 = 25;
optional GpioAction pin25 = 26;
optional GpioAction pin26 = 27;
optional GpioAction pin27 = 28;
optional GpioAction pin28 = 29;
optional GpioAction pin29 = 30;
}
message AlternativePinMappings
{
@ -127,6 +162,10 @@ message AlternativePinMappings
optional int32 pinButtonR1 = 6;
optional int32 pinButtonL2 = 7;
optional int32 pinButtonR2 = 8;
optional int32 pinDpadUp = 9;
optional int32 pinDpadDown = 10;
optional int32 pinDpadLeft = 11;
optional int32 pinDpadRight = 12;
}
@ -159,6 +198,7 @@ message DisplayOptions
optional bool invert = 16;
optional int32 displaySaverTimeout = 17;
optional bool turnOffWhenSuspended = 18;
}
message LEDOptions
@ -195,6 +235,8 @@ message LEDOptions
optional int32 pledPin3 = 28;
optional int32 pledPin4 = 29;
optional uint32 pledColor = 30;
optional bool turnOffWhenSuspended = 31;
};
// This has to be kept in sync with AnimationOptions in AnimationStation.hpp
@ -263,10 +305,17 @@ message AnalogOptions
{
optional bool enabled = 1;
optional int32 analogAdcPinX = 2;
optional int32 analogAdcPinY = 3;
optional int32 analogAdc1PinX = 2;
optional int32 analogAdc1PinY = 3;
optional bool forced_circularity = 4;
optional uint32 analog_deadzone = 5;
optional int32 analogAdc2PinX = 6;
optional int32 analogAdc2PinY = 7;
optional DpadMode analogAdc1Mode = 8;
optional DpadMode analogAdc2Mode = 9;
optional InvertMode analogAdc1Invert = 10;
optional InvertMode analogAdc2Invert = 11;
optional bool auto_calibrate = 12;
}
message TurboOptions
@ -298,20 +347,23 @@ message SliderOptions
{
optional bool enabled = 1;
optional int32 pinLS = 2;
optional int32 pinRS = 3;
optional int32 deprecatedPinSliderOne = 2;
optional int32 deprecatedPinSliderTwo = 3;
optional DpadMode deprecatedModeOne = 4;
optional DpadMode deprecatedModeTwo = 5;
optional DpadMode modeDefault = 6;
}
message SOCDSliderOptions
{
optional bool enabled = 1;
optional int32 pinOne = 2;
optional int32 pinTwo = 3;
optional int32 deprecatedPinOne = 2;
optional int32 deprecatedPinTwo = 3;
optional SOCDMode modeDefault = 4;
optional SOCDMode modeOne = 5;
optional SOCDMode modeTwo = 6;
optional SOCDMode deprecatedModeOne = 5;
optional SOCDMode deprecatedModeTwo = 6;
}
message ReverseOptions
@ -342,10 +394,10 @@ message DualDirectionalOptions
{
optional bool enabled = 1;
optional int32 upPin = 2;
optional int32 downPin = 3;
optional int32 leftPin = 4;
optional int32 rightPin = 5;
optional int32 deprecatedUpPin = 2;
optional int32 deprecatedDownPin = 3;
optional int32 deprecatedLeftPin = 4;
optional int32 deprecatedRightPin = 5;
optional DpadMode dpadMode = 6;
optional uint32 combineMode = 7;
@ -358,7 +410,7 @@ message TiltOptions
optional int32 tilt1Pin = 2;
optional int32 tilt2Pin = 3;
optional int32 tiltFunctionPin = 4;
optional int32 deprecatedTiltFunctionPin = 4;
optional int32 tiltLeftAnalogUpPin = 5;
optional int32 tiltLeftAnalogDownPin = 6;
optional int32 tiltLeftAnalogLeftPin = 7;
@ -369,6 +421,15 @@ message TiltOptions
optional int32 tiltRightAnalogRightPin = 12;
optional SOCDMode tiltSOCDMode = 13;
optional int32 factorTilt1LeftX = 14;
optional int32 factorTilt1LeftY = 15;
optional int32 factorTilt1RightX = 16;
optional int32 factorTilt1RightY = 17;
optional int32 factorTilt2LeftX = 18;
optional int32 factorTilt2LeftY = 19;
optional int32 factorTilt2RightX = 20;
optional int32 factorTilt2RightY = 21;
}
message BuzzerOptions
@ -409,13 +470,130 @@ message PS4Options
optional bytes rsaRN = 12 [(nanopb).max_size = 256];
}
message PSPassthroughOptions
{
optional bool enabled = 1;
optional int32 pinDplus = 2;
optional int32 pin5V = 3;
}
message WiiOptions
{
message AnalogAxis
{
optional int32 axisType = 1;
optional int32 minRange = 2;
optional int32 maxRange = 3;
}
message StickOptions
{
optional AnalogAxis x = 1;
optional AnalogAxis y = 2;
}
message NunchukOptions
{
optional int32 buttonC = 1;
optional int32 buttonZ = 2;
optional StickOptions stick = 3;
}
message ClassicOptions
{
optional int32 buttonA = 1;
optional int32 buttonB = 2;
optional int32 buttonX = 3;
optional int32 buttonY = 4;
optional int32 buttonL = 5;
optional int32 buttonZL = 6;
optional int32 buttonR = 7;
optional int32 buttonZR = 8;
optional int32 buttonMinus = 9;
optional int32 buttonPlus = 10;
optional int32 buttonHome = 11;
optional int32 buttonUp = 12;
optional int32 buttonDown = 13;
optional int32 buttonLeft = 14;
optional int32 buttonRight = 15;
optional StickOptions rightStick = 17;
optional StickOptions leftStick = 16;
optional AnalogAxis leftTrigger = 18;
optional AnalogAxis rightTrigger = 19;
}
message TaikoOptions
{
optional int32 buttonKatLeft = 1;
optional int32 buttonKatRight = 2;
optional int32 buttonDonLeft = 3;
optional int32 buttonDonRight = 4;
}
message GuitarOptions
{
optional int32 buttonRed = 1;
optional int32 buttonGreen = 2;
optional int32 buttonYellow = 3;
optional int32 buttonBlue = 4;
optional int32 buttonOrange = 5;
optional int32 buttonPedal = 6;
optional int32 buttonMinus = 7;
optional int32 buttonPlus = 8;
optional int32 strumUp = 9;
optional int32 strumDown = 10;
optional StickOptions stick = 11;
optional AnalogAxis whammyBar = 12;
}
message DrumOptions
{
optional int32 buttonRed = 1;
optional int32 buttonGreen = 2;
optional int32 buttonYellow = 3;
optional int32 buttonBlue = 4;
optional int32 buttonOrange = 5;
optional int32 buttonPedal = 6;
optional int32 buttonMinus = 7;
optional int32 buttonPlus = 8;
optional StickOptions stick = 9;
}
message TurntableOptions
{
optional int32 buttonLeftRed = 1;
optional int32 buttonLeftGreen = 2;
optional int32 buttonLeftBlue = 3;
optional int32 buttonRightRed = 4;
optional int32 buttonRightGreen = 5;
optional int32 buttonRightBlue = 6;
optional int32 buttonMinus = 7;
optional int32 buttonPlus = 8;
optional int32 buttonEuphoria = 9;
optional StickOptions stick = 10;
optional AnalogAxis leftTurntable = 11;
optional AnalogAxis rightTurntable = 12;
optional AnalogAxis effects = 13;
optional AnalogAxis fader = 14;
}
message ControllerOptions
{
optional NunchukOptions nunchuk = 1;
optional ClassicOptions classic = 2;
optional TaikoOptions taiko = 3;
optional GuitarOptions guitar = 4;
optional DrumOptions drum = 5;
optional TurntableOptions turntable = 6;
}
optional bool enabled = 1;
optional int32 i2cBlock = 2;
optional int32 i2cSDAPin = 3;
optional int32 i2cSCLPin = 4;
optional int32 i2cSpeed = 5;
optional ControllerOptions controllers = 6;
}
message SNESOptions
@ -431,6 +609,7 @@ message KeyboardHostOptions
optional bool enabled = 1;
optional int32 pinDplus = 2;
optional KeyboardMapping mapping = 3;
optional int32 pin5V = 4;
}
message FocusModeOptions
@ -441,6 +620,36 @@ message FocusModeOptions
optional bool oledLockEnabled = 4;
optional bool rgbLockEnabled = 5;
optional bool buttonLockEnabled = 6;
optional bool macroLockEnabled = 7;
}
message MacroInput
{
optional uint32 buttonMask = 1;
optional uint32 duration = 2;
optional uint32 waitDuration = 3 [default = 0];
}
message Macro
{
optional MacroType macroType = 1;
optional string macroLabel = 2 [(nanopb).max_length = 64];
repeated MacroInput macroInputs = 3 [(nanopb).max_count = 30];
optional bool enabled = 4;
optional bool useMacroTriggerButton = 5;
optional int32 macroTriggerPin = 6 [default = -1];
optional uint32 macroTriggerButton = 7;
optional bool exclusive = 8 [default = true];
optional bool interruptible = 9 [default = true];
optional bool showFrames = 10 [default = false];
}
message MacroOptions
{
optional bool enabled = 1;
optional int32 pin = 2;
optional bool macroBoardLedEnabled = 4;
repeated Macro macroList = 3 [(nanopb).max_count = 6];
}
message AddonOptions
@ -454,7 +663,7 @@ message AddonOptions
optional AnalogADS1219Options analogADS1219Options = 7;
optional DualDirectionalOptions dualDirectionalOptions = 8;
optional BuzzerOptions buzzerOptions = 9;
optional ExtraButtonOptions extraButtonOptions = 10;
optional ExtraButtonOptions deprecatedExtraButtonOptions = 10;
optional PlayerNumberOptions playerNumberOptions = 11;
optional PS4Options ps4Options = 12 [(nanopb).disallow_export = true];
optional WiiOptions wiiOptions = 13;
@ -463,6 +672,14 @@ message AddonOptions
optional FocusModeOptions focusModeOptions = 16;
optional KeyboardHostOptions keyboardHostOptions = 17;
optional TiltOptions tiltOptions = 18;
optional PSPassthroughOptions psPassthroughOptions = 19;
optional MacroOptions macroOptions = 20;
}
message MigrationHistory
{
optional bool hotkeysMigrated = 1 [default = false];
optional bool gpioMappingsMigrated = 2 [default = false];
}
message Config
@ -471,7 +688,7 @@ message Config
optional GamepadOptions gamepadOptions = 2;
optional HotkeyOptions hotkeyOptions = 3;
optional PinMappings pinMappings = 4;
optional PinMappings deprecatedPinMappings = 4;
optional KeyboardMapping keyboardMapping = 5;
optional DisplayOptions displayOptions = 6;
optional LEDOptions ledOptions = 7;
@ -479,4 +696,8 @@ message Config
optional AddonOptions addonOptions = 9;
optional ForcedSetupOptions forcedSetupOptions = 10;
optional ProfileOptions profileOptions = 11;
optional string boardConfig = 12 [(nanopb).max_length = 63];
optional GpioMappings gpioMappings = 13;
optional MigrationHistory migrations = 14;
}

View File

@ -19,6 +19,7 @@ enum ButtonLayout
BUTTON_LAYOUT_FIGHTBOARD_STICK = 10;
BUTTON_LAYOUT_FIGHTBOARD_MIRRORED = 11;
BUTTON_LAYOUT_CUSTOMA = 12;
BUTTON_LAYOUT_OPENCORE0WASDA = 13;
}
enum ButtonLayoutRight
@ -42,6 +43,9 @@ enum ButtonLayoutRight
BUTTON_LAYOUT_FIGHTBOARD = 14;
BUTTON_LAYOUT_FIGHTBOARD_STICK_MIRRORED = 15;
BUTTON_LAYOUT_CUSTOMB = 16;
BUTTON_LAYOUT_KEYBOARD8B = 17;
BUTTON_LAYOUT_OPENCORE0WASDB = 18;
BUTTON_LAYOUT_BSS = 99;
}
enum SplashMode
@ -73,6 +77,7 @@ enum OnBoardLedMode
ON_BOARD_LED_MODE_OFF = 0;
ON_BOARD_LED_MODE_MODE_INDICATOR = 1;
ON_BOARD_LED_MODE_INPUT_TEST = 2;
ON_BOARD_LED_MODE_PS_AUTH = 3;
}
enum InputMode
@ -96,6 +101,16 @@ enum DpadMode
DPAD_MODE_RIGHT_ANALOG = 2;
}
enum InvertMode
{
option (nanopb_enumopt).long_names = false;
INVERT_NONE = 0;
INVERT_X = 1;
INVERT_Y = 2;
INVERT_XY = 3;
}
enum SOCDMode
{
option (nanopb_enumopt).long_names = false;
@ -107,6 +122,48 @@ enum SOCDMode
SOCD_MODE_BYPASS = 4; // U+D=UD, L+R=LR (No cleaning applied)
}
enum GpioAction
{
option (nanopb_enumopt).long_names = false;
// the lowest value is the default, which should be NONE;
// reserving some numbers in case we need more not-mapped type values
NONE = -10;
RESERVED = -5;
ASSIGNED_TO_ADDON = 0;
BUTTON_PRESS_UP = 1;
BUTTON_PRESS_DOWN = 2;
BUTTON_PRESS_LEFT = 3;
BUTTON_PRESS_RIGHT = 4;
BUTTON_PRESS_B1 = 5;
BUTTON_PRESS_B2 = 6;
BUTTON_PRESS_B3 = 7;
BUTTON_PRESS_B4 = 8;
BUTTON_PRESS_L1 = 9;
BUTTON_PRESS_R1 = 10;
BUTTON_PRESS_L2 = 11;
BUTTON_PRESS_R2 = 12;
BUTTON_PRESS_S1 = 13;
BUTTON_PRESS_S2 = 14;
BUTTON_PRESS_A1 = 15;
BUTTON_PRESS_A2 = 16;
BUTTON_PRESS_L3 = 17;
BUTTON_PRESS_R3 = 18;
BUTTON_PRESS_FN = 19;
BUTTON_PRESS_DDI_UP = 20;
BUTTON_PRESS_DDI_DOWN = 21;
BUTTON_PRESS_DDI_LEFT = 22;
BUTTON_PRESS_DDI_RIGHT = 23;
SUSTAIN_DP_MODE_DP = 24;
SUSTAIN_DP_MODE_LS = 25;
SUSTAIN_DP_MODE_RS = 26;
SUSTAIN_SOCD_MODE_UP_PRIO = 27;
SUSTAIN_SOCD_MODE_NEUTRAL = 28;
SUSTAIN_SOCD_MODE_SECOND_WIN = 29;
SUSTAIN_SOCD_MODE_FIRST_WIN = 30;
SUSTAIN_SOCD_MODE_BYPASS = 31;
}
enum GamepadHotkey
{
option (nanopb_enumopt).long_names = false;
@ -130,6 +187,10 @@ enum GamepadHotkey
HOTKEY_LOAD_PROFILE_2 = 16;
HOTKEY_LOAD_PROFILE_3 = 17;
HOTKEY_LOAD_PROFILE_4 = 18;
HOTKEY_L3_BUTTON = 19;
HOTKEY_R3_BUTTON = 20;
HOTKEY_TOUCHPAD_BUTTON = 21;
HOTKEY_REBOOT_DEFAULT = 22;
}
// This has to be kept in sync with LEDFormat in NeoPico.hpp
@ -167,3 +228,20 @@ enum ForcedSetupMode
FORCED_SETUP_MODE_LOCK_WEB_CONFIG = 2;
FORCED_SETUP_MODE_LOCK_BOTH = 3;
};
enum PS4ControllerType
{
option (nanopb_enumopt).long_names = false;
PS4_CONTROLLER = 0;
PS4_ARCADESTICK = 7;
}
enum MacroType
{
option (nanopb_enumopt).long_names = false;
ON_PRESS = 1;
ON_HOLD_REPEAT = 2;
ON_TOGGLE = 3;
};

Binary file not shown.

Binary file not shown.

View File

@ -55,13 +55,13 @@ def test_concatenate_to_usb(tmp_path):
def test_padding_firmware(firmware_binary):
"""Test that firmware is padded to the expected size."""
padded = pad_firmware_up_to_storage(firmware_binary)
assert len(padded) == 2088960
assert len(padded) == 2080768
def test_padding_firmware_can_truncate():
"""Test that firmware is padded to the expected size."""
padded = pad_firmware_up_to_storage(bytearray(b'\x00' * 4 * 1024 * 1024), or_truncate=True)
assert len(padded) == 2088960
assert len(padded) == 2080768
def test_firmware_plus_storage(firmware_binary, storage_dump):
@ -70,7 +70,7 @@ def test_firmware_plus_storage(firmware_binary, storage_dump):
# if this is valid, we should be able to find the storage and footer again
storage = get_storage_section(whole_board)
footer_size, _, _ = get_config_footer(storage)
assert footer_size == 2032
assert footer_size == 3309
def test_firmware_plus_config_binary(firmware_binary, config_binary):
@ -79,7 +79,7 @@ def test_firmware_plus_config_binary(firmware_binary, config_binary):
# if this is valid, we should be able to find the storage and footer again
storage = get_storage_section(whole_board)
footer_size, _, _ = get_config_footer(storage)
assert footer_size == 2032
assert footer_size == 3309
def test_chunky_firmware_plus_config_binary(config_binary):
@ -88,7 +88,7 @@ def test_chunky_firmware_plus_config_binary(config_binary):
# if this is valid, we should be able to find the storage and footer again
storage = get_storage_section(whole_board)
footer_size, _, _ = get_config_footer(storage)
assert footer_size == 2032
assert footer_size == 3309
def test_replace_config_in_binary(config_binary):
@ -98,7 +98,7 @@ def test_replace_config_in_binary(config_binary):
# if this is valid, we should be able to find the storage and footer again
storage = get_storage_section(whole_board)
footer_size, _, _ = get_config_footer(storage)
assert footer_size == 2032
assert footer_size == 3309
def test_replace_config_in_binary_not_big_enough(config_binary):
@ -108,7 +108,7 @@ def test_replace_config_in_binary_not_big_enough(config_binary):
# if this is valid, we should be able to find the storage and footer again
storage = get_storage_section(whole_board)
footer_size, _, _ = get_config_footer(storage)
assert footer_size == 2032
assert footer_size == 3309
def test_padding_firmware_too_big(firmware_binary):
@ -128,15 +128,15 @@ def test_write_new_config_to_whole_board(whole_board_dump, tmp_path):
board_dump = file.read()
config = get_config(get_storage_section(board_dump))
assert config.boardVersion == 'v0.7.2'
config.boardVersion = 'v0.7.2-COOL'
assert config.boardVersion == 'v0.7.5'
config.boardVersion = 'v0.7.5-COOL'
write_new_config_to_filename(config, tmp_file, inject=True)
# read new file
with open(tmp_file, 'rb') as file:
new_board_dump = file.read()
config = get_config(get_storage_section(new_board_dump))
assert config.boardVersion == 'v0.7.2-COOL'
assert config.boardVersion == 'v0.7.5-COOL'
assert len(board_dump) == len(new_board_dump)
@ -149,14 +149,14 @@ def test_write_new_config_to_firmware(firmware_binary, tmp_path):
config_pb2 = get_config_pb2()
config = config_pb2.Config()
config.boardVersion = 'v0.7.2-COOL'
config.boardVersion = 'v0.7.5-COOL'
write_new_config_to_filename(config, tmp_file, inject=True)
# read new file
with open(tmp_file, 'rb') as file:
new_board_dump = file.read()
config = get_config(get_storage_section(new_board_dump))
assert config.boardVersion == 'v0.7.2-COOL'
assert config.boardVersion == 'v0.7.5-COOL'
assert len(new_board_dump) == 2 * 1024 * 1024
@ -166,7 +166,7 @@ def test_write_new_config_to_config_bin(firmware_binary, tmp_path):
tmp_file = os.path.join(tmp_path, 'config.bin')
config_pb2 = get_config_pb2()
config = config_pb2.Config()
config.boardVersion = 'v0.7.2-COOL'
config.boardVersion = 'v0.7.5-COOL'
write_new_config_to_filename(config, tmp_file)
# read new file
@ -174,7 +174,7 @@ def test_write_new_config_to_config_bin(firmware_binary, tmp_path):
config_dump = file.read()
config = get_config(config_dump)
config_size, _, _ = get_config_footer(config_dump)
assert config.boardVersion == 'v0.7.2-COOL'
assert config.boardVersion == 'v0.7.5-COOL'
assert len(config_dump) == config_size + 12
@ -188,8 +188,8 @@ def test_write_new_config_to_usb(config_binary):
write_new_config_to_usb(config, end_out, end_in)
# check that it got padded
assert len(serialized) == 2044
padded_serialized = bytearray(b'\x00' * 2052) + serialized
assert len(serialized) == 3321
padded_serialized = bytearray(b'\x00' * 775) + serialized
assert mock_write.call_args.args[2] % 4096 == 0
assert mock_write.call_args.args[3] == padded_serialized

View File

@ -44,7 +44,7 @@ def test_concatenate_invocation(tmpdir):
with open(out_filename, 'rb') as out_file, open('tests/test-files/test-storage-area.bin', 'rb') as storage_file:
out = out_file.read()
storage = storage_file.read()
assert out[2088960:2097152] == storage
assert out[2080768:2097152] == storage
def test_storage_dump_invocation():
@ -52,7 +52,7 @@ def test_storage_dump_invocation():
result = run(['visualize-storage', '-P', 'tests/test-files/proto-files',
'--filename', 'tests/test-files/test-storage-area.bin'],
capture_output=True, encoding='utf8')
assert 'boardVersion: "v0.7.2"' in result.stdout
assert 'boardVersion: "v0.7.5"' in result.stdout
def test_debug_storage_dump_invocation():
@ -60,8 +60,8 @@ def test_debug_storage_dump_invocation():
result = run(['visualize-storage', '-d', '-P', 'tests/test-files/proto-files',
'--filename', 'tests/test-files/test-storage-area.bin'],
capture_output=True, encoding='utf8')
assert 'boardVersion: "v0.7.2"' in result.stdout
assert 'length of content to look for footer in: 8192' in result.stderr
assert 'boardVersion: "v0.7.5"' in result.stdout
assert 'length of content to look for footer in: 16384' in result.stderr
def test_storage_dump_json_invocation():
@ -70,4 +70,4 @@ def test_storage_dump_json_invocation():
'--filename', 'tests/test-files/test-storage-area.bin'],
capture_output=True, encoding='utf8')
to_dict = json.loads(result.stdout)
assert to_dict['boardVersion'] == 'v0.7.2'
assert to_dict['boardVersion'] == 'v0.7.5'

View File

@ -73,12 +73,12 @@ async def test_simple_tree_building():
"""Test some basics of the config tree being built."""
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
async with app.run_test() as pilot:
check_node = pilot.app.query_one(Tree).root.children[2]
assert "boardVersion = 'v0.7.2'" in check_node.label
check_node = pilot.app.query_one(Tree).root.children[3]
assert "boardVersion = 'v0.7.5'" in check_node.label
parent_config, field_descriptor, field_value = check_node.data
assert parent_config == pilot.app.config
assert field_descriptor == pilot.app.config.DESCRIPTOR.fields_by_name['boardVersion']
assert field_value == 'v0.7.2'
assert field_value == 'v0.7.5'
app.exit()
@ -89,7 +89,7 @@ async def test_simple_toggle():
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
async with app.run_test() as pilot:
tree = pilot.app.query_one(Tree)
display_node = tree.root.children[3]
display_node = tree.root.children[5]
invert_node = display_node.children[11]
assert 'False' in invert_node.label
@ -104,7 +104,7 @@ async def test_simple_edit_via_input_field():
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
async with app.run_test() as pilot:
tree = pilot.app.query_one(Tree)
display_node = tree.root.children[3]
display_node = tree.root.children[5]
i2cspeed_node = display_node.children[10]
assert pilot.app.config.displayOptions.i2cSpeed == 400000
@ -128,7 +128,7 @@ async def test_simple_edit_via_input_field_enum():
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
async with app.run_test() as pilot:
tree = pilot.app.query_one(Tree)
gamepad_node = tree.root.children[5]
gamepad_node = tree.root.children[7]
dpadmode_node = gamepad_node.children[0]
assert pilot.app.config.gamepadOptions.dpadMode == 0
@ -152,8 +152,8 @@ async def test_simple_edit_via_input_field_string():
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
async with app.run_test() as pilot:
tree = pilot.app.query_one(Tree)
version_node = tree.root.children[2]
assert pilot.app.config.boardVersion == 'v0.7.2'
version_node = tree.root.children[3]
assert pilot.app.config.boardVersion == 'v0.7.5'
tree.select_node(version_node)
tree.action_select_cursor()
@ -173,7 +173,7 @@ async def test_add_node_to_repeated():
app = ConfigEditor(config_filename=os.path.join(HERE, 'test-files/test-config.bin'))
async with app.run_test() as pilot:
tree = pilot.app.query_one(Tree)
profile_node = tree.root.children[10]
profile_node = tree.root.children[13]
altpinmappings_node = profile_node.children[0]
tree.root.expand_all()
@ -207,8 +207,8 @@ async def test_save(config_binary, tmp_path):
app = ConfigEditor(config_filename=new_filename)
async with app.run_test() as pilot:
pilot.app.config.boardVersion = 'v0.7.2-bss-wuz-here'
pilot.app.config.boardVersion = 'v0.7.5-bss-wuz-here'
await pilot.press('s')
config = get_config_from_file(new_filename)
assert config.boardVersion == 'v0.7.2-bss-wuz-here'
assert config.boardVersion == 'v0.7.5-bss-wuz-here'

View File

@ -96,9 +96,9 @@ def test_exit_xip():
def test_erase():
"""Test that we can send a command to erase a section of memory."""
end_out, end_in = mock.MagicMock(), mock.MagicMock()
pico.erase(end_out, end_in, 0x101FE000, 8192)
pico.erase(end_out, end_in, 0x101FC000, 8192)
payload = struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x3, 8, 0, 0x101FE000, 8192)
payload = struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x3, 8, 0, 0x101FC000, 8192)
end_out.write.assert_called_with(payload)
end_in.read.assert_called_once()
@ -107,12 +107,12 @@ def test_read():
"""Test that we can read a memory of a BOOTSEL board in a variety of conditions."""
end_out, end_in = mock.MagicMock(), mock.MagicMock()
end_in.read.return_value = array('B', b'\x11' * 256)
content = pico.read(end_out, end_in, 0x101FE000, 256)
content = pico.read(end_out, end_in, 0x101FC000, 256)
expected_writes = [
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 1)),
mock.call(struct.pack('<LLBBxxL16x', 0x431fd10b, 1, 0x6, 0, 0)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FE000, 256)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FC000, 256)),
mock.call(b'\xc0'),
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 0)),
]
@ -125,12 +125,12 @@ def test_read_shorter_than_chunk():
"""Test that we can read a memory of a BOOTSEL board in a variety of conditions."""
end_out, end_in = mock.MagicMock(), mock.MagicMock()
end_in.read.return_value = array('B', b'\x11' * 256)
content = pico.read(end_out, end_in, 0x101FE000, 128)
content = pico.read(end_out, end_in, 0x101FC000, 128)
expected_writes = [
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 1)),
mock.call(struct.pack('<LLBBxxL16x', 0x431fd10b, 1, 0x6, 0, 0)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FE000, 256)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FC000, 256)),
mock.call(b'\xc0'),
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 0)),
]
@ -143,15 +143,15 @@ def test_read_bigger_than_chunk():
"""Test that we can read a memory of a BOOTSEL board in a variety of conditions."""
end_out, end_in = mock.MagicMock(), mock.MagicMock()
end_in.read.return_value = array('B', b'\x11' * 256)
content = pico.read(end_out, end_in, 0x101FE000, 512)
content = pico.read(end_out, end_in, 0x101FC000, 512)
expected_writes = [
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 1)),
mock.call(struct.pack('<LLBBxxL16x', 0x431fd10b, 1, 0x6, 0, 0)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FE000, 256)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FC000, 256)),
mock.call(b'\xc0'),
mock.call(struct.pack('<LLBBxxL16x', 0x431fd10b, 1, 0x6, 0, 0)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FE000+256, 256)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x84, 8, 256, 0x101FC000+256, 256)),
mock.call(b'\xc0'),
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 0)),
]
@ -172,13 +172,13 @@ def test_reboot():
def test_write():
"""Test that we can write to a board in BOOTSEL mode."""
end_out, end_in = mock.MagicMock(), mock.MagicMock()
_ = pico.write(end_out, end_in, 0x101FE000, b'\x00\x01\x02\x03')
_ = pico.write(end_out, end_in, 0x101FC000, b'\x00\x01\x02\x03')
expected_writes = [
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 1)),
mock.call(struct.pack('<LLBBxxL16x', 0x431fd10b, 1, 0x6, 0, 0)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x3, 8, 0, 0x101FE000, 4)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x5, 8, 4, 0x101FE000, 4)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x3, 8, 0, 0x101FC000, 4)),
mock.call(struct.pack('<LLBBxxLLL8x', 0x431fd10b, 1, 0x5, 8, 4, 0x101FC000, 4)),
mock.call(b'\x00\x01\x02\x03'),
mock.call(struct.pack('<LLBBxxLL12x', 0x431fd10b, 1, 0x1, 1, 0, 0)),
]

View File

@ -26,8 +26,8 @@ def with_pb2s(test, *args, **kwargs):
def test_config_footer(storage_dump):
"""Test that a config footer is identified as expected."""
size, crc, magic = storage.get_config_footer(storage_dump)
assert size == 2032
assert crc == 3799109329
assert size == 3309
assert crc == 2661279683
assert magic == '0x65e3f1d2'
@ -76,7 +76,7 @@ def test_get_config_from_file_storage_dump():
"""Test that we can open a storage dump file and find its config."""
filename = os.path.join(HERE, 'test-files', 'test-storage-area.bin')
config = storage.get_config_from_file(filename)
assert config.boardVersion == 'v0.7.2'
assert config.boardVersion == 'v0.7.5'
assert config.addonOptions.bootselButtonOptions.enabled is False
assert config.addonOptions.ps4Options.enabled is False
@ -86,7 +86,7 @@ def test_get_config_from_file_whole_board_dump():
"""Test that we can open a storage dump file and find its config."""
filename = os.path.join(HERE, 'test-files', 'test-whole-board.bin')
config = storage.get_config_from_file(filename, whole_board=True)
assert config.boardVersion == 'v0.7.2'
assert config.boardVersion == 'v0.7.5'
assert config.addonOptions.bootselButtonOptions.enabled is False
@ -109,24 +109,27 @@ def test_get_config_from_file_file_not_fonud_raise():
def test_config_parses(storage_dump):
"""Test that we need the config_pb2 to exist/be compiled for reading the config to work."""
config = storage.get_config(storage_dump)
assert config.boardVersion == 'v0.7.2'
assert config.hotkeyOptions.hotkey01.dpadMask == 1
assert config.boardVersion == 'v0.7.5'
assert config.hotkeyOptions.hotkey01.dpadMask == 0
assert config.hotkeyOptions.hotkey02.dpadMask == 1
@with_pb2s
def test_config_from_whole_board_parses(whole_board_dump):
"""Test that we can read in a whole board and still find the config section."""
config = storage.get_config(storage.get_storage_section(whole_board_dump))
assert config.boardVersion == 'v0.7.2'
assert config.hotkeyOptions.hotkey01.dpadMask == 1
assert config.boardVersion == 'v0.7.5'
assert config.hotkeyOptions.hotkey01.dpadMask == 0
assert config.hotkeyOptions.hotkey02.dpadMask == 1
@with_pb2s
def test_serialize_config_with_footer(storage_dump):
def test_serialize_config_with_footer(storage_dump, config_binary):
"""Test that reserializing a read in config matches the original."""
config = storage.get_config(storage_dump)
assert config.boardVersion == 'v0.7.2'
assert config.boardVersion == 'v0.7.5'
reserialized = storage.serialize_config_with_footer(config)
assert config_binary == reserialized
assert storage_dump[-12:] == reserialized[-12:]
@ -134,7 +137,7 @@ def test_serialize_config_with_footer(storage_dump):
def test_serialize_modified_config_with_footer(storage_dump):
"""Test that we can serialize a modified config."""
config = storage.get_config(storage_dump)
config.boardVersion == 'v0.7.2-cool'
config.boardVersion = 'v0.7.5-cool'
serialized = storage.serialize_config_with_footer(config)
config_size, _, _ = storage.get_config_footer(serialized)
assert config_size == config.ByteSize()
@ -144,7 +147,7 @@ def test_serialize_modified_config_with_footer(storage_dump):
def test_pad_config_to_storage(config_binary):
"""Test that we can properly pad a config section to the correct storage section size."""
storage_section = storage.pad_config_to_storage_size(config_binary)
assert len(storage_section) == 8192
assert len(storage_section) == 16384
def test_pad_config_to_storage_raises(config_binary):
@ -167,5 +170,5 @@ def test_get_config_from_usb(config_binary):
config, _, _ = storage.get_config_from_usb()
mock_get.assert_called_once()
mock_read.assert_called_with(mock_out, mock_in, 0x101FE000, 8192)
mock_read.assert_called_with(mock_out, mock_in, 0x101FC000, 16384)
assert config == storage.get_config(config_binary)