From: <Or...@us...> - 2008-06-29 17:37:49
|
Revision: 287 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=287&view=rev Author: Oracle_ Date: 2008-06-29 10:37:55 -0700 (Sun, 29 Jun 2008) Log Message: ----------- Fixed bug with big outputs, updated source. Modified Paths: -------------- ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp ACMServer/trunk/sharp tester/SourceTest/SourceTest.h ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp ACMServer/trunk/sharp tester/TestLibrary/dllmain.cpp ACMServer/trunk/sharp tester/tester/Program.cs ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt Modified: ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp 2008-06-28 12:23:27 UTC (rev 286) +++ ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp 2008-06-29 17:37:55 UTC (rev 287) @@ -2,7 +2,6 @@ #include "stdafx.h" //#define _WIN32_WINNT 0x0500 //need for easy compiling on different machine -#include <stdio.h> #include "SourceTest.h" #include <LM.h> #include <Aclapi.h> @@ -36,74 +35,58 @@ System::Runtime::InteropServices::Marshal::FreeHGlobal(IntPtr(buf)); } -String^ ToStr(int x) //fast convert integer to Managed String +String^ ReadFullFile(String^ filename) { - char intg[15]; - _itoa_s(x,intg,10); - return %String(intg); -} - -bool FileExists(String^ path) //checks whether file exists or not -{ - char* buf=StrToArr(path); - OFSTRUCT of; - ZeroMemory(&of,sizeof(of)); - of.cBytes=sizeof(of); - bool res=(OpenFile(buf,&of,OF_EXIST)!=HFILE_ERROR); - FreeArr(buf); + StreamReader^ r; + int cycle=0; + while (cycle<1000) + { + ++cycle; + try + { + r=File::OpenText(filename); + } catch (...) + { + Sleep(1); + continue; + } + break; + } + if (r->Equals(StreamReader::Null)) + return ""; + String^ res=r->ReadToEnd(); + delete (IDisposable^)r; return res; } -String^ ReadFullFile(String^ filename) -{ - HANDLE h; - wchar_t* bufW=StrToArrW(filename); - int cycle=0; - do - { - h=CreateFile(bufW,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL); - Sleep(1); - ++cycle; - } while (h==INVALID_HANDLE_VALUE&&cycle<100); - if (h==INVALID_HANDLE_VALUE) - return ""; - FreeArr(bufW); - DWORD size=GetFileSize(h,NULL); - char* res=new char[size+20];ZeroMemory(res,(size+2)*sizeof(char)); - char* buf=new char[size+20]; - DWORD curlen=0; - cycle=0; - do - { - ZeroMemory(buf, (size+20)*sizeof(char)); - DWORD rlen=0; - ReadFile(h,buf,size,&rlen,NULL); - curlen+=rlen; - strcat_s(res,size+10,buf); - Sleep(1); - ++cycle; - } while (curlen<size&&cycle<100); - CloseHandle(h); - String^ r=gcnew String(res); - delete[] res; - delete[] buf; - if (curlen<size) - return ""; - return r; -} - TSource::TSource() { -FSrc=gcnew String(""); -FExePath=gcnew String(""); -FProblemPath=gcnew String(""); -FState=ssNone; -FCompPath=gcnew String(""); +FSrc=""; +FExePath=""; +FProblemPath=""; +FState=TSourceState::ssNone; +FCompPath=""; FRunAll=true; -lib=LoadLibraryA("TestLibrary.dll"); +FLim=gcnew TLimits(); +FRes=gcnew ArrayList(); +FLang=TLang::lPascal; +FSummary=gcnew TSummary(); +FThreads=gcnew ArrayList(); +FCompResult=gcnew TCompResult(); + +if ((lib=LoadLibrary(L"TestLibrary.dll"))!=NULL) +{ + DLLFreeChar=(TFreeFunc)GetProcAddress(lib,"FreeChar"); + DLLCheckCL=(TCheckSrc)GetProcAddress(lib,"CheckCL"); + DLLCheckDF=(TCheckSrc)GetProcAddress(lib,"CheckDF"); + DLLCheckAnswer=(TCheckAnswer)GetProcAddress(lib,"CheckAnswer"); + DLLCheckTL=(TCheckLim)GetProcAddress(lib,"CheckTL"); + DLLCheckRTL=(TCheckLim)GetProcAddress(lib,"CheckRTL"); +} FSecurity=NULL; InitSecure(false); init(); //initializing of critical section +SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS); } void TSource::InitSecure(bool SetPrivAnyway) @@ -118,47 +101,44 @@ if (lib!=NULL) FreeLibrary(lib); delete FSecurity; -FRes.Clear(); -FThreads.Clear(); +FRes->Clear(); +FThreads->Clear(); final(); +SetPriorityClass(GetCurrentProcess(),NORMAL_PRIORITY_CLASS); } void TSource::CheckCL() //checking size of source { if (lib==NULL) //no library was found { - if (FSrc->Length>FLim.CodeLimit) - FCompResult.res=crCL; - FCompResult.Details+="Used std checker for Code Limit\n"; + if (FSrc->Length>FLim->CodeLimit) + FCompResult->res=TCompRes::crCL; + FCompResult->Details+="Used std checker for Code Limit\n"; } else { - TCheckSrc prc=(TCheckSrc)GetProcAddress(lib,"CheckCL"); char* buf,*bufA; - if (prc(bufA=StrToArr(FSrc),FLim.CodeLimit,buf)) FCompResult.res=crCL; + if (DLLCheckCL(bufA=StrToArr(FSrc),FLim->CodeLimit,buf)) FCompResult->res=TCompRes::crCL; FreeArr(bufA); - FCompResult.Details+=gcnew String(buf); - TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar"); - prc2(buf); + FCompResult->Details+=gcnew String(buf); + DLLFreeChar(buf); } - FState=ssCheckedCL; + FState=TSourceState::ssCheckedCL; } void TSource::CheckDF() //checking for DF in source { if (lib==NULL) //no library was found { - FCompResult.Details+="No checker for DF\n"; + FCompResult->Details+="No checker for DF\n"; } else { - TCheckSrc prc=(TCheckSrc)GetProcAddress(lib,"CheckDF"); char* buf,*bufA; - if (prc(bufA=StrToArr(FSrc),(int)FLang,buf)) FCompResult.res=crDF; + if (DLLCheckDF(bufA=StrToArr(FSrc),(int)FLang,buf)) FCompResult->res=TCompRes::crDF; FreeArr(bufA); - FCompResult.Details+=gcnew String(buf); - TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar"); - prc2(buf); + FCompResult->Details+=gcnew String(buf); + DLLFreeChar(buf); } - FState=ssCheckedDF; + FState=TSourceState::ssCheckedDF; } void TSource::Compile() //compiles the source @@ -177,7 +157,7 @@ String^ outpath=gcnew String(FTempPath+"compoutput.txt"); FExePath=FTempPath+"source.exe"; - if (FileExists(FExePath)) //delete previsious source + if (File::Exists(FExePath)) //delete previsious source { DeleteFile((LPCTSTR)(bufW=StrToArrW(FExePath))); FreeArr(bufW); @@ -203,35 +183,35 @@ if (!CreateProcess(NULL,bufW,&sec,&sec,true,CREATE_NEW_CONSOLE|CREATE_NO_WINDOW,NULL,NULL,&si,&pi)) { FreeArr(bufW); - FCompResult.res=crIE; - FCompResult.Details+="Can not run the compiler\n"; + FCompResult->res=TCompRes::crIE; + FCompResult->Details+="Can not run the compiler\n"; return; } FreeArr(bufW); - if (WaitForSingleObject(pi.hProcess,FLim.CompilationTimeLimit)==WAIT_TIMEOUT) + if (WaitForSingleObject(pi.hProcess,FLim->CompilationTimeLimit)==WAIT_TIMEOUT) { TerminateProcess(pi.hProcess,0); - FCompResult.res=crCTL; - FCompResult.UsedTime=FLim.CompilationTimeLimit; - FCompResult.Details+="Time out during compilation\n"; + FCompResult->res=TCompRes::crCTL; + FCompResult->UsedTime=FLim->CompilationTimeLimit; + FCompResult->Details+="Time out during compilation\n"; return; } - FCompResult.UsedTime=GetTickCount()-start; + FCompResult->UsedTime=GetTickCount()-start; Sleep(CONST_SLEEP); //waiting for creating the file CloseHandle(si.hStdOutput); si.hStdOutput=NULL; - if (!FileExists(FExePath)) //compilation error + if (!File::Exists(FExePath)) //compilation error { - FCompResult.res=crCE; - FCompResult.Details+="EXE file not found\n"+ReadFullFile(outpath); + FCompResult->res=TCompRes::crCE; + FCompResult->Details+="EXE file not found\n"+ReadFullFile(outpath); return; } - FCompResult.Details+=ReadFullFile(outpath); + FCompResult->Details+=ReadFullFile(outpath); - }__finally + }finally { if (pi.hProcess!=NULL) CloseHandle(pi.hProcess); @@ -239,14 +219,14 @@ CloseHandle(pi.hThread); if (si.hStdOutput!=NULL) CloseHandle(si.hStdOutput); - FState=ssCompiled; + FState=TSourceState::ssCompiled; } } void TSource::AddThread() { Threading::Thread^ t=gcnew Threading::Thread(gcnew System::Threading::ThreadStart(this,&TSource::ThreadProc)); - FThreads.Add(t); + FThreads->Add(t); t->Start(); } @@ -266,7 +246,7 @@ Summary->res->UsedMemory=max(Results[n-1]->UsedMemory,Summary->res->UsedMemory); Summary->res->UsedTime=max(Results[n-1]->UsedTime,Summary->res->UsedTime); Summary->res->UsedRealTime=max(Results[n-1]->UsedRealTime,Summary->res->UsedRealTime); - if (Results[n-1]->res!=trAC) + if (Results[n-1]->res!=TRes::trAC) { Summary->res->res=Results[n-1]->res; if (!RunAll) { NeedTest=false; break; } @@ -281,40 +261,40 @@ void TSource::RunTests() //runs all tests of problem { - FState=ssIsRunning; + FState=TSourceState::ssIsRunning; CurrentTest=0; NeedTest=true; FTestCnt=1; - FRes.Clear(); - while (FileExists(FProblemPath+"test"+ToStr(FTestCnt)+"\\in.txt")||FileExists(FProblemPath+"test"+ToStr(FTestCnt)+"\\out.txt")||FileExists(FProblemPath+"test"+ToStr(FTestCnt)+"\\points.txt")) + FRes->Clear(); + while (File::Exists(FProblemPath+"test"+FTestCnt.ToString()+"\\in.txt")||File::Exists(FProblemPath+"test"+FTestCnt.ToString()+"\\out.txt")||File::Exists(FProblemPath+"test"+FTestCnt.ToString()+"\\points.txt")) { - FRes.Add(%TResult()); + FRes->Add(%TResult()); FTestCnt++; } - FThreads.Clear(); - for (int i=0;i<min(FLim.MaxThreads-1,FTestCnt-1);i++) + FThreads->Clear(); + for (int i=0;i<min(FLim->MaxThreads,FTestCnt-1);i++) AddThread(); - for (int i=0;i<FThreads.Count;i++) + for (int i=0;i<FThreads->Count;i++) ((Threading::Thread^)FThreads[i])->Join(INFINITE); - FState=ssFinish; + FState=TSourceState::ssFinish; } -void TSource::LoadTest(int index,TTest% test) //loads test from file +void TSource::LoadTest(int index,TTest^ test) //loads test from file { try { lock(); - if (FileExists(FProblemPath+"test"+ToStr(index)+"\\in.txt")) - test.input=ReadFullFile(FProblemPath+"test"+ToStr(index)+"\\in.txt"); else - test.input=""; - if (FileExists(FProblemPath+"test"+ToStr(index)+"\\out.txt")) - test.output=ReadFullFile(FProblemPath+"test"+ToStr(index)+"\\out.txt"); else - test.output=""; - if (FileExists(FProblemPath+"test"+ToStr(index)+"\\points.txt")) - test.points.Parse(ReadFullFile(FProblemPath+"test"+ToStr(index)+"\\points.txt")); else - test.points=1; -}__finally + if (File::Exists(FProblemPath+"test"+index.ToString()+"\\in.txt")) + test->input=ReadFullFile(FProblemPath+"test"+index.ToString()+"\\in.txt"); else + test->input=""; + if (File::Exists(FProblemPath+"test"+index.ToString()+"\\out.txt")) + test->output=ReadFullFile(FProblemPath+"test"+index.ToString()+"\\out.txt"); else + test->output=""; + if (File::Exists(FProblemPath+"test"+index.ToString()+"\\points.txt")) + test->points=int::Parse(ReadFullFile(FProblemPath+"test"+index.ToString()+"\\points.txt")); else + test->points=1; +}finally { unlock(); } @@ -324,25 +304,23 @@ { try { - TTest t; + TTest^ t=gcnew TTest(); LoadTest(index,t); lock(); if (lib==NULL) //lib was not found { - if (output!=t.output) + if (output!=t->output) return carWA; return carAC; } else { char* buf1,*buf2,*buf3,*buf4=NULL; - TCheckAnswer prc=(TCheckAnswer)GetProcAddress(lib,"CheckAnswer"); - TCheckAnsRes res=(TCheckAnsRes)prc(buf1=StrToArr(t.input),buf2=StrToArr(output),buf3=StrToArr(t.output),buf4); + TCheckAnsRes res=(TCheckAnsRes)DLLCheckAnswer(buf1=StrToArr(t->input),buf2=StrToArr(output),buf3=StrToArr(t->output),buf4); Details+=gcnew String(buf4); - TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar"); - FreeArr(buf1);FreeArr(buf2);FreeArr(buf3);prc2(buf4); + FreeArr(buf1);FreeArr(buf2);FreeArr(buf3);DLLFreeChar(buf4); return res; } -} __finally +} finally { unlock(); } @@ -355,9 +333,8 @@ lock(); if (lib==NULL) return usedtime>timelimit; - TCheckLim prc=(TCheckLim)GetProcAddress(lib,"CheckTL"); - return prc(usedtime,timelimit); -}__finally + return DLLCheckTL(usedtime,timelimit); +}finally { unlock(); } @@ -369,9 +346,8 @@ lock(); if (lib==NULL) return usedrealtime>realtimelimit; - TCheckLim prc=(TCheckLim)GetProcAddress(lib,"CheckRTL"); - return prc(usedrealtime,realtimelimit); -}__finally + return DLLCheckRTL(usedrealtime,realtimelimit); +}finally { unlock(); } @@ -382,18 +358,18 @@ try { CheckCL(); - if (FCompResult.res==crOK) + if (FCompResult->res==TCompRes::crOK) CheckDF(); else return ; - if (FCompResult.res==crOK) + if (FCompResult->res==TCompRes::crOK) Compile(); else return ; - if (FCompResult.res==crOK) + if (FCompResult->res==TCompRes::crOK) RunTests(); else return ; -} __finally +} finally { - (*FSummary.compres)=FCompResult; + FSummary->compres=FCompResult; } } @@ -431,16 +407,16 @@ wchar_t* bufW; try { - Results[index-1]->res=trAC; + Results[index-1]->res=TRes::trAC; Results[index-1]->points=0; Results[index-1]->Details=""; Results[index-1]->UsedMemory=-1; Results[index-1]->UsedRealTime=-1; Results[index-1]->UsedTime=-1; - String^ inpath=ProblemPath+"test"+ToStr(index)+"\\in.txt"; - String^ oupath=TempPath+"out"+ToStr(index)+".txt"; - String^ erpath=TempPath+"err"+ToStr(index)+".txt"; - String^ pointpath=ProblemPath+"test"+ToStr(index)+"\\points.txt"; + String^ inpath=ProblemPath+"test"+index.ToString()+"\\in.txt"; + String^ oupath=TempPath+"out"+index.ToString()+".txt"; + String^ erpath=TempPath+"err"+index.ToString()+".txt"; + String^ pointpath=ProblemPath+"test"+index.ToString()+"\\points.txt"; si.cb=sizeof(si); si.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; @@ -451,18 +427,18 @@ SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT|SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX); lock(); - if (!FSecurity->RunProcess(bufW=StrToArrW(ExePath),TRUE,CREATE_SUSPENDED|CREATE_NO_WINDOW|HIGH_PRIORITY_CLASS,&si,&pi,Results[index-1]->Details)) + if (!FSecurity->RunProcess(bufW=StrToArrW(ExePath),TRUE,CREATE_SUSPENDED|CREATE_NO_WINDOW|NORMAL_PRIORITY_CLASS,&si,&pi,Results[index-1]->Details)) { FreeArr(bufW); Results[index-1]->points=0; int err=GetLastError(); if ((err==193)||(err==1455)) { - Results[index-1]->res=trRE; + Results[index-1]->res=TRes::trRE; Results[index-1]->Details+="Too large array"; } else { - Results[index-1]->res=trIE; + Results[index-1]->res=TRes::trIE; Results[index-1]->Details+="Can not start process"; } unlock(); @@ -483,8 +459,6 @@ AssignProcessToJobObject(job,pi.hProcess); - SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL); - ResumeThread(pi.hThread); DWORD start=GetTickCount(); @@ -493,7 +467,7 @@ if ((int)GetFileSize(si.hStdOutput,NULL)>Lim->OutputLimit) { TerminateJobObject(job,0); - Results[index-1]->res=trOL; + Results[index-1]->res=TRes::trOL; Results[index-1]->Details+="Size of output file excided OutputLimit"; break; } @@ -501,14 +475,14 @@ if (CheckRTL((int)(GetTickCount()-start),Lim->RealTimeLimit)) { TerminateJobObject(job,0); - Results[index-1]->res=trRTL; + Results[index-1]->res=TRes::trRTL; Results[index-1]->Details+="Real time limit"; break; } if (CheckTL((int)(acc.ThisPeriodTotalKernelTime.QuadPart+acc.ThisPeriodTotalUserTime.QuadPart),Lim->TimeLimit*10000)) { TerminateJobObject(job,0); - Results[index-1]->res=trTL; + Results[index-1]->res=TRes::trTL; Results[index-1]->Details+="Time Limit"; break; } @@ -525,18 +499,18 @@ GetExitCodeProcess(pi.hProcess,&code); if (code==5) { - Results[index-1]->res=trDF; + Results[index-1]->res=TRes::trDF; Results[index-1]->Details+="Access denied."; } else if (code!=0) { - Results[index-1]->res=trRE; - Results[index-1]->Details+="Runtime error #"+ToStr((int)code); + Results[index-1]->res=TRes::trRE; + Results[index-1]->Details+="Runtime error #"+code.ToString(); } needbreak=true; break; case JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT: - Results[index-1]->res=trML; + Results[index-1]->res=TRes::trML; Results[index-1]->Details+="Memory Limit"; needbreak=true; break; @@ -544,13 +518,13 @@ GetExitCodeProcess(pi.hProcess,&code); if (code==5) { - Results[index-1]->res=trDF; + Results[index-1]->res=TRes::trDF; Results[index-1]->Details+="Access denied."; } else if (code!=0) { - Results[index-1]->res=trRE; - Results[index-1]->Details+="Runtime error #"+ToStr((int)code); + Results[index-1]->res=TRes::trRE; + Results[index-1]->Details+="Runtime error #"+code.ToString(); } needbreak=true; break; @@ -563,8 +537,6 @@ } Sleep(1); } - - SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL); CloseHandle(si.hStdOutput);si.hStdOutput=NULL; CloseHandle(si.hStdInput);si.hStdInput=NULL; @@ -576,11 +548,11 @@ Results[index-1]->UsedMemory=mem.PeakProcessMemoryUsed; Results[index-1]->UsedTime=(int)((acc.ThisPeriodTotalKernelTime.QuadPart+acc.ThisPeriodTotalUserTime.QuadPart)/10000); Results[index-1]->UsedRealTime=GetTickCount()-start; - if (Results[index-1]->res!=trAC) return; + if (Results[index-1]->res!=TRes::trAC) return; - if (!FileExists(oupath)) + if (!File::Exists(oupath)) { - Results[index-1]->res=trWA; + Results[index-1]->res=TRes::trWA; Results[index-1]->Details+="No output file"; return; } @@ -591,7 +563,7 @@ if (r==carAC) { - if (FileExists(pointpath)) + if (File::Exists(pointpath)) Results[index-1]->points.Parse(ReadFullFile(pointpath)); else Results[index-1]->points=1; return ; @@ -600,20 +572,20 @@ switch (r) { case carOE: - Results[index-1]->res=trOE; + Results[index-1]->res=TRes::trOE; break; case carPE: - Results[index-1]->res=trPE; + Results[index-1]->res=TRes::trPE; break; case carWA: - Results[index-1]->res=trWA; + Results[index-1]->res=TRes::trWA; break; case carIE: - Results[index-1]->res=trIE; + Results[index-1]->res=TRes::trIE; break; }; -}__finally +}finally { if (pi.hProcess!=NULL) CloseHandle(pi.hProcess); @@ -639,62 +611,79 @@ try { CheckCL(); - if (FCompResult.res==crOK) + if (FCompResult->res==TCompRes::crOK) CheckDF(); else return ; - if (FCompResult.res==crOK) + if (FCompResult->res==TCompRes::crOK) Compile(); else return ; - if (FCompResult.res==crOK) + if (FCompResult->res==TCompRes::crOK) RunTest(index); else return ; -} __finally +} finally { - (*FSummary.compres)=FCompResult; + FSummary->compres=FCompResult; } } void TSource::LoadLimits() { String^ path=FProblemPath+"Limits.txt"; - if (!FileExists(path)) + if (!File::Exists(path)) return; - char* buf; - FILE* f; - try + if (FState!=TSourceState::ssNone) { - if (FState!=ssNone) - { - throw "Can not load limits if state is higher than ssNone"; - return; - } - fopen_s(&f,buf=StrToArr(path),"rt"); - fscanf_s(f,"CodeLimit: %d\nCompilationTimeLimit: %d\nMemoryLimit: %d\n",&FLim.CodeLimit,&FLim.CompilationTimeLimit,&FLim.MemoryLimit); - fscanf_s(f,"OutputLimit: %d\nRealTimeLimit: %d\nTimeLimit: %d\n",&FLim.OutputLimit,&FLim.RealTimeLimit,&FLim.TimeLimit); - fscanf_s(f,"MaxThreads: %d",&FLim.MaxThreads); - }__finally - { - fclose(f); - FreeArr(buf); + throw "Can not load limits if state is higher than ssNone"; + return; } + StreamReader^ r=File::OpenText(path); + String^ buf=r->ReadLine(); + int i=0; + while (!((buf[i]>='0')&&(buf[i]<='9'))) i++; + FLim->CodeLimit=int::Parse(buf->Substring(i,buf->Length-i)); + + buf=r->ReadLine();i=0; + while (!((buf[i]>='0')&&(buf[i]<='9'))) i++; + FLim->CompilationTimeLimit=int::Parse(buf->Substring(i,buf->Length-i)); + + buf=r->ReadLine();i=0; + while (!((buf[i]>='0')&&(buf[i]<='9'))) i++; + FLim->MemoryLimit=int::Parse(buf->Substring(i,buf->Length-i)); + + buf=r->ReadLine();i=0; + while (!((buf[i]>='0')&&(buf[i]<='9'))) i++; + FLim->OutputLimit=int::Parse(buf->Substring(i,buf->Length-i)); + + buf=r->ReadLine();i=0; + while (!((buf[i]>='0')&&(buf[i]<='9'))) i++; + FLim->RealTimeLimit=int::Parse(buf->Substring(i,buf->Length-i)); + + buf=r->ReadLine();i=0; + while (!((buf[i]>='0')&&(buf[i]<='9'))) i++; + FLim->TimeLimit=int::Parse(buf->Substring(i,buf->Length-i)); + + buf=r->ReadLine();i=0; + while (!((buf[i]>='0')&&(buf[i]<='9'))) i++; + FLim->MaxThreads=int::Parse(buf->Substring(i,buf->Length-i)); + r->Close(); } String^ TSource::TestResultToString(TRes res) { switch (res) { - case trAC:return "Accepted"; - case trWA:return "Wrong Answer"; - case trTL:return "Time Limit"; - case trML:return "Memory Limit"; - case trRTL:return "Real Time Limit"; - case trRE:return "Runtime Error"; - case trDF:return "Destricted Function"; - case trIE:return "Internal Error"; - case trOL:return "Output Limit"; - case trPE:return "Presentation Error"; - case trOE:return "Output Error"; + case TRes::trAC:return "Accepted"; + case TRes::trWA:return "Wrong Answer"; + case TRes::trTL:return "Time Limit"; + case TRes::trML:return "Memory Limit"; + case TRes::trRTL:return "Real Time Limit"; + case TRes::trRE:return "Runtime Error"; + case TRes::trDF:return "Destricted Function"; + case TRes::trIE:return "Internal Error"; + case TRes::trOL:return "Output Limit"; + case TRes::trPE:return "Presentation Error"; + case TRes::trOE:return "Output Error"; default:return "Unknown Error"; } } @@ -703,12 +692,12 @@ { switch (res) { - case crOK:return "No Error"; - case crCE:return "Compilation Error"; - case crCL:return "Code Limit"; - case crCTL:return "Compilation Time Limit"; - case crDF:return "Destricted Function"; - case crIE:return "Internal Error"; + case TCompRes::crOK:return "No Error"; + case TCompRes::crCE:return "Compilation Error"; + case TCompRes::crCL:return "Code Limit"; + case TCompRes::crCTL:return "Compilation Time Limit"; + case TCompRes::crDF:return "Destricted Function"; + case TCompRes::crIE:return "Internal Error"; default:return "Unknown Error"; } } Modified: ACMServer/trunk/sharp tester/SourceTest/SourceTest.h =================================================================== --- ACMServer/trunk/sharp tester/SourceTest/SourceTest.h 2008-06-28 12:23:27 UTC (rev 286) +++ ACMServer/trunk/sharp tester/SourceTest/SourceTest.h 2008-06-29 17:37:55 UTC (rev 287) @@ -64,7 +64,7 @@ ///TCompRes is all possible results of compilation ///</summary> - public enum TCompRes //result of compilation + public enum class TCompRes //result of compilation { crOK, //all ok crCE, //compilation error @@ -78,7 +78,7 @@ ///TRes is all possible results of running the source ///</summary> - public enum TRes + public enum class TRes { trAC, //accepted trWA, //wrong answer @@ -108,7 +108,7 @@ TResult() { - res=trAC; + res=TRes::trAC; points=0; UsedMemory=0; UsedTime=0; @@ -156,7 +156,7 @@ TCompResult() { - res=crOK; + res=TCompRes::crOK; UsedTime=0; Details=""; } @@ -173,7 +173,7 @@ ///TSourceState is all possible states of source during its testing ///</summary> - public enum TSourceState + public enum class TSourceState { ssNone=0, //no actions were taken ssCheckedCL=1, //CodeLimit checked @@ -236,7 +236,7 @@ ///TLang is all possible languages of source (needed for CheckDF) ///</summary> - public enum TLang + public enum class TLang { lCpp=0, lPascal=1 @@ -275,10 +275,10 @@ String^ FTempPath; //this is the place where temporary files will be created bool FRunAll; //if true then all tests will run (no matter on errors) TSourceState FState; //state of source - TCompResult FCompResult; //result of compilation - ArrayList FRes; //results of each test *MT* - TSummary FSummary; //summary results of all tests *MT* - TLimits FLim; //limits for testing + TCompResult^ FCompResult; //result of compilation + ArrayList^ FRes; //results of each test *MT* + TSummary^ FSummary; //summary results of all tests *MT* + TLimits^ FLim; //limits for testing TTestHandler^ FTestHandler; //event, that occures when test is completed *MT* TLang FLang; //language of source TSecure *FSecurity; //security class *MT* @@ -290,12 +290,18 @@ //int CheckAnswer(char* input, char* output, char* rightoutput, char*& Details) - checks WA,OE,PE //void FreeChar(char* buf); - must free memory used by buf //if there is no library called TestLibrary.dll then standart check is performed + TFreeFunc DLLFreeChar; + TCheckSrc DLLCheckCL; + TCheckSrc DLLCheckDF; + TCheckAnswer DLLCheckAnswer; + TCheckLim DLLCheckTL; + TCheckLim DLLCheckRTL; CRITICAL_SECTION* cs; //for multithreading void init() { cs=new CRITICAL_SECTION; - InitializeCriticalSectionAndSpinCount(cs,100); + InitializeCriticalSectionAndSpinCount(cs,5); } void lock() @@ -319,7 +325,7 @@ int FCurrentTest; //current test for testing *MT* bool FNeedTest; //if found WA, or all test completed *MT* int FTestCnt; - ArrayList FThreads; + ArrayList^ FThreads; property int CurrentTest { void set(int value) @@ -328,7 +334,7 @@ { lock(); FCurrentTest=value; - }__finally + }finally { unlock(); } @@ -340,7 +346,7 @@ { lock(); return FCurrentTest; - }__finally + }finally { unlock(); } @@ -355,7 +361,7 @@ { lock(); FNeedTest=value; - }__finally + }finally { unlock(); } @@ -367,7 +373,7 @@ { lock(); return FNeedTest; - }__finally + }finally { unlock(); } @@ -380,7 +386,7 @@ { lock(); return FTestCnt; - } __finally + } finally { unlock(); } @@ -401,7 +407,7 @@ TCheckAnsRes CheckAnswer(int index,String^ output, String^% Details); void ProcessAll(); //gets result for all tests void ProcessTest(int index); //gets result for only 1 test - void LoadTest(int index,TTest% test); //load test from file + void LoadTest(int index,TTest^ test); //load test from file void LoadLimits(); //loads limits from a file Limits.txt static String^ TestResultToString(TRes res); static String^ CompileResultToString(TCompRes res); @@ -413,9 +419,9 @@ try { lock(); - FLim=(*value); + FLim=value; } - __finally { + finally { unlock(); } } @@ -424,9 +430,9 @@ try { lock(); - return %FLim; + return FLim; } - __finally { + finally { unlock(); } } @@ -440,7 +446,7 @@ { lock(); return FSrc; - }__finally { + }finally { unlock(); } } @@ -451,7 +457,7 @@ { lock(); FSrc=value; - } __finally { + } finally { unlock(); } } @@ -465,7 +471,7 @@ { lock(); return FExePath; - }__finally{ + }finally{ unlock(); } } @@ -478,7 +484,7 @@ { lock(); return FProblemPath; - }__finally { + }finally { unlock(); } } @@ -488,7 +494,7 @@ try{ lock(); FProblemPath=value; - }__finally { + }finally { unlock(); } } @@ -501,8 +507,8 @@ try { lock(); - return %FCompResult; - }__finally { + return FCompResult; + }finally { unlock(); } } @@ -514,8 +520,8 @@ try { lock(); - return (FState); - }__finally { + return FState; + }finally { unlock(); } }; @@ -525,7 +531,7 @@ { lock(); FState=(value); - }__finally { + }finally { unlock(); } }; @@ -538,14 +544,14 @@ try { lock(); - if (index>=FRes.Count) + if (index>=FRes->Count) { throw "The index is not accesible"; return (%TResult()); } return (TResult^)FRes[index]; } - __finally + finally { unlock(); } @@ -559,8 +565,8 @@ try { lock(); - return (%FSummary); - }__finally + return FSummary; + }finally { unlock(); } @@ -571,9 +577,9 @@ try { lock(); - FSummary=(*value); + FSummary=value; } - __finally { + finally { unlock(); } } @@ -587,7 +593,7 @@ { lock(); return FTestHandler; - }__finally + }finally { unlock(); } @@ -599,7 +605,7 @@ { lock(); FTestHandler=value; - }__finally + }finally { unlock(); } @@ -614,7 +620,7 @@ { lock(); return (FCompPath); - }__finally + }finally { unlock(); } @@ -626,7 +632,7 @@ { lock(); FCompPath=value; - }__finally + }finally { unlock(); } @@ -641,7 +647,7 @@ { lock(); return FTempPath; - }__finally + }finally { unlock(); } @@ -654,7 +660,7 @@ lock(); FTempPath=value; System::IO::Directory::CreateDirectory(FTempPath); - }__finally + }finally { unlock(); } @@ -669,7 +675,7 @@ { lock(); FRunAll=value; - } __finally + } finally { unlock(); } @@ -681,7 +687,7 @@ { lock(); return FRunAll; - }__finally + }finally { unlock(); } @@ -696,7 +702,7 @@ { lock(); FLang=value; - } __finally + } finally { unlock(); } @@ -708,7 +714,7 @@ { lock(); return FLang; - }__finally + }finally { unlock(); } Modified: ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp =================================================================== --- ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp 2008-06-28 12:23:27 UTC (rev 286) +++ ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp 2008-06-29 17:37:55 UTC (rev 287) @@ -7,14 +7,14 @@ TESTLIBRARY_API bool CheckCL(char* src, int cl, char*& details) { details=new char[20]; - strcpy_s(details,20,"CheckCL from DLL\n"); + strcpy_s(details,20,"DLLCheckCL"); return ((int)strlen(src)>cl); } TESTLIBRARY_API bool CheckDF(char* src, int lang, char*& details) { details=new char[20]; - strcpy_s(details,20,"CheckDF from DLL\n"); + strcpy_s(details,20,"DLLCheckDF"); return false; } @@ -38,10 +38,7 @@ if (strcmp(output,rightoutput)==0) return 0; Details=new char[30]; - strcpy(Details,output); - strcat(Details," RIGHT: "); - strcat(Details,rightoutput); - strcat(Details,"\n"); + strcpy_s(Details,30,"DLLCheckAns"); int curo=0; for (int i=0;;i++,curo++) { Modified: ACMServer/trunk/sharp tester/TestLibrary/dllmain.cpp =================================================================== --- ACMServer/trunk/sharp tester/TestLibrary/dllmain.cpp 2008-06-28 12:23:27 UTC (rev 286) +++ ACMServer/trunk/sharp tester/TestLibrary/dllmain.cpp 2008-06-29 17:37:55 UTC (rev 287) @@ -1,7 +1,7 @@ // dllmain.cpp : Defines the entry point for the DLL application. #pragma once #include "stdafx.h" -#include <stdio.h> +#include <fstream> extern double TLx,TLk; BOOL APIENTRY DllMain( HMODULE hModule, @@ -12,18 +12,18 @@ switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: - FILE* f; + { TLx=0;TLk=1; - if (fopen_s(&f,"Times.txt","rt")==0) + std::ifstream f("Times.txt"); + if (!f.bad()) { - fscanf_s(f,"%Lf %Lf",&TLk,&TLx); - fclose(f); + f>>TLk>>TLx; + f.close(); } - break; - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; + } + case DLL_THREAD_ATTACH:; + case DLL_THREAD_DETACH:; + case DLL_PROCESS_DETACH:; } return TRUE; } \ No newline at end of file Modified: ACMServer/trunk/sharp tester/tester/Program.cs =================================================================== --- ACMServer/trunk/sharp tester/tester/Program.cs 2008-06-28 12:23:27 UTC (rev 286) +++ ACMServer/trunk/sharp tester/tester/Program.cs 2008-06-29 17:37:55 UTC (rev 287) @@ -38,47 +38,52 @@ { DateTime start=DateTime.Now; MiniMax rt=new MiniMax(),t=new MiniMax(),mem=new MiniMax(),ct=new MiniMax(); - //for (int i = 0; i < 10000; i++) + for (int i = 0; i < 1; i++) { - TSource c = new TSource(); StreamReader s = new StreamReader("InData.txt", Encoding.Default); String compiler = s.ReadLine(); String problem = s.ReadLine(); String temp = s.ReadLine(); String source = s.ReadLine(); s.Close(); - s = File.OpenText(source); - c.CompPath = compiler; - c.ProblemPath = problem; - c.LoadLimits(); - c.Src = s.ReadToEnd(); - s.Close(); - c.TempPath = temp; - c.TestHandler += new TTestHandler(func); - c.Language = (TLang)1; - c.ProcessAll(); - c.State = (TSourceState)6; - Console.WriteLine("Compile result: {0}\nCompilation details: {1}\nUsed Time for compile: {2}", TSource.CompileResultToString(c.Summary.compres.res),c.Summary.compres.Details,c.Summary.compres.UsedTime); - Console.WriteLine("Test result: {0}", TSource.TestResultToString(c.Summary.res.res)); - Console.WriteLine("Points: {0}", c.Summary.res.points); - Console.WriteLine("Used Time: {0}", c.Summary.res.UsedTime); - Console.WriteLine("Used Memory: {0}", c.Summary.res.UsedMemory); - Console.WriteLine("Used Real Time: {0}", c.Summary.res.UsedRealTime); - //Console.ReadKey(); - Console.WriteLine(" CompRes: {0}, TestRes: {1}", TSource.CompileResultToString(c.Summary.compres.res), TSource.TestResultToString(c.Summary.res.res)); + int index=1; + while (File.Exists(Path.GetDirectoryName(source) + "\\" + Path.GetFileNameWithoutExtension(source) + index.ToString() + Path.GetExtension(source))) + { + Console.WriteLine("----------------------------------------------------------------"); + Console.WriteLine("------------------------Test Number {0}-------------------------", index); + Console.WriteLine("----------------------------------------------------------------"); + s = File.OpenText(Path.GetDirectoryName(source) + "\\" + Path.GetFileNameWithoutExtension(source) + index.ToString() + Path.GetExtension(source)); + TSource c = new TSource(); + c.CompPath = compiler; + c.ProblemPath = problem; + c.LoadLimits(); + c.Src = s.ReadToEnd(); + s.Close(); + c.TempPath = temp; + c.TestHandler += new TTestHandler(func); + c.Language = TLang.lPascal; + c.ProcessAll(); + c.State = TSourceState.ssFinish; + Console.WriteLine("Compile result: {0}\nCompilation details: {1}\nUsed Time for compile: {2}", TSource.CompileResultToString(c.Summary.compres.res), c.Summary.compres.Details, c.Summary.compres.UsedTime); + Console.WriteLine("Test result: {0}", TSource.TestResultToString(c.Summary.res.res)); + Console.WriteLine("Points: {0}", c.Summary.res.points); + Console.WriteLine("Used Time: {0}", c.Summary.res.UsedTime); + Console.WriteLine("Used Memory: {0}", c.Summary.res.UsedMemory); + Console.WriteLine("Used Real Time: {0}", c.Summary.res.UsedRealTime); + //Console.ReadKey(); + index++; + c.Dispose(); + } + /*Console.WriteLine(" CompRes: {0}, TestRes: {1}", TSource.CompileResultToString(c.Summary.compres.res), TSource.TestResultToString(c.Summary.res.res)); rt.update(c.Summary.res.UsedRealTime); t.update(c.Summary.res.UsedTime); ct.update(c.Summary.compres.UsedTime); - mem.update(c.Summary.res.UsedMemory); - /*if (c.Summary.res.res != 0) - { - System.Media.SystemSounds.Beep.Play(); - Console.ReadKey(); - }*/ + mem.update(c.Summary.res.UsedMemory);*/ + } - Console.WriteLine("Used Time: {0} ms", (System.DateTime.Now.Ticks - start.Ticks)/10000); + /*Console.WriteLine("Used Time: {0} ms", (System.DateTime.Now.Ticks - start.Ticks)/10000); Console.WriteLine("MAX: CompTime {0} ms, Time {1} ms, RealTime {2} ms, Memory {3} byte", ct.max, t.max, rt.max, mem.max); - Console.WriteLine("Diff: CompTime {0} ms, Time {1} ms, RealTime {2} ms, Memory {3} byte",ct.diff(),t.diff(),rt.diff(),mem.diff()); + Console.WriteLine("Diff: CompTime {0} ms, Time {1} ms, RealTime {2} ms, Memory {3} byte",ct.diff(),t.diff(),rt.diff(),mem.diff());*/ Console.ReadKey(); } } Modified: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt =================================================================== --- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt 2008-06-28 12:23:27 UTC (rev 286) +++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt 2008-06-29 17:37:55 UTC (rev 287) @@ -1,7 +1,7 @@ CodeLimit: 1024 CompilationTimeLimit: 10000 -MemoryLimit: 10000000 +MemoryLimit: 21000000 OutputLimit: 1024 RealTimeLimit: 100000 -TimeLimit: 500 +TimeLimit: 1000 MaxThreads: 4 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |