Files
philips-tv-speicher-voll/patches/usb-freesize/tools/test_usb_size_policy.py

36 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Unit tests for the tvfw USB size fallback and unit contract."""
MIB = 1024 * 1024
def sizes_mib(dm_ready, dm_total_kib, dm_free_kib, stat_total_bytes, stat_free_bytes):
if dm_ready and dm_total_kib is not None and dm_free_kib is not None:
total = dm_total_kib // 1024
free = dm_free_kib // 1024
if total > 0 and 0 <= free <= total:
return total, free, "dm"
if stat_total_bytes is None or stat_free_bytes is None:
return None
total = stat_total_bytes // MIB
free = stat_free_bytes // MIB
if total <= 0 or not 0 <= free <= total:
return None
return total, free, "statfs"
def main():
gib = 1024 * MIB
assert sizes_mib(False, None, None, 64 * gib, 48 * gib) == (65536, 49152, "statfs")
assert sizes_mib(True, 64 * 1024 * 1024, 48 * 1024 * 1024, None, None) == (65536, 49152, "dm")
assert sizes_mib(True, 0, 0, 64 * gib, 48 * gib) == (65536, 49152, "statfs")
assert sizes_mib(True, 64 * 1024 * 1024, 70 * 1024 * 1024, 64 * gib, 48 * gib) == (65536, 49152, "statfs")
assert sizes_mib(False, None, None, 3 * 1024 * gib, 2 * 1024 * gib) == (3145728, 2097152, "statfs")
assert sizes_mib(False, None, None, 64 * gib, 0) == (65536, 0, "statfs")
assert sizes_mib(False, None, None, None, None) is None
print("PASS: property states, DM validation, StatFs fallback, >2TiB, real zero, unknown")
if __name__ == "__main__":
main()