Files
rust_raidguardx/raidguard_c_gui_server_mock/README.md
T

4.4 KiB
Raw Blame History

RAIDGuard X Mock Driver (C)

Mock driver for RAIDGuard X GUI Server - provides simulated RAID controller for testing without hardware.

目錄結構

raidguard_c_gui_server_mock/
├── mock_driver.h      # Header file
├── mock_driver.c      # Implementation
├── test_mock_driver.c # Test program
├── Makefile          # Build file
└── README.md         # This file

建構

make

執行測試

./test_mock_driver        # 基本測試
./test_all_pages         # 完整頁面測試

使用方式

1. 初始化

#include "mock_driver.h"

// 初始化 Mock Driver
mock_init();

// 啟用詳細輸出
mock_set_verbose(true);

2. 設定控制器

// 設定控制器數量 (預設 1)
mock_set_controller_count(2);

// 設定控制器序號
mock_set_controller_serial(0, "MOCK00000001");
mock_set_controller_serial(1, "MOCK00000002");

// 設定控制器型號
mock_set_controller_model(0, "Accusys GEN2");

3. 查詢控制器資訊

UCHAR pageBuf[1024];
UCHAR heatsink;

// 查詢控制器資訊
CHAR result = mock_QuaryDTR(0, pageBuf, &heatsink);

if (result == 1) {
    // 取得序號
    printf("SN: %.16s\n", pageBuf);
    
    // 取得型號
    printf("Model: %.20s\n", pageBuf + 16);
    
    // 取得韌體版本
    printf("FW: %.8s\n", pageBuf + 64);
}

4. 取得事件

EVENT_INFO evt;
UCHAR result = mock_GetCtlrEvent(0, &evt);

if (result == SYSOK && evt.bStatus) {
    // 處理事件
    printf("Event Type: %d\n", evt.bEventBuf[0]);
}

5. 模擬事件

// 模擬磁碟上線事件
mock_generate_disk_event(5, 0x01);

// 模擬 RAID 重建事件
mock_generate_raid_event(0, 0x02);

// 自訂事件
UCHAR customEvent[] = {
    0x03, 0x00, 0x00, 0x00,  // Event Type
    0x00, 0x00, 0x00, 0x00,  // Timestamp
    0x00, 0x00, 0x00, 0x00,  // Data
    0x00, 0x00, 0x00, 0x00
};
mock_push_event(customEvent, 16);

6. 清理

mock_cleanup();

API 參考

初始化與清理

函數 說明
mock_init() 初始化 Mock Driver
mock_cleanup() 清理資源
mock_set_verbose(bool) 設定詳細輸出

控制器設定

函數 說明
mock_set_controller_count(int) 設定控制器數量
mock_set_controller_serial(int, const char*) 設定控制器序號
mock_set_controller_model(int, const char*) 設定控制器型號
mock_set_controller_status(int, UCHAR) 設定控制器狀態

Driver 函數

函數 說明
mock_QuaryDTR(UCHAR, UCHAR*, UCHAR*) 查詢控制器資訊
mock_DevIoControl(...) I/O Control (模擬)
mock_GetCtlrEvent(UCHAR, EVENT_INFO*) 取得事件

事件模擬

函數 說明
mock_push_event(UCHAR*, int) 推入自訂事件
mock_clear_events() 清除所有事件
mock_generate_disk_event(int, int) 產生磁碟事件
mock_generate_raid_event(int, int) 產生 RAID 事件

模擬的 Page 資料

Page 大小 內容
0x00 1024 Controller Info (序號, 型號, 韌體, 狀態)
0x01 1024 RAID Snapshot (RAID 0-1 狀態)
0x07 512 LUN Map Table
0x0A 1024 RAID Info 0-1 (狀態, 等級, 容量)
0x0B 1024 RAID Info 2-3
0x0E 1024 Event Log (8 筆事件, 含時間戳記)
0x14 512 Enclosure Info (風扇, 電源, 溫度)
0x1B 512 Disk List (8 個磁碟槽)

整合到 GS

要將 Mock Driver 整合到 GS (DtrGuiSrv),請在編譯時使用 -DENABLE_MOCK_MODE

ifdef ENABLE_MOCK_MODE
    CFLAGS += -DENABLE_MOCK_MODE
    SRCS += mock_driver.c
    
    # 置換函數
    CFLAGS += -DQuaryDTR=mock_QuaryDTR
    CFLAGS += -DDevIoControl=mock_DevIoControl
    CFLAGS += -DGetCtlrEvent=mock_GetCtlrEvent
endif

或使用 FFI

#ifdef ENABLE_MOCK_MODE
    #include "mock_driver.h"
    #define DevIoControl mock_DevIoControl
    #define QuaryDTR mock_QuaryDTR
    #define GetCtlrEvent mock_GetCtlrEvent
#endif

開發日誌

  • 2026-03-29: 新增頁面

    • Page 14: Event Log (8 筆事件,含時間戳記與訊息)
    • Page 20: Enclosure Info (風扇、電源、溫度、電池)
    • test_all_pages 完整測試
  • 2024-03-29: 初始版本

    • 基本控制器模擬
    • 事件佇列
    • Page 0-1, 7, 10, 27 資料

License

Proprietary - Accusys Inc.