Add all pages test and accessor functions
This commit is contained in:
@@ -6,22 +6,33 @@ SRCS = test_mock_driver.c mock_driver.c
|
|||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
TARGET = test_mock_driver
|
TARGET = test_mock_driver
|
||||||
|
|
||||||
all: $(TARGET)
|
# Test programs
|
||||||
|
TEST_ALL = test_all_pages
|
||||||
|
TEST_ALL_SRCS = test_all_pages.c mock_driver.c
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
all: $(TARGET) $(TEST_ALL)
|
||||||
$(CC) $(CFLAGS) -o $@ $(OBJS)
|
|
||||||
|
$(TARGET): test_mock_driver.o mock_driver.o
|
||||||
|
$(CC) $(CFLAGS) -o $@ test_mock_driver.o mock_driver.o
|
||||||
|
|
||||||
|
$(TEST_ALL): $(TEST_ALL_SRCS)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(TEST_ALL_SRCS)
|
||||||
|
|
||||||
test_mock_driver.o: test_mock_driver.c mock_driver.h
|
test_mock_driver.o: test_mock_driver.c mock_driver.h
|
||||||
mock_driver.o: mock_driver.c mock_driver.h
|
mock_driver.o: mock_driver.c mock_driver.h
|
||||||
|
test_all_pages.o: test_all_pages.c mock_driver.h
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TARGET) $(OBJS)
|
rm -f $(TARGET) $(TEST_ALL) *.o
|
||||||
|
|
||||||
run: $(TARGET)
|
run: $(TARGET)
|
||||||
./$(TARGET)
|
./$(TARGET)
|
||||||
|
|
||||||
|
run-all: $(TEST_ALL)
|
||||||
|
./$(TEST_ALL)
|
||||||
|
|
||||||
# Enable verbose output
|
# Enable verbose output
|
||||||
debug: CFLAGS += -DVERBOSE=1
|
debug: CFLAGS += -DVERBOSE=1
|
||||||
debug: $(TARGET)
|
debug: $(TARGET)
|
||||||
|
|
||||||
.PHONY: all clean run debug
|
.PHONY: all clean run run-all debug
|
||||||
|
|||||||
@@ -443,3 +443,16 @@ void mock_print_config(void) {
|
|||||||
printf("Pending Events: %d\n", g_mockEventCount);
|
printf("Pending Events: %d\n", g_mockEventCount);
|
||||||
printf("=========================\n");
|
printf("=========================\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// Accessors for testing
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
MOCK_CTRL_INFO* mock_get_ctrl_info(int index) {
|
||||||
|
if (index < 0 || index >= MAX_DTR_IN_HOST) return NULL;
|
||||||
|
return &g_mockCtrl[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
int mock_get_event_queue_count(void) {
|
||||||
|
return g_mockEventCount;
|
||||||
|
}
|
||||||
|
|||||||
@@ -104,4 +104,8 @@ void mock_register_default_events(void);
|
|||||||
int mock_load_config(const char *filename);
|
int mock_load_config(const char *filename);
|
||||||
void mock_print_config(void);
|
void mock_print_config(void);
|
||||||
|
|
||||||
|
// Accessors for testing
|
||||||
|
MOCK_CTRL_INFO* mock_get_ctrl_info(int index);
|
||||||
|
int mock_get_event_queue_count(void);
|
||||||
|
|
||||||
#endif // MOCK_DRIVER_H
|
#endif // MOCK_DRIVER_H
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,202 @@
|
|||||||
|
/*
|
||||||
|
* test_all_pages.c
|
||||||
|
*
|
||||||
|
* Test all mock driver pages
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "mock_driver.h"
|
||||||
|
|
||||||
|
void print_hex(const char *label, unsigned char *buf, int len) {
|
||||||
|
printf("%s:\n", label);
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
printf("%02X ", buf[i]);
|
||||||
|
if ((i + 1) % 16 == 0) printf("\n");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_page0(void) {
|
||||||
|
printf("\n========== TEST PAGE 0: Controller Info ==========\n");
|
||||||
|
unsigned char buf[1024];
|
||||||
|
unsigned char heatsink;
|
||||||
|
|
||||||
|
CHAR result = mock_QuaryDTR(0, buf, &heatsink);
|
||||||
|
printf("Result: %d\n", result);
|
||||||
|
|
||||||
|
printf("Serial Number: %.16s\n", buf + 0);
|
||||||
|
printf("Model Name: %.32s\n", buf + 16);
|
||||||
|
printf("Firmware Version: %.8s\n", buf + 64);
|
||||||
|
printf("BIOS Version: %.8s\n", buf + 72);
|
||||||
|
printf("Status: 0x%02X\n", buf[96]);
|
||||||
|
printf("RAID Ports: %d\n", buf[104]);
|
||||||
|
printf("Disk Count: %d\n", buf[105]);
|
||||||
|
printf("Controller #: %d\n", buf[106]);
|
||||||
|
|
||||||
|
print_hex("Full Page 0 (first 128 bytes)", buf, 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_page1(void) {
|
||||||
|
printf("\n========== TEST PAGE 1: RAID Snapshot ==========\n");
|
||||||
|
|
||||||
|
// Use accessor to get internal data
|
||||||
|
MOCK_CTRL_INFO *ctrl = mock_get_ctrl_info(0);
|
||||||
|
unsigned char *buf = ctrl->bPage1Data;
|
||||||
|
|
||||||
|
printf("RAID 0 Status: 0x%02X\n", buf[0]);
|
||||||
|
printf("RAID 0 Level: 0x%02X\n", buf[1]);
|
||||||
|
printf("RAID 0 Disk Count: %d\n", buf[2]);
|
||||||
|
|
||||||
|
printf("RAID 1 Status: 0x%02X\n", buf[128]);
|
||||||
|
printf("RAID 1 Level: 0x%02X\n", buf[129]);
|
||||||
|
printf("RAID 1 Disk Count: %d\n", buf[130]);
|
||||||
|
|
||||||
|
print_hex("Full Page 1 (first 256 bytes)", buf, 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_page7(void) {
|
||||||
|
printf("\n========== TEST PAGE 7: LUN Map Table ==========\n");
|
||||||
|
|
||||||
|
MOCK_CTRL_INFO *ctrl = mock_get_ctrl_info(0);
|
||||||
|
unsigned char *buf = ctrl->bPage7Data;
|
||||||
|
|
||||||
|
printf("LUN 0: 0x%02X\n", buf[0]);
|
||||||
|
printf("RAID ID 0: 0x%02X\n", buf[1]);
|
||||||
|
printf("Enable: 0x%02X\n", buf[2]);
|
||||||
|
|
||||||
|
print_hex("Full Page 7", buf, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_page10(void) {
|
||||||
|
printf("\n========== TEST PAGE 10: RAID Info 0-1 ==========\n");
|
||||||
|
|
||||||
|
MOCK_CTRL_INFO *ctrl = mock_get_ctrl_info(0);
|
||||||
|
unsigned char *buf = ctrl->bPage10Data;
|
||||||
|
|
||||||
|
printf("RAID 0 Status: 0x%02X\n", buf[0]);
|
||||||
|
printf("RAID 0 Level: 0x%02X\n", buf[1]);
|
||||||
|
printf("RAID 0 Disks: %d\n", buf[2]);
|
||||||
|
printf("RAID 0 Stripe: 0x%02X\n", buf[3]);
|
||||||
|
|
||||||
|
// Capacity (big-endian)
|
||||||
|
unsigned long long capacity = 0;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
capacity = (capacity << 8) | buf[8 + i];
|
||||||
|
}
|
||||||
|
printf("RAID 0 Capacity: %llu bytes\n", capacity);
|
||||||
|
|
||||||
|
print_hex("Full Page 10", buf, 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_page11(void) {
|
||||||
|
printf("\n========== TEST PAGE 11: RAID Info 2-3 ==========\n");
|
||||||
|
|
||||||
|
MOCK_CTRL_INFO *ctrl = mock_get_ctrl_info(0);
|
||||||
|
unsigned char *buf = ctrl->bPage11Data;
|
||||||
|
|
||||||
|
printf("Status: 0x%02X\n", buf[0]);
|
||||||
|
|
||||||
|
print_hex("Full Page 11", buf, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_page14(void) {
|
||||||
|
printf("\n========== TEST PAGE 14: RAID Info 6-7 ==========\n");
|
||||||
|
|
||||||
|
MOCK_CTRL_INFO *ctrl = mock_get_ctrl_info(0);
|
||||||
|
unsigned char *buf = ctrl->bPage14Data;
|
||||||
|
|
||||||
|
print_hex("Full Page 14", buf, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_page27(void) {
|
||||||
|
printf("\n========== TEST PAGE 27: Disk List ==========\n");
|
||||||
|
|
||||||
|
MOCK_CTRL_INFO *ctrl = mock_get_ctrl_info(0);
|
||||||
|
unsigned char *buf = ctrl->bPage27Data;
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
int offset = i * 16;
|
||||||
|
printf("Disk %d: Slot=0x%02X Status=0x%02X Type=0x%02X\n",
|
||||||
|
i, buf[offset], buf[offset+1], buf[offset+2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
print_hex("Full Page 27", buf, 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_devioctl(void) {
|
||||||
|
printf("\n========== TEST DevIoControl ==========\n");
|
||||||
|
|
||||||
|
unsigned char outBuf[1024];
|
||||||
|
USHORT errCode;
|
||||||
|
UCHAR result;
|
||||||
|
|
||||||
|
// Test IOCTL 0x9001 - GET_CONTROLLER_INFO
|
||||||
|
result = mock_DevIoControl(0, 0x9001, 0, NULL, 1024, (char*)outBuf, &errCode);
|
||||||
|
printf("IOCTL 0x9001 (Controller Info): result=0x%02X err=0x%04X\n", result, errCode);
|
||||||
|
printf(" SN: %.16s\n", outBuf);
|
||||||
|
|
||||||
|
// Test IOCTL 0x9002 - GET_RAID_INFO
|
||||||
|
result = mock_DevIoControl(0, 0x9002, 0, NULL, 1024, (char*)outBuf, &errCode);
|
||||||
|
printf("IOCTL 0x9002 (RAID Info): result=0x%02X err=0x%04X\n", result, errCode);
|
||||||
|
printf(" RAID 0 Status: 0x%02X\n", outBuf[0]);
|
||||||
|
|
||||||
|
// Test IOCTL 0x9020 - GET_INBAND_EVENT
|
||||||
|
result = mock_DevIoControl(0, 0x9020, 0, NULL, 512, (char*)outBuf, &errCode);
|
||||||
|
printf("IOCTL 0x9020 (Event): result=0x%02X err=0x%04X\n", result, errCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_events(void) {
|
||||||
|
printf("\n========== TEST Events ==========\n");
|
||||||
|
|
||||||
|
// Generate various events
|
||||||
|
mock_clear_events();
|
||||||
|
|
||||||
|
// Disk events
|
||||||
|
mock_generate_disk_event(0, 0x01); // Online
|
||||||
|
mock_generate_disk_event(1, 0x01); // Online
|
||||||
|
mock_generate_disk_event(2, 0x02); // Offline
|
||||||
|
mock_generate_disk_event(3, 0x03); // Error
|
||||||
|
|
||||||
|
// RAID events
|
||||||
|
mock_generate_raid_event(0, 0x10); // Rebuild start
|
||||||
|
mock_generate_raid_event(0, 0x11); // Rebuild done
|
||||||
|
|
||||||
|
printf("Generated 6 events\n");
|
||||||
|
|
||||||
|
// Read all events
|
||||||
|
EVENT_INFO evt;
|
||||||
|
int count = 0;
|
||||||
|
while (mock_GetCtlrEvent(0, &evt) == SYSOK && evt.bStatus && count < 10) {
|
||||||
|
printf("Event %d: Type=0x%02X Slot/ID=0x%02X\n",
|
||||||
|
count + 1, evt.bEventBuf[0], evt.bEventBuf[3]);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
printf("Total events read: %d\n", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
printf("=== Mock Driver - All Pages Test ===\n");
|
||||||
|
|
||||||
|
// Enable verbose
|
||||||
|
mock_set_verbose(true);
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
mock_init();
|
||||||
|
|
||||||
|
// Run all tests
|
||||||
|
test_page0();
|
||||||
|
test_page1();
|
||||||
|
test_page7();
|
||||||
|
test_page10();
|
||||||
|
test_page11();
|
||||||
|
test_page14();
|
||||||
|
test_page27();
|
||||||
|
test_devioctl();
|
||||||
|
test_events();
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
mock_cleanup();
|
||||||
|
|
||||||
|
printf("\n=== All Tests Completed ===\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>English</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>com.apple.xcode.dsym.test_all_pages</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>dSYM</string>
|
||||||
|
<key>CFBundleSignature</key>
|
||||||
|
<string>????</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
triple: 'arm64-apple-darwin'
|
||||||
|
binary-path: test_all_pages
|
||||||
|
relocations: []
|
||||||
|
...
|
||||||
Reference in New Issue
Block a user