update
This commit is contained in:
parent
26969b340e
commit
e13bcbb5f4
47
src/main.cpp
47
src/main.cpp
@ -1,5 +1,6 @@
|
||||
#include "json/reader.h"
|
||||
#include "json/value.h"
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@ -8,7 +9,9 @@
|
||||
#include<json/json.h>
|
||||
#include <ostream>
|
||||
#include <queue>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include<windows.h>
|
||||
@ -16,7 +19,7 @@
|
||||
#include "unistd.h"
|
||||
#endif
|
||||
|
||||
using std::cerr,std::endl,std::cout,std::ifstream,std::string,std::vector,std::queue,std::filesystem::path;
|
||||
using std::cerr,std::endl,std::cout,std::ifstream,std::string,std::vector,std::queue,std::filesystem::path,std::thread,std::chrono::time_point,std::chrono::steady_clock,std::chrono::high_resolution_clock;
|
||||
|
||||
#define AS_EQ(a,b){if((a)!=(b)){cerr<<"assert eq failed :"<<endl<<#a<<":"<<(a)<<endl<<#b<<":"<<(b)<<endl;exit(1);}}
|
||||
#define AS_NE(a,b){if((a)==(b)){cerr<<"assert not eq failed :"<<endl<<#a<<":"<<(a)<<endl<<#b<<":"<<(b)<<endl;exit(1);}}
|
||||
@ -47,6 +50,7 @@ std::filesystem::path getAbsolutePath(std::filesystem::path rootPath,std::filesy
|
||||
string getProtectPath(const std::filesystem::path &p);
|
||||
|
||||
struct Test{
|
||||
unsigned int id;
|
||||
std::filesystem::path in;
|
||||
std::filesystem::path ans;
|
||||
friend std::ostream& operator<<(std::ostream& os,Test &t){
|
||||
@ -55,6 +59,11 @@ struct Test{
|
||||
}
|
||||
};
|
||||
|
||||
struct ProgramRet{
|
||||
time_point<steady_clock> start;
|
||||
time_point<steady_clock> end;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T getValueOrPanic(T value);
|
||||
|
||||
@ -116,20 +125,44 @@ int main(int argc, char* argv[]) {
|
||||
if(jsonValue["tests"].size()==0)LOG("cannot find tests");
|
||||
LOG("parsing tests")
|
||||
vector<Test> tests;
|
||||
for(auto i:jsonValue["tests"]){
|
||||
auto &jsonTests = jsonValue["tests"];
|
||||
for(unsigned int i=1;i<=jsonTests.size();i++){
|
||||
tests.push_back({
|
||||
.in=getAbsolutePath(projectPath, getValueOrPanic(i["in"]).asString()),
|
||||
.ans=getAbsolutePath(projectPath,getValueOrPanic(i["ans"]).asString())
|
||||
.id = i,
|
||||
.in=getAbsolutePath(projectPath, getValueOrPanic(jsonTests[i-1]["in"]).asString()),
|
||||
.ans=getAbsolutePath(projectPath,getValueOrPanic(jsonTests[i-1]["ans"]).asString()),
|
||||
});
|
||||
}
|
||||
queue<std::function<void()>> tasks;
|
||||
queue<std::function<ProgramRet()>> tasks;
|
||||
const auto testsPath = projectPath/"tests";
|
||||
printValue(testsPath)
|
||||
const string exePathStr = getProtectPath(exePath);
|
||||
for(auto i:tests){
|
||||
tasks.push([i,&exePathStr](){
|
||||
tasks.push([i,&exePathStr,&testsPath]()->ProgramRet{
|
||||
string commands;
|
||||
commands = commands+exePathStr+" < "+getProtectPath(i.in)+" > ";
|
||||
std::stringstream ss;
|
||||
ss<<i.id;
|
||||
string id_str;
|
||||
ss>>id_str;
|
||||
path outPath = testsPath/(id_str+".out") ;
|
||||
commands = commands+exePathStr+" < "+getProtectPath(i.in)+" > "+getProtectPath(outPath);
|
||||
LOG(commands)
|
||||
auto start = high_resolution_clock::now();
|
||||
system(commands.c_str());
|
||||
auto end=high_resolution_clock::now();
|
||||
return ProgramRet{
|
||||
.start=start,
|
||||
.end = end
|
||||
};
|
||||
});
|
||||
}
|
||||
while(tasks.size()>0){
|
||||
auto i = tasks.front();
|
||||
tasks.pop();
|
||||
thread newThread(i);
|
||||
AS_EQ(newThread.joinable(),true);
|
||||
newThread.join();
|
||||
}
|
||||
}
|
||||
|
||||
string getProtectPath(const std::filesystem::path &p){
|
||||
|
1
tests/1.in
Normal file
1
tests/1.in
Normal file
@ -0,0 +1 @@
|
||||
1
|
Loading…
Reference in New Issue
Block a user