Jan Kundrát | c98da38 | 2024-10-08 16:47:04 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2024 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Jan Kundrát <jan.kundrat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "trompeloeil_doctest.h" |
| 9 | #include <filesystem> |
| 10 | #include "ietf-hardware/IETFHardware.h" |
| 11 | #include "pretty_printers.h" |
| 12 | #include "test_log_setup.h" |
| 13 | #include "tests/configure.cmake.h" |
| 14 | |
| 15 | using namespace std::literals; |
| 16 | |
| 17 | TEST_CASE("EEPROM with UID/EID") |
| 18 | { |
| 19 | using namespace velia::ietf_hardware; |
| 20 | using namespace data_reader; |
| 21 | TEST_INIT_LOGS; |
| 22 | const auto sysfs = CMAKE_CURRENT_SOURCE_DIR + "/tests/sysfs/"s; |
| 23 | |
| 24 | REQUIRE(*hexEEPROM(sysfs, 1, 0x5c, 16, 0, 16) == "1E70C61C941000628C2EA000A000000C"); |
| 25 | |
| 26 | auto working = EepromWithUid("x:eeprom", "x", sysfs, 0, 0x52, 256, 256 - 6, 6); |
| 27 | REQUIRE(working().data == DataTree{ |
| 28 | {"/ietf-hardware:hardware/component[name='x:eeprom']/class", "iana-hardware:module"}, |
| 29 | {"/ietf-hardware:hardware/component[name='x:eeprom']/parent", "x"}, |
| 30 | {"/ietf-hardware:hardware/component[name='x:eeprom']/serial-num", "294100B13DA3"}, |
| 31 | {"/ietf-hardware:hardware/component[name='x:eeprom']/state/oper-state", "enabled"}, |
| 32 | }); |
| 33 | |
| 34 | auto missing = EepromWithUid("x:eeprom", "x", sysfs, 0, 0x53, 256, 256 - 6, 6); |
| 35 | REQUIRE(missing().data == DataTree{ |
| 36 | {"/ietf-hardware:hardware/component[name='x:eeprom']/class", "iana-hardware:module"}, |
| 37 | {"/ietf-hardware:hardware/component[name='x:eeprom']/parent", "x"}, |
| 38 | {"/ietf-hardware:hardware/component[name='x:eeprom']/state/oper-state", "disabled"}, |
| 39 | }); |
| 40 | |
| 41 | auto corrupted = EepromWithUid("x:eeprom", "x", sysfs, 0, 0x53, 16, 2, 6); |
| 42 | REQUIRE(corrupted().data == DataTree{ |
| 43 | {"/ietf-hardware:hardware/component[name='x:eeprom']/class", "iana-hardware:module"}, |
| 44 | {"/ietf-hardware:hardware/component[name='x:eeprom']/parent", "x"}, |
| 45 | {"/ietf-hardware:hardware/component[name='x:eeprom']/state/oper-state", "disabled"}, |
| 46 | }); |
| 47 | |
| 48 | REQUIRE_THROWS_WITH(EepromWithUid("x:eeprom", "x", sysfs, 0, 0x20, 256, 256 - 6, 6), |
| 49 | "EEPROM: no I2C device defined at bus 0 address 0x20"); |
| 50 | |
| 51 | REQUIRE_THROWS_WITH(hexEEPROM(sysfs, 0, 0, 10, 5, 6), |
| 52 | "EEPROM: region out of range"); |
| 53 | } |