1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

ut logfs: add support for testing a 2nd partition

This commit is contained in:
Stacey Sheldon 2013-04-18 23:32:52 -04:00 committed by Alessio Morale
parent 8ab50bca13
commit 4f9ce60930
2 changed files with 123 additions and 8 deletions

View File

@ -13,7 +13,8 @@ extern struct pios_flash_ut_cfg flash_config;
#include "pios_flashfs_logfs_priv.h"
extern struct flashfs_logfs_cfg flashfs_config;
extern struct flashfs_logfs_cfg flashfs_config_partition_a;
extern struct flashfs_logfs_cfg flashfs_config_partition_b;
#include "pios_flashfs.h" /* PIOS_FLASHFS_* */
@ -30,6 +31,9 @@ extern struct flashfs_logfs_cfg flashfs_config;
#define OBJ3_ID 0x99999999
#define OBJ3_SIZE (256 - 12) // leave room for the slot header
#define OBJ4_ID 0x90901111
#define OBJ4_SIZE (768) // only fits in partition b slots
// To use a test fixture, derive a class from testing::Test.
class LogfsTestRaw : public testing::Test {
protected:
@ -62,6 +66,11 @@ protected:
for (uint32_t i = 0; i < sizeof(obj3); i++) {
obj3[i] = 0x30 + (i % 10);
}
/* Set up obj4 */
for (uint32_t i = 0; i < sizeof(obj4); i++) {
obj4[i] = 0x40 + (i % 10);
}
}
virtual void TearDown() {
@ -72,6 +81,7 @@ protected:
unsigned char obj1_alt[OBJ1_SIZE];
unsigned char obj2[OBJ2_SIZE];
unsigned char obj3[OBJ3_SIZE];
unsigned char obj4[OBJ4_SIZE];
};
TEST_F(LogfsTestRaw, FlashInit) {
@ -86,7 +96,7 @@ TEST_F(LogfsTestRaw, LogfsInit) {
EXPECT_EQ(0, PIOS_Flash_UT_Init(&flash_id, &flash_config));
uintptr_t fs_id;
EXPECT_EQ(0, PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_config, &pios_ut_flash_driver, flash_id));
EXPECT_EQ(0, PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_config_partition_a, &pios_ut_flash_driver, flash_id));
PIOS_FLASHFS_Logfs_Destroy(fs_id);
PIOS_Flash_UT_Destroy(flash_id);
@ -101,7 +111,7 @@ protected:
/* Init the flash and the flashfs so we don't need to repeat this in every test */
uintptr_t flash_id;
EXPECT_EQ(0, PIOS_Flash_UT_Init(&flash_id, &flash_config));
EXPECT_EQ(0, PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_config, &pios_ut_flash_driver, flash_id));
EXPECT_EQ(0, PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_config_partition_a, &pios_ut_flash_driver, flash_id));
}
virtual void TearDown() {
@ -195,7 +205,7 @@ TEST_F(LogfsTestCooked, WriteVerifyZeroLength) {
}
TEST_F(LogfsTestCooked, WriteMaxSize) {
/* Write a zero length object */
/* Write a max length object */
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id, OBJ3_ID, 0, obj3, sizeof(obj3)));
}
@ -228,7 +238,7 @@ TEST_F(LogfsTestCooked, WriteVerifyMultiInstance) {
TEST_F(LogfsTestCooked, FillFilesystemAndGarbageCollect) {
/* Fill up the entire filesystem with multiple instances of obj1 */
for (uint32_t i = 0; i < (flashfs_config.arena_size / flashfs_config.slot_size) - 1; i++) {
for (uint32_t i = 0; i < (flashfs_config_partition_a.arena_size / flashfs_config_partition_a.slot_size) - 1; i++) {
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id, OBJ1_ID, i, obj1, sizeof(obj1)));
}
@ -282,3 +292,97 @@ TEST_F(LogfsTestCooked, WriteManyVerify) {
EXPECT_EQ(0, PIOS_FLASHFS_ObjLoad(fs_id, OBJ3_ID, 0, obj3_check, sizeof(obj3_check)));
EXPECT_EQ(0, memcmp(obj3, obj3_check, sizeof(obj3)));
}
class LogfsTestCookedMultiPart : public LogfsTestRaw {
protected:
virtual void SetUp() {
/* First, we need to set up the super fixture (LogfsTestRaw) */
LogfsTestRaw::SetUp();
/* Init the flash and the flashfs so we don't need to repeat this in every test */
EXPECT_EQ(0, PIOS_Flash_UT_Init(&flash_id, &flash_config));
EXPECT_EQ(0, PIOS_FLASHFS_Logfs_Init(&fs_id_a, &flashfs_config_partition_a, &pios_ut_flash_driver, flash_id));
EXPECT_EQ(0, PIOS_FLASHFS_Logfs_Init(&fs_id_b, &flashfs_config_partition_b, &pios_ut_flash_driver, flash_id));
}
virtual void TearDown() {
PIOS_FLASHFS_Logfs_Destroy(fs_id_b);
PIOS_FLASHFS_Logfs_Destroy(fs_id_a);
PIOS_Flash_UT_Destroy(flash_id);
}
uintptr_t flash_id;
uintptr_t fs_id_a;
uintptr_t fs_id_b;
};
TEST_F(LogfsTestCookedMultiPart, WriteOneWriteOneVerify) {
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_a, OBJ1_ID, 0, obj1, sizeof(obj1)));
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_b, OBJ2_ID, 0, obj2, sizeof(obj2)));
/* OBJ1 found in A */
unsigned char obj1_check[OBJ1_SIZE];
memset(obj1_check, 0, sizeof(obj1_check));
EXPECT_EQ(0, PIOS_FLASHFS_ObjLoad(fs_id_a, OBJ1_ID, 0, obj1_check, sizeof(obj1_check)));
EXPECT_EQ(0, memcmp(obj1, obj1_check, sizeof(obj1)));
/* OBJ2 found in B */
unsigned char obj2_check[OBJ2_SIZE];
memset(obj2_check, 0, sizeof(obj2_check));
EXPECT_EQ(0, PIOS_FLASHFS_ObjLoad(fs_id_b, OBJ2_ID, 0, obj2_check, sizeof(obj2_check)));
EXPECT_EQ(0, memcmp(obj2, obj2_check, sizeof(obj2)));
}
TEST_F(LogfsTestCookedMultiPart, WriteOneWriteOneFormatOneVerify) {
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_a, OBJ1_ID, 0, obj1, sizeof(obj1)));
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_b, OBJ2_ID, 0, obj2, sizeof(obj2)));
EXPECT_EQ(0, PIOS_FLASHFS_Format(fs_id_a));
/* OBJ2 still found in B */
unsigned char obj2_check[OBJ2_SIZE];
memset(obj2_check, 0, sizeof(obj2_check));
EXPECT_EQ(0, PIOS_FLASHFS_ObjLoad(fs_id_b, OBJ2_ID, 0, obj2_check, sizeof(obj2_check)));
EXPECT_EQ(0, memcmp(obj2, obj2_check, sizeof(obj2)));
}
TEST_F(LogfsTestCookedMultiPart, WriteOneWriteOneNoCross) {
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_a, OBJ1_ID, 0, obj1, sizeof(obj1)));
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_b, OBJ2_ID, 0, obj2, sizeof(obj2)));
/* OBJ1 not found in B */
unsigned char obj1_check[OBJ1_SIZE];
memset(obj1_check, 0, sizeof(obj1_check));
EXPECT_EQ(-3, PIOS_FLASHFS_ObjLoad(fs_id_b, OBJ1_ID, 0, obj1_check, sizeof(obj1_check)));
/* OBJ2 not found in A */
unsigned char obj2_check[OBJ2_SIZE];
memset(obj2_check, 0, sizeof(obj2_check));
EXPECT_EQ(-3, PIOS_FLASHFS_ObjLoad(fs_id_a, OBJ2_ID, 0, obj2_check, sizeof(obj2_check)));
}
TEST_F(LogfsTestCookedMultiPart, WriteOneWriteOneDeleteOne) {
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_a, OBJ1_ID, 0, obj1, sizeof(obj1)));
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_b, OBJ2_ID, 0, obj2, sizeof(obj2)));
EXPECT_EQ(0, PIOS_FLASHFS_ObjDelete(fs_id_a, OBJ1_ID, 0));
/* OBJ1 not found in A */
unsigned char obj1_check[OBJ1_SIZE];
memset(obj1_check, 0, sizeof(obj1_check));
EXPECT_EQ(-3, PIOS_FLASHFS_ObjLoad(fs_id_a, OBJ1_ID, 0, obj1_check, sizeof(obj1_check)));
/* OBJ2 still found in B */
unsigned char obj2_check[OBJ2_SIZE];
memset(obj2_check, 0, sizeof(obj2_check));
EXPECT_EQ(0, PIOS_FLASHFS_ObjLoad(fs_id_b, OBJ2_ID, 0, obj2_check, sizeof(obj2_check)));
}
TEST_F(LogfsTestCookedMultiPart, WriteLarge) {
EXPECT_EQ(0, PIOS_FLASHFS_ObjSave(fs_id_b, OBJ4_ID, 0, obj4, sizeof(obj4)));
/* OBJ4 found in B */
unsigned char obj4_check[OBJ4_SIZE];
memset(obj4_check, 0, sizeof(obj4_check));
EXPECT_EQ(0, PIOS_FLASHFS_ObjLoad(fs_id_b, OBJ4_ID, 0, obj4_check, sizeof(obj4_check)));
}

