62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
"""Test TFTP logging functionality.
|
|
|
|
This script tests that TFTP commands are properly logged to the separate log widget.
|
|
"""
|
|
from pydownloadfwviasrio.tftp_client import SRIOTFTPClient
|
|
from pydownloadfwviasrio.core.core import FirmwareFlasher
|
|
from pydownloadfwviasrio.profiles import FlashProfile
|
|
|
|
|
|
def general_log(msg: str) -> None:
|
|
"""Simula il log generale."""
|
|
print(f"[GENERAL] {msg}")
|
|
|
|
|
|
def tftp_log(msg: str) -> None:
|
|
"""Simula il log TFTP."""
|
|
print(f"[TFTP ] {msg}")
|
|
|
|
|
|
def test_logging():
|
|
"""Test che i log siano separati correttamente."""
|
|
print("=" * 60)
|
|
print("Testing TFTP logging separation")
|
|
print("=" * 60)
|
|
|
|
# Create a test profile
|
|
profile = FlashProfile(
|
|
name="TEST_TARGET",
|
|
slot_address="0x10",
|
|
ip="192.168.1.100",
|
|
port=69,
|
|
base_address=0x01000000,
|
|
size=0x100000,
|
|
binary_path=None,
|
|
)
|
|
|
|
# Create client and flasher
|
|
client = SRIOTFTPClient(profile.ip, profile.port)
|
|
flasher = FirmwareFlasher(profile=profile, client=client)
|
|
|
|
# Test data
|
|
test_data = b"\xAA\xBB\xCC\xDD" * 64 # 256 bytes
|
|
address = 0x01000000
|
|
|
|
print("\n--- Testing WRITE operation ---")
|
|
print("Expected: General log shows progress, TFTP log shows commands")
|
|
print()
|
|
|
|
# Simulate write (will fail because no server, but we'll see the log messages)
|
|
try:
|
|
flasher.write(address, test_data, log=general_log, tftp_log=tftp_log)
|
|
except Exception as e:
|
|
print(f"\n[INFO] Operation failed as expected (no server): {e}")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Test completed!")
|
|
print("=" * 60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_logging()
|