XNSim/XNMonitorServer/test/test_initialize.cpp

96 lines
3.1 KiB
C++

#include <iostream>
#include <string>
#include <cstring>
#include "../XNMonitorInterface.h"
int main()
{
std::cout << "=== XNMonitorServer 初始化测试 ===" << std::endl;
// 测试参数
const char *domainId = "10";
int domainIdLen = strlen(domainId);
int confID = 1;
int forceGen = 0;
char errorMsg[1024];
int errorMsgSize = sizeof(errorMsg);
std::cout << "测试参数:" << std::endl;
std::cout << " domainId: " << domainId << std::endl;
std::cout << " confID: " << confID << std::endl;
std::cout << " forceGen: " << forceGen << std::endl;
std::cout << std::endl;
// 调用XN_Initialize
std::cout << "正在调用 XN_Initialize..." << std::endl;
int result = XN_Initialize(domainId, domainIdLen, confID, forceGen, errorMsg, errorMsgSize);
if (result == 0) {
std::cout << "✓ XN_Initialize 调用成功!" << std::endl;
std::cout << "返回信息: " << errorMsg << std::endl;
// 测试其他功能
std::cout << std::endl << "=== 测试其他功能 ===" << std::endl;
// 测试系统信息监控
std::cout << "正在启动系统信息监控..." << std::endl;
int sysResult = XN_StartMonitorSystemInfo(errorMsg, errorMsgSize);
if (sysResult == 0) {
std::cout << "✓ 系统信息监控启动成功" << std::endl;
// 获取系统信息
char sysInfo[2048];
int sysInfoSize = sizeof(sysInfo);
int getSysResult = XN_GetSystemInfo(sysInfo, sysInfoSize);
if (getSysResult == 0) {
std::cout << "✓ 获取系统信息成功" << std::endl;
std::cout << "系统信息: " << sysInfo << std::endl;
} else {
std::cout << "✗ 获取系统信息失败: " << sysInfo << std::endl;
}
// 停止系统信息监控
XN_StopMonitorSystemInfo();
std::cout << "✓ 系统信息监控已停止" << std::endl;
} else {
std::cout << "✗ 系统信息监控启动失败: " << errorMsg << std::endl;
}
// 测试模型信息监控
std::cout << std::endl << "正在启动模型信息监控..." << std::endl;
int modelResult = XN_StartMonitorModelInfo(errorMsg, errorMsgSize);
if (modelResult == 0) {
std::cout << "✓ 模型信息监控启动成功" << std::endl;
// 获取模型信息
char modelInfo[2048];
int modelInfoSize = sizeof(modelInfo);
int getModelResult = XN_GetModelInfo(modelInfo, modelInfoSize);
if (getModelResult == 0) {
std::cout << "✓ 获取模型信息成功" << std::endl;
std::cout << "模型信息: " << modelInfo << std::endl;
} else {
std::cout << "✗ 获取模型信息失败: " << modelInfo << std::endl;
}
// 停止模型信息监控
XN_StopMonitorModelInfo();
std::cout << "✓ 模型信息监控已停止" << std::endl;
} else {
std::cout << "✗ 模型信息监控启动失败: " << errorMsg << std::endl;
}
// 清理资源
std::cout << std::endl << "=== 清理资源 ===" << std::endl;
XN_Cleanup();
std::cout << "✓ 资源清理完成" << std::endl;
} else {
std::cout << "✗ XN_Initialize 调用失败!" << std::endl;
std::cout << "错误信息: " << errorMsg << std::endl;
}
std::cout << std::endl << "=== 测试完成 ===" << std::endl;
return result;
}