Skip to content

Commit

Permalink
Configure code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshDreamland committed Jan 20, 2018
1 parent 60f3144 commit cda076c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 34 deletions.
19 changes: 19 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
coverage:
precision: 2
round: down
range: "70...100"

status:
project:
default: on
patch:
default: on
changes:
default: off

comment:
layout: "header, reach, diff, flags, files, footer"
behavior: default
require_changes: no
require_base: no
require_head: yes
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ script:
Xvfb :1 -screen 0 1024x768x24 &
xfwm4 &
./test-runner
bash <(curl -s https://codecov.io/bash) -f "*.info"
else
./ci-build.sh
fi
8 changes: 0 additions & 8 deletions CommandLine/testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ BINARY := ../../test-runner
SRC_DIR := .
OBJ_DIR := .eobjs
TESTCASES_DIR := $(SRC_DIR)/Tests
EMAKE := ../../emake

OS := $(shell uname -s)
ifeq ($(OS), Linux)
Expand Down Expand Up @@ -44,10 +43,3 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | obj_dirs
# Include rules for known (previously-built) files
-include $(DEPENDS)
.SUFFIXES:

# ==============================================================================
# == CUSTOM RULES ==============================================================
# ==============================================================================

$(EMAKE):
$(MAKE) -C $(dir $(EMAKE)) $(notdir $(EMAKE))
84 changes: 58 additions & 26 deletions CommandLine/testing/Platform/TestHarness-X11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ using std::to_string;
using std::unique_ptr;
using std::getenv;

void gather_coverage();

string get_window_caption(Display *disp, Window win) {
char *caption;
XFetchName(disp, win, &caption);
Expand Down Expand Up @@ -118,27 +120,30 @@ class X11_TestHarness final: public TestHarness {
void wait() final {
usleep(250000);
}
X11_TestHarness(Display *disp, pid_t game_pid, Window game_window):
pid(game_pid), window_id(game_window), display(disp) {}
X11_TestHarness(Display *disp, pid_t game_pid, Window game_window, bool lcov):
pid(game_pid), window_id(game_window), display(disp), run_lcov(lcov) {}
~X11_TestHarness() {
if (game_is_running()) {
kill(pid, SIGKILL);
std::cerr << "Game still running; killed" << std::endl;
}
if (run_lcov) {
gather_coverage();
}
}

private:
pid_t pid;
Window window_id;
Display *display;
bool run_lcov;
int return_code = 0x10000;
};

constexpr const char *kDefaultExtensions =
"Paths,DateTime,DataStructures,MotionPlanning,Alarms,Timelines,"
"ParticleSystems";

static int testNumber = 1;
int build_game(const string &game, const TestConfig &tc, const string &out) {
if (pid_t emake = fork()) {
int status = 0;
Expand Down Expand Up @@ -178,31 +183,55 @@ int build_game(const string &game, const TestConfig &tc, const string &out) {
};

execvp(emake_cmd.c_str(), (char**) args);

if (compiler == "--compiler=TestHarness")
{
string srcDir = "--directory=" + string(getenv("HOME")) + "/.enigma/.eobjs/Linux/Linux/TestHarness/Debug";
string outFile = "--output-file=coverage_" + to_string(testNumber) + ".info";

const char *const lcovArgs[] = {
"lcov",
"--quiet",
"--no-external",
"--base-directory=ENIGMAsystem/SHELL/",
"--capture",
srcDir.c_str(),
outFile.c_str(),
nullptr
};

execvp("lcov", (char**) lcovArgs);

testNumber++;
}

abort();
}

void gather_coverage() {
static int test_num = 0;
test_num++;

pid_t child = fork();
if (child) {
if (child == -1) {
std::cerr << "Coverage failed to execute for test " << test_num << "!\n";
return;
}
int status = -1;
if (waitpid(child, &status, 0) == -1) {
std::cerr << "Waiting on coverage report for test " << test_num
<< " somehow failed..." << std::endl;
return;
}
if (WIFEXITED(status)) {
int code = WEXITSTATUS(status);
if (code) {
std::cerr << "LCOV run for test " << test_num << " exited with status "
<< code << "..." << std::endl;
}
std::cout << "Coverage completed successfully for test " << test_num
<< '.' << std::endl;
}
return;
}

string src_dir = "--directory=" + string(getenv("HOME"))
+ "/.enigma/.eobjs/Linux/Linux/TestHarness/Debug";
string out_file = "--output-file=coverage_" + to_string(test_num) + ".info";

const char *const lcovArgs[] = {
"lcov",
"--quiet",
"--no-external",
"--base-directory=ENIGMAsystem/SHELL/",
"--capture",
src_dir.c_str(),
out_file.c_str(),
nullptr
};

execvp("lcov", (char**) lcovArgs);
}

} // namespace

bool TestHarness::windowing_supported() {
Expand All @@ -222,15 +251,18 @@ unique_ptr<TestHarness> launch(const string &game, const TestConfig &tc) {

pid_t pid = fork();
if (!pid) execl(out.c_str(), out.c_str(), nullptr);
if (pid == -1) return nullptr;
usleep(250000); // Give the window a quarter second to load and display.

bool gen_cov_report = tc.compiler.empty() || tc.compiler == "TestHarness";

Display *display = XOpenDisplay(0);
Window root = XDefaultRootWindow(display);
for (int i = 0; i < 50; ++i) { // Try for over ten seconds to grab the window
Window win = find_window_by_pid(display, root, pid);
if (win != None)
return std::unique_ptr<X11_TestHarness>(
new X11_TestHarness(display, pid, win));
new X11_TestHarness(display, pid, win, gen_cov_report));
usleep(250000);
}

Expand Down

0 comments on commit cda076c

Please sign in to comment.