mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-07 08:07:20 +02:00
Extract testing to individual functions
This commit is contained in:
parent
a9572e6896
commit
784cb0053d
@ -242,28 +242,8 @@ static int run_dual_client_tests(void)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int run_cpu_governor_tests(struct GameModeConfig *config)
|
||||||
* game_mode_run_feature_tests runs a set of tests for each current feature (based on the current
|
|
||||||
* config) returns 0 for success, -1 for failure
|
|
||||||
*/
|
|
||||||
static int game_mode_run_feature_tests(void)
|
|
||||||
{
|
{
|
||||||
int status = 0;
|
|
||||||
LOG_MSG(":: Feature tests\n");
|
|
||||||
|
|
||||||
/* If we reach here, we should assume the basic requests and register functions are working */
|
|
||||||
|
|
||||||
/* Grab the config */
|
|
||||||
/* Note: this config may pick up a local gamemode.ini, or the daemon may have one, we may need
|
|
||||||
* to cope with that */
|
|
||||||
GameModeConfig *config = config_create();
|
|
||||||
config_init(config);
|
|
||||||
|
|
||||||
/* Does the CPU governor get set properly? */
|
|
||||||
{
|
|
||||||
int cpustatus = 0;
|
|
||||||
LOG_MSG("::: Verifying CPU governor setting\n");
|
|
||||||
|
|
||||||
/* get the two config parameters we care about */
|
/* get the two config parameters we care about */
|
||||||
char desiredgov[CONFIG_VALUE_MAX] = { 0 };
|
char desiredgov[CONFIG_VALUE_MAX] = { 0 };
|
||||||
config_get_desired_governor(config, desiredgov);
|
config_get_desired_governor(config, desiredgov);
|
||||||
@ -282,12 +262,10 @@ static int game_mode_run_feature_tests(void)
|
|||||||
LOG_ERROR(
|
LOG_ERROR(
|
||||||
"Could not get current CPU governor state, this indicates an error! See rest "
|
"Could not get current CPU governor state, this indicates an error! See rest "
|
||||||
"of log.\n");
|
"of log.\n");
|
||||||
cpustatus = -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only continue if we had no error before */
|
|
||||||
if (cpustatus == 0) {
|
|
||||||
/* Start gamemode */
|
/* Start gamemode */
|
||||||
gamemode_request_start();
|
gamemode_request_start();
|
||||||
|
|
||||||
@ -295,7 +273,8 @@ static int game_mode_run_feature_tests(void)
|
|||||||
const char *currentgov = get_gov_state();
|
const char *currentgov = get_gov_state();
|
||||||
if (strncmp(currentgov, desiredgov, CONFIG_VALUE_MAX) != 0) {
|
if (strncmp(currentgov, desiredgov, CONFIG_VALUE_MAX) != 0) {
|
||||||
LOG_ERROR("Govenor was not set to %s (was actually %s)!", desiredgov, currentgov);
|
LOG_ERROR("Govenor was not set to %s (was actually %s)!", desiredgov, currentgov);
|
||||||
cpustatus = -1;
|
gamemode_request_end();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End gamemode */
|
/* End gamemode */
|
||||||
@ -304,25 +283,16 @@ static int game_mode_run_feature_tests(void)
|
|||||||
/* Verify the governor has been set back */
|
/* Verify the governor has been set back */
|
||||||
currentgov = get_gov_state();
|
currentgov = get_gov_state();
|
||||||
if (strncmp(currentgov, defaultgov, CONFIG_VALUE_MAX) != 0) {
|
if (strncmp(currentgov, defaultgov, CONFIG_VALUE_MAX) != 0) {
|
||||||
LOG_ERROR("Govenor was not set back to %s (was actually %s)!",
|
LOG_ERROR("Govenor was not set back to %s (was actually %s)!", defaultgov, currentgov);
|
||||||
defaultgov,
|
return -1;
|
||||||
currentgov);
|
|
||||||
cpustatus = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpustatus == 0)
|
return 0;
|
||||||
LOG_MSG("::: Passed\n");
|
}
|
||||||
else {
|
|
||||||
LOG_MSG("::: Failed!\n");
|
|
||||||
status = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Do custom scripts run? */
|
static int run_custom_scripts_tests(struct GameModeConfig *config)
|
||||||
{
|
{
|
||||||
int scriptstatus = 0;
|
int scriptstatus = 0;
|
||||||
LOG_MSG("::: Verifying Scripts\n");
|
|
||||||
|
|
||||||
/* Grab and test the start scripts */
|
/* Grab and test the start scripts */
|
||||||
char startscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
|
char startscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
|
||||||
@ -368,12 +338,105 @@ static int game_mode_run_feature_tests(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Specal value for no scripts */
|
||||||
if (endscripts[0][0] == '\0' && startscripts[0][0] == '\0')
|
if (endscripts[0][0] == '\0' && startscripts[0][0] == '\0')
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return scriptstatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
int run_gpu_optimisation_tests(struct GameModeConfig *config)
|
||||||
|
{
|
||||||
|
/* First check if these are turned on */
|
||||||
|
char apply[CONFIG_VALUE_MAX];
|
||||||
|
config_get_apply_gpu_optimisations(config, apply);
|
||||||
|
if (strlen(apply) == 0) {
|
||||||
|
/* Special value for disabled */
|
||||||
|
return 1;
|
||||||
|
} else if (strncmp(apply, "accept-responsibility", CONFIG_VALUE_MAX) != 0) {
|
||||||
|
LOG_ERROR(
|
||||||
|
"apply_gpu_optimisations set to value other than \"accept-responsibility\" (%s), will "
|
||||||
|
"not apply GPU optimisations!\n",
|
||||||
|
apply);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get current GPU values */
|
||||||
|
GameModeGPUInfo gpuinfo;
|
||||||
|
gpuinfo.device = config_get_gpu_device(config);
|
||||||
|
gpuinfo.vendor = config_get_gpu_vendor(config);
|
||||||
|
|
||||||
|
if (gpuinfo.vendor == Vendor_NVIDIA)
|
||||||
|
gpuinfo.nv_perf_level = config_get_nv_perf_level(config);
|
||||||
|
|
||||||
|
if (game_mode_get_gpu(&gpuinfo) != 0) {
|
||||||
|
LOG_ERROR("Could not get current GPU info, see above!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO continue to run gamemode and check GPU stats */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* game_mode_run_feature_tests runs a set of tests for each current feature (based on the current
|
||||||
|
* config) returns 0 for success, -1 for failure
|
||||||
|
*/
|
||||||
|
static int game_mode_run_feature_tests(void)
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
LOG_MSG(":: Feature tests\n");
|
||||||
|
|
||||||
|
/* If we reach here, we should assume the basic requests and register functions are working */
|
||||||
|
|
||||||
|
/* Grab the config */
|
||||||
|
/* Note: this config may pick up a local gamemode.ini, or the daemon may have one, we may need
|
||||||
|
* to cope with that */
|
||||||
|
GameModeConfig *config = config_create();
|
||||||
|
config_init(config);
|
||||||
|
|
||||||
|
/* Does the CPU governor get set properly? */
|
||||||
|
{
|
||||||
|
LOG_MSG("::: Verifying CPU governor setting\n");
|
||||||
|
|
||||||
|
int cpustatus = run_cpu_governor_tests(config);
|
||||||
|
|
||||||
|
if (cpustatus == 0)
|
||||||
|
LOG_MSG("::: Passed\n");
|
||||||
|
else {
|
||||||
|
LOG_MSG("::: Failed!\n");
|
||||||
|
// Consider the CPU governor feature required
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do custom scripts run? */
|
||||||
|
{
|
||||||
|
LOG_MSG("::: Verifying Scripts\n");
|
||||||
|
int scriptstatus = run_custom_scripts_tests(config);
|
||||||
|
|
||||||
|
if (scriptstatus == 1)
|
||||||
LOG_MSG("::: Passed (no scripts configured to run)\n");
|
LOG_MSG("::: Passed (no scripts configured to run)\n");
|
||||||
else if (scriptstatus == 0)
|
else if (scriptstatus == 0)
|
||||||
LOG_MSG("::: Passed\n");
|
LOG_MSG("::: Passed\n");
|
||||||
else {
|
else {
|
||||||
LOG_MSG("::: Failed!\n");
|
LOG_MSG("::: Failed!\n");
|
||||||
|
// Any custom scripts should be expected to work
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do GPU optimisations get applied? */
|
||||||
|
{
|
||||||
|
int gpustatus = run_gpu_optimisation_tests(config);
|
||||||
|
|
||||||
|
if (gpustatus == 1)
|
||||||
|
LOG_MSG("::: Passed (gpu optimisations not configured to run)\n");
|
||||||
|
else if (gpustatus == 0)
|
||||||
|
LOG_MSG("::: Passed\n");
|
||||||
|
else {
|
||||||
|
LOG_MSG("::: Failed!\n");
|
||||||
|
// Any custom scripts should be expected to work
|
||||||
status = 1;
|
status = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,25 +444,6 @@ static int game_mode_run_feature_tests(void)
|
|||||||
/* Does the screensaver get inhibited? */
|
/* Does the screensaver get inhibited? */
|
||||||
/* TODO: Unknown if this is testable, org.freedesktop.ScreenSaver has no query method */
|
/* TODO: Unknown if this is testable, org.freedesktop.ScreenSaver has no query method */
|
||||||
|
|
||||||
/* Do GPU optimisations get applied? */
|
|
||||||
{
|
|
||||||
/* First get current GPU values */
|
|
||||||
GameModeGPUInfo gpuinfo;
|
|
||||||
gpuinfo.device = config_get_gpu_device(config);
|
|
||||||
gpuinfo.vendor = config_get_gpu_vendor(config);
|
|
||||||
|
|
||||||
if( gpuinfo.vendor == Vendor_NVIDIA )
|
|
||||||
gpuinfo.nv_perf_level = config_get_nv_perf_level(config);
|
|
||||||
|
|
||||||
if( game_mode_get_gpu(&gpuinfo) != 0 )
|
|
||||||
{
|
|
||||||
LOG_ERROR("Could not get current GPU info, see above!\n");
|
|
||||||
status = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO continue to run gamemode and check GPU stats */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Was the process reniced? */
|
/* Was the process reniced? */
|
||||||
/* Was the scheduling applied? */
|
/* Was the scheduling applied? */
|
||||||
/* Were io priorities changed? */
|
/* Were io priorities changed? */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user