Forráskód Böngészése

Add tests for platform profile

Note that the platform profile feature is considered required. Maybe
this shouldn't be the case, as I'm not sure how standard this feature is
yet.
MithicSpirit 1 hónapja
szülő
commit
1e3e55c5d8
1 módosított fájl, 71 hozzáadás és 0 törlés
  1. 71 0
      daemon/gamemode-tests.c

+ 71 - 0
daemon/gamemode-tests.c

@@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "common-gpu.h"
 #include "common-helpers.h"
 #include "common-logging.h"
+#include "common-profile.h"
 
 #include "gamemode.h"
 #include "gamemode-config.h"
@@ -357,6 +358,59 @@ static int run_cpu_governor_tests(struct GameModeConfig *config)
 	return 0;
 }
 
+/* Check the platform profile setting works */
+static int run_platform_profile_tests(struct GameModeConfig *config)
+{
+	/* get the two config parameters we care about */
+	char desiredprof[CONFIG_VALUE_MAX] = { 0 };
+	config_get_desired_profile(config, desiredprof);
+
+	if (desiredprof[0] == '\0')
+		strcpy(desiredprof, "performance");
+
+	char defaultprof[CONFIG_VALUE_MAX] = { 0 };
+	config_get_default_profile(config, defaultprof);
+
+	if (defaultprof[0] == '\0') {
+		const char *currentprof = get_profile_state();
+		if (currentprof) {
+			strncpy(defaultprof, currentprof, CONFIG_VALUE_MAX - 1);
+		} else {
+			LOG_ERROR(
+			    "Could not get current platform profile state, this indicates an error! See rest "
+			    "of log.\n");
+			return -1;
+		}
+	}
+
+	/* Start gamemode */
+	gamemode_request_start();
+
+	/* Verify the platform profile is the desired one */
+	const char *currentprof = get_profile_state();
+	if (strncmp(currentprof, desiredprof, CONFIG_VALUE_MAX) != 0) {
+		LOG_ERROR("Platform profile was not set to %s (was actually %s)!\n",
+		          desiredprof,
+		          currentprof);
+		gamemode_request_end();
+		return -1;
+	}
+
+	/* End gamemode */
+	gamemode_request_end();
+
+	/* Verify the platform profile has been set back */
+	currentprof = get_profile_state();
+	if (strncmp(currentprof, defaultprof, CONFIG_VALUE_MAX) != 0) {
+		LOG_ERROR("Platform profile was not set back to %s (was actually %s)!\n",
+		          defaultprof,
+		          currentprof);
+		return -1;
+	}
+
+	return 0;
+}
+
 static int run_custom_scripts_tests(struct GameModeConfig *config)
 {
 	int scriptstatus = 0;
@@ -808,6 +862,23 @@ static int game_mode_run_feature_tests(struct GameModeConfig *config)
 		}
 	}
 
+	/* Does the platform profile get set properly? */
+	{
+		LOG_MSG("::: Verifying platform profile setting\n");
+
+		int govstatus = run_platform_profile_tests(config);
+
+		if (govstatus == 0)
+			LOG_MSG("::: Passed\n");
+		else {
+			LOG_MSG("::: Failed!\n");
+			LOG_MSG("    -- You may need to add your user to the gamemode group:");
+			LOG_MSG("    -- $ sudo usermod -aG gamemode $(whoami)");
+			// Consider the platform profile feature requried
+			status = -1;
+		}
+	}
+
 	/* Do custom scripts run? */
 	{
 		LOG_MSG("::: Verifying Scripts\n");