测试套件增设破坏性用例总开关(默认只读),GD5F/存储/RTC 破坏性用例改为按需开启
This commit is contained in:
+65
-35
@@ -49,28 +49,36 @@ static void sd2506_phase_basic(void)
|
||||
(unsigned int)r.second, (unsigned int)r.week);
|
||||
}
|
||||
|
||||
/* TC-RTC-002: 写固定时间,立即回读比对。
|
||||
/* TC-RTC-002: 写固定时间,立即回读比对(破坏性:改设备 RTC 时间,套件结束会复原)。
|
||||
* 若 FAIL -> 先查 sd2506.h 寄存器宏后缀是否为 H(曾因 0x0FH 被 KEIL 编译为 0
|
||||
* 导致 SD2506_REG_CTR1 指向秒寄存器、WRTC 写错地址)。详见 docs/SD2506_Trap_Records.md。 */
|
||||
sd2506_time_t t;
|
||||
t.year = 2026; t.month = 8; t.day = 28; t.hour = 12; t.minute = 0; t.second = 0; t.week = 4;
|
||||
ret = sd2506_set_time(&t);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_set_time() ret=%d (expect 0)", ret);
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
{
|
||||
sd2506_time_t t;
|
||||
int match;
|
||||
|
||||
ret = sd2506_get_time(&r);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_get_time() after set ret=%d (expect 0)", ret);
|
||||
if (ret == SD2506_OK) {
|
||||
DBG_INFO(" set : %04u-%02u-%02u %02u:%02u:%02u",
|
||||
(unsigned int)t.year, (unsigned int)t.month, (unsigned int)t.day,
|
||||
(unsigned int)t.hour, (unsigned int)t.minute, (unsigned int)t.second);
|
||||
DBG_INFO(" readback: %04u-%02u-%02u %02u:%02u:%02u",
|
||||
(unsigned int)r.year, (unsigned int)r.month, (unsigned int)r.day,
|
||||
(unsigned int)r.hour, (unsigned int)r.minute, (unsigned int)r.second);
|
||||
t.year = 2026; t.month = 8; t.day = 28; t.hour = 12; t.minute = 0; t.second = 0; t.week = 4;
|
||||
ret = sd2506_set_time(&t);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_set_time() ret=%d (expect 0)", ret);
|
||||
|
||||
ret = sd2506_get_time(&r);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_get_time() after set ret=%d (expect 0)", ret);
|
||||
if (ret == SD2506_OK) {
|
||||
DBG_INFO(" set : %04u-%02u-%02u %02u:%02u:%02u",
|
||||
(unsigned int)t.year, (unsigned int)t.month, (unsigned int)t.day,
|
||||
(unsigned int)t.hour, (unsigned int)t.minute, (unsigned int)t.second);
|
||||
DBG_INFO(" readback: %04u-%02u-%02u %02u:%02u:%02u",
|
||||
(unsigned int)r.year, (unsigned int)r.month, (unsigned int)r.day,
|
||||
(unsigned int)r.hour, (unsigned int)r.minute, (unsigned int)r.second);
|
||||
}
|
||||
match = (r.year == t.year && r.month == t.month && r.day == t.day &&
|
||||
r.hour == t.hour && r.minute == t.minute &&
|
||||
(r.second == t.second || r.second == ((t.second + 1U) % 60U)));
|
||||
SD2506_TEST_CHECK(match, "set==readback (in-session write takes effect)");
|
||||
}
|
||||
int match = (r.year == t.year && r.month == t.month && r.day == t.day &&
|
||||
r.hour == t.hour && r.minute == t.minute &&
|
||||
(r.second == t.second || r.second == ((t.second + 1U) % 60U)));
|
||||
SD2506_TEST_CHECK(match, "set==readback (in-session write takes effect)");
|
||||
#else
|
||||
DBG_INFO("TC-RTC-002 skipped: destructive tests disabled (RTC time write)");
|
||||
#endif
|
||||
|
||||
/* TC-RTC-003: 走时。写后等 3s,应前进约 3 秒 */
|
||||
if (ret == SD2506_OK) {
|
||||
@@ -147,25 +155,37 @@ static void sd2506_phase_api(void)
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]);
|
||||
}
|
||||
|
||||
/* TC-RTC-014: 用户 SRAM 读写回环(addr=0, len=8) */
|
||||
uint8_t wbuf[8] = {0xA1U, 0xB2U, 0xC3U, 0xD4U, 0xE5U, 0xF6U, 0x07U, 0x18U};
|
||||
uint8_t rbuf[8] = {0};
|
||||
ret = sd2506_write_sram(0U, wbuf, 8U);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_write_sram() ret=%d (expect 0)", ret);
|
||||
if (ret == SD2506_OK) {
|
||||
ret = sd2506_read_sram(0U, rbuf, 8U);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_read_sram() ret=%d (expect 0)", ret);
|
||||
int sram_ok = (memcmp(wbuf, rbuf, 8U) == 0);
|
||||
SD2506_TEST_CHECK(sram_ok, "SRAM write==readback");
|
||||
/* TC-RTC-014: 用户 SRAM 读写回环(addr=0, len=8;破坏性:写芯片 SRAM) */
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
{
|
||||
uint8_t wbuf[8] = {0xA1U, 0xB2U, 0xC3U, 0xD4U, 0xE5U, 0xF6U, 0x07U, 0x18U};
|
||||
uint8_t rbuf[8] = {0};
|
||||
ret = sd2506_write_sram(0U, wbuf, 8U);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_write_sram() ret=%d (expect 0)", ret);
|
||||
if (ret == SD2506_OK) {
|
||||
ret = sd2506_read_sram(0U, rbuf, 8U);
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_read_sram() ret=%d (expect 0)", ret);
|
||||
int sram_ok = (memcmp(wbuf, rbuf, 8U) == 0);
|
||||
SD2506_TEST_CHECK(sram_ok, "SRAM write==readback");
|
||||
}
|
||||
}
|
||||
#else
|
||||
DBG_INFO("TC-RTC-014 skipped: destructive tests disabled (RTC SRAM write)");
|
||||
#endif
|
||||
|
||||
/* TC-RTC-015: 报警设置 + 清除(验证 API 通路,不影响时间寄存器) */
|
||||
sd2506_time_t at;
|
||||
at.year = 2026; at.month = 8; at.day = 28; at.hour = 12; at.minute = 0; at.second = 30; at.week = 4;
|
||||
ret = sd2506_set_alarm(&at, (uint8_t)(SD2506_AL_EN_EAS | SD2506_AL_EN_EAMN));
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_set_alarm() ret=%d (expect 0)", ret);
|
||||
ret = sd2506_clear_alarm();
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_clear_alarm() ret=%d (expect 0)", ret);
|
||||
/* TC-RTC-015: 报警设置 + 清除(破坏性:写报警寄存器;验证 API 通路,不影响时间寄存器) */
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
{
|
||||
sd2506_time_t at;
|
||||
at.year = 2026; at.month = 8; at.day = 28; at.hour = 12; at.minute = 0; at.second = 30; at.week = 4;
|
||||
ret = sd2506_set_alarm(&at, (uint8_t)(SD2506_AL_EN_EAS | SD2506_AL_EN_EAMN));
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_set_alarm() ret=%d (expect 0)", ret);
|
||||
ret = sd2506_clear_alarm();
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_clear_alarm() ret=%d (expect 0)", ret);
|
||||
}
|
||||
#else
|
||||
DBG_INFO("TC-RTC-015 skipped: destructive tests disabled (RTC alarm write)");
|
||||
#endif
|
||||
|
||||
SD2506_TEST_REPORT("Phase 2 API");
|
||||
}
|
||||
@@ -175,6 +195,12 @@ static void sd2506_phase_api(void)
|
||||
void sd2506_test_run(void)
|
||||
{
|
||||
DBG_INFO("SD2506 test suite started");
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
DBG_INFO("mode: DESTRUCTIVE (RTC time / SRAM / alarm writes enabled)");
|
||||
#else
|
||||
DBG_INFO("mode: READ-ONLY (destructive cases skipped; set "
|
||||
"ENABLE_DESTRUCTIVE_TESTS in test_config.h to run them)");
|
||||
#endif
|
||||
|
||||
int ret = sd2506_init();
|
||||
SD2506_TEST_CHECK(ret == SD2506_OK, "sd2506_init() ret=%d (expect 0)", ret);
|
||||
@@ -188,12 +214,14 @@ void sd2506_test_run(void)
|
||||
(unsigned int)((c1 >> 7) & 1U));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
/* 记录原始时间,测试结束恢复,避免把板子时间留在测试值 */
|
||||
sd2506_time_t orig;
|
||||
int have_orig = (sd2506_get_time(&orig) == SD2506_OK);
|
||||
if (!have_orig) {
|
||||
DBG_INFO(" WARN: cannot read original time; restore step will be skipped");
|
||||
}
|
||||
#endif
|
||||
|
||||
memset(&g_sd2506_test_stats, 0, sizeof(g_sd2506_test_stats));
|
||||
|
||||
@@ -205,11 +233,13 @@ void sd2506_test_run(void)
|
||||
sd2506_phase_api();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_DESTRUCTIVE_TESTS
|
||||
/* 恢复原始时间(用公共 API,写保护逻辑已由 sd2506.c 正确处理) */
|
||||
if (have_orig) {
|
||||
int r = sd2506_set_time(&orig);
|
||||
DBG_INFO(" restored original time (ret=%d)", r);
|
||||
}
|
||||
#endif
|
||||
|
||||
DBG_INFO("SD2506 test suite done");
|
||||
for (;;) {
|
||||
|
||||
Reference in New Issue
Block a user