Browse Source

Add game_mode_run_tests function to trigger tests

Marc Di Luzio 6 years ago
parent
commit
94cfa2de54
3 changed files with 18 additions and 6 deletions
  1. 5 0
      daemon/gamemode.h
  2. 12 6
      daemon/main.c
  3. 1 0
      daemon/meson.build

+ 5 - 0
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);

+ 12 - 6
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);

+ 1 - 0
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',