You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While writing functional tests, it is often the case that some code paths only happen based on the return values of certain APDUs.
Therefore, to get a good test coverage, it would be very helpful to hook into the syscall emulation and programmatically control the syscalls' return values.
In the best of all possible worlds, python tests would have a speculos fixture running an app, that has god-mode control over the device:
deftest_something(speculos):
defmock_os_my_syscall(param):
return1ifparam==0xF00else0speculos.on("os_my_syscall", mock_os_my_syscall)
# test stuff
Ideally, it should be possible to alter the behavior during execution, to test more complex interactions where the syscall is called multiple times and its return values is different.
My current use case is to test code depending on the result of os_global_pin_is_validated; so even less powerful customization on speculos might be enough.
The text was updated successfully, but these errors were encountered:
I added a proof-of-concept code in the hook-syscalls branch. An HTTP request is made each time the syscall os_global_pin_is_validated is called and the HTTP response is used to set the return value of the syscall. The syscall id id is passed in the URL (GET /?syscall=0x6000a03c HTTP/1.0).
As an example, here is an HTTP server wich returns the same value than the syscall implementation (0xaa is BOLOS_UX_OK and 0x9000a078 is SYSCALL_os_global_pin_is_validated_ID_OUT).
cd /tmp/echo '0xaa 0x9000a078' > index.htmlpython3 -m http.server
./speculos.py --hook-syscalls ./apps/btc.elf
Free free to customize that for your needs, ie.:
develop your own HTTP server
modify the hook_syscall function to add mocked syscalls
While writing functional tests, it is often the case that some code paths only happen based on the return values of certain APDUs.
Therefore, to get a good test coverage, it would be very helpful to hook into the syscall emulation and programmatically control the syscalls' return values.
In the best of all possible worlds, python tests would have a
speculos
fixture running an app, that has god-mode control over the device:Ideally, it should be possible to alter the behavior during execution, to test more complex interactions where the syscall is called multiple times and its return values is different.
My current use case is to test code depending on the result of
os_global_pin_is_validated
; so even less powerful customization on speculos might be enough.The text was updated successfully, but these errors were encountered: