diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-18 11:38:38 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-26 21:13:06 +0100 |
commit | 876c432f7a581ea3839deb77f756166572ac1db7 (patch) | |
tree | 8d1fb4eda50327f12101f7a9e9bc1fe7f102af02 /unittest/test_storage.py | |
parent | f7cbdc09858b7d26765e819c89e4289d30877f74 (diff) | |
download | libnitrokey-876c432f7a581ea3839deb77f756166572ac1db7.tar.gz libnitrokey-876c432f7a581ea3839deb77f756166572ac1db7.tar.bz2 |
Stress test for firmware export feature
Export the firmware multiple times, and test its size.
Hardcoded device set to /dev/sde1
Related: https://github.com/Nitrokey/nitrokey-app/issues/399
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest/test_storage.py')
-rw-r--r-- | unittest/test_storage.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/unittest/test_storage.py b/unittest/test_storage.py index 04b0581..380d42e 100644 --- a/unittest/test_storage.py +++ b/unittest/test_storage.py @@ -395,3 +395,70 @@ def test_struct_multiline_prodtest(C): fwb=info_st.FirmwareVersionInternal_u8 ) print(info) + +@pytest.mark.other +@pytest.mark.firmware +def test_export_firmware_extended_fedora29(C): + """ + Check, whether the firmware file is exported correctly, and in correct size. + Apparently, the auto-remounting side effect of the v0.46 change, is disturbing the export process. + Unmounting the UV just before the export gives the device 20/20 success rate. + Test case for issue https://github.com/Nitrokey/nitrokey-app/issues/399 + """ + + skip_if_device_version_lower_than({'S': 43}) + skip_if_not_fedora() + + import pexpect + from time import sleep + import os + exist = os.path.exists + + device = '/dev/sde1' + firmware_abs_path = '/run/media/sz/Nitrokey/firmware.bin' + pexpect.run(f'udisksctl mount -b {device}') + checks = 0 + checks_add = 0 + + if exist(firmware_abs_path): + os.remove(firmware_abs_path) + + assert not exist(firmware_abs_path) + + ATTEMPTS = 20 + for i in range(ATTEMPTS): + # if umount is disabled, success rate is 3/10, enabled: 10/10 + # pexpect.run(f'udisksctl unmount -b {device}') + assert C.NK_export_firmware(DefaultPasswords.ADMIN) == DeviceErrorCode.STATUS_OK + pexpect.run(f'udisksctl mount -b {device}') + sleep(1) + firmware_file_exist = exist(firmware_abs_path) + if firmware_file_exist: + checks += 1 + getsize = os.path.getsize(firmware_abs_path) + print('Firmware file exist, size: {}'.format(getsize)) + checks_add += 1 if getsize >= 100 * 1024 else 0 + # checks_add += 1 if os.path.getsize(firmware_abs_path) == 256*1024 else 0 + os.remove(firmware_abs_path) + assert not exist(firmware_abs_path) + + print('CHECK {} ; CHECK ADDITIONAL {}'.format(checks, checks_add)) + + assert checks == ATTEMPTS + assert checks_add == checks + + +def skip_if_not_fedora(): + import os + exist = os.path.exists + + def skip(): + pytest.skip('Fedora specific test, due to the mount path. Could be suited for Debian.') + + os_release_fp = '/etc/os-release' + if not exist(os_release_fp): + skip() + with open(os_release_fp) as f: + os_release_lines = f.readlines() + if 'Fedora' not in os_release_lines[0]: + skip() |