测试套件增设破坏性用例总开关(默认只读),GD5F/存储/RTC 破坏性用例改为按需开启
This commit is contained in:
+52
-26
@@ -12,6 +12,7 @@
|
||||
|
||||
#define DBG_TAG "[STORAGE-TEST]"
|
||||
#include "dbg_log.h"
|
||||
#include "test_config.h" /* 破坏性用例开关 ENABLE_DESTRUCTIVE_TESTS 的唯一来源 */
|
||||
#include "storage_test.h"
|
||||
#include "nand_ftl.h"
|
||||
#include "diskio.h"
|
||||
@@ -26,6 +27,7 @@ storage_test_stats_t g_storage_stats;
|
||||
static FATFS fs;
|
||||
static FIL fil;
|
||||
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
/* 性能缓冲 2048B = 恰好一个 NAND 页(RAM 预算:4096 时套件链接溢出 0x604,
|
||||
* L6406E 实测;2048 分块仍覆盖整页写路径,128KB 总量不变) */
|
||||
static uint8_t s_perf_buf[2048];
|
||||
@@ -252,6 +254,8 @@ static void storage_test_badblock(void)
|
||||
* 后跑一次套件,即可清除运行时注入坏块 + 清 dhara map 回出厂态) */
|
||||
}
|
||||
|
||||
#endif /* ENABLE_DESTRUCTIVE_TESTS: s_perf_buf + TC-STO-01/02/03(写、擦、坏块注入) */
|
||||
|
||||
/* TC-STO-05: 文件名/路径合法性校验(守护 ".fschk 无限重格式化" 真根因)
|
||||
* 本移植 FF_USE_LFN=0,只支持严格 8.3 短名(主名≤8、扩展≤3、不以点开头)。
|
||||
* 非法名字 f_open 必返 FR_INVALID_NAME(纯 RAM 名字判定、不碰盘);合法但
|
||||
@@ -324,6 +328,7 @@ static void storage_test_name_validation(void)
|
||||
STORAGE_TEST_CHECK(bok, "TC-STO-05 invalid names rejected (FR_INVALID_NAME)");
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
/* TC-STO-06: 打开模式与写回字节数语义(守护 FA_OPEN_APPEND / 短写陷阱)
|
||||
* 本移植 FA_OPEN_APPEND 不含 FA_WRITE → 不带写位打开 f_write 必返 FR_DENIED;
|
||||
* 追加写必须 FA_WRITE|FA_OPEN_APPEND。另 f_write 簇耗尽返 FR_OK+短写(无错误
|
||||
@@ -381,6 +386,7 @@ static void storage_test_open_modes(void)
|
||||
|
||||
(void)f_unlink("mode.tmp");
|
||||
}
|
||||
#endif /* ENABLE_DESTRUCTIVE_TESTS: TC-STO-06 */
|
||||
#endif /* !ENABLE_STORAGE_RECOVERY_TESTS: 共享缓冲 + 正常测试函数 */
|
||||
|
||||
#ifdef ENABLE_STORAGE_RECOVERY_TESTS
|
||||
@@ -391,45 +397,65 @@ static void storage_test_recover(void);
|
||||
/* 正常存储测试套件主体(恢复模式见文件末尾 storage_test_run 分发) */
|
||||
static void storage_test_run_normal(void)
|
||||
{
|
||||
static uint8_t work[FF_MAX_SS];
|
||||
char read_buf[64];
|
||||
const char *test_str = "Hello FatFS + dhara FTL!";
|
||||
FRESULT res;
|
||||
|
||||
memset(&g_storage_stats, 0, sizeof(g_storage_stats));
|
||||
|
||||
/* ==================== FTL + FatFS 文件系统测试 ==================== */
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
DBG_INFO("mode: DESTRUCTIVE (write/erase/format/badblock-inject enabled)");
|
||||
#else
|
||||
DBG_INFO("mode: READ-ONLY (destructive cases skipped; set "
|
||||
"ENABLE_DESTRUCTIVE_TESTS in test_config.h to run them)");
|
||||
#endif
|
||||
|
||||
FRESULT res = f_mount(&fs, "", 1);
|
||||
/* ==================== 挂载 ==================== */
|
||||
|
||||
res = f_mount(&fs, "", 1);
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
if (res == FR_NO_FILESYSTEM) {
|
||||
static uint8_t work[FF_MAX_SS];
|
||||
MKFS_PARM opts = { FM_FAT32, 0, 0, 0, 0 };
|
||||
res = f_mkfs("", &opts, work, sizeof(work));
|
||||
STORAGE_TEST_CHECK(res == FR_OK, "f_mkfs");
|
||||
res = f_mount(&fs, "", 1);
|
||||
}
|
||||
#else
|
||||
if (res == FR_NO_FILESYSTEM) {
|
||||
DBG_INFO("read-only mode: no filesystem on volume, skip write cases "
|
||||
"(mkfs self-heal disabled)");
|
||||
}
|
||||
#endif
|
||||
STORAGE_TEST_CHECK(res == FR_OK, "f_mount");
|
||||
|
||||
if (res == FR_OK) {
|
||||
UINT bw, br;
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
/* ==================== FTL + FatFS 文件系统测试 ==================== */
|
||||
{
|
||||
char read_buf[64];
|
||||
const char *test_str = "Hello FatFS + dhara FTL!";
|
||||
|
||||
res = f_open(&fil, "test.txt", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
STORAGE_TEST_CHECK(res == FR_OK, "f_open(write)");
|
||||
if (res == FR_OK) {
|
||||
f_write(&fil, test_str, (UINT)strlen(test_str), &bw);
|
||||
STORAGE_TEST_CHECK(bw == (UINT)strlen(test_str), "f_write (%u bytes)", bw);
|
||||
f_close(&fil);
|
||||
UINT bw, br;
|
||||
|
||||
res = f_open(&fil, "test.txt", FA_READ);
|
||||
STORAGE_TEST_CHECK(res == FR_OK, "f_open(read)");
|
||||
res = f_open(&fil, "test.txt", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
STORAGE_TEST_CHECK(res == FR_OK, "f_open(write)");
|
||||
if (res == FR_OK) {
|
||||
f_read(&fil, read_buf, (UINT)(sizeof(read_buf) - 1), &br);
|
||||
f_write(&fil, test_str, (UINT)strlen(test_str), &bw);
|
||||
STORAGE_TEST_CHECK(bw == (UINT)strlen(test_str), "f_write (%u bytes)", bw);
|
||||
f_close(&fil);
|
||||
read_buf[br] = '\0';
|
||||
STORAGE_TEST_CHECK(br == (UINT)strlen(test_str) &&
|
||||
memcmp(test_str, read_buf, br) == 0,
|
||||
"data verify \"%s\"", read_buf);
|
||||
|
||||
res = f_open(&fil, "test.txt", FA_READ);
|
||||
STORAGE_TEST_CHECK(res == FR_OK, "f_open(read)");
|
||||
if (res == FR_OK) {
|
||||
f_read(&fil, read_buf, (UINT)(sizeof(read_buf) - 1), &br);
|
||||
f_close(&fil);
|
||||
read_buf[br] = '\0';
|
||||
STORAGE_TEST_CHECK(br == (UINT)strlen(test_str) &&
|
||||
memcmp(test_str, read_buf, br) == 0,
|
||||
"data verify \"%s\"", read_buf);
|
||||
}
|
||||
}
|
||||
f_unlink("test.txt");
|
||||
}
|
||||
f_unlink("test.txt");
|
||||
}
|
||||
|
||||
/* ==================== FTL + FatFS 性能测试 ==================== */
|
||||
@@ -478,19 +504,19 @@ static void storage_test_run_normal(void)
|
||||
total_kb, tr, (total_kb * 1000) / tr);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_DESTRUCTIVE_TESTS: 文件系统写读 + 性能压测 */
|
||||
|
||||
/* ==================== 存储集成测试(TC-STO-05~06 契约 + 01~03 集成) ========== */
|
||||
/* ==================== 存储集成测试(TC-STO-05 契约 + 01~03 集成) ========== */
|
||||
|
||||
/* 纯语义契约测试(非破坏性,先跑):名字合法性 + 打开模式 */
|
||||
/* 纯语义契约测试(非破坏性):文件名合法性 */
|
||||
storage_test_name_validation();
|
||||
storage_test_open_modes();
|
||||
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
/* 破坏性用例:打开模式契约 + 掉电恢复 / 大文件 / 坏块注入集成 */
|
||||
storage_test_open_modes();
|
||||
storage_test_powerloss();
|
||||
storage_test_largefile();
|
||||
storage_test_badblock();
|
||||
|
||||
#ifdef ENABLE_STORAGE_RECOVERY_TESTS
|
||||
storage_test_recover();
|
||||
#endif
|
||||
|
||||
/* ==================== 汇总报告 ==================== */
|
||||
|
||||
Reference in New Issue
Block a user