int __cdecl wmain(int argc, PWSTR argv[]) { if (argc < 2) return EXIT_FAILURE; SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); STARTUPINFOW si = { sizeof si }; PROCESS_INFORMATION pi; if (!CreateProcessW(nullptr, argv[1], nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi)) { printf_red("!CreateProcess:%x\n", GetLastError()); return EXIT_FAILURE; } if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_OBJECT_0) { printf_red("!WaitForSingleObject:%x\n", GetLastError()); return EXIT_FAILURE; } ULONG exit_code; if (!GetExitCodeProcess(pi.hProcess, &exit_code)) { printf_red("!GetExitCodeProcess:%x\n", GetLastError()); return EXIT_FAILURE; } if (exit_code != EXIT_SUCCESS) printf_red("Process ABEND:%x\n", exit_code); return exit_code; }
int CAccountTrade::OnRspUserLogin(char *pMsg,int client_fd) { int ret = 0; int iSendLen = sizeof(MsgHead) + sizeof(TradeRspUserLoginFromATF); TradeRspUserLoginFromATF *pRsp = (TradeRspUserLoginFromATF *)(pMsg + sizeof(MsgHead)); FillMsgOnRspLogin(pRsp); ret = TcpSendData(m_clientSock,pMsg,iSendLen); if(ret != iSendLen) { g_log.error("[ExchgServer]TCP send OnRspUserLogin error,expect %dB, actual %dB.\n",iSendLen,ret); memset(m_curOpErrReason,0,sizeof(m_curOpErrReason)); sprintf(m_curOpErrReason,"TCP send OnRspUserLogin error,expect %dB, actual %dB.",iSendLen,ret); return ATF_FAIL; } else { if(IS_DEBUG) { printf_red("[ExchgServer]Send OnRspUserLogin(%dB)\n",ret); } g_log.info("[ExchgServer]Send OnRspUserLogin(%dB)\n",ret); return ATF_SUCC; } }
int CAccountTrade::OnFrontDisconnected(char *pMsg,int client_fd) { int ret = 0; int iSendLen = sizeof(MsgHead); ret = TcpSendData(m_clientSock,pMsg,iSendLen); if(ret != iSendLen) { g_log.error("[ExchgServer]TCP send OnFrontDisconnected error,expect %dB, actual %dB.\n",iSendLen,ret); memset(m_curOpErrReason,0,sizeof(m_curOpErrReason)); sprintf(m_curOpErrReason,"TCP send OnFrontDisconnected error,expect %dB, actual %dB.",iSendLen,ret); return ATF_FAIL; } else { if(IS_DEBUG) { printf_red("[ExchgServer]Send OnFrontDisconnected(%dB)\n",ret); } g_log.info("[ExchgServer]Send OnFrontDisconnected(%dB)\n",ret); } m_connect = DISCONNECTED; m_login = NOT_LOGIN; m_sessionID++; CloseFd(); return ATF_SUCC; }
int __cdecl main() { PVOID address = ULongToPtr(1); SIZE_T length = 512; NTSTATUS status = ZwAllocateVirtualMemory(GetCurrentProcess(), &address, 0, &length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (NT_SUCCESS(status)) { *static_cast<volatile int*>(ULongToPtr(0)) = 0; puts_red(strcpy(static_cast<char*>(ULongToPtr(1)), "null page allocated")); } else switch (status) { case STATUS_INVALID_PARAMETER_2: puts_green("null page alloc failed (may Windows 8 or MS13-031)"); break; case STATUS_CONFLICTING_ADDRESSES: puts_green("null page alloc failed (may EMET)"); break; default: printf_red("!ZwAllocateVirtualMemory"); printf("->0x%lx\n", status); } return EXIT_SUCCESS; }
int CTask::report() { TestCase *pCase = m_casesList; m_uiSuccCases = m_uiTotalCases - m_uiFailCases; m_ulTimeTaskDone = time_diff_ms(m_stTimeStartTask,m_stTimeEndTask); int sec = m_ulTimeTaskDone/1000; int msec = m_ulTimeTaskDone%1000; if(0 == sec) { //g_log.info("[==========]%u tese cases ran.(%lu ms total)\n", m_uiTotalWorkItem, m_ulTimeTaskDone); printf_green("[==========]%u tese cases ran.(%lu ms total)\n", m_uiTotalCases, m_ulTimeTaskDone); } else { //g_log.info("[==========]%u tese cases ran.(%d.%d s total)\n", m_uiTotalWorkItem, sec, msec); printf_green("[==========]%u tese cases ran.(%d.%d s total)\n", m_uiTotalCases, sec, msec); } //g_log.info("[==PASSED==]%u tese cases!\n",m_succWorkItem); printf_green("[==PASSED==]%u tese cases!\n",m_uiSuccCases); if(m_uiFailCases > 0) { //g_log.info("[==FAILED==]%u tese cases,listed below:\n",m_failWorkItem); printf_red("[==FAILED==]%u tese cases,listed below:\n",m_uiFailCases); pCase = m_casesList; while(pCase != NULL) { if(WORKITEM_DONE_FAIL == pCase->status) { //g_log.info("[==FAILED==]%s\n",pItem->fileName); printf_red("[==FAILED==]%s(Reason: %s)\n",pCase->fileName,pCase->errReason); } pCase = pCase->next; } } printf_yellow("[==STATIC==]transactionName\t\ttotal \tlost \tsuccess \tavgTime(usec)\tminTime(usec)\tmaxTime(usec)\tmaxIdx\n"); printf_yellow("[==STATIC==]QuoteInterval \t\t%-19lld\t%-19lld\t%-19lld\t%-10d\t%-10d\t%-10d\t%-19lld\n", m_stQuoteIntervalStatic.quoteNum, m_stQuoteIntervalStatic.quoteNum - m_stQuoteIntervalStatic.quoteNum, m_stQuoteIntervalStatic.quoteNum, m_stQuoteIntervalStatic.avgQuoteInterval, m_stQuoteIntervalStatic.minQuoteInterval, m_stQuoteIntervalStatic.maxQuoteInterval, m_stQuoteIntervalStatic.maxIdx); printf_yellow("[==STATIC==]tradeProcTime \t\t%-19lld\t%-19lld\t%-19lld\t%-10d\t%-10d\t%-10d\t%-19lld\n", m_stQuoteIntervalStatic.quoteNum, m_stQuoteIntervalStatic.quoteNum - m_stTradeProcTimeStatic.tradeNum, m_stTradeProcTimeStatic.tradeNum, m_stTradeProcTimeStatic.avgTimeTradeProcess, m_stTradeProcTimeStatic.mixTimeTradeProcess, m_stTradeProcTimeStatic.maxTimeTradeProcess, m_stTradeProcTimeStatic.maxIdx); PrintResultToXML(); return ATF_SUCC; }
int CTask::run() { unsigned long timeDiff = 0; TestCase *pCase = NULL; unsigned int uiCaseDone = 0; CCasesParser cases; //load test cases if(ATF_SUCC != cases.GetCasesList(m_arrTestcasesPath,m_casesList,&m_uiTotalCases)) { g_log.error("Failed to get cases list !\n"); return ATF_FAIL; } if(READABLE == m_exchgConf.isValid) m_pExchgSvr = new ExchgServer(m_exchgConf); if(READABLE == m_quoteConf.isValid) m_pQuoteSvr = new QuoteServer(m_quoteConf); pCase = m_casesList; while(NULL != pCase) { //g_log.info("[RUN ] %s :\n",pItem->fileName); printf_green("[RUN ] %s :\n",pCase->fileName); pCase->startTime = time_get_now(); if(0 == uiCaseDone) m_stTimeStartTask = pCase->startTime; pCase->status = WORKITEM_DOING; //m_pExchgSvr->SetTradeMode(pCase->exchgOrder.tradeMode); //start exchange simulator if(READABLE == m_exchgConf.isValid) m_pExchgSvr->StartNewOrder(&pCase->exchgOrder); //start quote data server if(READABLE == m_quoteConf.isValid) m_pQuoteSvr->StartNewOrder(&pCase->quoteOrder); if(READABLE == m_quoteConf.isValid) { if(READABLE == m_exchgConf.isValid) { if(LIMITED == pCase->exchgOrder.tradeMode) { while(1) { sleep(1); if(NO_TASK == m_pQuoteSvr->m_status && NO_TASK == m_pExchgSvr->m_status) { g_log.debug("%s done.\n",pCase->fileName); break; } } } /*else { while(!m_pQuoteSvr->GetQuoteSendFlag()) { sleep(1); } sleep(1); m_pExchgSvr->Finish(); }*/ } else { while(1) { sleep(1); if(NO_TASK == m_pQuoteSvr->m_status) { g_log.debug("%s done.\n",pCase->fileName); break; } } } } else { if(READABLE == m_exchgConf.isValid) { if(LIMITED == pCase->exchgOrder.tradeMode) { while(1) { sleep(1); if(NO_TASK == m_pExchgSvr->m_status) { g_log.debug("%s done.\n",pCase->fileName); break; } } } } } pCase->endTime = time_get_now(); if(uiCaseDone == m_uiTotalCases - 1) m_stTimeEndTask = pCase->endTime; timeDiff = time_diff_ms(pCase->startTime,pCase->endTime); GetCaseResult(pCase); if(WORKITEM_DONE_SUCC == pCase->status) { //g_log.info("[==SUCCESS==]%s(%lu ms)\n\n",pItem->fileName,timeDiff); printf_green("[==SUCCESS==]%s(%lu ms)\n\n",pCase->fileName,timeDiff); } else if(WORKITEM_DONE_FAIL == pCase->status) { //g_log.info("[==FAILED==]%s(%lu ms)\n\n",pItem->fileName,timeDiff); printf_red("[==FAILED==]%s(%lu ms)\n\n",pCase->fileName,timeDiff); } pCase = pCase->next; uiCaseDone++; } finishTransact(); //get static info from ATF agent GotStaticInfo(); report(); printf("All test cases done.\n"); return ATF_SUCC; }
void CAccountTrade::HandleMsgFromClient() { int ret = 0; int rcvMsgSize = 0; char msgName[64] = {0}; char *pBuf = m_tcpbuf; if(m_clientSock < 0) return; memset(m_curOpErrReason,0,sizeof(m_curOpErrReason)); OP &rcvOpe = *m_iterCur; ret = MsgIDToMsgName(rcvOpe.msgID,msgName,sizeof(msgName)); if(ATF_FAIL == ret) return; if(RCV == rcvOpe.direction) { int expectLen = GotMsgSize(rcvOpe.msgID); rcvMsgSize = TcpRecvData(m_clientSock, pBuf,expectLen); if(rcvMsgSize < 1) { rcvOpe.result = OPERATE_FAIL; sprintf(rcvOpe.errReason,"[ExchgServer]Failed to rcv %s(%d)",msgName,rcvMsgSize); g_log.error("[ExchgServer]Recv %s(%d) error.\n",msgName,rcvMsgSize); m_iterCur = m_iterEnd - 2; } else { char *pBuf = m_tcpbuf; if(ATF_FAIL == CheckMsg(rcvOpe.pMsg,rcvOpe.msgSize,pBuf,rcvMsgSize)) { rcvOpe.result = OPERATE_FAIL; sprintf(rcvOpe.errReason,"%s",m_curOpErrReason); g_log.error("[ExchgServer]Recv %s(%d) error.\n",msgName,rcvMsgSize); m_iterCur = m_iterEnd - 2; } else { if(IS_DEBUG) { printf_red("[ExchgServer]Recv %s(%dB), right.\n",msgName,rcvMsgSize); } g_log.info("[ExchgServer]Recv %s(%d), right.\n",msgName,rcvMsgSize); rcvOpe.result = OPERATE_SUCC; } } m_iterCur++; while((m_iterCur != m_iterEnd)) { memset(m_curOpErrReason,0,sizeof(m_curOpErrReason)); OP &sendOp = *m_iterCur; MsgIDToMsgName(sendOp.msgID,msgName,sizeof(msgName)); if(SEND == sendOp.direction) { int result = ATF_SUCC; switch(sendOp.msgID) { case MSGID_S2C_TRADE_RSP_CONN: result = OnFrontConnected(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_RSP_LOGIN: result = OnRspUserLogin(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_DISCONNECT: result = OnFrontDisconnected(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_OnRtnOrder: result = OnRtnOrder(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_OnRtnTrade: result = OnRtnTrade(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_OnRspOrderInsert: result = OnRspOrderInsert(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_OnErrRtnOrderInsert: result = OnErrRtnOrderInsert(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_OnRspOrderAction: result = OnRspOrderAction(sendOp.pMsg, m_clientSock); break; case MSGID_S2C_TRADE_OnErrRtnOrderAction: result = OnErrRtnOrderAction(sendOp.pMsg, m_clientSock); break; default: { } break; } if(ATF_FAIL == result) { sendOp.result = OPERATE_FAIL; sprintf(sendOp.errReason,"%s",m_curOpErrReason); m_iterCur = m_iterEnd - 2; } else { sendOp.result = OPERATE_SUCC; } ++m_iterCur; //all operations are over if(m_iterCur == m_iterEnd) { if(LIMITED == m_tradeMode) { m_iProgress = DONE; if(IS_DEBUG) { //printf_red("[ExchgServer]:task done \n"); printf_blue("client %u had finished his job.\n",m_frontID); } } } } else return; } } }
int CAccountTrade::CmpMsgReqOrderInsert(ReqOrderInsertToATF * pExpectMsg,ReqOrderInsertToATF *pActualMsg) { int ret = ATF_SUCC; if(pExpectMsg->order.CombOffsetFlag[0] != pActualMsg->order.CombOffsetFlag[0]) { g_log.error("Invalid CombOffsetFlag:expect %s,actual %s\n",pExpectMsg->order.CombOffsetFlag,pActualMsg->order.CombOffsetFlag); sprintf(m_curOpErrReason,"Invalid CombOffsetFlag:expect %s,actual %s",pExpectMsg->order.CombOffsetFlag,pActualMsg->order.CombOffsetFlag); ret = ATF_FAIL; } if(pExpectMsg->order.OrderPriceType != pActualMsg->order.OrderPriceType) { g_log.error("Invalid OrderPriceType:expect %d,actual %d\n",pExpectMsg->order.OrderPriceType,pActualMsg->order.OrderPriceType); sprintf(m_curOpErrReason,"Invalid OrderPriceType:expect %d,actual %d",pExpectMsg->order.OrderPriceType,pActualMsg->order.OrderPriceType); ret = ATF_FAIL; } if(pExpectMsg->order.TimeCondition != pActualMsg->order.TimeCondition) { g_log.error("Invalid TimeCondition:expect %d,actual %d\n",pExpectMsg->order.TimeCondition,pActualMsg->order.TimeCondition); sprintf(m_curOpErrReason,"Invalid TimeCondition:expect %d,actual %d",pExpectMsg->order.TimeCondition,pActualMsg->order.TimeCondition); ret = ATF_FAIL; } if(pExpectMsg->order.VolumeCondition != pActualMsg->order.VolumeCondition) { g_log.error("Invalid VolumeCondition:expect %ds,actual %d\n",pExpectMsg->order.VolumeCondition,pActualMsg->order.VolumeCondition); sprintf(m_curOpErrReason,"Invalid VolumeCondition:expect %d,actual %d",pExpectMsg->order.VolumeCondition,pActualMsg->order.VolumeCondition); ret = ATF_FAIL; } if(pExpectMsg->order.ContingentCondition != pActualMsg->order.ContingentCondition) { g_log.error("Invalid ContingentCondition:expect %d,actual %d\n",pExpectMsg->order.ContingentCondition,pActualMsg->order.ContingentCondition); sprintf(m_curOpErrReason,"Invalid ContingentCondition:expect %d,actual %d",pExpectMsg->order.ContingentCondition,pActualMsg->order.ContingentCondition); ret = ATF_FAIL; } if(pExpectMsg->order.LimitPrice!= pActualMsg->order.LimitPrice) { g_log.error("Invalid LimitPrice:expect %f,actual %f\n",pExpectMsg->order.LimitPrice,pActualMsg->order.LimitPrice); sprintf(m_curOpErrReason,"Invalid LimitPrice:expect %f,actual %f",pExpectMsg->order.LimitPrice,pActualMsg->order.LimitPrice); ret = ATF_FAIL; } if(pExpectMsg->order.VolumeTotalOriginal != pActualMsg->order.VolumeTotalOriginal) { g_log.error("Invalid VolumeTotalOriginal:expect %d,actual %d\n",pExpectMsg->order.VolumeTotalOriginal,pActualMsg->order.VolumeTotalOriginal); sprintf(m_curOpErrReason,"Invalid VolumeTotalOriginal:expect %d,actual %d",pExpectMsg->order.VolumeTotalOriginal,pActualMsg->order.VolumeTotalOriginal); ret = ATF_FAIL; } if(pExpectMsg->order.Direction != pActualMsg->order.Direction) { g_log.error("Invalid Direction:expect %d,actual %d\n",pExpectMsg->order.Direction,pActualMsg->order.Direction); sprintf(m_curOpErrReason,"Invalid Direction:expect %d,actual %d",pExpectMsg->order.Direction,pActualMsg->order.Direction); ret = ATF_FAIL; } if(ATF_SUCC == ret) { m_mOrder.insert(pair<int,ReqOrderInsertToATF>(m_iOrderNum++,*pActualMsg)); ++gOrderSysID; char sysID[64] = {0}; sprintf(sysID,"%lld",gOrderSysID); m_mOrderRef2SysID.insert(pair<std::string,std::string>(pActualMsg->order.OrderRef,sysID)); if(IS_DEBUG) { static long long iOrderIn = 0; printf_red("order pushed into vector %lld\n",iOrderIn); iOrderIn++; } return ATF_SUCC; } else { return ATF_FAIL; } }