Skip to content

Commit

Permalink
Revert ":white_check_mark: (firmware): Set os-version path as argumen…
Browse files Browse the repository at this point in the history
…t + getCurrentVersion as public method"

This reverts commit 1d31501.
  • Loading branch information
YannLocatelli committed Jul 27, 2022
1 parent fdaaa42 commit 57efa3f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 54 deletions.
6 changes: 4 additions & 2 deletions libs/FirmwareKit/include/FirmwareKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace leka {

class FirmwareKit : public interface::FirmwareUpdate
{
static constexpr auto os_version_path = "/fs/sys/os-version";

public:
explicit FirmwareKit(interface::FlashMemory &flash, const char *format = "/fs/usr/os/LekaOS-%i.%i.%i.bin")
: _flash(flash), _path_format(format)
Expand All @@ -23,12 +25,12 @@ class FirmwareKit : public interface::FirmwareUpdate
}

auto getCurrentVersion() -> leka::FirmwareVersion final;
auto getCurrentVersionFromFile(const std::filesystem::path &os_version_path = std::filesystem::path {
"/fs/sys/os-version"}) -> leka::FirmwareVersion;

auto loadUpdate(const leka::FirmwareVersion &version) -> bool final;

private:
auto getCurrentVersionFromFile() -> leka::FirmwareVersion;

auto loadUpdate(const char *path) -> bool;

interface::FlashMemory &_flash;
Expand Down
2 changes: 1 addition & 1 deletion libs/FirmwareKit/source/FirmwareKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ auto FirmwareKit::getCurrentVersion() -> FirmwareVersion
return getCurrentVersionFromFile();
}

auto FirmwareKit::getCurrentVersionFromFile(const std::filesystem::path &os_version_path) -> FirmwareVersion
auto FirmwareKit::getCurrentVersionFromFile() -> FirmwareVersion
{
auto file_content = std::array<char, 16> {};

Expand Down
52 changes: 1 addition & 51 deletions libs/FirmwareKit/tests/FirmwareKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,11 @@ class FirmwareKitTest : public ::testing::Test
update.write(content.data(), std::size(content));
update.close();
}
void TearDown() override
{
std::remove(os_version_path.c_str());
std::remove("/tmp/update-v1.2.3");
}
void TearDown() override { std::remove("/tmp/update-v1.2.3"); }

mock::FlashMemory mock_flash;
FirmwareKit firmwarekit;

FirmwareVersion default_current_version = FirmwareVersion {1, 0, 0};

std::filesystem::path os_version_path {"/tmp/os-version"};

std::array<char, 6> content = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66}; // "abcdef"
};

Expand All @@ -59,48 +51,6 @@ TEST_F(FirmwareKitTest, instantiation)
ASSERT_NE(&firmwarekit, nullptr);
}

TEST_F(FirmwareKitTest, getCurrentVersionFromFile)
{
auto expected_version = FirmwareVersion {
.major = 1,
.minor = 23,
.revision = 255,
};
std::string os_version_content = "1.23.255\n";

std::ofstream os_version {os_version_path.c_str()};
os_version.write(os_version_content.data(), std::size(os_version_content));
os_version.close();

auto actual_version = firmwarekit.getCurrentVersionFromFile(os_version_path);

EXPECT_EQ(actual_version.major, expected_version.major);
EXPECT_EQ(actual_version.minor, expected_version.minor);
EXPECT_EQ(actual_version.revision, expected_version.revision);
}

TEST_F(FirmwareKitTest, getCurrentVersionFromFileDefaultPath)
{
// This test will output default firmware version since it uses default path in /fs and this cannot be opened in UT

auto actual_version = firmwarekit.getCurrentVersionFromFile();

EXPECT_EQ(actual_version.major, default_current_version.major);
EXPECT_EQ(actual_version.minor, default_current_version.minor);
EXPECT_EQ(actual_version.revision, default_current_version.revision);
}

TEST_F(FirmwareKitTest, getCurrentVersionDefault)
{
// This test will output default firmware version since it uses getCurrentVersionFromFile with default path

auto actual_version = firmwarekit.getCurrentVersion();

EXPECT_EQ(actual_version.major, default_current_version.major);
EXPECT_EQ(actual_version.minor, default_current_version.minor);
EXPECT_EQ(actual_version.revision, default_current_version.revision);
}

TEST_F(FirmwareKitTest, loadUpdate)
{
auto version = FirmwareVersion {.major = 1, .minor = 2, .revision = 3};
Expand Down

0 comments on commit 57efa3f

Please sign in to comment.