Skip to content

Commit a02d905

Browse files
ValentiWorkLearningVKorniienko
authored and
VKorniienko
committed
Added gtest suite for the filesystem handling #17
1 parent feccd06 commit a02d905

11 files changed

+129
-17
lines changed

Firmware/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ add_subdirectory(utils)
7070
add_subdirectory(logger)
7171
add_subdirectory(graphics)
7272
add_subdirectory(service_providers)
73+
add_subdirectory(filesystem)
7374

7475
set (NORDIC_TARGET theOpenWatch)
7576
add_executable(${NORDIC_TARGET} ${PROJECT_SOURCES})

Firmware/firmware_tests/coroutine/fs_ideas/filesystem_holder.hpp Firmware/filesystem/filesystem/filesystem_holder.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#pragma once
2-
#include "ih_block_device.hpp"
2+
#include "block_device_wrapper/ih_block_device.hpp"
33
#include <lfs.h>
44
#include <memory>
55
#include <string>
6-
#include <utils/CoroUtils.hpp>
6+
#include <utils/coroutine/Task.hpp>
7+
#include <utils/coroutine/SyncWait.hpp>
78

89
#include <cstdint>
910
#include <span>

Firmware/firmware_tests/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ add_executable(
3434
drivers/windond_flash/flash_fixture.hpp
3535
drivers/spi/mock_gpio.hpp
3636
drivers/spi/mock_spi.hpp
37-
)
37+
38+
filesystem/filesystem_fixture.hpp
39+
filesystem/filesystem_in_memory_test.cpp)
3840

3941
mark_as_advanced(
4042
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
@@ -62,7 +64,7 @@ target_link_libraries(
6264
watch_display
6365
lvgl_lib
6466
drivers_ih
65-
67+
filesystem
6668
buttons_driver
6769
windbond_spi_flash_driver
6870
)

Firmware/firmware_tests/coroutine/CMakeLists.txt

+2-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ if( UNIX )
66
find_package(Threads REQUIRED)
77
endif()
88

9-
find_package(spdlog REQUIRED)
10-
119
add_executable(coroutine_experiments_app ${PROJECT_SOURCES})
1210

1311
target_sources(
@@ -16,12 +14,7 @@ target_sources(
1614
coroutine_thoughts.cpp
1715
thoughts.hpp
1816
st7789_draft.hpp
19-
fs_ideas/filesystem_holder.hpp
20-
21-
fs_ideas/platform_filesystem.hpp
22-
wrapper/ih_block_device.hpp
23-
wrapper/heap_block_device.hpp
24-
wrapper/adaptor_block_device.hpp)
17+
)
2518

2619
target_include_directories(
2720
coroutine_experiments_app
@@ -50,8 +43,7 @@ target_link_libraries(
5043
watch_display
5144
UtilsLibrary
5245
logger_service
53-
littlefs
54-
spdlog::spdlog
46+
filesystem
5547
)
5648
if(UNIX)
5749
target_link_libraries( coroutine_experiments_app PUBLIC Threads::Threads)

Firmware/firmware_tests/coroutine/coroutine_thoughts.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#include <spi/spi_wrapper_async_templated.hpp>
2020

2121
#include "st7789_draft.hpp"
22+
#include <filesystem/platform_filesystem.hpp>
23+
#include <filesystem/block_device_wrapper/heap_block_device.hpp>
24+
#include <filesystem/block_device_wrapper/adaptor_block_device.hpp>
2225

23-
#include "fs_ideas/platform_filesystem.hpp"
24-
#include "wrapper/heap_block_device.hpp"
25-
#include "wrapper/adaptor_block_device.hpp"
2626
#include <spdlog/spdlog.h>
2727

2828
using TFilesystem = Platform::Fs::Holder<Wrapper::LogAdaptorBlockDevice<Wrapper::HeapBlockDevice<
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
#include <gtest/gtest.h>
3+
4+
#include <filesystem/platform_filesystem.hpp>
5+
#include <filesystem/block_device_wrapper/heap_block_device.hpp>
6+
#include <filesystem/block_device_wrapper/adaptor_block_device.hpp>
7+
8+
9+
#include <utils/coroutine/SyncWait.hpp>
10+
11+
struct FilesystemParamInterfaceData
12+
{
13+
std::string_view fileData;
14+
std::string_view filename;
15+
};
16+
17+
class FilesystemTopLevelTestFixture
18+
: public ::testing::Test
19+
, public ::testing::WithParamInterface<FilesystemParamInterfaceData>
20+
{
21+
22+
public:
23+
24+
using TFilesystem = Platform::Fs::Holder<Wrapper::LogAdaptorBlockDevice<Wrapper::HeapBlockDevice<
25+
Wrapper::kBlockSize,
26+
Wrapper::kSectorsCount,
27+
Wrapper::kReadSize,
28+
Wrapper::kEraseSize>>>;
29+
30+
using TFile = Platform::Fs::File<TFilesystem>;
31+
32+
protected:
33+
void SetUp() override
34+
{
35+
CoroUtils::syncWait(m_testFilesystem.initializeFs());
36+
}
37+
38+
39+
40+
protected:
41+
TFilesystem m_testFilesystem;
42+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "filesystem_fixture.hpp"
2+
#include <gmock/gmock.h>
3+
#include <gtest/gtest.h>
4+
#include <utils/coroutine/SyncWait.hpp>
5+
6+
7+
constexpr auto HelloWorldData = FilesystemParamInterfaceData{ .fileData = "Hello world!", .filename = "helloworld.txt" };
8+
9+
constexpr auto kNmeaDataExample = std::string_view{
10+
"$GPGSA,A,1,,,,,,,,,,,,,,,* 1E\n"
11+
"$GPGSV,1,1,0,,,,,,,,,,,,,,,,* 49\n"
12+
"$GPRMC,114811.00,A,5548.2054190,N,03732.8518300,E,0.22,0.00,210618,0.0,E,A * 30\n"
13+
"$GPGGA,114811.00,5548.2054190,N,03732.8518300,E,1,06,1.0,179.534,M,14.753,M,0.0,* 45\n"
14+
"$GPGSA,A,3,02,21,25,26,31,,,,,,,,5.4,1.2,5.3,1 * 2B\n"
15+
"$GAGSA,A,3,30,,,,,,,,,,,,0.0,0.0,0.0,3 * 3F\n"
16+
"$GPGSV,2,1,05,02,23,059,28,21,30,222,32,25,41,166,35,26,36,303,34,1 * 67\n"
17+
"$GPGSV,2,2,05,31,27,254,34,,,,,,,,,,,,,1 * 52\n"
18+
"$GAGSV,1,1,01,30,23,183,33,,,,,,,,,,,,,7 * 4A\n"
19+
"$GPRMC,114812.00,A,5548.2052305,N,03732.8513810,E,0.17,0.00,210618,0.0,E,A * 3C\n"
20+
"$GPGGA,114812.00,5548.2052305,N,03732.8513810,E,1,06,1.0,178.149,M,14.753,M,0.0,* 40\n"
21+
"$GPGSA,A,3,02,21,25,26,31,,,,,,,,5.4,1.2,5.3,1 * 2B\n"
22+
"$GAGSA,A,3,30,,,,,,,,,,,,0.0,0.0,0.0,3 * 3F\n"
23+
"$GPGSV,2,1,05,02,23,059,28,21,30,222,31,25,41,166,36,26,36,303,34,1 * 67\n"
24+
"$GPGSV,2,2,05,31,27,254,34,,,,,,,,,,,,,1 * 52\n"
25+
"$GAGSV,1,1,01,30,23,183,32,,,,,,,,,,,,,7 * 4B\n"
26+
"$GPRMC,114813.00,A,5548.2048307,N,03732.8514121,E,0.28,0.00,210618,0.0,E,A * 34\n"
27+
"$GPGGA,114813.00,5548.2048307,N,03732.8514121,E,1,06,1.0,172.326,M,14.753,M,0.0,* 45\n"
28+
"$GPGSA,A,3,02,21,25,26,31,,,,,,,,5.4,1.2,5.3,1 * 2B\n"
29+
"$GAGSA,A,3,30,,,,,,,,,,,,0.0,0.0,0.0,3 * 3F\n"
30+
"$GPGSV,2,1,05,02,23,059,28,21,31,222,32,25,41,166,36,26,36,303,34,1 * 65\n"
31+
"$GPGSV,2,2,05,31,27,254,34,,,,,,,,,,,,,1 * 52\n"
32+
"$GAGSV,1,1,01,30,23,183,32,,,,,,,,,,,,,7 * 4B\n"
33+
"$GPRMC,114814.00,A,5548.2047440,N,03732.8516481,E,0.19,0.00,210618,0.0,E,A * 37\n"
34+
"$GPGGA,114814.00,5548.2047440,N,03732.8516481,E,1,06,1.0,172.488,M,14.753,M,0.0,* 47\n"
35+
"$GPGSA,A,3,02,21,25,26,31,,,,,,,,5.4,1.2,5.3,1 * 2B\n"
36+
"$GAGSA,A,3,30,,,,,,,,,,,,0.0,0.0,0.0,3 * 3F\n"
37+
"$GPGSV,2,1,05,02,23,059,28,21,31,222,32,25,41,166,35,26,36,303,34,1 * 66\n"
38+
"$GPGSV,2,2,05,31,27,254,34,,,,,,,,,,,,,1 * 52\n"
39+
"$GAGSV,1,1,01,30,23,183,32,,,,,,,,,,,,,7 * 4B\n"
40+
41+
};
42+
43+
constexpr auto NmeaData = FilesystemParamInterfaceData{ .fileData = kNmeaDataExample,.filename = "nmea_data.txt" };
44+
45+
46+
TEST_P(FilesystemTopLevelTestFixture, CheckFileReadWriteProcedure)
47+
{
48+
spdlog::warn("simpleRwTest begin");
49+
auto lfs = m_testFilesystem.fsInstance();
50+
{
51+
auto filename = std::move(CoroUtils::syncWait(m_testFilesystem.openFile(GetParam().filename)));
52+
CoroUtils::syncWait(filename.write(
53+
std::span(reinterpret_cast<const std::uint8_t*>(GetParam().fileData.data()), GetParam().fileData.size())));
54+
}
55+
56+
std::vector<std::uint8_t> readFrom;
57+
readFrom.resize(GetParam().fileData.size());
58+
59+
{
60+
auto holdedFile = std::move(CoroUtils::syncWait(m_testFilesystem.openFile(GetParam().filename)));
61+
auto resultRead = CoroUtils::syncWait( holdedFile.read(std::span(readFrom.data(), GetParam().fileData.size())));
62+
}
63+
64+
auto kCompareStringView{
65+
std::string_view{reinterpret_cast<const char*>(readFrom.data()), readFrom.size()} };
66+
EXPECT_EQ(kCompareStringView, GetParam().fileData);
67+
}
68+
69+
70+
INSTANTIATE_TEST_SUITE_P(
71+
FilesystemTopLevelTesting,
72+
FilesystemTopLevelTestFixture,
73+
::testing::Values(
74+
FilesystemParamInterfaceData{}));

0 commit comments

Comments
 (0)