424 lines
21 KiB
C
424 lines
21 KiB
C
/* Windows双bank与不可变下载测试。只在参数目录内创建独立用例目录,无递归删除。 */
|
|
#include "iec104_example_energy_freeze.h"
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <windows.h>
|
|
|
|
static ExampleEnergyFreeze energy, second;
|
|
static IEC60870_EnergyFreezeConfig_t config;
|
|
static const uint32_t interval_ioas[] = {0x6409U, 0x640aU};
|
|
static const uint32_t day_ioas[] = {0x6411U, 0x6412U};
|
|
static const uint32_t flow_ioas[] = {0x6419U, 0x641aU};
|
|
static const char *const units[] = {"kWh", "kvarh"};
|
|
static const float values[] = {1.25f, 2.5f};
|
|
static const uint8_t quality[] = {0U, 0U}, indices[] = {0U, 1U};
|
|
static unsigned interrupt_after;
|
|
static uint64_t start;
|
|
|
|
/**
|
|
* 功能:在指定次数的真实同步完成后返回false,模拟提交阶段中断。
|
|
* 输入参数:无。
|
|
* 输出参数:无。
|
|
* 返回值:true 允许继续当前持久操作;false 表示命中本轮指定中断点。
|
|
* 说明:零计数表示不注入故障。
|
|
*/
|
|
bool Example_Energy_Freeze_Test_Continue(void)
|
|
{
|
|
if (interrupt_after == 0U) { return true; }
|
|
return --interrupt_after != 0U;
|
|
}
|
|
|
|
/**
|
|
* 功能:在指定父目录下生成唯一名称并创建空测试目录,避免不同故障场景共享持久文件。
|
|
* 输入参数:parent——测试父目录(只读);path——测试路径。
|
|
* 输出参数:path——生成的测试目录或文件路径。
|
|
* 返回值:无。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
static void Create_Directory(const char *parent, char *path)
|
|
{
|
|
assert(GetTempFileNameA(parent, "eft", 0U, path));
|
|
assert(DeleteFileA(path)); assert(CreateDirectoryA(path, NULL));
|
|
}
|
|
|
|
/**
|
|
* 功能:删除当前用例拥有的已知持久文件和空测试目录。
|
|
* 输入参数:path——测试路径(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:只删除本用例的energy.store及已空的临时目录,残留其他文件会使清理断言失败。
|
|
*/
|
|
static void Remove_Directory(const char *path)
|
|
{
|
|
char file[MAX_PATH];
|
|
int n = snprintf(file, sizeof(file), "%s/energy.store", path);
|
|
assert(n > 0 && (size_t)n < sizeof(file));
|
|
assert(DeleteFileA(file)); assert(RemoveDirectoryA(path));
|
|
}
|
|
|
|
/**
|
|
* 功能:使用固定测试设备名、单位和当前配置打开持久后端,保留返回值供成功及拒绝恢复两类断言。
|
|
* 输入参数:path——测试路径(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:true 表示本次操作或核对成功;false 表示拒绝、失败或命中注入故障。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
static bool Open(const char *path)
|
|
{
|
|
return Example_Energy_Freeze_Open(&energy, path, &config, "ENERGY_TEST", units);
|
|
}
|
|
|
|
/**
|
|
* 功能:独占打开已有energy.store供定点破坏,调用方须先关闭正常后端,避免绕过文件共享锁。
|
|
* 输入参数:path——测试路径(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:成功打开的独占文件句柄,由调用方负责关闭;打开失败由断言终止用例。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
static HANDLE Raw_Open(const char *path)
|
|
{
|
|
char file[MAX_PATH];
|
|
HANDLE handle;
|
|
int n = snprintf(file, sizeof(file), "%s/energy.store", path);
|
|
assert(n > 0 && (size_t)n < sizeof(file));
|
|
handle = CreateFileA(file, GENERIC_READ | GENERIC_WRITE, 0U, NULL,
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
assert(handle != INVALID_HANDLE_VALUE);
|
|
return handle;
|
|
}
|
|
|
|
/**
|
|
* 功能:在绝对文件偏移写足指定字节并Flush,确保后续重新打开看到的是本次构造的介质状态。
|
|
* 输入参数:file——已打开的测试文件句柄;offset——文件、记录或缓冲区偏移;bytes——报文字节缓冲区(只读);length——字节长度。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
static void Change(HANDLE file, uint32_t offset, const uint8_t *bytes, DWORD length)
|
|
{
|
|
LARGE_INTEGER at;
|
|
DWORD done = 0U;
|
|
at.QuadPart = offset;
|
|
assert(SetFilePointerEx(file, at, NULL, FILE_BEGIN));
|
|
assert(WriteFile(file, bytes, length, &done, NULL) && done == length);
|
|
assert(FlushFileBuffers(file));
|
|
}
|
|
|
|
/**
|
|
* 功能:翻转指定字节的最低位并持久同步,用于破坏头、载荷或提交标记而不改动其他字段。
|
|
* 输入参数:file——已打开的测试文件句柄;offset——文件、记录或缓冲区偏移。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
static void Flip(HANDLE file, uint32_t offset)
|
|
{
|
|
LARGE_INTEGER at;
|
|
DWORD done = 0U;
|
|
uint8_t byte;
|
|
at.QuadPart = offset;
|
|
assert(SetFilePointerEx(file, at, NULL, FILE_BEGIN));
|
|
assert(ReadFile(file, &byte, 1U, &done, NULL) && done == 1U);
|
|
byte ^= 1U; Change(file, offset, &byte, 1U);
|
|
}
|
|
|
|
/**
|
|
* 功能:验证文件独占,并在FLOW及后续META的六个同步点中断。
|
|
* 输入参数:parent——测试父目录(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:重开须按已提交事件恢复,已落盘重试返回DUPLICATE。
|
|
*/
|
|
static void Test_Interruptions(const char *parent)
|
|
{
|
|
unsigned stage;
|
|
for (stage = 1U; stage <= 6U; ++stage) {
|
|
char path[MAX_PATH];
|
|
IEC60870_EnergyFreezeFlowReverse_t event;
|
|
Create_Directory(parent, path);
|
|
assert(Open(path));
|
|
assert(!Example_Energy_Freeze_Open(&second, path, &config, "LOCK", units));
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start, indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
interrupt_after = stage;
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start + 1U, indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_ERROR);
|
|
assert(energy.core.faulted);
|
|
Example_Energy_Freeze_Close(&energy); interrupt_after = 0U;
|
|
assert(Open(path));
|
|
assert(IEC60870_EnergyFreeze_FlowReverse_Count(&energy.core) == (stage <= 2U ? 1U : 2U));
|
|
assert(IEC60870_EnergyFreeze_Get_FlowReverse(&energy.core, stage <= 2U ? 0U : 1U, &event) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(event.sequence == (stage <= 2U ? 1U : 2U));
|
|
if (stage >= 3U) {
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start + 1U, indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_DUPLICATE);
|
|
}
|
|
Example_Energy_Freeze_Close(&energy); Remove_Directory(path);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 功能:验证目录名称严格匹配、枚举关闭后缓存仍可下载,新事件或新目录不会改变打开的下载快照。
|
|
* 输入参数:parent——测试父目录(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:同时检查越界读和路径穿越拒绝、FRZ内容及重开后的封存有效性。
|
|
*/
|
|
static void Test_Snapshots(const char *parent)
|
|
{
|
|
char path[MAX_PATH];
|
|
uint8_t before[4096], after[4096];
|
|
uint32_t size, day = IEC60870_EnergyFreeze_Window_Day(start, 0U);
|
|
ExampleEnergyFreezeEntry entry;
|
|
Create_Directory(parent, path); assert(Open(path));
|
|
assert(!Open(path));
|
|
assert(!Example_Energy_Freeze_Directory_Open(&energy, (const uint8_t *)"", 0U));
|
|
assert(!Example_Energy_Freeze_Directory_Open(&energy, (const uint8_t *)"HISTORY/frz", 11U));
|
|
assert(Example_Energy_Freeze_Directory_Open(&energy, (const uint8_t *)"HISTORY/FRZ", 11U));
|
|
assert(Example_Energy_Freeze_Directory_Count(&energy) == 0U);
|
|
Example_Energy_Freeze_Directory_Close(&energy);
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start, indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(Example_Energy_Freeze_Directory_Open(&energy, (const uint8_t *)"HISTORY/FLOWREV", 15U));
|
|
assert(Example_Energy_Freeze_Directory_Get(&energy, 0U, &entry));
|
|
assert(strcmp(entry.name, "HISTORY/FLOWREV/flowrev.xml") == 0);
|
|
Example_Energy_Freeze_Directory_Close(&energy);
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start + 1U, indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(Example_Energy_Freeze_Read_Open(&energy, (const uint8_t *)entry.name, strlen(entry.name), &size));
|
|
assert(size == entry.size && size < sizeof(before));
|
|
assert(Example_Energy_Freeze_Read(&energy, 0U, before, size)); before[size] = 0U;
|
|
assert(strstr((const char *)before, "num=\"2\"") != NULL);
|
|
assert(!Example_Energy_Freeze_Read(&energy, size + 1U, before, 0U));
|
|
assert(Example_Energy_Freeze_Directory_Open(&energy, (const uint8_t *)"HISTORY/FLOWREV", 15U));
|
|
Example_Energy_Freeze_Directory_Close(&energy);
|
|
assert(Example_Energy_Freeze_Read(&energy, 0U, after, size) && memcmp(before, after, size) == 0);
|
|
Example_Energy_Freeze_Read_Close(&energy);
|
|
assert(!Example_Energy_Freeze_Read_Open(&energy, (const uint8_t *)"../energy.store", 15U, &size));
|
|
assert(IEC60870_EnergyFreeze_Record_Interval(&energy.core, start, start, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(IEC60870_EnergyFreeze_Derive_Day(&energy.core, start, day) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(IEC60870_EnergyFreeze_Advance(&energy.core, start + UINT64_C(86400000) + config.max_delay_ms) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(Example_Energy_Freeze_Directory_Open(&energy, (const uint8_t *)"HISTORY/FRZ", 11U));
|
|
assert(Example_Energy_Freeze_Directory_Count(&energy) == 1U);
|
|
assert(Example_Energy_Freeze_Directory_Get(&energy, 0U, &entry));
|
|
assert(entry.time.time.hour == 0U && entry.time.time.minute == 0U);
|
|
Example_Energy_Freeze_Directory_Close(&energy);
|
|
assert(Example_Energy_Freeze_Read_Open(&energy, (const uint8_t *)entry.name, strlen(entry.name), &size));
|
|
assert(size < sizeof(before)); assert(Example_Energy_Freeze_Read(&energy, 0U, before, size)); before[size] = 0U;
|
|
assert(strstr((const char *)before, "sectNum=\"1\"") != NULL);
|
|
assert(strstr((const char *)before, "type=\"DayFrz\" tm=") != NULL);
|
|
Example_Energy_Freeze_Close(&energy);
|
|
assert(Open(path));
|
|
assert(IEC60870_EnergyFreeze_Validate_Seal(&energy.core, day) == IEC60870_ENERGY_FREEZE_OK);
|
|
Example_Energy_Freeze_Close(&energy); Remove_Directory(path);
|
|
}
|
|
|
|
/**
|
|
* 功能:验证以下场景与约束:构造两份可靠提交副本。
|
|
* 输入参数:parent——测试父目录(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:即使旧副本损坏,v5也须整槽报错,不能回退掩盖损坏。
|
|
*/
|
|
static void Test_Bank_States(const char *parent)
|
|
{
|
|
unsigned scenario;
|
|
for (scenario = 0U; scenario < 5U; ++scenario) {
|
|
char path[MAX_PATH];
|
|
HANDLE file;
|
|
uint8_t bytes[368], marker[4] = {0U, 0U, 0U, 0U};
|
|
size_t size;
|
|
Create_Directory(parent, path); assert(Open(path));
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start, indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(energy.core.store.read(energy.core.store.context, IEC60870_ENERGY_FREEZE_FLOWREV, 0U,
|
|
bytes, sizeof(bytes), &size) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(energy.core.store.commit(energy.core.store.context, IEC60870_ENERGY_FREEZE_FLOWREV, 0U, bytes, size));
|
|
Example_Energy_Freeze_Close(&energy); file = Raw_Open(path);
|
|
if (scenario == 0U) { Flip(file, 2483232U + 32U + 45U); }
|
|
else if (scenario == 1U) { Flip(file, 2483232U + 20U); }
|
|
else if (scenario == 2U) { Change(file, 2483232U + 24U, marker, 4U); }
|
|
else if (scenario == 3U) { marker[0] = 1U; Change(file, 2483232U + 24U, marker, 4U); }
|
|
else { Flip(file, 0U); }
|
|
CloseHandle(file);
|
|
if (scenario == 2U || scenario == 3U) {
|
|
assert(Open(path)); assert(IEC60870_EnergyFreeze_FlowReverse_Count(&energy.core) == 1U);
|
|
Example_Energy_Freeze_Close(&energy);
|
|
} else { assert(!Open(path)); }
|
|
Remove_Directory(path);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 功能:验证以下场景与约束:清除已封存INTERVAL的提交标记,验证重新打开不能把已封存记录丢失当成普通缺测。
|
|
* 输入参数:parent——测试父目录(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
static void Test_Sealed_Missing(const char *parent)
|
|
{
|
|
char path[MAX_PATH];
|
|
HANDLE file;
|
|
uint8_t marker[4] = {0U, 0U, 0U, 0U};
|
|
uint32_t day = IEC60870_EnergyFreeze_Window_Day(start, 0U);
|
|
Create_Directory(parent, path); assert(Open(path));
|
|
assert(IEC60870_EnergyFreeze_Record_Interval(&energy.core, start, start, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
assert(IEC60870_EnergyFreeze_Advance(&energy.core, start + UINT64_C(86400000) + config.max_delay_ms) == IEC60870_ENERGY_FREEZE_OK);
|
|
Example_Energy_Freeze_Close(&energy); file = Raw_Open(path);
|
|
Change(file, 32U + ((day % 32U) * 96U) * 800U + 24U, marker, 4U);
|
|
CloseHandle(file);
|
|
assert(!Open(path)); Remove_Directory(path);
|
|
}
|
|
|
|
/**
|
|
* 功能:验证以下场景与约束:真实环回绕后slot0保存seq1/257两代。
|
|
* 输入参数:parent——测试父目录(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:最新载荷坏不能退选seq1;
|
|
* 最新标记不可见时,虽然旧的1..256仍连续,META的257水位也必须发现回退。
|
|
*/
|
|
static void Test_Flow_Wrap_Corruption(const char *parent)
|
|
{
|
|
unsigned scenario;
|
|
for (scenario = 0U; scenario < 2U; ++scenario) {
|
|
char path[MAX_PATH];
|
|
HANDLE file;
|
|
IEC60870_EnergyFreezeFlowReverse_t event;
|
|
unsigned i;
|
|
Create_Directory(parent, path); assert(Open(path));
|
|
for (i = 0U; i < 257U; ++i) {
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start + i,
|
|
indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
}
|
|
assert(IEC60870_EnergyFreeze_FlowReverse_Count(&energy.core) == 256U);
|
|
assert(IEC60870_EnergyFreeze_Get_FlowReverse(&energy.core, 0U, &event) == IEC60870_ENERGY_FREEZE_OK && event.sequence == 2U);
|
|
assert(IEC60870_EnergyFreeze_Get_FlowReverse(&energy.core, 255U, &event) == IEC60870_ENERGY_FREEZE_OK && event.sequence == 257U);
|
|
Example_Energy_Freeze_Close(&energy);
|
|
assert(Open(path));
|
|
assert(IEC60870_EnergyFreeze_FlowReverse_Count(&energy.core) == 256U);
|
|
Example_Energy_Freeze_Close(&energy); file = Raw_Open(path);
|
|
Flip(file, 2483232U + 128U + (scenario == 0U ? 32U + 45U : 24U));
|
|
CloseHandle(file);
|
|
assert(!Open(path)); Remove_Directory(path);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 功能:验证已有零长度文件拒绝重建,值语义指纹改变拒绝恢复。
|
|
* 输入参数:parent——测试父目录(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:改回原配置后原持久内容仍可打开。
|
|
*/
|
|
static void Test_Empty_And_Config(const char *parent)
|
|
{
|
|
char path[MAX_PATH];
|
|
HANDLE file;
|
|
LARGE_INTEGER at;
|
|
Create_Directory(parent, path); assert(Open(path)); Example_Energy_Freeze_Close(&energy);
|
|
file = Raw_Open(path); at.QuadPart = 0;
|
|
assert(SetFilePointerEx(file, at, NULL, FILE_BEGIN) && SetEndOfFile(file)); CloseHandle(file);
|
|
assert(!Open(path)); Remove_Directory(path);
|
|
Create_Directory(parent, path); assert(Open(path));
|
|
assert(IEC60870_EnergyFreeze_Append_FlowReverse(&energy.core, start, indices, values, quality, 2U) == IEC60870_ENERGY_FREEZE_OK);
|
|
Example_Energy_Freeze_Close(&energy); ++config.value_semantics;
|
|
assert(!Open(path)); --config.value_semantics;
|
|
assert(Open(path)); Example_Energy_Freeze_Close(&energy); Remove_Directory(path);
|
|
}
|
|
|
|
static IEC60870_EnergyFreezeResult_t (*original_read)(void *, IEC60870_EnergyFreezeKind_t,
|
|
uint32_t, uint8_t *, size_t, size_t *);
|
|
static unsigned directory_reads;
|
|
|
|
/**
|
|
* 功能:计数目录生成的逻辑读取后原样委托真实后端,用于区分XML算法成本与底层双bank读取成本。
|
|
* 输入参数:context——业务回调的测试上下文;kind——记录或对象类别;index——待访问或核对的条目下标;bytes——报文字节缓冲区;capacity——调用方提供的缓冲容量;size——数据长度或文件大小。
|
|
* 输出参数:bytes——写入或读出的数据字节;size——本次数据、文件或 ASDU 的实际长度。
|
|
* 返回值:本次核心或后端操作的状态枚举,保留成功、空记录、拒绝及错误等区别。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
static IEC60870_EnergyFreezeResult_t Count_Read(void *context, IEC60870_EnergyFreezeKind_t kind,
|
|
uint32_t index, uint8_t *bytes, size_t capacity, size_t *size)
|
|
{
|
|
++directory_reads;
|
|
return original_read(context, kind, index, bytes, capacity, size);
|
|
}
|
|
|
|
/**
|
|
* 功能:验证以下场景与约束:实测完整30日、每天96间隔加DAY、8点的目录生成。
|
|
* 输入参数:parent——测试父目录(只读)。
|
|
* 输出参数:无。
|
|
* 返回值:无。
|
|
* 说明:计时不包含造数和持久写入。
|
|
*/
|
|
static void Test_Full_Directory_Cost(const char *parent)
|
|
{
|
|
char path[MAX_PATH];
|
|
uint32_t interval[8], daily[8], flow[8];
|
|
float sample[8];
|
|
uint8_t q[8] = {0U};
|
|
const char *const point_units[8] = {"kWh", "kvarh", "kvarh", "kvarh", "kWh", "kvarh", "kvarh", "kvarh"};
|
|
IEC60870_EnergyFreezeConfig_t full = config;
|
|
LARGE_INTEGER frequency, begin, end;
|
|
unsigned d, slot, point;
|
|
uint64_t bytes = 0U;
|
|
for (point = 0U; point < 8U; ++point) {
|
|
interval[point] = 0x6409U + point; daily[point] = 0x6411U + point; flow[point] = 0x6419U + point;
|
|
}
|
|
full.interval_ioas = interval; full.day_ioas = daily; full.point_count = 8U;
|
|
full.flowrev_ioas = flow; full.flowrev_count = 8U;
|
|
Create_Directory(parent, path);
|
|
assert(Example_Energy_Freeze_Open(&energy, path, &full, "ENERGY_DIRECTORY_COST", point_units));
|
|
for (d = 0U; d < 30U; ++d) {
|
|
uint64_t window = start + (uint64_t)d * UINT64_C(86400000);
|
|
uint32_t day = IEC60870_EnergyFreeze_Window_Day(window, 0U);
|
|
for (slot = 0U; slot < 96U; ++slot) {
|
|
uint64_t nominal = window + (uint64_t)slot * 900000U;
|
|
uint64_t now = nominal + (slot == 0U ? full.max_delay_ms : 0U);
|
|
for (point = 0U; point < 8U; ++point) { sample[point] = (float)(10000U + d * 1000U + slot * 8U + point) / 1000.0f; }
|
|
assert(IEC60870_EnergyFreeze_Record_Interval(&energy.core, now, nominal, sample, q, 8U) == IEC60870_ENERGY_FREEZE_OK);
|
|
if (slot == 0U) {
|
|
assert(IEC60870_EnergyFreeze_Derive_Day(&energy.core, now, day) == IEC60870_ENERGY_FREEZE_OK);
|
|
}
|
|
}
|
|
assert(IEC60870_EnergyFreeze_Advance(&energy.core, window + UINT64_C(86400000) + full.max_delay_ms) == IEC60870_ENERGY_FREEZE_OK);
|
|
}
|
|
original_read = energy.core.store.read; energy.core.store.read = Count_Read; directory_reads = 0U;
|
|
assert(QueryPerformanceFrequency(&frequency) && QueryPerformanceCounter(&begin));
|
|
assert(Example_Energy_Freeze_Directory_Open(&energy, (const uint8_t *)"HISTORY/FRZ", 11U));
|
|
assert(QueryPerformanceCounter(&end)); energy.core.store.read = original_read;
|
|
assert(Example_Energy_Freeze_Directory_Count(&energy) == 30U);
|
|
assert(directory_reads == 30U * 99U);
|
|
for (d = 0U; d < 30U; ++d) {
|
|
ExampleEnergyFreezeEntry entry;
|
|
assert(Example_Energy_Freeze_Directory_Get(&energy, d, &entry));
|
|
bytes += entry.size;
|
|
}
|
|
printf("energy freeze directory30: elapsed_ms=%.3f logical_reads=%u physical_bank_reads=%u xml_bytes=%lu\n",
|
|
(double)(end.QuadPart - begin.QuadPart) * 1000.0 / (double)frequency.QuadPart,
|
|
directory_reads, directory_reads * 2U, (unsigned long)bytes);
|
|
Example_Energy_Freeze_Close(&energy); Remove_Directory(path);
|
|
}
|
|
|
|
/**
|
|
* 功能:使用命令行父目录运行持久故障、快照和目录成本用例,配置两点基线并报告宿主对象大小。
|
|
* 输入参数:argc——命令行参数数量;argv——命令行参数数组。
|
|
* 输出参数:无。
|
|
* 返回值:正常完成返回 0;参数、运行或断言失败以非零状态结束进程。
|
|
* 说明:本辅助入口用于构造或核对上述测试场景,相关状态保存在当前测试夹具中。
|
|
*/
|
|
int main(int argc, char **argv)
|
|
{
|
|
uint32_t day;
|
|
assert(argc == 2);
|
|
IEC60870_EnergyFreeze_Config_Default(&config);
|
|
config.interval_ioas = interval_ioas; config.day_ioas = day_ioas; config.point_count = 2U;
|
|
config.flowrev_ioas = flow_ioas; config.flowrev_count = 2U;
|
|
config.grid_tolerance_ms = 1000U; config.max_delay_ms = 60000U;
|
|
day = IEC60870_EnergyFreeze_Window_Day(UINT64_C(1794412800000), 0U);
|
|
assert(IEC60870_EnergyFreeze_Window_Start(day, 0U, &start));
|
|
Test_Interruptions(argv[1]); Test_Snapshots(argv[1]); Test_Bank_States(argv[1]);
|
|
Test_Sealed_Missing(argv[1]); Test_Flow_Wrap_Corruption(argv[1]);
|
|
Test_Empty_And_Config(argv[1]); Test_Full_Directory_Cost(argv[1]);
|
|
printf("energy freeze host tests passed; core=%lu adapter=%lu\n",
|
|
(unsigned long)sizeof(IEC60870_EnergyFreeze_t), (unsigned long)sizeof(ExampleEnergyFreeze));
|
|
return 0;
|
|
}
|