~aleteoryx/muditaos

06e7a1a32a8711bae81560800ed9203042b30739 — Lucjan Bryndza 5 years ago 497621f
[EGD-4758] Add Littlefs unit test

This is an initial implementation of littlefs
unit tests
M module-vfs/tests/CMakeLists.txt => module-vfs/tests/CMakeLists.txt +22 -0
@@ 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")

A module-vfs/tests/genlfstestimg.sh => module-vfs/tests/genlfstestimg.sh +43 -0
@@ 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/*


A module-vfs/tests/unittest_filesystem_littlefs.cpp => module-vfs/tests/unittest_filesystem_littlefs.cpp +13 -0
@@ 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 <catch2/catch.hpp>
#include <purefs/fs/filesystem.hpp>
#include <purefs/blkdev/disk_manager.hpp>
#include <purefs/blkdev/disk_image.hpp>
#include <purefs/fs/drivers/filesystem_vfat.hpp>
#include <sys/statvfs.h>
#include <sys/stat.h>

TEST_CASE("Littlefs: Basic tests")
{}