Skip to content

Commit

Permalink
4.11c
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Apr 11, 2019
1 parent b00c448 commit c7a4a64
Show file tree
Hide file tree
Showing 25 changed files with 261 additions and 165 deletions.
2 changes: 1 addition & 1 deletion Checker/Adapters/BZOJJudger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static bool readOpt(Option& opt,
opt.insert("MemoryLimit", maxMem << 10);
opt.insert("CompareMode", CompareMode::Text);
opt.insert("TimeSamples",
fs::path("BZOJ-Samples"));
fs::path("Checker/BZOJ-Samples"));
return true;
}
static bool runBZOJ(const fs::path& exec) {
Expand Down
2 changes: 0 additions & 2 deletions Checker/Adapters/DefaultJudger.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../Judger.hpp"
#include "../OJAdapter.hpp"
#include "../PerfAnalyzer.hpp"
#include "../Platforms/Platform.hpp"
#include "../Scanner.hpp"
#include "../Timer.hpp"
Expand Down Expand Up @@ -99,7 +98,6 @@ bool runAll(const Option& opt,
#endif
timer.addSample();
}

return flag;
}
#define Input(name) \
Expand Down
5 changes: 3 additions & 2 deletions Checker/Adapters/LOJJudger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ static bool readOpt(Option& opt,
opt.insert("TimeLimit", maxTime * 1000);
opt.insert("MemoryLimit", maxMem << 10);
opt.insert("CompareMode", compareMode);
opt.insert("TimeSamples", fs::path("LOJ-Samples"));
opt.insert("TimeSamples",
fs::path("Checker/LOJ-Samples"));
return true;
}
#ifdef SYZOJTOOLS
#ifdef USE_SYZOJTOOLS
static bool testSYZOJTools(const Option& opt) {
std::string testCmd = "which syzoj";
if(system(testCmd.c_str()))
Expand Down
67 changes: 43 additions & 24 deletions Checker/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,60 @@
cmake_minimum_required (VERSION 2.8)
project(Checker)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" HAS_CXX17)
if(NOT HAS_CXX17)
message(FATAL_ERROR "Unsupported c++ complier")
endif(NOT HAS_CXX17)

find_program(HAS_WGET wget)

if(NOT HAS_WGET)
message(FATAL_ERROR "No wget")
endif(NOT HAS_WGET)

find_program(HAS_UNZIP unzip)

if(NOT HAS_UNZIP)
message(FATAL_ERROR "No unzip")
endif(NOT HAS_UNZIP)

set (CHECKER_VERSION_MAJOR 2)
set (CHECKER_VERSION_MINOR 8)
set (CHECKER_VERSION_PATCH 1)
set (CHECKER_VERSION_PATCH 2)
set (CHECKER_SRC_DIR "${PROJECT_SOURCE_DIR}")

option(BZOJ_JUDGER "bzoj-judger" ON)
option(LOJ_JUDGER "loj-judger" ON)
option(USE_SYZOJTOOLS "syzoj-tools for loj" OFF)

add_definitions(-O2 -std=c++17 -lstdc++fs -Wall -Wextra)

set (SHAREDSRC Adapters/DefaultJudger.cpp Checker.cpp Common.cpp
Judger.cpp OJAdapter.cpp OJAPI.cpp PerfAnalyzer.cpp RunnerShared.cpp
Scanner.cpp Timer.cpp)

set (ADAPTERSRC )

if (BZOJ_JUDGER)
set (ADAPTERSRC ${ADAPTERSRC} Adapters/BZOJJudger.cpp)
endif (BZOJ_JUDGER)

if (LOJ_JUDGER)
set (ADAPTERSRC ${ADAPTERSRC} Adapters/LOJJudger.cpp)
endif (LOJ_JUDGER)
configure_file (
"${PROJECT_SOURCE_DIR}/CheckerConfig.hpp.in"
"${PROJECT_BINARY_DIR}/CheckerConfig.hpp"
)

include_directories(${PROJECT_BINARY_DIR})
set(CMAKE_CXX_FLAGS "-O2 -std=c++17 -Wall -Wextra ${CMAKE_CXX_FLAGS}")
if (WIN32)
add_definitions(-D__WIN32 -DUNICODE -D_UNICODE)
set (PLATFORMSRC Platforms/PlatformWindows.cpp RunnerWindows.cpp)
set(CMAKE_CXX_FLAGS "-D__WIN32 -DUNICODE -D_UNICODE ${CMAKE_CXX_FLAGS}")
aux_source_directory(Platforms/Windows PlatformSrc)
elseif (UNIX)
set (PLATFORMSRC Platforms/PlatformLinux.cpp RunnerLinux.cpp)
aux_source_directory(Platforms/Linux PlatformSrc)
else ()
message(FATAL_ERROR "Unsupported system")
endif (WIN32)

configure_file (
"${PROJECT_SOURCE_DIR}/CheckerConfig.hpp.in"
"${PROJECT_BINARY_DIR}/CheckerConfig.hpp"
)
set (JudgerSrc Adapters/DefaultJudger.cpp)
if(BZOJ_JUDGER)
set (JudgerSrc ${JudgerSrc} Adapters/BZOJJudger.cpp)
endif(BZOJ_JUDGER)

if(LOJ_JUDGER)
set (JudgerSrc ${JudgerSrc} Adapters/LOJJudger.cpp)
endif(LOJ_JUDGER)

set (SharedSrc Checker.cpp Common.cpp Judger.cpp OJAdapter.cpp OJAPI.cpp
RunnerShared.cpp Scanner.cpp Timer.cpp)

add_executable(Checker ${SHAREDSRC} ${PLATFORMSRC} ${ADAPTERSRC})
link_libraries(stdc++fs)
add_executable(Checker ${SharedSrc} ${JudgerSrc} ${PlatformSrc})
2 changes: 1 addition & 1 deletion Checker/Checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {
std::cout.precision(2);
std::cout << std::fixed;

line("Checker 2.8.1", '*');
line("Checker " VERSION, '*');
std::cout << "Built at " << __TIME__ << " on "
<< __DATE__ << std::endl;
platformInfo();
Expand Down
1 change: 1 addition & 0 deletions Checker/CheckerConfig.hpp.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#define VERSION "@CHECKER_VERSION_MAJOR@.@CHECKER_VERSION_MINOR@.@CHECKER_VERSION_PATCH@"
#cmakedefine USE_SYZOJTOOLS
#define SOURCE_DIR "@CHECKER_SRC_DIR@"
40 changes: 13 additions & 27 deletions Checker/Common.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Common.hpp"
#include "Platforms/Platform.hpp"
#include <algorithm>
#include <chrono>
#include <cstdlib>
Expand All @@ -7,14 +8,6 @@
#include <iostream>
#include <iterator>
#include <random>
#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);
Expand All @@ -24,8 +17,13 @@ std::string file2Str(const fs::path& path) {
if(siz <= 0) {
in.clear();
std::string res;
while(in)
res.push_back(in.get());
while(in) {
int ch = in.get();
if(ch != EOF)
res.push_back(ch);
else
break;
}
return res;
} else {
std::vector<char> data(siz);
Expand All @@ -34,18 +32,6 @@ std::string file2Str(const fs::path& path) {
data.data() + siz);
}
}
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) {
std::cout << '\r' << col << str << "\033[0m"
Expand Down Expand Up @@ -89,13 +75,13 @@ TempFile::~TempFile() {
}
}
static void clearCache() {
if(fs::exists("Cache")) {
if(fs::exists("Checker/Cache")) {
using DirIter = fs::directory_iterator;
std::vector<fs::path> deferred;
using Clock = fs::file_time_type::clock;
using namespace std::chrono;
auto ct = Clock::now();
for(auto it : DirIter("Cache")) {
for(auto it : DirIter("Checker/Cache")) {
it.refresh();
if(!it.is_regular_file())
continue;
Expand All @@ -110,7 +96,7 @@ static void clearCache() {
for(auto p : deferred)
fs::remove(p);
} else
fs::create_directory("Cache");
fs::create_directory("Checker/Cache");
}
static bool verifyZip(const fs::path& file) {
std::string cmd = "unzip -t -q " + file.string();
Expand All @@ -124,7 +110,7 @@ fs::path downloadFile(const std::string& url,
if(fs::exists(url))
return url;
else {
fs::path cacheFile = "Cache/" + pid;
fs::path cacheFile = "Checker/Cache/" + pid;
if(verify && fs::exists(cacheFile) &&
!verifyZip(cacheFile))
fs::remove(cacheFile);
Expand Down Expand Up @@ -166,7 +152,7 @@ bool unzip(const fs::path& path) {
return res == 0;
}
std::string readConfig(const std::string& optName) {
std::ifstream in("checker.config");
std::ifstream in("Checker/checker.config");
std::string line;
while(std::getline(in, line)) {
std::size_t pos = line.find('#');
Expand Down
1 change: 1 addition & 0 deletions Checker/Common.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "CheckerConfig.hpp"
#include <any>
#include <charconv>
#include <cstdint>
Expand Down
10 changes: 5 additions & 5 deletions Checker/Judger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ static std::string newline(std::string str) {
return str;
}
template <typename T>
static bool compareImpl(
const fs::path& out, const fs::path& stdi,
const fs::path& stdo,
const std::function<bool(const T&, const T&)>&
cmp) {
static bool
compareImpl(const fs::path& out, const fs::path& stdi,
const fs::path& stdo,
const std::function<bool(const T&,
const T&)>& cmp) {
std::ifstream outf(out), stdof(stdo);
using Iter = std::istream_iterator<T>;
if(std::equal(Iter(outf), Iter(), Iter(stdof),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "PerfAnalyzer.hpp"
#include "Common.hpp"
#include "../../Common.hpp"
#include <iostream>
#include <regex>
const int64_t invalid =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "Common.hpp"
#include "../../Common.hpp"
class PerformanceInfo {
private:
int64_t cacheRef, cacheMiss, branchCnt, branchMiss,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "../Common.hpp"
#include "Platform.hpp"
#include "../../Common.hpp"
#include "../Platform.hpp"
#include <cstdlib>
#include <iostream>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
void platformInfo() {
system("lsb_release -d");
}
Expand Down Expand Up @@ -62,3 +66,8 @@ std::string getCallName(long callid) {
return match[1].str();
return "Unknown";
}
int getConsoleWidth() {
struct winsize size;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
return size.ws_col;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once
#include "../Common.hpp"
#include "../../Common.hpp"
std::string getCallName(long callid);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Common.hpp"
#include "Runner.hpp"
#include "../../Common.hpp"
#include "../../Runner.hpp"
#include <algorithm>
#include <asm/unistd.h>
#include <charconv>
Expand Down
6 changes: 4 additions & 2 deletions Checker/Platforms/Platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#include "../Common.hpp"
#include "../Runner.hpp"
#ifdef __WIN32
#include "PlatformWindows.hpp"
#include "Windows/PlatformWindows.hpp"
#else
#include "PlatformLinux.hpp"
#include "Linux/PerfAnalyzer.hpp"
#include "Linux/PlatformLinux.hpp"
#endif
void initPlatform();
void platformInfo();
fs::path selfPath();
void reportJudgeError(const RunResult& res);
int getConsoleWidth();
Loading

0 comments on commit c7a4a64

Please sign in to comment.