Skip to content

Commit

Permalink
4.8a
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Apr 8, 2019
1 parent 12da95d commit 66a9f0c
Show file tree
Hide file tree
Showing 15 changed files with 536 additions and 108 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"MIMode": "gdb",
"windows": {
"externalConsole": true,
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe"
"miDebuggerPath": "C:/msys64/usr/bin/gdb.exe"
},
"linux": {
"externalConsole": false
Expand All @@ -42,7 +42,7 @@
"MIMode": "gdb",
"windows": {
"externalConsole": true,
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe"
"miDebuggerPath": "C:/msys64/usr/bin/gdb.exe"
},
"linux": {
"externalConsole": false
Expand All @@ -68,7 +68,7 @@
"MIMode": "gdb",
"windows": {
"externalConsole": true,
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe"
"miDebuggerPath": "C:/msys64/usr/bin/gdb.exe"
},
"linux": {
"externalConsole": false
Expand Down
72 changes: 52 additions & 20 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@
{
"label": "DEBUG",
"command": "g++",
"args": [
"-O0",
"${file}",
"-o",
"bin/${fileBasenameNoExtension}.out",
"-Wall",
"-std=c++17",
"-D_FORTIFY_SOURCE=2",
"-ggdb3",
"-Wextra",
//"-ftrapv"
],
"linux": {
"args": [
"-O0",
"${file}",
"-o",
"bin/${fileBasenameNoExtension}.out",
"-Wall",
"-std=c++17",
"-D_FORTIFY_SOURCE=2",
"-ggdb3",
"-Wextra",
//"-ftrapv"
]
},
"windows": {
"args": [
"-O0",
"${file}",
"-o",
"bin/${fileBasenameNoExtension}.out",
"-Wall",
"-std=c++17",
"-D_FORTIFY_SOURCE=2",
"-ggdb3",
"-Wextra",
"-Wl,-stack=16777216",
"-D__USE_MINGW_ANSI_STDIO"
//"-ftrapv"
]
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
Expand Down Expand Up @@ -72,14 +90,28 @@
{
"label": "RELEASE",
"command": "g++",
"args": [
"-O2",
"${file}",
"-o",
"bin/${fileBasenameNoExtension}.out",
"-Wall",
"-std=c++17"
],
"linux": {
"args": [
"-O2",
"${file}",
"-o",
"bin/${fileBasenameNoExtension}.out",
"-Wall",
"-std=c++17"
]
},
"windows": {
"args": [
"-O2",
"${file}",
"-o",
"bin/${fileBasenameNoExtension}.out",
"-Wall",
"-std=c++17",
"-Wl,-stack=16777216",
"-D__USE_MINGW_ANSI_STDIO"
]
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
Expand Down
21 changes: 18 additions & 3 deletions Checker/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@
#include <fstream>
#include <iostream>
#include <iterator>
#ifdef __WIN32
#include <windows.h>
#else
#include <sys/ioctl.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#endif
#include <vector>
std::string file2Str(const fs::path& path) {
std::ifstream in(path);
using Iter = std::istream_iterator<char>;
return { Iter(in), Iter() };
}
static int getConsoleWidth() {
#ifdef __WIN32
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(
GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwSize.X;
#else
struct winsize size;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
return size.ws_col;
#endif
}
void showLine(const std::string& col,
const std::string& str) {
struct winsize size;
ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
std::cout << '\r' << col << str << "\033[0m"
<< std::string(size.ws_col - str.size(),
<< std::string(getConsoleWidth() -
str.size(),
' ')
<< std::flush;
}
Expand Down
20 changes: 11 additions & 9 deletions Checker/Judger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@
#include <iterator>
template <typename T>
static bool compareImpl(
const fs::path& out, const fs::path& stdout,
const fs::path& out, const fs::path& stdo,
const std::function<bool(const T&, const T&)>&
cmp) {
std::ifstream outf(out), stdof(stdout);
std::ifstream outf(out), stdof(stdo);
using Iter = std::istream_iterator<T>;
return std::equal(Iter(outf), Iter(), Iter(stdof),
Iter(), cmp);
}
static bool compare(CompareMode mode,
const fs::path& out,
const fs::path& stdout,
FT& maxErr) {
const fs::path& stdo, FT& maxErr) {
switch(mode) {
case CompareMode::Text: {
return compareImpl<std::string>(
out, stdout,
out, stdo,
std::equal_to<std::string>());
} break;
case CompareMode::FloatingPoint: {
auto cmp = [&](FT a, FT b) {
auto cmp = [&maxErr](FT a, FT b) {
if(!std::isfinite(a) ||
!std::isfinite(b))
return false;
Expand All @@ -36,7 +35,7 @@ static bool compare(CompareMode mode,
maxErr = std::max(maxErr, err);
return err < eps;
};
return compareImpl<FT>(out, stdout, cmp);
return compareImpl<FT>(out, stdo, cmp);
}
default:
std::cout << "Unknown Comparer"
Expand Down Expand Up @@ -70,8 +69,11 @@ RunResult test(const Option& opt, const Data& data,
std::cout << "[Exited with code "
<< res.sig << "]";
else if(res.sig != -1)
std::cout << "[SIG=" << res.sig << ":"
<< strsignal(res.sig) << "]";
std::cout << "[SIG=" << res.sig
#if !defined(__WIN32)
<< ":" << strsignal(res.sig)
#endif
<< "]";
std::cout << "(" << toString(res.ret) << ") ";
}
if(res.st == Status::SE || res.st == Status::UKE)
Expand Down
3 changes: 1 addition & 2 deletions Checker/Runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ struct RunResult {
};
void initRunner();
RunResult run(const Option& opt, const Timer& timer,
const std::string& in,
const std::string& out);
const fs::path& in, const fs::path& out);
std::string toString(Status st);
std::string toString(RuntimeError st);
std::string getCallName(long callid);
73 changes: 5 additions & 68 deletions Checker/Runner.cpp → Checker/RunnerLinux.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Runner.hpp"
#include "Common.hpp"
#include "Runner.hpp"
#include <algorithm>
#include <asm/unistd.h>
#include <charconv>
Expand All @@ -13,74 +13,11 @@
#include <sys/user.h>
#include <sys/wait.h>
#include <unistd.h>
RunResult::RunResult()
: usrTime(0), totTime(0), mem(0), syscallcnt(0),
st(Status::UKE), ret(RuntimeError::Unknown),
sig(-1), maxErr(0.0) {}
std::string toString(Status st) {
switch(st) {
case Status::AC:
return "\033[32mAccepted\033[0m";
break;
case Status::WA:
return "\033[31mWrong Answer\033[0m";
break;
case Status::MLE:
return "\033[33mMemory Limit "
"Exceeded\033[0m";
break;
case Status::TLE:
return "\033[36mTime Limit "
"Exceeded\033[0m";
break;
case Status::RE:
return "\033[35mRuntime Error\033[0m";
break;
case Status::UKE:
return "\033[35mUnknown Error\033[0m";
break;
case Status::SE:
return "\033[35mJudge System Error\033[0m";
break;
case Status::SKIPPED:
return "\033[33mSkipped\033[0m";
break;
default:
throw;
break;
}
}
std::string toString(RuntimeError st) {
switch(st) {
case RuntimeError::FloatingPointError:
return "Floating Point Error";
break;
case RuntimeError::FloatingPointErrorO2:
return "(SIGFPE):Floating Point "
"Error(-O2?)";
break;
case RuntimeError::NonzeroExitCode:
return "Nonzero Exit Code";
break;
case RuntimeError::SegmentationFault:
return "Segmentation Fault";
break;
case RuntimeError::Exception:
return "Uncaught C++ Exception";
break;
case RuntimeError::Unknown:
return "Unknown";
break;
default:
throw;
break;
}
}
const int magic = 0xe7;
static void runTask(const Option& opt,
const Timer& timer,
const std::string& in,
const std::string& out) {
const fs::path& in,
const fs::path& out) {
ptrace(PT_TRACE_ME, 0, NULL, NULL);
bool flag = true;
flag &= freopen(in.c_str(), "r", stdin) != NULL;
Expand Down Expand Up @@ -211,8 +148,8 @@ static RunResult watchTask(const Option& opt,
return res;
}
RunResult run(const Option& opt, const Timer& timer,
const std::string& in,
const std::string& out) {
const fs::path& in,
const fs::path& out) {
pid_t id = vfork();
if(id < 0) {
RunResult res;
Expand Down
64 changes: 64 additions & 0 deletions Checker/RunnerShared.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "Runner.hpp"
RunResult::RunResult()
: usrTime(0), totTime(0), mem(0), syscallcnt(0),
st(Status::UKE), ret(RuntimeError::Unknown),
sig(-1), maxErr(0.0) {}
std::string toString(Status st) {
switch(st) {
case Status::AC:
return "\033[32mAccepted\033[0m";
break;
case Status::WA:
return "\033[31mWrong Answer\033[0m";
break;
case Status::MLE:
return "\033[33mMemory Limit "
"Exceeded\033[0m";
break;
case Status::TLE:
return "\033[36mTime Limit "
"Exceeded\033[0m";
break;
case Status::RE:
return "\033[35mRuntime Error\033[0m";
break;
case Status::UKE:
return "\033[35mUnknown Error\033[0m";
break;
case Status::SE:
return "\033[35mJudge System Error\033[0m";
break;
case Status::SKIPPED:
return "\033[33mSkipped\033[0m";
break;
default:
throw;
break;
}
}
std::string toString(RuntimeError st) {
switch(st) {
case RuntimeError::FloatingPointError:
return "Floating Point Error";
break;
case RuntimeError::FloatingPointErrorO2:
return "(SIGFPE):Floating Point "
"Error(-O2?)";
break;
case RuntimeError::NonzeroExitCode:
return "Nonzero Exit Code";
break;
case RuntimeError::SegmentationFault:
return "Segmentation Fault";
break;
case RuntimeError::Exception:
return "Uncaught C++ Exception";
break;
case RuntimeError::Unknown:
return "Unknown";
break;
default:
throw;
break;
}
}
6 changes: 6 additions & 0 deletions Checker/RunnerWindows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Runner.hpp"
#include <Windows.h>
void initRunner() {}
std::string getCallName(long) {
return "Unknown";
}
4 changes: 4 additions & 0 deletions Checker/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x86_64-w64-mingw32-g++ Common.cpp Judger.cpp OJAdapter.cpp OJAPI.cpp Timer.cpp ^
PerfAnalyzer.cpp RunnerShared.cpp Scanner.cpp Checker.cpp RunnerWindows.cpp ^
Adapters/BZOJJudger.cpp Adapters/LOJJudger.cpp Adapters/DefaultJudger.cpp ^
-o ../bin/checker.out -O2 -std=c++17 -lstdc++fs -Wall -Wextra -D__WIN32
2 changes: 1 addition & 1 deletion Checker/build.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
g++ Common.cpp Judger.cpp OJAdapter.cpp OJAPI.cpp Timer.cpp \
PerfAnalyzer.cpp Runner.cpp Scanner.cpp Checker.cpp \
PerfAnalyzer.cpp RunnerCommon.cpp Scanner.cpp Checker.cpp RunnerLinux.cpp \
Adapters/BZOJJudger.cpp Adapters/LOJJudger.cpp Adapters/DefaultJudger.cpp \
-o ../bin/checker.out -O2 -std=c++17 -lstdc++fs -Wall -Wextra
Loading

0 comments on commit 66a9f0c

Please sign in to comment.