Files
STM32F4-Base/test/gd5f_test.h
2026-08-27 18:22:44 +08:00

90 lines
3.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 模块名称GD5F2GQ5UE Driver Test Suite
* 模块功能GD5F2GQ5UE SPI NAND Flash 驱动测试入口,按阶段组织测试用例,
* 覆盖 gd5f2gq5ue.c 全部公开/私有函数,并延伸到 FTLnand_ftl
* FatFS diskio。详见 docs/GD5F2GQ5UE_Test_Guide.md。
* 适用平台STM32F4 系列GD5F2GQ5UE SPI NAND
* 作者:王建锋
* 创建日期2026-08-26
*
* === 测试阶段一览(与指南 TC 一一对应)===
* Phase | 描述
* ---------|-----------------------------------------------
* Phase 1 | 初始化与 ID 识别init / read_id / reset
* Phase 2 | 坏块管理BBTscan / is_block_bad / mark+clear / rescan
* Phase 3 | 页读写(跨页 / 非对齐 / 多页 / 单字节)
* Phase 4 | 块擦除(单块 / 多块 / 非对齐负向 / 擦写读闭环)
* Phase 5 | ECC 验证(开启下写读 / check_ecc
* Phase 6 | SPI 原语page_read / program_load+exec / block_erase / write_enable / wait_busy
* Phase 7 | DMA 边界(阈值 32/33/整页)
* Phase 8 | FTL 层nand_ftl_init / nand_ftl_format
* Phase 9 | FatFS diskio可选
* Phase 10 | 边界条件offset 越界 / size=0 / 未擦除写入 / 写保护解除)
*/
#ifndef __GD5F_TEST_H
#define __GD5F_TEST_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "gd5f2gq5ue.h"
/* ======================== 阶段使能开关 ======================== */
/* 取消注释对应阶段即可启用;总开关 ENABLE_GD5F_TESTS 控制是否编译并运行测试。
* 启用后defaultTask 中的常规 FTL/FatFS 存储测试会被跳过(独占 NAND
* 注意:测试会擦除/写入若干块,且 Phase 8/9 会格式化 FTL/FatFS仅用于测试构建。 */
//#define ENABLE_GD5F_TESTS /* 总开关(由 test_config.h 的 TEST_SUITE_GD5F 自动开启) */
//#define ENABLE_GD5F_PHASE1_TESTS
//#define ENABLE_GD5F_PHASE2_TESTS
//#define ENABLE_GD5F_PHASE3_TESTS
//#define ENABLE_GD5F_PHASE4_TESTS
//#define ENABLE_GD5F_PHASE5_TESTS
//#define ENABLE_GD5F_PHASE6_TESTS
//#define ENABLE_GD5F_PHASE7_TESTS
//#define ENABLE_GD5F_PHASE8_TESTS
//#define ENABLE_GD5F_PHASE9_TESTS
//#define ENABLE_GD5F_PHASE10_TESTS
/* ======================== 测试统计与断言 ======================== */
typedef struct {
uint16_t total;
uint16_t passed;
uint16_t failed;
} gd5f_test_stats_t;
extern gd5f_test_stats_t g_gd5f_test_stats;
#define GD5F_TEST_CHECK(cond, fmt, ...) do { \
g_gd5f_test_stats.total++; \
if (cond) { \
g_gd5f_test_stats.passed++; \
DBG_INFO("[PASS] " fmt, ##__VA_ARGS__); \
} else { \
g_gd5f_test_stats.failed++; \
DBG_ERROR("[FAIL] " fmt, ##__VA_ARGS__); \
} \
} while (0)
#define GD5F_TEST_REPORT(name) do { \
DBG_INFO("=== %s: %d/%d PASSED (failed=%d) ===", \
name, g_gd5f_test_stats.passed, g_gd5f_test_stats.total, \
g_gd5f_test_stats.failed); \
} while (0)
#if defined(ENABLE_GD5F_TESTS)
void gd5f_test_run(void);
#else
#define gd5f_test_run() ((void)0)
#endif
#ifdef __cplusplus
}
#endif
#endif /* __GD5F_TEST_H */