View File

@ -7,15 +7,15 @@
const struct pios_flash_ut_cfg flash_config = {
.size_of_flash = 0x00200000,
.size_of_flash = 0x00300000,
.size_of_sector = 0x00010000,
};
#include "pios_flashfs_logfs_priv.h"
const struct flashfs_logfs_cfg flashfs_config = {
const struct flashfs_logfs_cfg flashfs_config_partition_a = {
.fs_magic = 0x89abceef,
.total_fs_size = 0x00200000, /* 2M bytes (32 sectors = entire chip) */
.total_fs_size = 0x00200000, /* 2M bytes (32 sectors) */
.arena_size = 0x00010000, /* 256 * slot size */
.slot_size = 0x00000100, /* 256 bytes */
@ -24,3 +24,14 @@ const struct flashfs_logfs_cfg flashfs_config = {
.page_size = 0x00000100, /* 256 bytes */
};
const struct flashfs_logfs_cfg flashfs_config_partition_b = {
.fs_magic = 0x89abceef,
.total_fs_size = 0x00100000, /* 1M bytes (16 sectors) */
.arena_size = 0x00010000, /* 64 * slot size */
.slot_size = 0x00000400, /* 256 bytes */
.start_offset = 0x00200000, /* start after partition a */
.sector_size = 0x00010000, /* 64K bytes */
.page_size = 0x00000100, /* 256 bytes */
};