From 94cfa2de54c887343eb5f682c79fc23d9b0b5bc4 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 26 Jan 2019 10:23:23 +0000 Subject: [PATCH] Add game_mode_run_tests function to trigger tests --- daemon/gamemode.h | 5 +++++ daemon/main.c | 18 ++++++++++++------ daemon/meson.build | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/daemon/gamemode.h b/daemon/gamemode.h index f7f5c96..93d295e 100644 --- a/daemon/gamemode.h +++ b/daemon/gamemode.h @@ -131,3 +131,8 @@ void game_mode_apply_scheduling(const GameModeContext *self, const pid_t client) bool game_mode_detect_wine_loader(const char *exe); bool game_mode_detect_wine_preloader(const char *exe); char *game_mode_resolve_wine_preloader(const pid_t pid); + +/** gamemode-tests.c + * Provides a test suite to verify gamemode behaviour + */ +int game_mode_run_tests(void); diff --git a/daemon/main.c b/daemon/main.c index 234b26a..341a778 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -97,6 +97,7 @@ int main(int argc, char *argv[]) bool daemon = false; bool use_syslog = false; int opt = 0; + int status; while ((opt = getopt(argc, argv, "dlsrtvh")) != -1) { switch (opt) { case 'd': @@ -106,8 +107,6 @@ int main(int argc, char *argv[]) use_syslog = true; break; case 's': { - int status; - if ((status = gamemode_query_status()) < 0) { fprintf(stderr, "gamemode status request failed: %s\n", gamemode_error_string()); exit(EXIT_FAILURE); @@ -126,8 +125,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - int status = gamemode_query_status(); - if (status == 2) { + if ((status = gamemode_query_status()) == 2) { fprintf(stdout, "gamemode request succeeded and is active\n"); } else if (status == 1) { fprintf(stderr, @@ -144,8 +142,16 @@ int main(int argc, char *argv[]) exit(EXIT_SUCCESS); break; case 't': - fprintf(stdout, "Running tests...\n"); - exit(EXIT_SUCCESS); + if ((status = game_mode_run_tests()) == 0) { + fprintf(stdout, "gamemode tests succeeded\n"); + exit(EXIT_SUCCESS); + } else if (status == -1) { + fprintf(stderr, "gamemode tests failed\n"); + exit(EXIT_FAILURE); + } else { + fprintf(stderr, "gamemode test results unknown: %d\n", status); + exit(EXIT_FAILURE); + } break; case 'v': fprintf(stdout, VERSION_TEXT); diff --git a/daemon/meson.build b/daemon/meson.build index 1e9fec8..02a4519 100644 --- a/daemon/meson.build +++ b/daemon/meson.build @@ -23,6 +23,7 @@ daemon_sources = [ 'gamemode-proc.c', 'gamemode-sched.c', 'gamemode-wine.c', + 'gamemode-tests.c', 'daemonize.c', 'dbus_messaging.c', 'governors.c',