Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "trompeloeil_doctest.h" |
| 9 | #include <filesystem> |
Tomáš Pecka | 9b1c967 | 2020-11-11 15:24:06 +0100 | [diff] [blame] | 10 | #include "fs-helpers/utils.h" |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 11 | #include "ietf-hardware/sysfs/EMMC.h" |
| 12 | #include "pretty_printers.h" |
| 13 | #include "test_log_setup.h" |
| 14 | #include "tests/configure.cmake.h" |
| 15 | |
| 16 | using namespace std::literals; |
| 17 | |
Tomáš Pecka | 491f4f2 | 2020-11-05 15:44:00 +0100 | [diff] [blame] | 18 | TEST_CASE("EMMC driver") |
| 19 | { |
| 20 | TEST_INIT_LOGS; |
| 21 | |
| 22 | const auto fakeRoot = CMAKE_CURRENT_BINARY_DIR + "/tests/emmc/"s; |
| 23 | removeDirectoryTreeIfExists(fakeRoot); |
| 24 | |
| 25 | SECTION("Test correct structure") |
| 26 | { |
| 27 | std::string sourceDir; |
| 28 | velia::ietf_hardware::sysfs::EMMC::Attributes expected; |
| 29 | |
| 30 | SECTION("device1") |
| 31 | { |
| 32 | sourceDir = CMAKE_CURRENT_SOURCE_DIR + "/tests/sysfs/emmc/device1"s; |
| 33 | expected = { |
| 34 | {"date", "02/2015"}, |
| 35 | {"serial", "0x00a8808d"}, |
| 36 | {"name", "8GME4R"}, |
| 37 | // life_time: 0x01 0x02 (i.e., 0-10% and 10-20%) |
| 38 | // pre_eol_info: 0x01 (i.e., normal) |
| 39 | {"life_time", "10"}}; |
| 40 | } |
| 41 | |
| 42 | SECTION("device2") |
| 43 | { |
| 44 | sourceDir = CMAKE_CURRENT_SOURCE_DIR + "/tests/sysfs/emmc/device2"s; |
| 45 | expected = { |
| 46 | {"date", "02/2015"}, |
| 47 | {"serial", "0x00a8808d"}, |
| 48 | {"name", "8GME4R"}, |
| 49 | // life_time: 0x0B 0x02 (i.e., 100-?% and 10-20%) |
| 50 | // pre_eol_info: 0x03 (i.e., urgent) |
| 51 | {"life_time", "100"}}; |
| 52 | } |
| 53 | |
| 54 | std::filesystem::copy(sourceDir, fakeRoot, std::filesystem::copy_options::recursive); |
| 55 | auto emmcAttrs = velia::ietf_hardware::sysfs::EMMC(fakeRoot); |
| 56 | REQUIRE(emmcAttrs.attributes() == expected); |
| 57 | } |
| 58 | |
| 59 | SECTION("Test emmc (<5) / device3") |
| 60 | { |
| 61 | std::filesystem::copy(CMAKE_CURRENT_SOURCE_DIR + "/tests/sysfs/emmc/device3"s, fakeRoot, std::filesystem::copy_options::recursive); |
| 62 | |
| 63 | // health reporting missing (emmc < 5). When one file is missing, the attributes method invocation throws |
| 64 | REQUIRE_THROWS_AS(velia::ietf_hardware::sysfs::EMMC(fakeRoot).attributes(), std::invalid_argument); |
| 65 | } |
| 66 | } |