-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrading.cpp
More file actions
96 lines (90 loc) · 2.69 KB
/
Grading.cpp
File metadata and controls
96 lines (90 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Grading.h"
using namespace std;
using namespace boost::filesystem;
using namespace tinyxml2;
Grading::Grading()
{
submitList = new SubmitList();
}
void Grading::process()
{
while (true)
{
readTask();
while (!submitList->empty())
{
cout << submitList->nextTask().getUserID() << endl;
compileAndRun(submitList->nextTask());
submitList->remove();
}
}
}
void Grading::readTask()
{
string processFolder = serverPath + "\\Unprocess";
boost::filesystem::path unprocessPath(unprocess);
if (!boost::filesystem::exists(unprocessPath))
return;
boost::filesystem::directory_iterator it(unprocessPath), eod;
BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(it, eod))
{
if (is_regular_file(p))
if (p.extension().string() == ".xml")
{
path newFilePath(unprocessPath.string() + "\\NewFile.xml");
while (!exists(newFilePath))
{
try
{
rename(p, newFilePath);
}
catch (const exception& ex)
{}
catch (...)
{}
}
Submit newSubmit = Submit::fromXMLFile(newFilePath.string());
newSubmit.copyFile();
submitList->add(newSubmit);
boost::filesystem::remove(newFilePath);
boost::filesystem::remove_all(serverPath + "\\Unprocess\\" + newSubmit.getFolderName());
}
}
}
void Grading::processFolder(Submit s)
{
}
std::string Grading::getCompileStr(Submit t, std::string compileStd)
{
string compile = "set PATH=%PATH%;" + compileToolPath + " && " + " g++ " + compileStd + " ";
path submitPath(serverPath + "\\" + t.getUserFolderName() + "\\" + t.getSubmitFolderName());
string xmlPath = t.getXMLFilePath();
tinyxml2::XMLDocument doc;
doc.LoadFile(xmlPath.c_str());
XMLElement* ele = doc.FirstChildElement("Files")->FirstChildElement("File");
while (ele != nullptr)
{
compile += submitPath.string() + "\\" + std::string(ele->GetText()) + " ";
ele = ele->NextSiblingElement("File");
}
compile += "-o " + t.getExecutionFilePath();
return compile;
}
void Grading::compileAndRun(Submit s)
{
string timeout = "20";
string compileStr = getCompileStr(s, "-std=c++11");
system(compileStr.c_str());
for (int i = 0; i < N_TESTCASE; ++i)
{
string testcasePath = "<\"" + testCaseFilePath + "\\Test" + to_string(i + 1) + "\\input1.txt\"";
string outputPath = ">\"" + serverPath + "\\_" + s.getUserID() + "\\" + s.getSubmitFolderName() + "\\output.txt\"";
string run = s.getExecutionFilePath() + " " + testcasePath + " " + outputPath + " && timeout /t " +
timeout + " && taskkill /im " + s.getExecutionFileName() + " /f";
system(run.c_str());
}
}
bool Grading::compare(std::string path, std::string path2)
{
return true;
}