From 06e7a1a32a8711bae81560800ed9203042b30739 Mon Sep 17 00:00:00 2001 From: Lucjan Bryndza Date: Wed, 16 Dec 2020 15:40:11 +0100 Subject: [PATCH] [EGD-4758] Add Littlefs unit test This is an initial implementation of littlefs unit tests --- module-vfs/tests/CMakeLists.txt | 22 ++++++++++ module-vfs/tests/genlfstestimg.sh | 43 +++++++++++++++++++ .../tests/unittest_filesystem_littlefs.cpp | 13 ++++++ 3 files changed, 78 insertions(+) create mode 100755 module-vfs/tests/genlfstestimg.sh create mode 100644 module-vfs/tests/unittest_filesystem_littlefs.cpp diff --git a/module-vfs/tests/CMakeLists.txt b/module-vfs/tests/CMakeLists.txt index cc22d84db3d026fb52c78711fcb4d02c435f7984..28368a205eb554ca3118e956f32942b43278afea 100644 --- a/module-vfs/tests/CMakeLists.txt +++ b/module-vfs/tests/CMakeLists.txt @@ -26,6 +26,28 @@ add_catch2_executable( module-vfs ) +set(LITTLEFS_IMAGE "lfstest.img") + +add_custom_command( + OUTPUT ${LITTLEFS_IMAGE} + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/genlfstestimg.sh 1G ${LITTLEFS_IMAGE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS genlittlefs +) + +add_custom_target( test_lfs_image DEPENDS ${LITTLEFS_IMAGE} ) + +add_catch2_executable( + NAME vfs-littlefs + SRCS + ${CMAKE_CURRENT_LIST_DIR}/unittest_filesystem_littlefs.cpp + LIBS + module-vfs + DEPS + test_lfs_image +) + + # prepare test assets set(ASSETS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test_dir") set(ASSETS_TARGET_DIR "${CMAKE_BINARY_DIR}/module-vfs/test_dir") diff --git a/module-vfs/tests/genlfstestimg.sh b/module-vfs/tests/genlfstestimg.sh new file mode 100755 index 0000000000000000000000000000000000000000..cfddfcc9cf0246cf9514b5726e949efb88a0e506 --- /dev/null +++ b/module-vfs/tests/genlfstestimg.sh @@ -0,0 +1,43 @@ +#!/bin/bash -e +#Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +#For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +usage() { +cat << ==usage +Usage: $(basename $0) [image_size] [image_file] + image_size Target disk image size + image_file Target image name +==usage +} + + +if [ $# -ne 2 ]; then + echo "Error! Invalid argument count" + usage + exit -1 +fi +IMAGE_SIZE="$1" +IMAGE_FILE="$2" + +_REQ_CMDS="sfdisk truncate" +for cmd in $_REQ_CMDS; do + if [ ! $(command -v $cmd) ]; then + echo "Error! $cmd is not installed, please use 'sudo apt install' for install required tool" + exit -1 + fi +done +truncate -s $IMAGE_SIZE $IMAGE_FILE + +SECTOR_START=2048 +SECTOR_END=$(( $(stat -c "%s" $IMAGE_FILE)/512 - $SECTOR_START)) + + + +sfdisk $IMAGE_FILE << ==sfdisk +label: dos +unit: sectors + +/dev/sdz1 : start= 2048, size=$SECTOR_END, type=9e, bootable +==sfdisk +./genlittlefs --image $IMAGE_FILE --block_size=4096 --overwrite --partition_num 1 -- assets/* + diff --git a/module-vfs/tests/unittest_filesystem_littlefs.cpp b/module-vfs/tests/unittest_filesystem_littlefs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f75cf8445d1d98acb0ac2b88d93eef20689a1ae6 --- /dev/null +++ b/module-vfs/tests/unittest_filesystem_littlefs.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#define CATCH_CONFIG_MAIN +#include +#include +#include +#include +#include +#include +#include + +TEST_CASE("Littlefs: Basic tests") +{}