From: <Or...@us...> - 2008-09-24 19:51:55
|
Revision: 372 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=372&view=rev Author: Oracle_ Date: 2008-09-24 19:51:37 +0000 (Wed, 24 Sep 2008) Log Message: ----------- Fixed bug with waiting for files. Modified Paths: -------------- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/problem/ProblemData.txt ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.h ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.h Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs 2008-09-22 20:14:18 UTC (rev 371) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs 2008-09-24 19:51:37 UTC (rev 372) @@ -13,7 +13,7 @@ { Console.SetOut(File.CreateText("D:\\logout.txt")); string[] data=File.ReadAllLines("InData.txt"); - for (int ind = 1; ind <= 1; ind++) + for (int ind = 1; ind <= 5; ind++) { string src = File.ReadAllText("src\\source" + ind.ToString() + ".txt"); TestEnv test = new TestEnv(src, data[0], data[1], data[2]); Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/problem/ProblemData.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/problem/ProblemData.txt 2008-09-22 20:14:18 UTC (rev 371) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/problem/ProblemData.txt 2008-09-24 19:51:37 UTC (rev 372) @@ -4,6 +4,6 @@ OutputLimit: 1024 RealTimeLimit: 20000 TimeLimit: 1000 -MaxThreads: 4 +MaxThreads: 16 Checker: scriptExample.txt CheckPlugin: Plugin.dll \ No newline at end of file Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp 2008-09-22 20:14:18 UTC (rev 371) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp 2008-09-24 19:51:37 UTC (rev 372) @@ -28,7 +28,7 @@ { if (!File::Exists(ExeFile)) break; - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(10); } } @@ -37,9 +37,14 @@ si->CreateNoWindow=true; StreamWriter^ src=File::CreateText(srcpath); src->Write(source); + src->Flush(); src->Close(); - WaitForFile(srcpath); + System::Threading::Thread::Sleep(CONST_SLEEP); + for (int i=0;i<CONST_SLEEP;i++) + if (!File::Exists(srcpath)) + System::Threading::Thread::Sleep(5); else + break; si->FileName=comppath; si->Arguments="\""+srcpath+"\" \""+temp; @@ -57,7 +62,10 @@ } UsedTime=comp->TotalProcessorTime; - WaitForFile(ExeFile); + for (int i=0;i<CONST_SLEEP;i++) + if (!File::Exists(ExeFile)) + System::Threading::Thread::Sleep(5); else + break; if (!File::Exists(ExeFile)) //compilation error { @@ -74,24 +82,4 @@ { comp->Close(); } -} - -void Compiler::WaitForFile(String^ FileName) -{ - for (int i=0;i<CONST_SLEEP;++i) - if (!File::Exists(FileName)) - System::Threading::Thread::Sleep(1); - for (int i=0;i<CONST_SLEEP;++i) - { - try - { - FileStream^ f=File::OpenRead(FileName); - f->Close(); - break; - } catch(...) - { - System::Threading::Thread::Sleep(1); - continue; - } - } } \ No newline at end of file Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.h =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.h 2008-09-22 20:14:18 UTC (rev 371) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.h 2008-09-24 19:51:37 UTC (rev 372) @@ -22,7 +22,6 @@ String^ comppath; String^ source; String^ temp; - void WaitForFile(String^ FileName); public: String^ Details; CompRes Result; Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp 2008-09-22 20:14:18 UTC (rev 371) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp 2008-09-24 19:51:37 UTC (rev 372) @@ -1,4 +1,3 @@ - #include "SecureClass.h" #include <Lm.h> #include <Userenv.h> Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp 2008-09-22 20:14:18 UTC (rev 371) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp 2008-09-24 19:51:37 UTC (rev 372) @@ -24,7 +24,7 @@ exe=ExeFile; prob=ProblemPath; temp=TempPath; - TestAll=true; + FTestAll=true; SecType=secure; CONST_SLEEP=WaitForFile; } @@ -72,6 +72,7 @@ lock(); bufW=(wchar_t*)Marshal::StringToHGlobalUni(exe).ToPointer(); unlock(); + if (!sec->Init(bufW)) { int err=sec->LastError(); @@ -87,6 +88,7 @@ Marshal::FreeHGlobal(IntPtr(bufW)); return false; } + if (sec->CheckSecure()) { result->res=TestResult::DestrictedFunction; @@ -94,6 +96,7 @@ Marshal::FreeHGlobal(IntPtr(bufW)); return false; } + if (!sec->CreateProc(bufW,TRUE,CREATE_SUSPENDED|CREATE_NO_WINDOW|ABOVE_NORMAL_PRIORITY_CLASS,&si)) { Marshal::FreeHGlobal(IntPtr(bufW)); @@ -118,6 +121,7 @@ } Marshal::FreeHGlobal(IntPtr(bufW)); + job=CreateJobObject(NULL,NULL); mem.BasicLimitInformation.LimitFlags=JOB_OBJECT_LIMIT_JOB_MEMORY; mem.JobMemoryLimit=data->MemoryLimit; @@ -250,8 +254,11 @@ CloseHandle(si.hStdOutput);si.hStdOutput=NULL; CloseHandle(si.hStdInput);si.hStdInput=NULL; - WaitForFile(oupath); - + for (int i=0;i<CONST_SLEEP;i++) + if (!File::Exists(oupath)) + Sleep(5); else + break; + if (!File::Exists(oupath)) { result->res=TestResult::WrongAnswer; @@ -259,10 +266,8 @@ return false; } - WaitForFile(oupath); + Checker^ check=gcnew Tester::Checker(Path::GetFullPath(data->Checker),test->tests[index-1]->input,ReadAllFile(oupath),test->tests[index-1]->output); - Checker^ check=gcnew Tester::Checker(Path::GetFullPath(data->Checker),test->tests[index-1]->input,File::ReadAllText(oupath),test->tests[index-1]->output); - switch (check->Check()) { case CheckResult::OE: @@ -320,11 +325,7 @@ if (n<=test->tests->Length) { if (!ExecuteTest(n)) - { - lock(); StopTest=true; - unlock(); - } } else break; } @@ -332,7 +333,7 @@ void Runner::RunTests() { - StopTest=false; + FStopTest=false; CurrentTest=0; threads=gcnew array<Threading::Thread^>(min(data->MaxThreads,testfield->tests->Length)); for (int i=0;i<threads->Length;i++) @@ -381,22 +382,19 @@ LeaveCriticalSection(cs); } -void Runner::WaitForFile(String^ FileName) +String^ Runner::ReadAllFile(String^ FileName) { for (int i=0;i<CONST_SLEEP;++i) - if (!File::Exists(FileName)) - Sleep(1); - for (int i=0;i<CONST_SLEEP;++i) { try { - FileStream^ f=File::OpenRead(FileName); - f->Close(); - break; + String^ res=File::ReadAllText(FileName); + return res; } catch(...) { - Sleep(1); + Sleep(5); continue; } } + return ""; } \ No newline at end of file Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.h =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.h 2008-09-22 20:14:18 UTC (rev 371) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.h 2008-09-24 19:51:37 UTC (rev 372) @@ -70,7 +70,31 @@ String^ temp; String^ exe; void ThreadProc(); - bool StopTest; //true if testing should be stopped + bool FStopTest; + + property bool StopTest + { + bool get() + { + try + { + lock(); + return FStopTest; + } finally + { + unlock(); + } + } + + void set(bool value) + { + lock(); + FStopTest=value; + unlock(); + } + } + + bool FTestAll; array<Threading::Thread^>^ threads; int CurrentTest; //next test needed to be tested @@ -79,14 +103,13 @@ void destroylock(); void lock(); //locks access to other theads void unlock(); //unlocks access to other threads - void WaitForFile(String^ FileName); //waits for file handle + String^ ReadAllFile(String^ FileName); //waits for file handle and returns all file text TestLoader^ testfield; DataLoader^ datafield; PluginLoader^ plugfield; public: array<TestRes^>^ results; - bool TestAll; //set false if break testing after ExecuteTest return false (not AC) SecureType SecType; int CONST_SLEEP; @@ -95,7 +118,29 @@ void RunTests(); void TerminateThreads(); ~Runner(); + + property bool TestAll //set false if break testing after ExecuteTest return false (not AC) + { + bool get() + { + try + { + lock(); + return FTestAll; + } finally + { + unlock(); + } + } + void set(bool value) + { + lock(); + FTestAll=value; + unlock(); + } + } + property TestLoader^ test { TestLoader^ get() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |