Explorar o código

Fix up logging in the tests to use our macros

Marc Di Luzio %!s(int64=6) %!d(string=hai) anos
pai
achega
3ae26596bc
Modificáronse 1 ficheiros con 23 adicións e 34 borrados
  1. 23 34
      daemon/gamemode-tests.c

+ 23 - 34
daemon/gamemode-tests.c

@@ -48,13 +48,11 @@ static int verify_gamemode_initial(void)
 	int status = 0;
 
 	if ((status = gamemode_query_status()) != 0 && status != -1) {
-		fprintf(
-		    stderr,
-		    "ERROR: gamemode is currently active, tests require gamemode to start deactivated!\n");
+		LOG_ERROR("gamemode is currently active, tests require gamemode to start deactivated!\n");
 		status = -1;
 	} else if (status == -1) {
-		fprintf(stderr, "ERROR: gamemode_query_status failed: %s!\n", gamemode_error_string());
-		fprintf(stderr, "ERROR: is gamemode installed correctly?\n");
+		LOG_ERROR("gamemode_query_status failed: %s!\n", gamemode_error_string());
+		LOG_ERROR("is gamemode installed correctly?\n");
 		status = -1;
 	} else {
 		status = 0;
@@ -70,13 +68,11 @@ static int verify_active_and_registered(void)
 
 	if (status != 2) {
 		if (status == -1) {
-			fprintf(stderr, "ERROR: gamemode_query_status failed: %s\n", gamemode_error_string());
+			LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
 		} else if (status == 1) {
-			fprintf(stderr,
-			        "ERROR: gamemode was active but did not have this process registered\n");
+			LOG_ERROR("gamemode was active but did not have this process registered\n");
 		}
-		fprintf(stderr,
-		        "ERROR: gamemode failed to activate correctly when requested (expected 2)!\n");
+		LOG_ERROR("gamemode failed to activate correctly when requested (expected 2)!\n");
 		status = -1;
 	} else {
 		status = 0;
@@ -92,9 +88,9 @@ static int verify_deactivated(void)
 
 	if (status != 0) {
 		if (status == -1) {
-			fprintf(stderr, "ERROR: gamemode_query_status failed: %s\n", gamemode_error_string());
+			LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
 		}
-		fprintf(stderr, "ERROR: gamemode failed to deactivate when requested (expected 0)!\n");
+		LOG_ERROR("gamemode failed to deactivate when requested (expected 0)!\n");
 		status = -1;
 	} else {
 		status = 0;
@@ -110,11 +106,9 @@ static int verify_other_client_connected(void)
 
 	if (status != 1) {
 		if (status == -1) {
-			fprintf(stderr, "ERROR: gamemode_query_status failed: %s\n", gamemode_error_string());
+			LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
 		}
-		fprintf(
-		    stderr,
-		    "ERROR: gamemode_query_status failed to return other client connected (expected 1)!\n");
+		LOG_ERROR("gamemode_query_status failed to return other client connected (expected 1)!\n");
 		status = -1;
 	} else {
 		status = 0;
@@ -128,7 +122,7 @@ static int verify_other_client_connected(void)
  */
 static int run_basic_client_tests(void)
 {
-	fprintf(stdout, "   *basic client tests*\n");
+	LOG_MSG("   *basic client tests*\n");
 
 	/* First verify that gamemode is not currently active on the system
 	 * As well as it being currently installed and queryable
@@ -138,7 +132,7 @@ static int run_basic_client_tests(void)
 
 	/* Verify that gamemode_request_start correctly start gamemode */
 	if (gamemode_request_start() != 0) {
-		fprintf(stderr, "ERROR: gamemode_request_start failed: %s\n", gamemode_error_string());
+		LOG_ERROR("gamemode_request_start failed: %s\n", gamemode_error_string());
 		return -1;
 	}
 
@@ -148,7 +142,7 @@ static int run_basic_client_tests(void)
 
 	/* Verify that gamemode_request_end corrently de-registers gamemode */
 	if (gamemode_request_end() != 0) {
-		fprintf(stderr, "ERROR: gamemode_request_end failed: %s!\n", gamemode_error_string());
+		LOG_ERROR("gamemode_request_end failed: %s!\n", gamemode_error_string());
 		return -1;
 	}
 
@@ -156,7 +150,7 @@ static int run_basic_client_tests(void)
 	if (verify_deactivated() != 0)
 		return -1;
 
-	fprintf(stdout, "       *passed*\n");
+	LOG_MSG("       *passed*\n");
 
 	return 0;
 }
@@ -169,12 +163,12 @@ static int run_dual_client_tests(void)
 	int status = 0;
 
 	/* Try running some process interop tests */
-	fprintf(stdout, "   *dual clients tests*\n");
+	LOG_MSG("   *dual clients tests*\n");
 
 	/* Get the current path to this binary */
 	char mypath[PATH_MAX];
 	if (readlink("/proc/self/exe", mypath, PATH_MAX) == -1) {
-		fprintf(stderr, "ERROR: could not read current exe path: %s\n", strerror(errno));
+		LOG_ERROR("could not read current exe path: %s\n", strerror(errno));
 		return -1;
 	}
 
@@ -183,10 +177,7 @@ static int run_dual_client_tests(void)
 	if (child == 0) {
 		/* Relaunch self with -r (request and wait for signal) */
 		if (execl(mypath, mypath, "-r", (char *)NULL) == -1) {
-			fprintf(stderr,
-			        "ERROR: failed to re-launch self (%s) with execv: %s\n",
-			        mypath,
-			        strerror(errno));
+			LOG_ERROR("failed to re-launch self (%s) with execv: %s\n", mypath, strerror(errno));
 			return -1;
 		}
 	}
@@ -203,7 +194,7 @@ static int run_dual_client_tests(void)
 
 	/* Verify that gamemode_request_start correctly start gamemode */
 	if (gamemode_request_start() != 0) {
-		fprintf(stderr, "ERROR: gamemode_request_start failed: %s\n", gamemode_error_string());
+		LOG_ERROR("gamemode_request_start failed: %s\n", gamemode_error_string());
 		status = -1;
 	}
 
@@ -213,7 +204,7 @@ static int run_dual_client_tests(void)
 
 	/* Request end of gamemode (de-register ourselves) */
 	if (gamemode_request_end() != 0) {
-		fprintf(stderr, "ERROR: gamemode_request_end failed: %s!\n", gamemode_error_string());
+		LOG_ERROR("gamemode_request_end failed: %s!\n", gamemode_error_string());
 		status = -1;
 	}
 
@@ -223,9 +214,7 @@ static int run_dual_client_tests(void)
 
 	/* Send SIGINT to child to wake it up*/
 	if (kill(child, SIGINT) == -1) {
-		fprintf(stderr,
-		        "ERROR: failed to send continue signal to other client: %s\n",
-		        strerror(errno));
+		LOG_ERROR("failed to send continue signal to other client: %s\n", strerror(errno));
 		status = -1;
 	}
 
@@ -235,7 +224,7 @@ static int run_dual_client_tests(void)
 	// Wait for the child to finish up
 	int wstatus;
 	while (waitpid(child, &wstatus, WNOHANG) == 0) {
-		fprintf(stdout, "   Waiting for child to quit...\n");
+		LOG_MSG("   Waiting for child to quit...\n");
 		usleep(10000);
 	}
 
@@ -244,7 +233,7 @@ static int run_dual_client_tests(void)
 		return -1;
 
 	if (status == 0)
-		fprintf(stdout, "       *passed*\n");
+		LOG_MSG("       *passed*\n");
 
 	return status;
 }
@@ -258,7 +247,7 @@ static int run_dual_client_tests(void)
 int game_mode_run_client_tests()
 {
 	int status = 0;
-	fprintf(stdout, "Running tests...\n");
+	LOG_MSG("Running tests...\n");
 
 	/* Run the basic tests */
 	if (run_basic_client_tests() != 0)