|
From: <Or...@us...> - 2008-06-22 10:53:07
|
Revision: 270
http://acmcontester.svn.sourceforge.net/acmcontester/?rev=270&view=rev
Author: Oracle_
Date: 2008-06-20 11:17:38 -0700 (Fri, 20 Jun 2008)
Log Message:
-----------
Added multithreading
Modified Paths:
--------------
ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp
ACMServer/trunk/sharp tester/SourceTest/SourceTest.h
ACMServer/trunk/sharp tester/SourceTest.sln
ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp
ACMServer/trunk/sharp tester/tester/Program.cs
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/source.txt
Added Paths:
-----------
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/out.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/in.txt
ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/out.txt
Modified: ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp
===================================================================
--- ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp 2008-06-20 14:07:46 UTC (rev 269)
+++ ACMServer/trunk/sharp tester/SourceTest/SourceTest.cpp 2008-06-20 18:17:38 UTC (rev 270)
@@ -10,6 +10,8 @@
const wchar_t USER_NAME[]={L"TestingUser"}; //username for testing
const wchar_t USER_PASSW[]={L"USER12345"}; //password of user for testing
+const int CONST_SLEEP=100; //constant used for waiting for files to be created/flushed on disk
+const int MAX_THREAD=2; //maximum parallel threads
namespace SourceTest
{
@@ -24,7 +26,6 @@
return (wchar_t*)System::Runtime::InteropServices::Marshal::StringToHGlobalUni(str).ToPointer();
}
-
void FreeArr(char* buf) //destroys C++ string
{
System::Runtime::InteropServices::Marshal::FreeHGlobal(IntPtr(buf));
@@ -42,7 +43,6 @@
return %String(intg);
}
-
bool FileExists(String^ path) //checks whether file exists or not
{
char* buf=StrToArr(path);
@@ -54,6 +54,44 @@
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("");
@@ -80,59 +118,47 @@
if (lib!=NULL)
FreeLibrary(lib);
delete FSecurity;
+FRes.Clear();
+FThreads.Clear();
final();
}
void TSource::CheckCL() //checking size of source
{
- try
+ if (lib==NULL) //no library was found
{
- lock();
- if (lib==NULL) //no library was found
- {
- if (FSrc->Length>FLim.CodeLimit)
- FCompResult.res=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;
- FreeArr(bufA);
- FCompResult.Details+=gcnew String(buf);
- TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar");
- prc2(buf);
- }
- FState=ssCheckedCL;
- }__finally
+ if (FSrc->Length>FLim.CodeLimit)
+ FCompResult.res=crCL;
+ FCompResult.Details+="Used std checker for Code Limit\n";
+ } else
{
- unlock();
+ TCheckSrc prc=(TCheckSrc)GetProcAddress(lib,"CheckCL");
+ char* buf,*bufA;
+ if (prc(bufA=StrToArr(FSrc),FLim.CodeLimit,buf)) FCompResult.res=crCL;
+ FreeArr(bufA);
+ FCompResult.Details+=gcnew String(buf);
+ TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar");
+ prc2(buf);
}
+ FState=ssCheckedCL;
}
void TSource::CheckDF() //checking for DF in source
{
- try
+ if (lib==NULL) //no library was found
{
- lock();
- if (lib==NULL) //no library was found
- {
- 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;
- FreeArr(bufA);
- FCompResult.Details+=gcnew String(buf);
- TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar");
- prc2(buf);
- }
- FState=ssCheckedDF;
- }__finally
+ FCompResult.Details+="No checker for DF\n";
+ } else
{
- unlock();
+ TCheckSrc prc=(TCheckSrc)GetProcAddress(lib,"CheckDF");
+ char* buf,*bufA;
+ if (prc(bufA=StrToArr(FSrc),(int)FLang,buf)) FCompResult.res=crDF;
+ FreeArr(bufA);
+ FCompResult.Details+=gcnew String(buf);
+ TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar");
+ prc2(buf);
}
+ FState=ssCheckedDF;
}
void TSource::Compile() //compiles the source
@@ -147,187 +173,210 @@
wchar_t* bufW;
try
{
- lock();
- String^ srcpath=gcnew String(FTempPath+"source.txt");
- String^ outpath=gcnew String(FTempPath+"compoutput.txt");
- FExePath=FTempPath+"source.exe";
-
- if (FileExists(FExePath)) //delete previsious source
- {
- DeleteFile((LPCTSTR)(bufW=StrToArrW(FExePath)));
- FreeArr(bufW);
- }
-
- si.cb=sizeof(si);
- si.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
- si.wShowWindow=FALSE;
- si.hStdOutput=CreateFile(bufW=StrToArrW(outpath),GENERIC_WRITE,0,&sec,CREATE_ALWAYS,0,NULL);
+ String^ srcpath=gcnew String(FTempPath+"source.txt");
+ String^ outpath=gcnew String(FTempPath+"compoutput.txt");
+ FExePath=FTempPath+"source.exe";
+
+ if (FileExists(FExePath)) //delete previsious source
+ {
+ DeleteFile((LPCTSTR)(bufW=StrToArrW(FExePath)));
FreeArr(bufW);
- HANDLE src=CreateFile(bufW=StrToArrW(srcpath),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
- FreeArr(bufW);
- DWORD len;
- WriteFile(src,bufA=StrToArr(FSrc),FSrc->Length,&len,NULL);
- FreeArr(bufA);
- CloseHandle(src);
-
- Sleep(100); //waiting for file to flush on hard
+ Sleep(CONST_SLEEP); //waiting for file to destroy
+ }
- DWORD start=GetTickCount();
- bufW=StrToArrW("\""+FCompPath+"\" \""+srcpath+"\" \""+FTempPath);
- 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";
- return;
- }
+ si.cb=sizeof(si);
+ si.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
+ si.wShowWindow=FALSE;
+ si.hStdOutput=CreateFile(bufW=StrToArrW(outpath),GENERIC_WRITE,0,&sec,CREATE_ALWAYS,0,NULL);
+ FreeArr(bufW);
+ HANDLE src=CreateFile(bufW=StrToArrW(srcpath),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
+ FreeArr(bufW);
+ DWORD len;
+ WriteFile(src,bufA=StrToArr(FSrc),FSrc->Length,&len,NULL);
+ FreeArr(bufA);
+ CloseHandle(src);
+
+ Sleep(CONST_SLEEP); //waiting for file to flush on hard
+
+ DWORD start=GetTickCount();
+ bufW=StrToArrW("\""+FCompPath+"\" \""+srcpath+"\" \""+FTempPath);
+ if (!CreateProcess(NULL,bufW,&sec,&sec,true,CREATE_NEW_CONSOLE|CREATE_NO_WINDOW,NULL,NULL,&si,&pi))
+ {
FreeArr(bufW);
- 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";
- return;
- }
- FCompResult.UsedTime=GetTickCount()-start;
+ FCompResult.res=crIE;
+ FCompResult.Details+="Can not run the compiler\n";
+ return;
+ }
+ FreeArr(bufW);
+ 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";
+ return;
+ }
+ FCompResult.UsedTime=GetTickCount()-start;
- Sleep(100); //waiting for creating the file
- CloseHandle(si.hStdOutput);
+ Sleep(CONST_SLEEP); //waiting for creating the file
+
+ CloseHandle(si.hStdOutput); si.hStdOutput=NULL;
- HANDLE oup=CreateFile(bufW=StrToArrW(outpath),GENERIC_READ,0,&sec,OPEN_EXISTING,0,NULL);
- FreeArr(bufW);
- DWORD size=GetFileSize(oup,NULL);
- char* compres=new char[size+2]; compres[size+1]='\0';
- ReadFile(oup,compres,size,&len,NULL);
- CloseHandle(oup);
+ if (!FileExists(FExePath)) //compilation error
+ {
+ FCompResult.res=crCE;
+ FCompResult.Details+="EXE file not found\n"+ReadFullFile(outpath);
+ return;
+ }
- if (!FileExists(FExePath)) //compilation error
- {
- FCompResult.res=crCE;
- FCompResult.Details+=gcnew String("EXE file not found\n")+gcnew String(compres);
- delete[] compres;
- return;
- }
+ FCompResult.Details+=ReadFullFile(outpath);
- FCompResult.Details+=gcnew String(compres);
- delete[] compres;
-
}__finally
{
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
+ if (pi.hProcess!=NULL)
+ CloseHandle(pi.hProcess);
+ if (pi.hThread!=NULL)
+ CloseHandle(pi.hThread);
+ if (si.hStdOutput!=NULL)
+ CloseHandle(si.hStdOutput);
FState=ssCompiled;
- unlock();
}
}
-void TSource::RunTests() //runs all tests of problem
+void TSource::AddThread()
{
-try
+ Threading::Thread^ t=gcnew Threading::Thread(gcnew System::Threading::ThreadStart(this,&TSource::ThreadProc));
+ FThreads.Add(t);
+ t->Start();
+}
+
+void TSource::ThreadProc()
{
+ while (true)
+ {
+ if (!NeedTest) break;
lock();
- int n=1;
- while (FileExists(FProblemPath+"test"+ToStr(n)+"\\in.txt")||FileExists(FProblemPath+"test"+ToStr(n)+"\\out.txt")||FileExists(FProblemPath+"test"+ToStr(n)+"\\points.txt"))
+ ++CurrentTest;
+ int n=CurrentTest;
+ unlock();
+ if (n<TestCnt())
{
RunTest(n);
- FSummary.res->points+=((TResult^)FRes[n-1])->points;
- FSummary.res->UsedMemory=max(((TResult^)FRes[n-1])->UsedMemory,FSummary.res->UsedMemory);
- FSummary.res->UsedTime=max(((TResult^)FRes[n-1])->UsedTime,FSummary.res->UsedTime);
- FSummary.res->UsedRealTime=max(((TResult^)FRes[n-1])->UsedRealTime,FSummary.res->UsedRealTime);
- if (((TResult^)FRes[n-1])->res!=trAC)
+ Summary->res->points+=Results[n-1]->points;
+ 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)
{
- FSummary.res->res=((TResult^)FRes[n-1])->res;
- if (!FRunAll) break;
+ Summary->res->res=Results[n-1]->res;
+ if (!RunAll) { NeedTest=false; break; }
}
- n++;
+ } else
+ {
+ NeedTest=false;
+ break;
}
-}__finally
+ }
+}
+
+void TSource::RunTests() //runs all tests of problem
{
+ FState=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.Add(%TResult());
+ FTestCnt++;
+ }
+
+ FThreads.Clear();
+ for (int i=0;i<min(MAX_THREAD,FTestCnt-1);i++)
+ AddThread();
+ for (int i=0;i<FThreads.Count;i++)
+ ((Threading::Thread^)FThreads[i])->Join(INFINITE);
FState=ssFinish;
- unlock();
}
-}
void TSource::LoadTest(int index,TTest% test) //loads test from file
{
-FILE* inp,*oup,*points;
-char *bufA;
try
{
lock();
- test.input="";
- test.output="";
- test.points=1;
-
- if (fopen_s(&inp,bufA=StrToArr(FProblemPath+"test"+ToStr(index)+"\\in.txt"),"rt")==0)
- {
- fseek(inp,0,SEEK_END);
- int size=ftell(inp);
- fseek(inp,0,SEEK_SET);
- char* buf=new char[size+1];ZeroMemory(buf,(size+1)*sizeof(char));
- fread(buf,sizeof(char),size,inp);
- test.input=gcnew String(buf);
- }
- FreeArr(bufA);
-
- if (fopen_s(&oup,bufA=StrToArr(FProblemPath+"\\test"+ToStr(index)+"\\out.txt"),"rt")==0)
- {
- fseek(oup,0,SEEK_END);
- int size=ftell(inp);
- fseek(oup,0,SEEK_SET);
- char* buf=new char[size+1];ZeroMemory(buf,(size+1)*sizeof(char));
- fread(buf,sizeof(char),size,oup);
- test.output=gcnew String(buf);
- }
- FreeArr(bufA);
-
- if (fopen_s(&points,bufA=StrToArr(FProblemPath+"\\test"+ToStr(index)+"\\points.txt"),"rt")==0)
- {
- fscanf_s(points,"%d",&test.points);
- }
- FreeArr(bufA);
-
+ 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 (inp!=NULL)
- fclose(inp);
- if (oup!=NULL)
- fclose(oup);
- if (points!=NULL)
- fclose(points);
unlock();
}
}
TCheckAnsRes TSource::CheckAnswer(int index,String^ output, String^% Details) //checks answer for test
{
- try
+try
+{
+ TTest t;
+ LoadTest(index,t);
+ lock();
+ if (lib==NULL) //lib was not found
{
- lock();
- TTest t;
- LoadTest(index,t);
- if (lib==NULL) //lib was not found
- {
- 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);
- Details+=gcnew String(buf4);
- TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar");
- FreeArr(buf1);FreeArr(buf2);FreeArr(buf3);prc2(buf4);
- return res;
- }
- }__finally
+ if (output!=t.output)
+ return carWA;
+ return carAC;
+ } else
{
- unlock();
+ 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);
+ Details+=gcnew String(buf4);
+ TFreeFunc prc2=(TFreeFunc)GetProcAddress(lib,"FreeChar");
+ FreeArr(buf1);FreeArr(buf2);FreeArr(buf3);prc2(buf4);
+ return res;
}
+} __finally
+{
+ unlock();
}
+}
+bool TSource::CheckTL(int usedtime, int timelimit)
+{
+try
+{
+ lock();
+ if (lib==NULL)
+ return usedtime>timelimit;
+ TCheckLim prc=(TCheckLim)GetProcAddress(lib,"CheckTL");
+ return prc(usedtime,timelimit);
+}__finally
+{
+ unlock();
+}
+}
+bool TSource::CheckRTL(int usedrealtime, int realtimelimit)
+{
+try
+{
+ lock();
+ if (lib==NULL)
+ return usedrealtime>realtimelimit;
+ TCheckLim prc=(TCheckLim)GetProcAddress(lib,"CheckRTL");
+ return prc(usedrealtime,realtimelimit);
+}__finally
+{
+ unlock();
+}
+}
+
void TSource::ProcessAll() //executes all actions needed to get Summary result for all tests
{
try
@@ -375,63 +424,57 @@
sec.lpSecurityDescriptor=NULL;
JOBOBJECT_BASIC_ACCOUNTING_INFORMATION acc;
JOBOBJECT_EXTENDED_LIMIT_INFORMATION mem;
-HANDLE job;
-JOBOBJECT_ASSOCIATE_COMPLETION_PORT port;
+HANDLE job=NULL;
+JOBOBJECT_ASSOCIATE_COMPLETION_PORT port; ZeroMemory(&port,sizeof(port));
JOBOBJECT_BASIC_UI_RESTRICTIONS uilim;
DWORD len=0;
wchar_t* bufW;
-char* bufA;
try
{
- lock();
- FRes.Add(%TResult());
- TResult^ it=(TResult^)FRes[FRes.Count-1];
- it->res=trAC;
- it->points=0;
- it->Details="";
- it->UsedMemory=-1;
- it->UsedRealTime=-1;
- it->UsedTime=-1;
- String^ inpath=FProblemPath+"test"+ToStr(index)+"\\in.txt";
- String^ oupath=FTempPath+"out.txt";
- String^ erpath=FTempPath+"err.txt";
- String^ pointpath=FProblemPath+"test"+ToStr(index)+"\\points.txt";
+ Results[index-1]->res=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";
- FState=ssIsRunning;
-
- TTest t;
- LoadTest(index,t);
si.cb=sizeof(si);
si.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow=FALSE;
- si.hStdInput=CreateFile(bufW=StrToArrW(inpath),GENERIC_READ,0,&sec,OPEN_EXISTING,0,NULL); FreeArr(bufW);
+ si.hStdInput=CreateFile(bufW=StrToArrW(inpath),GENERIC_READ,FILE_SHARE_READ,&sec,OPEN_EXISTING,0,NULL); FreeArr(bufW);
si.hStdOutput=CreateFile(bufW=StrToArrW(oupath),GENERIC_WRITE,0,&sec,CREATE_ALWAYS,0,NULL); FreeArr(bufW);
- si.hStdError=CreateFile(bufW=StrToArrW(erpath),GENERIC_WRITE,0,&sec,CREATE_ALWAYS,0,NULL); FreeArr(bufW);
+ si.hStdError=CreateFile(bufW=StrToArrW(erpath),GENERIC_WRITE,FILE_SHARE_WRITE,&sec,CREATE_ALWAYS,0,NULL); FreeArr(bufW);
SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT|SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX);
-
- if (!FSecurity->RunProcess(bufW=StrToArrW(FExePath),TRUE,CREATE_SUSPENDED|CREATE_NO_WINDOW,&si,&pi,it->Details))
+ lock();
+ if (!FSecurity->RunProcess(bufW=StrToArrW(ExePath),TRUE,CREATE_SUSPENDED|CREATE_NO_WINDOW|HIGH_PRIORITY_CLASS,&si,&pi,Results[index-1]->Details))
{
FreeArr(bufW);
- it->points=0;
+ Results[index-1]->points=0;
int err=GetLastError();
if ((err==193)||(err==1455))
{
- it->res=trRE;
- it->Details+=gcnew String("Too large array");
+ Results[index-1]->res=trRE;
+ Results[index-1]->Details+="Too large array";
} else
{
- it->res=trIE;
- it->Details+=gcnew String("Can not start process");
+ Results[index-1]->res=trIE;
+ Results[index-1]->Details+="Can not start process";
}
+ unlock();
return ;
}
FreeArr(bufW);
+ unlock();
job=CreateJobObject(NULL,NULL);
mem.BasicLimitInformation.LimitFlags=JOB_OBJECT_LIMIT_PROCESS_MEMORY;
- mem.ProcessMemoryLimit=FLim.MemoryLimit;
+ mem.ProcessMemoryLimit=Lim->MemoryLimit;
SetInformationJobObject(job,JobObjectExtendedLimitInformation,&mem,sizeof(mem));
- port.CompletionKey=(void*)123;
+ port.CompletionKey=(void*)index;
port.CompletionPort=CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 0);
SetInformationJobObject(job,JobObjectAssociateCompletionPortInformation,&port,sizeof(port));
@@ -440,93 +483,74 @@
AssignProcessToJobObject(job,pi.hProcess);
+ SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);
+
ResumeThread(pi.hThread);
+
DWORD start=GetTickCount();
while (true)
{
- if ((int)GetFileSize(si.hStdOutput,NULL)>FLim.OutputLimit)
+ if ((int)GetFileSize(si.hStdOutput,NULL)>Lim->OutputLimit)
{
TerminateJobObject(job,0);
- it->res=trOL;
- it->Details+=gcnew String("Size of output file excided OutputLimit");
+ Results[index-1]->res=trOL;
+ Results[index-1]->Details+="Size of output file excided OutputLimit";
break;
}
QueryInformationJobObject(job,JobObjectBasicAccountingInformation,&acc,sizeof(acc),NULL);
- if (lib==NULL)
+ if (CheckRTL((int)(GetTickCount()-start),Lim->RealTimeLimit))
{
- if ((int)(GetTickCount()-start)>FLim.RealTimeLimit)
- {
TerminateJobObject(job,0);
- it->res=trRTL;
- it->Details+=gcnew String("Real time limit");
+ Results[index-1]->res=trRTL;
+ Results[index-1]->Details+="Real time limit";
break;
}
- if ((acc.ThisPeriodTotalKernelTime.QuadPart+acc.ThisPeriodTotalUserTime.QuadPart)>FLim.TimeLimit*10000)
+ if (CheckTL((int)(acc.ThisPeriodTotalKernelTime.QuadPart+acc.ThisPeriodTotalUserTime.QuadPart),Lim->TimeLimit*10000))
{
TerminateJobObject(job,0);
- it->res=trTL;
- it->Details+=gcnew String("Time Limit");
+ Results[index-1]->res=trTL;
+ Results[index-1]->Details+="Time Limit";
break;
}
- } else
- {
- TCheckLim prc=(TCheckLim)GetProcAddress(lib,"CheckTL");
- if (prc((int)(acc.ThisPeriodTotalKernelTime.QuadPart+acc.ThisPeriodTotalUserTime.QuadPart),(int)(FLim.TimeLimit*10000)))
- {
- TerminateJobObject(job,0);
- it->res=trTL;
- it->Details+=gcnew String("Time Limit");
- break;
- }
- prc=(TCheckLim)GetProcAddress(lib,"CheckRTL");
- if (prc((int)(GetTickCount()-start),FLim.RealTimeLimit))
- {
- TerminateJobObject(job,0);
- it->res=trRTL;
- it->Details+=gcnew String("Real time Limit");
- break;
- }
- }
unsigned long len,key;
HANDLE proc;
- if (GetQueuedCompletionStatus(port.CompletionPort, &len, &key, (LPOVERLAPPED*)&proc, 1))
+ if (GetQueuedCompletionStatus(port.CompletionPort, &len, &key, (LPOVERLAPPED*)&proc, 1)&&(key==index))
{
DWORD code=0;
bool needbreak=false;
- if (key==123)
switch(len)
{
case JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS:
GetExitCodeProcess(pi.hProcess,&code);
if (code==5)
{
- it->res=trDF;
- it->Details+=gcnew String("Access denied.");
+ Results[index-1]->res=trDF;
+ Results[index-1]->Details+="Access denied.";
} else
if (code!=0)
{
- it->res=trRE;
- it->Details+=gcnew String("Runtime error #"+ToStr((int)code));
+ Results[index-1]->res=trRE;
+ Results[index-1]->Details+="Runtime error #"+ToStr((int)code);
}
needbreak=true;
break;
case JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT:
- it->res=trML;
- it->Details+=gcnew String("Memory Limit");
+ Results[index-1]->res=trML;
+ Results[index-1]->Details+="Memory Limit";
needbreak=true;
break;
case JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO:
GetExitCodeProcess(pi.hProcess,&code);
if (code==5)
{
- it->res=trDF;
- it->Details+=gcnew String("Access denied.");
+ Results[index-1]->res=trDF;
+ Results[index-1]->Details+="Access denied.";
} else
if (code!=0)
{
- it->res=trRE;
- it->Details+=gcnew String("Runtime error #"+ToStr((int)code));
+ Results[index-1]->res=trRE;
+ Results[index-1]->Details+="Runtime error #"+ToStr((int)code);
}
needbreak=true;
break;
@@ -539,74 +563,74 @@
}
Sleep(1);
}
- CloseHandle(si.hStdOutput);
- CloseHandle(si.hStdInput);
- Sleep(100); //waiting for file
+ SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);
+
+ CloseHandle(si.hStdOutput);si.hStdOutput=NULL;
+ CloseHandle(si.hStdInput);si.hStdInput=NULL;
+ Sleep(CONST_SLEEP); //waiting for file
+
QueryInformationJobObject(job,JobObjectExtendedLimitInformation,&mem,sizeof(mem),NULL);
QueryInformationJobObject(job,JobObjectBasicAccountingInformation,&acc,sizeof(acc),NULL);
- it->UsedMemory=mem.PeakProcessMemoryUsed;
- it->UsedTime=(int)((acc.ThisPeriodTotalKernelTime.QuadPart+acc.ThisPeriodTotalUserTime.QuadPart)/10000);
- it->UsedRealTime=GetTickCount()-start;
- if (it->res!=trAC) return;
+ 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 (!FileExists(oupath))
{
- it->res=trWA;
- it->Details+=gcnew String("No output file");
+ Results[index-1]->res=trWA;
+ Results[index-1]->Details+="No output file";
return;
}
- HANDLE ouf=CreateFile(bufW=StrToArrW(oupath),GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); FreeArr(bufW);
- DWORD size=GetFileSize(ouf,NULL);
- char* buf=new char[size+1]; ZeroMemory(buf,(size+1)*sizeof(char));
- ReadFile(ouf,buf,size,&len,NULL);
- CloseHandle(ouf);
+ //Sleep(CONST_SLEEP); //waiting for closing all handles to this file
- TCheckAnsRes r=CheckAnswer(index,gcnew String(buf),it->Details);
- delete[] buf;
+ TCheckAnsRes r=CheckAnswer(index,ReadFullFile(oupath),Results[index-1]->Details);
+
if (r==carAC)
{
if (FileExists(pointpath))
- {
- FILE* point;
- fopen_s(&point,bufA=StrToArr(pointpath),"rt"); FreeArr(bufA);
- fscanf_s(point,"%d",&it->points);
- fclose(point);
- } else it->points=1;
+ Results[index-1]->points.Parse(ReadFullFile(pointpath)); else
+ Results[index-1]->points=1;
return ;
}
switch (r)
{
case carOE:
- it->res=trOE;
+ Results[index-1]->res=trOE;
break;
case carPE:
- it->res=trPE;
+ Results[index-1]->res=trPE;
break;
case carWA:
- it->res=trWA;
+ Results[index-1]->res=trWA;
break;
case carIE:
- it->res=trIE;
+ Results[index-1]->res=trIE;
break;
};
}__finally
{
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- CloseHandle(si.hStdInput);
- CloseHandle(si.hStdOutput);
- CloseHandle(si.hStdError);
- CloseHandle(port.CompletionPort);
- CloseHandle(job);
- FState=ssTestComplete;
- if (FTestHandler)
- FTestHandler(index,(TResult^)FRes[index-1]);
- unlock();
+ if (pi.hProcess!=NULL)
+ CloseHandle(pi.hProcess);
+ if (pi.hThread!=NULL)
+ CloseHandle(pi.hThread);
+ if (si.hStdInput!=NULL)
+ CloseHandle(si.hStdInput);
+ if (si.hStdOutput!=NULL)
+ CloseHandle(si.hStdOutput);
+ if (si.hStdError!=NULL)
+ CloseHandle(si.hStdError);
+ if (port.CompletionPort!=NULL)
+ CloseHandle(port.CompletionPort);
+ if (job!=NULL)
+ CloseHandle(job);
+ if (TestHandler)
+ TestHandler(index,Results[index-1]);
}
}
@@ -639,7 +663,6 @@
FILE* f;
try
{
- lock();
if (FState!=ssNone)
{
throw "Can not load limits if state is higher than ssNone";
@@ -652,7 +675,6 @@
{
fclose(f);
FreeArr(buf);
- unlock();
}
}
Modified: ACMServer/trunk/sharp tester/SourceTest/SourceTest.h
===================================================================
--- ACMServer/trunk/sharp tester/SourceTest/SourceTest.h 2008-06-20 14:07:46 UTC (rev 269)
+++ ACMServer/trunk/sharp tester/SourceTest/SourceTest.h 2008-06-20 18:17:38 UTC (rev 270)
@@ -202,6 +202,13 @@
(*compres)=(*value.compres);
}
+ TSummary operator=(TSummary value)
+ {
+ (*res)=(*value.res);
+ (*compres)=(*value.compres);
+ return (value);
+ }
+
};
///<summary>
///TTest holds information about one test
@@ -262,18 +269,18 @@
private:
String^ FSrc; //text of source
String^ FExePath; //executable file
- String^ FProblemPath; //path for problem
+ String^ FProblemPath; //path for problem *MT*
String^ FCompPath; //path for compiler
- 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
+ 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
- TSummary FSummary; //summary results of all tests
+ 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
+ TTestHandler^ FTestHandler; //event, that occures when test is completed *MT*
TLang FLang; //language of source
- TSecure *FSecurity; //security class
+ TSecure *FSecurity; //security class *MT*
HMODULE lib; //library that must export:
//bool CheckCL(char* src, int cl, char*& details) - must check codelimit
//bool CheckDF(char* src, int lang, char*& details) - must check DF
@@ -305,6 +312,82 @@
DeleteCriticalSection(cs);
delete cs;
}
+
+ void AddThread();
+ void ThreadProc();
+ int FCurrentTest; //current test for testing *MT*
+ bool FNeedTest; //if found WA, or all test completed *MT*
+ int FTestCnt;
+ ArrayList FThreads;
+ property int CurrentTest
+ {
+ void set(int value)
+ {
+ try
+ {
+ lock();
+ FCurrentTest=value;
+ }__finally
+ {
+ unlock();
+ }
+ }
+
+ int get()
+ {
+ try
+ {
+ lock();
+ return FCurrentTest;
+ }__finally
+ {
+ unlock();
+ }
+ }
+ }
+
+ property bool NeedTest
+ {
+ void set(bool value)
+ {
+ try
+ {
+ lock();
+ FNeedTest=value;
+ }__finally
+ {
+ unlock();
+ }
+ }
+
+ bool get()
+ {
+ try
+ {
+ lock();
+ return FNeedTest;
+ }__finally
+ {
+ unlock();
+ }
+ }
+ }
+
+ int TestCnt()
+ {
+ try
+ {
+ lock();
+ return FTestCnt;
+ } __finally
+ {
+ unlock();
+ }
+ }
+
+
+ bool CheckRTL(int usedrealtime, int realtimelimit);
+ bool CheckTL(int usedtime, int timelimit);
public:
TSource();
~TSource();
@@ -329,17 +412,23 @@
try
{
lock();
- if (FState>=ssIsRunning)
- {
- throw "Can not set limits if state is ssIsRunning or higher";
- return ;
- }
FLim=(*value);
}
__finally {
unlock();
}
}
+ TLimits^ get()
+ {
+ try
+ {
+ lock();
+ return %FLim;
+ }
+ __finally {
+ unlock();
+ }
+ }
}
property String^ Src
@@ -360,11 +449,6 @@
try
{
lock();
- if (FState!=ssNone)
- {
- throw "Can not set source unless state is ssNone";
- return;
- }
FSrc=value;
} __finally {
unlock();
@@ -379,11 +463,6 @@
try
{
lock();
- if (FState<ssCompiled)
- {
- throw "Can not get exepath unless state is ssCompiled or higher";
- return "";
- }
return FExePath;
}__finally{
unlock();
@@ -402,15 +481,11 @@
unlock();
}
}
+
void set(String^ value)
{
try{
lock();
- if (FState>ssCompiled)
- {
- throw "Can not set problempath if state is ssIsRunning or higher";
- return ;
- }
FProblemPath=value;
}__finally {
unlock();
@@ -425,11 +500,6 @@
try
{
lock();
- if (FState==ssNone)
- {
- throw "Can not get compresult if state is ssNone";
- return %FCompResult;
- }
return %FCompResult;
}__finally {
unlock();
@@ -467,11 +537,6 @@
try
{
lock();
- if (FState<ssIsRunning)
- {
- throw "Can not get test results if state is lower than ssIsRunning";
- return (%TResult());
- }
if (index>=FRes.Count)
{
throw "The index is not accesible";
@@ -493,17 +558,24 @@
try
{
lock();
- if (FState!=ssFinish)
- {
- throw "Can not get summary unlest state is ssFinish";
- return (%TSummary());
- }
return (%FSummary);
}__finally
{
unlock();
}
};
+
+ void set(TSummary^ value)
+ {
+ try
+ {
+ lock();
+ FSummary=(*value);
+ }
+ __finally {
+ unlock();
+ }
+ }
}
property TTestHandler^ TestHandler
@@ -552,11 +624,6 @@
try
{
lock();
- if (FState>ssCheckedDF)
- {
- throw "Can not set compiler path if state is higher than ssCheckedDF";
- return ;
- }
FCompPath=value;
}__finally
{
@@ -599,11 +666,6 @@
try
{
lock();
- if (FState>=ssIsRunning)
- {
- throw "Can not set RunAll if state is higher or equal ssIsRunning";
- return;
- }
FRunAll=value;
} __finally
{
@@ -631,11 +693,6 @@
try
{
lock();
- if (FState>=ssCheckedDF)
- {
- throw "Can not set Language if state is higher or equal ssCheckedDF";
- return;
- }
FLang=value;
} __finally
{
Modified: ACMServer/trunk/sharp tester/SourceTest.sln
===================================================================
--- ACMServer/trunk/sharp tester/SourceTest.sln 2008-06-20 14:07:46 UTC (rev 269)
+++ ACMServer/trunk/sharp tester/SourceTest.sln 2008-06-20 18:17:38 UTC (rev 270)
@@ -2,6 +2,9 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SourceTest", "SourceTest\SourceTest.vcproj", "{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}"
+ ProjectSection(ProjectDependencies) = postProject
+ {2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4} = {2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}
+ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tester", "tester\tester.csproj", "{2D663DAB-3573-4CB6-95A0-2425635CFEC3}"
EndProject
@@ -18,11 +21,13 @@
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Debug|Any CPU.ActiveCfg = Debug|Win32
+ {FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Debug|Any CPU.Build.0 = Debug|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Debug|Win32.ActiveCfg = Debug|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Debug|Win32.Build.0 = Debug|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Release|Any CPU.ActiveCfg = Release|Win32
+ {FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Release|Any CPU.Build.0 = Release|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Release|Mixed Platforms.Build.0 = Release|Win32
{FD28B5FF-FCE2-417C-998C-DA3B1B9D9315}.Release|Win32.ActiveCfg = Release|Win32
@@ -32,17 +37,21 @@
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Debug|Win32.ActiveCfg = Debug|Any CPU
+ {2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Debug|Win32.Build.0 = Debug|Any CPU
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Release|Any CPU.Build.0 = Release|Any CPU
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Release|Win32.ActiveCfg = Release|Any CPU
+ {2D663DAB-3573-4CB6-95A0-2425635CFEC3}.Release|Win32.Build.0 = Release|Any CPU
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Debug|Any CPU.ActiveCfg = Debug|Win32
+ {2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Debug|Any CPU.Build.0 = Debug|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Debug|Win32.ActiveCfg = Debug|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Debug|Win32.Build.0 = Debug|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Release|Any CPU.ActiveCfg = Release|Win32
+ {2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Release|Any CPU.Build.0 = Release|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Release|Mixed Platforms.Build.0 = Release|Win32
{2009FCA0-9B13-4D3D-8C89-DDCD3C40E4B4}.Release|Win32.ActiveCfg = Release|Win32
Modified: ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp
===================================================================
--- ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp 2008-06-20 14:07:46 UTC (rev 269)
+++ ACMServer/trunk/sharp tester/TestLibrary/TestLibrary.cpp 2008-06-20 18:17:38 UTC (rev 270)
@@ -35,10 +35,13 @@
TESTLIBRARY_API int CheckAnswer(char* input, char* output, char* rightoutput, char*& Details)
{
- Details=new char[30];
- strcpy(Details,"CheckAnswer from DLL\n");
if (strcmp(output,rightoutput)==0)
return 0;
+ Details=new char[30];
+ strcpy(Details,output);
+ strcat(Details," RIGHT: ");
+ strcat(Details,rightoutput);
+ strcat(Details,"\n");
int curo=0;
for (int i=0;;i++,curo++)
{
Modified: ACMServer/trunk/sharp tester/tester/Program.cs
===================================================================
--- ACMServer/trunk/sharp tester/tester/Program.cs 2008-06-20 14:07:46 UTC (rev 269)
+++ ACMServer/trunk/sharp tester/tester/Program.cs 2008-06-20 18:17:38 UTC (rev 270)
@@ -6,6 +6,26 @@
namespace tester
{
+ class MiniMax
+ {
+ public int min;
+ public int max;
+ public MiniMax()
+ {
+ min = 1000000000;
+ max = -1000000000;
+ }
+ public void update(int x)
+ {
+ min = Math.Min(min, x);
+ max = Math.Max(max, x);
+ }
+ public int diff()
+ {
+ return max - min;
+ }
+ };
+
class Program
{
static void func(int x,TResult res)
@@ -13,32 +33,52 @@
Console.WriteLine("test number {0}, result: {1}, details: {2}",x,TSource.TestResultToString(res.res),res.Details);
}
+ const int INF = 1000000000;
static void Main(string[] args)
{
- 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);
+ DateTime start=DateTime.Now;
+ MiniMax rt=new MiniMax(),t=new MiniMax(),mem=new MiniMax(),ct=new MiniMax();
+ //for (int i = 0; i < 10000; 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));
+ 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();
+ }*/
+ }
+ 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.ReadKey();
}
}
Modified: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt 2008-06-20 14:07:46 UTC (rev 269)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/limits.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -2,5 +2,5 @@
CompilationTimeLimit: 10000
MemoryLimit: 10000000
OutputLimit: 1024
-RealTimeLimit: 10000
-TimeLimit: 1000
+RealTimeLimit: 100000
+TimeLimit: 500
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test10/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test11/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test12/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test13/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test14/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test15/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test3/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test4/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test5/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test6/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test7/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test8/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/in.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/in.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/in.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1334 15
Added: ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/out.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/out.txt (rev 0)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/Test/test9/out.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -0,0 +1 @@
+1349
\ No newline at end of file
Modified: ACMServer/trunk/sharp tester/tester/SAMPLE/source.txt
===================================================================
--- ACMServer/trunk/sharp tester/tester/SAMPLE/source.txt 2008-06-20 14:07:46 UTC (rev 269)
+++ ACMServer/trunk/sharp tester/tester/SAMPLE/source.txt 2008-06-20 18:17:38 UTC (rev 270)
@@ -1,8 +1,18 @@
-program hello;
-uses windows;
-var a,b:integer;
-begin
-read(a,b);
-while true do;
-write(a+b);
-end.
\ No newline at end of file
+uses Windows; var f:Thandle; begin f:=CreateFile('Hello.txt',GENERIC_WRITE,0,nil,CREATE_ALWAYS,0,0); if (f=INVALID_HANDLE_VALUE) then while true do; CloseHandle(f); end.
+var a,b:Extended;
+i:Integer;
+x:array of Integer;
+begin
+ read(a,b);
+ for i:=1 to 5700000 do
+ a:=sqrt(a)*sqrt(a)+((sqrt(a)*sqrt(a))/sqrt(a))/sqrt(a)-1;
+ for i:=1 to 180000000 do ;
+ for i:=1 to 20 do
+ begin
+ SetLength(x,5000000);
+ x[1237]:=2178;
+ x[5237]:=2174;
+ SetLength(x,0);
+ end;
+ write(a+b:0:0);
+end.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|