Commit b820208c authored by Noah Orensa's avatar Noah Orensa
Browse files

add information about the run configuration in the results file

parent e5920067
......@@ -153,7 +153,10 @@ public:
_logStatsToStderr = val;
}
static bool runAll(std::ostream &out = std::cout);
static bool runAll(
const std::vector<std::pair<std::string, std::string>> &config = {},
std::ostream &out = std::cout
);
static void runWorker(uint32_t id);
};
......
#pragma once
#include <string>
#include <vector>
std::string formatDuration(double nanos);
std::string formatDurationJSON(double nanos);
......@@ -10,3 +11,5 @@ std::string formatSize(size_t size);
std::string indent(const std::string &str, int spaces);
std::string jsonify(const std::string &str);
std::string jsonify(size_t count, char const * const *str, int indent = 0);
std::string jsonify(const std::vector<std::string> &str, int indent = 0);
......@@ -7,12 +7,19 @@
#include <dirent.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <dtest_core/util.h>
#include <vector>
#include <string>
using namespace dtest;
static std::vector<std::string> dynamicTests;
static void loadTests(const char *path) {
std::cerr << "Loading " << path << "\n";
dynamicTests.push_back(path);
void *handle = dlopen(path, RTLD_NOW | RTLD_LOCAL);
if (handle == NULL) {
std::cerr << dlerror() << std::endl;
......@@ -56,14 +63,15 @@ static void findTests(const char *path) {
int main(int argc, char *argv[]) {
char cwd[PATH_MAX];
getcwd(cwd, PATH_MAX);
if (argc > 1) {
for (int i = 1; i < argc; ++i) {
findTests(argv[i]);
}
}
else {
char cwd[PATH_MAX];
getcwd(cwd, PATH_MAX);
findTests(cwd);
}
......@@ -72,7 +80,15 @@ int main(int argc, char *argv[]) {
std::fstream logFile;
logFile.open("dtest.log.json", std::ios_base::out | std::ios_base::trunc);
bool success = Test::runAll(logFile);
bool success = Test::runAll(
{
{ "executable", argv[0] },
{ "args", jsonify(argc - 1, argv + 1, 2) },
{ "working_dir", cwd },
{ "loaded_test_files", jsonify(dynamicTests, 2) },
},
logFile
);
logFile.close();
if (success) {
......
......@@ -90,7 +90,10 @@ std::string Test::_errorReport() {
return s.str();
}
bool Test::runAll(std::ostream &out) {
bool Test::runAll(
const std::vector<std::pair<std::string, std::string>> &config,
std::ostream &out
) {
_isDriver = true;
Context::_currentCtx = DriverContext::instance.ptr();
......@@ -125,7 +128,22 @@ bool Test::runAll(std::ostream &out) {
if (_logStatsToStderr) std::cerr << std::endl;
out << std::boolalpha;
out << "{\n \"tests\": [";
out << "{\n";
for (const auto &conf : config) {
out << " \"" << conf.first << "\": ";
if (conf.second.front() != '[' && conf.second.front() != '{') {
out << '"' << conf.second << '"';
}
else {
out << conf.second;
}
out << ",\n";
}
out << " \"tests\": [";
auto start = std::chrono::high_resolution_clock::now();
......
......@@ -86,3 +86,43 @@ std::string jsonify(const std::string &str) {
}
return s.str();
}
std::string jsonify(size_t count, char const * const *str, int indent) {
std::stringstream s;
std::string in = "";
in.resize(indent, ' ');
s << '[';
if (count > 0) s << '\n' << in;
else s << ' ';
for (size_t i = 0; i < count; ++i) {
s << " \"" << str[i];
if (i < count - 1) s << "\",\n" << in;
else s << "\"\n" << in;
}
s << ']';
return s.str();
}
std::string jsonify(const std::vector<std::string> &str, int indent) {
std::stringstream s;
std::string in = "";
in.resize(indent, ' ');
size_t count = str.size();
s << '[';
if (count > 0) s << '\n' << in;
else s << ' ';
for (size_t i = 0; i < count; ++i) {
s << " \"" << str[i];
if (i < count - 1) s << "\",\n" << in;
else s << "\"\n" << in;
}
s << ']';
return s.str();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment