feat: set tester
This commit is contained in:
@ -2,3 +2,4 @@ cmake_minimum_required(VERSION 3.10)
|
||||
project(BigInt)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(data)
|
||||
add_subdirectory(tester)
|
@ -3,6 +3,7 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS "-g -O2")
|
||||
set(ENV{MAKEFLAGS} "-j16")
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/libs/clipp)
|
||||
link_directories(${PROJECT_SOURCE_DIR}/src)
|
||||
add_executable(C1T1 Integer1/1.cpp)
|
||||
target_link_libraries(C1T1 int2048)
|
||||
|
7024
libs/clipp/clipp.h
Normal file
7024
libs/clipp/clipp.h
Normal file
File diff suppressed because it is too large
Load Diff
24596
libs/json/json.hpp
Normal file
24596
libs/json/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
7
tester/CMakeLists.txt
Normal file
7
tester/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS "-g -O2")
|
||||
set(ENV{MAKEFLAGS} "-j16")
|
||||
include_directories(${PROJECT_SOURCE_DIR}/libs/clipp)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/libs/json)
|
||||
add_executable(tester tester.cpp)
|
11
tester/config.json
Normal file
11
tester/config.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"StatusInterpreter":{"0":"OK","1":"Error"},
|
||||
"Cases":
|
||||
[
|
||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C1T1 >/tmp/C1T1.out && diff -b -B -u /tmp/C1T1.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/1.out","uid":"#1","tid":"/1/1"},
|
||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C1T2 </home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/2.in >/tmp/C1T2.out && diff -b -B -u /tmp/C1T2.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/2.out","uid":"#2","tid":"/1/2"},
|
||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C1T3 </home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/3.in >/tmp/C1T3.out && diff -b -B -u /tmp/C1T3.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/3.out","uid":"#3","tid":"/1/3"},
|
||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C1T4 </home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/4.in >/tmp/C1T4.out && diff -b -B -u /tmp/C1T4.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/4.out","uid":"#4","tid":"/1/4"},
|
||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C1T5 </home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/5.in >/tmp/C1T5.out && diff -b -B -u /tmp/C1T5.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/5.out","uid":"#5","tid":"/1/5"}
|
||||
]
|
||||
}
|
88
tester/tester.cpp
Normal file
88
tester/tester.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "clipp.h"
|
||||
#include "json.hpp"
|
||||
std::string getDirectory(const std::string &filepath) {
|
||||
size_t found = filepath.find_last_of("/\\");
|
||||
return filepath.substr(0, found);
|
||||
}
|
||||
#define DeEscape std::string
|
||||
int main(int argc, char *argv[]) {
|
||||
bool continuous = false;
|
||||
bool test_all = false;
|
||||
bool test_listed_cases = false;
|
||||
std::vector<std::string> listed_cases;
|
||||
std::string filePath(__FILE__);
|
||||
std::string directoryPath = getDirectory(filePath);
|
||||
std::string config_file = directoryPath + "/config.json";
|
||||
bool use_custoem_config = false;
|
||||
std::string new_config = "";
|
||||
bool test_sub_tree = false;
|
||||
std::string sub_tree;
|
||||
// clang-format off
|
||||
auto cli=(
|
||||
clipp::option("-f","--file").set(config_file).doc("config file path") & clipp::value("config file path",config_file),
|
||||
clipp::option("-c","--continuous").set(continuous).doc("continuous mode"),
|
||||
clipp::option("-a","--all").set(test_all).doc("test all"),
|
||||
clipp::option("-s","--subtree").set(test_sub_tree).doc("test subtree") & clipp::value("subtree",sub_tree),
|
||||
clipp::option("-l","--list").set(test_listed_cases).doc("test listed cases") & clipp::values("cases",listed_cases)
|
||||
);
|
||||
// clang-format on
|
||||
if (!parse(argc, argv, cli)) {
|
||||
std::cout << make_man_page(cli, argv[0]);
|
||||
return 0;
|
||||
}
|
||||
if (use_custoem_config) config_file = new_config;
|
||||
using json = nlohmann::json;
|
||||
std::ifstream conf(config_file);
|
||||
json config = json::parse(conf);
|
||||
std::unordered_map<std::string, std::string> index;
|
||||
for (int i = 0; i < config["Cases"].size(); i++) {
|
||||
index[DeEscape(config["Cases"][i]["tid"])] =
|
||||
DeEscape(config["Cases"][i]["command"]);
|
||||
index[DeEscape(config["Cases"][i]["uid"])] =
|
||||
DeEscape(config["Cases"][i]["command"]);
|
||||
}
|
||||
if (test_all) {
|
||||
listed_cases.clear();
|
||||
for (int i = 0; i < config["Cases"].size(); i++) {
|
||||
listed_cases.push_back(DeEscape(config["Cases"][i]["tid"]));
|
||||
}
|
||||
} else if (test_sub_tree) {
|
||||
listed_cases.clear();
|
||||
for (int i = 0; i < config["Cases"].size(); i++) {
|
||||
if (DeEscape(config["Cases"][i]["tid"]).find(sub_tree) == 0 &&
|
||||
(DeEscape(config["Cases"][i]["tid"]).length() == sub_tree.length() ||
|
||||
DeEscape(config["Cases"][i]["tid"])[sub_tree.length()] == '/')) {
|
||||
listed_cases.push_back(DeEscape(config["Cases"][i]["tid"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < listed_cases.size(); i++) {
|
||||
std::cerr << "Testing " << listed_cases[i] << std::endl;
|
||||
std::cerr << "Command " << index[listed_cases[i]] << std::endl;
|
||||
int status = system(index[listed_cases[i]].c_str()) / 256;
|
||||
if (status == 0) {
|
||||
std::cerr << "Test " << listed_cases[i] << " passed" << std::endl;
|
||||
} else {
|
||||
std::cerr << "Test " << listed_cases[i] << " failed" << std::endl;
|
||||
std::cerr << "status code: " << status << std::endl;
|
||||
std::cerr
|
||||
<< "Brief info: "
|
||||
<< (config["StatusInterpreter"].contains(std::to_string(status))
|
||||
? DeEscape(
|
||||
config["StatusInterpreter"][std::to_string(status)])
|
||||
: std::string("Unknown Error"))
|
||||
<< std::endl;
|
||||
if (!continuous) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user