1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039 |
- #define _GNU_SOURCE
- #include "common-external.h"
- #include "common-governors.h"
- #include "common-gpu.h"
- #include "common-helpers.h"
- #include "common-logging.h"
- #include "gamemode.h"
- #include "gamemode-config.h"
- #include "gamemode_client.h"
- #include <pthread.h>
- #include <sys/syscall.h>
- #include <sys/wait.h>
- struct GameModeConfig;
- static int verify_gamemode_initial(struct GameModeConfig *config)
- {
- int status = 0;
- if ((status = gamemode_query_status()) != 0 && status != -1) {
- long reaper = config_get_reaper_frequency(config);
- LOG_MSG("GameMode was active, waiting for the reaper thread (%ld seconds)!\n", reaper);
- sleep(1);
-
- for (int i = 0; i < reaper; i++) {
- if ((status = gamemode_query_status()) == 0) {
- status = 0;
- break;
- } else if (status == -1) {
- goto status_error;
- }
- LOG_MSG("Waiting...\n");
- sleep(1);
- }
- if (status == 1)
- LOG_ERROR("GameMode still active, cannot run tests!\n");
- } else if (status == -1) {
- goto status_error;
- } else {
- status = 0;
- }
- return status;
- status_error:
- LOG_ERROR("gamemode_query_status failed: %s!\n", gamemode_error_string());
- LOG_ERROR("is gamemode installed correctly?\n");
- return -1;
- }
- static int verify_active_and_registered(void)
- {
- int status = gamemode_query_status();
- if (status != 2) {
- if (status == -1) {
- LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
- } else if (status == 1) {
- LOG_ERROR("gamemode was active but did not have this process registered\n");
- }
- LOG_ERROR("gamemode failed to activate correctly when requested (expected 2)!\n");
- status = -1;
- } else {
- status = 0;
- }
- return status;
- }
- static int verify_deactivated(void)
- {
- int status = gamemode_query_status();
- if (status != 0) {
- if (status == -1) {
- LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
- }
- LOG_ERROR("gamemode failed to deactivate when requested (expected 0)!\n");
- status = -1;
- } else {
- status = 0;
- }
- return status;
- }
- static int verify_other_client_connected(void)
- {
- int status = gamemode_query_status();
- if (status != 1) {
- if (status == -1) {
- LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
- }
- LOG_ERROR("gamemode_query_status failed to return other client connected (expected 1)!\n");
- status = -1;
- } else {
- status = 0;
- }
- return status;
- }
- static int run_basic_client_tests(void)
- {
- LOG_MSG(":: Basic client tests\n");
-
- if (gamemode_request_start() != 0) {
- LOG_ERROR("gamemode_request_start failed: %s\n", gamemode_error_string());
- return -1;
- }
-
- if (verify_active_and_registered() != 0)
- return -1;
-
- if (gamemode_request_end() != 0) {
- LOG_ERROR("gamemode_request_end failed: %s!\n", gamemode_error_string());
- return -1;
- }
-
- if (verify_deactivated() != 0)
- return -1;
- LOG_MSG(":: Passed\n\n");
- return 0;
- }
- static int run_dual_client_tests(void)
- {
- int status = 0;
-
- LOG_MSG(":: Dual client tests\n");
-
- char mypath[PATH_MAX];
- memset(mypath, 0, sizeof(mypath));
- if (readlink("/proc/self/exe", mypath, PATH_MAX) == -1) {
- LOG_ERROR("could not read current exe path: %s\n", strerror(errno));
- return -1;
- }
-
- int child = fork();
- if (child == 0) {
-
- if (execl(mypath, mypath, "-r", (char *)NULL) == -1) {
- LOG_ERROR("failed to re-launch self (%s) with execl: %s\n", mypath, strerror(errno));
- return -1;
- }
- }
-
-
-
- usleep(10000);
-
- if (verify_other_client_connected() != 0)
- status = -1;
-
- if (gamemode_request_start() != 0) {
- LOG_ERROR("gamemode_request_start failed: %s\n", gamemode_error_string());
- status = -1;
- }
-
- if (verify_active_and_registered() != 0)
- status = -1;
-
- if (gamemode_request_end() != 0) {
- LOG_ERROR("gamemode_request_end failed: %s!\n", gamemode_error_string());
- status = -1;
- }
-
- if (verify_other_client_connected() != 0)
- status = -1;
-
- if (kill(child, SIGINT) == -1) {
- LOG_ERROR("failed to send continue signal to other client: %s\n", strerror(errno));
- status = -1;
- }
-
- usleep(100000);
-
- int wstatus;
- while (waitpid(child, &wstatus, WNOHANG) == 0) {
- LOG_MSG("...Waiting for child to quit...\n");
- usleep(100000);
- }
-
- if (verify_deactivated() != 0)
- return -1;
- if (status == 0)
- LOG_MSG(":: Passed\n\n");
- return status;
- }
- static int run_gamemoderun_and_reaper_tests(struct GameModeConfig *config)
- {
- int status = 0;
- LOG_MSG(":: Gamemoderun and reaper thread tests\n");
-
- int child = fork();
- if (child == 0) {
-
- fclose(stdout);
-
- if (execlp("gamemoderun", "gamemoderun", "sleep", "5", (char *)NULL) == -1) {
- LOG_ERROR("failed to launch gamemoderun with execl: %s\n", strerror(errno));
- return -1;
- }
- }
-
- usleep(100000);
-
- if (verify_other_client_connected() != 0)
- status = -1;
-
- if (kill(child, SIGTERM) == -1) {
- LOG_ERROR("failed to send continue signal to other client: %s\n", strerror(errno));
- status = -1;
- }
-
- int wstatus;
- while (waitpid(child, &wstatus, WNOHANG) == 0) {
- LOG_MSG("...Waiting for child to quit...\n");
- usleep(100000);
- }
-
- long freq = config_get_reaper_frequency(config);
- LOG_MSG("...Waiting for reaper thread (reaper_frequency set to %ld seconds)...\n", freq);
- sleep((unsigned int)freq);
-
- if (verify_deactivated() != 0)
- return -1;
- if (status == 0)
- LOG_MSG(":: Passed\n\n");
- return status;
- }
- static int run_cpu_governor_tests(struct GameModeConfig *config)
- {
-
- char desiredgov[CONFIG_VALUE_MAX] = { 0 };
- config_get_desired_governor(config, desiredgov);
- if (desiredgov[0] == '\0')
- strcpy(desiredgov, "performance");
- char defaultgov[CONFIG_VALUE_MAX] = { 0 };
- if (defaultgov[0] == '\0') {
- const char *currentgov = get_gov_state();
- if (currentgov) {
- strncpy(defaultgov, currentgov, CONFIG_VALUE_MAX - 1);
- } else {
- LOG_ERROR(
- "Could not get current CPU governor state, this indicates an error! See rest "
- "of log.\n");
- return -1;
- }
- }
-
- gamemode_request_start();
-
- const char *currentgov = get_gov_state();
- if (strncmp(currentgov, desiredgov, CONFIG_VALUE_MAX) != 0) {
- LOG_ERROR("Governor was not set to %s (was actually %s)!\n", desiredgov, currentgov);
- gamemode_request_end();
- return -1;
- }
-
- gamemode_request_end();
-
- currentgov = get_gov_state();
- if (strncmp(currentgov, defaultgov, CONFIG_VALUE_MAX) != 0) {
- LOG_ERROR("Governor was not set back to %s (was actually %s)!\n", defaultgov, currentgov);
- return -1;
- }
- return 0;
- }
- static int run_custom_scripts_tests(struct GameModeConfig *config)
- {
- int scriptstatus = 0;
- long timeout = config_get_script_timeout(config);
-
- char startscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
- memset(startscripts, 0, sizeof(startscripts));
- config_get_gamemode_start_scripts(config, startscripts);
- if (startscripts[0][0] != '\0') {
- int i = 0;
- while (i < CONFIG_LIST_MAX && *startscripts[i] != '\0') {
- LOG_MSG(":::: Running start script [%s]\n", startscripts[i]);
- const char *args[] = { "/bin/sh", "-c", startscripts[i], NULL };
- int ret = run_external_process(args, NULL, (int)timeout);
- if (ret == 0)
- LOG_MSG(":::: Passed\n");
- else {
- LOG_MSG(":::: Failed!\n");
- scriptstatus = -1;
- }
- i++;
- }
- }
-
- char endscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
- memset(endscripts, 0, sizeof(endscripts));
- config_get_gamemode_end_scripts(config, endscripts);
- if (endscripts[0][0] != '\0') {
- int i = 0;
- while (i < CONFIG_LIST_MAX && *endscripts[i] != '\0') {
- LOG_MSG(":::: Running end script [%s]\n", endscripts[i]);
- const char *args[] = { "/bin/sh", "-c", endscripts[i], NULL };
- int ret = run_external_process(args, NULL, (int)timeout);
- if (ret == 0)
- LOG_MSG(":::: Passed\n");
- else {
- LOG_MSG(":::: Failed!\n");
- scriptstatus = -1;
- }
- i++;
- }
- }
-
- if (endscripts[0][0] == '\0' && startscripts[0][0] == '\0')
- return 1;
- return scriptstatus;
- }
- int run_gpu_optimisation_tests(struct GameModeConfig *config)
- {
- int gpustatus = 0;
-
- char apply[CONFIG_VALUE_MAX];
- config_get_apply_gpu_optimisations(config, apply);
- if (strlen(apply) == 0) {
-
- 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;
- }
-
- GameModeGPUInfo *gpuinfo;
- game_mode_initialise_gpu(config, &gpuinfo);
- if (!gpuinfo) {
- LOG_ERROR("Failed to initialise gpuinfo!\n");
- return -1;
- }
-
- long expected_core = gpuinfo->nv_core;
- long expected_mem = gpuinfo->nv_mem;
- long expected_nv_powermizer_mode = gpuinfo->nv_powermizer_mode;
- char expected_amd_performance_level[CONFIG_VALUE_MAX];
- strncpy(expected_amd_performance_level, gpuinfo->amd_performance_level, CONFIG_VALUE_MAX - 1);
- expected_amd_performance_level[CONFIG_VALUE_MAX - 1] = '\0';
-
- game_mode_get_gpu(gpuinfo);
- long original_nv_core = gpuinfo->nv_core;
- long original_nv_mem = gpuinfo->nv_mem;
- long original_nv_powermizer_mode = gpuinfo->nv_powermizer_mode;
- char original_amd_performance_level[CONFIG_VALUE_MAX];
- strncpy(original_amd_performance_level, gpuinfo->amd_performance_level, CONFIG_VALUE_MAX - 1);
- original_amd_performance_level[CONFIG_VALUE_MAX - 1] = '\0';
-
- if (expected_nv_powermizer_mode == -1)
- expected_nv_powermizer_mode = original_nv_powermizer_mode;
- if (expected_core == -1)
- expected_core = original_nv_core;
- if (expected_mem == -1)
- expected_mem = original_nv_mem;
-
- gamemode_request_start();
- if (game_mode_get_gpu(gpuinfo) != 0) {
- LOG_ERROR("Could not get current GPU info, see above!\n");
- gamemode_request_end();
- game_mode_free_gpu(&gpuinfo);
- return -1;
- }
- if (gpuinfo->vendor == Vendor_NVIDIA &&
- (gpuinfo->nv_core != expected_core || gpuinfo->nv_mem != expected_mem ||
- gpuinfo->nv_powermizer_mode != expected_nv_powermizer_mode)) {
- LOG_ERROR(
- "Current Nvidia GPU clocks during gamemode do not match requested values!\n"
- "\tnv_core - expected:%ld was:%ld | nv_mem - expected:%ld was:%ld | nv_powermizer_mode "
- "- expected:%ld was:%ld\n",
- expected_core,
- gpuinfo->nv_core,
- expected_mem,
- gpuinfo->nv_mem,
- expected_nv_powermizer_mode,
- gpuinfo->nv_powermizer_mode);
- gpustatus = -1;
- } else if (gpuinfo->vendor == Vendor_AMD &&
- strcmp(expected_amd_performance_level, gpuinfo->amd_performance_level) != 0) {
- LOG_ERROR(
- "Current AMD GPU performance level during gamemode does not match requested value!\n"
- "\texpected:%s was:%s\n",
- expected_amd_performance_level,
- gpuinfo->amd_performance_level);
- gpustatus = -1;
- }
-
- gamemode_request_end();
- if (game_mode_get_gpu(gpuinfo) != 0) {
- LOG_ERROR("Could not get current GPU info, see above!\n");
- game_mode_free_gpu(&gpuinfo);
- return -1;
- }
- if (gpuinfo->vendor == Vendor_NVIDIA &&
- (gpuinfo->nv_core != original_nv_core || gpuinfo->nv_mem != original_nv_mem ||
- gpuinfo->nv_powermizer_mode != original_nv_powermizer_mode)) {
- LOG_ERROR(
- "Current Nvidia GPU clocks after gamemode do not matcch original values!\n"
- "\tnv_core - original:%ld was:%ld | nv_mem - original:%ld was:%ld | nv_powermizer_mode "
- "- original:%ld was:%ld\n",
- original_nv_core,
- gpuinfo->nv_core,
- original_nv_mem,
- gpuinfo->nv_mem,
- original_nv_powermizer_mode,
- gpuinfo->nv_powermizer_mode);
- gpustatus = -1;
- } else if (gpuinfo->vendor == Vendor_AMD &&
- strcmp(original_amd_performance_level, gpuinfo->amd_performance_level) != 0) {
- LOG_ERROR(
- "Current AMD GPU performance level after gamemode does not match requested value!\n"
- "\texpected:%s was:%s\n",
- original_amd_performance_level,
- gpuinfo->amd_performance_level);
- gpustatus = -1;
- }
- return gpustatus;
- }
- typedef struct {
- pthread_barrier_t *barrier;
- pid_t this;
- } ThreadInfo;
- static void *fake_thread_wait(void *arg)
- {
- ThreadInfo *info = (ThreadInfo *)arg;
-
- info->this = (pid_t)syscall(SYS_gettid);
-
- int ret = 0;
- ret = pthread_barrier_wait(info->barrier);
- if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)
- FATAL_ERROR("pthread_barrier_wait failed in child with error %d!\n", ret);
- ret = pthread_barrier_wait(info->barrier);
- if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD)
- FATAL_ERROR("pthread_barrier_wait failed in child with error %d!\n", ret);
- return NULL;
- }
- static pid_t run_tests_on_process_tree(int inactive, int active, int (*func)(pid_t))
- {
-
- pid_t child = fork();
- if (child == 0) {
-
- bool fail = false;
- const unsigned int numthreads = 3;
- pthread_barrier_t barrier;
- pthread_barrier_init(&barrier, NULL, numthreads + 1);
-
- gamemode_request_start();
-
- pthread_t threads[numthreads];
- ThreadInfo info[numthreads];
- for (unsigned int i = 0; i < numthreads; i++) {
- info[i].barrier = &barrier;
- int err = pthread_create(&threads[i], NULL, fake_thread_wait, &info[i]);
- if (err != 0) {
- LOG_ERROR("Failed to spawn thread! Error: %d\n", err);
- exit(EXIT_FAILURE);
- }
- }
-
- pthread_barrier_wait(&barrier);
-
- for (unsigned int i = 0; i < numthreads; i++)
- fail |= (active != func(info[i].this));
- if (fail) {
- LOG_ERROR("Initial values for new threads were incorrect!\n");
- gamemode_request_end();
- exit(-1);
- }
-
- gamemode_request_end();
-
- for (unsigned int i = 0; i < numthreads; i++)
- fail |= (inactive != func(info[i].this));
- if (fail) {
- LOG_ERROR("values for threads were not reset after gamemode_request_end!\n");
- exit(-1);
- }
-
- gamemode_request_start();
-
- for (unsigned int i = 0; i < numthreads; i++)
- fail |= (active != func(info[i].this));
- if (fail) {
- LOG_ERROR("values for threads were not set correctly!\n");
- gamemode_request_end();
- exit(-1);
- }
-
- gamemode_request_end();
-
- for (unsigned int i = 0; i < numthreads; i++)
- fail |= (inactive != func(info[i].this));
- if (fail) {
- LOG_ERROR("values for threads were not reset after gamemode_request_end!\n");
- exit(-1);
- }
-
- pthread_barrier_wait(&barrier);
-
- int ret = 0;
- for (unsigned int i = 0; i < numthreads; i++)
- ret &= pthread_join(threads[i], NULL);
- if (ret != 0)
- LOG_ERROR("Thread cleanup in multithreaded tests failed!\n");
-
- exit(ret);
- }
-
- int wstatus = 0;
- waitpid(child, &wstatus, 0);
- int status = 0;
- if (WIFEXITED(wstatus))
- status = WEXITSTATUS(wstatus);
- else {
- LOG_ERROR("Multithreaded child exited abnormally!\n");
- status = -1;
- }
- return status;
- }
- int run_renice_tests(struct GameModeConfig *config)
- {
-
- long int renice = config_get_renice_value(config);
- if (renice == 0) {
- return 1;
- }
-
- int val = game_mode_get_renice(getpid());
- if (val != 0) {
- LOG_ERROR("Initial renice value is non-zero: %d\n", val);
- return -1;
- }
- int ret = 0;
-
- gamemode_request_start();
-
- val = game_mode_get_renice(getpid());
- if (val != renice) {
- LOG_ERROR(
- "renice value not set correctly after gamemode_request_start\nExpected: %ld, Was: %d\n",
- renice,
- val);
- ret = -1;
- }
-
- gamemode_request_end();
-
- val = game_mode_get_renice(getpid());
- if (val != 0) {
- LOG_ERROR("renice value non-zero after gamemode_request_end\nExpected: 0, Was: %d\n", val);
- ret = -1;
- }
-
- val = run_tests_on_process_tree(0, (int)renice, game_mode_get_renice);
- if (val != 0) {
- LOG_ERROR("Multithreaded renice tests failed!\n");
- ret = -1;
- }
- return ret;
- }
- int run_ioprio_tests(struct GameModeConfig *config)
- {
-
- long int ioprio = config_get_ioprio_value(config);
- if (ioprio == IOPRIO_DONT_SET) {
- return 1;
- }
-
- int val = game_mode_get_ioprio(getpid());
- if (val != IOPRIO_DEFAULT) {
- LOG_ERROR("Initial ioprio value is non-default\nExpected: %d, Was: %d\n",
- IOPRIO_DEFAULT,
- val);
- return -1;
- }
- int ret = 0;
-
- gamemode_request_start();
-
- val = game_mode_get_ioprio(getpid());
- if (val != ioprio) {
- LOG_ERROR(
- "ioprio value not set correctly after gamemode_request_start\nExpected: %ld, Was: %d\n",
- ioprio,
- val);
- ret = -1;
- }
-
- gamemode_request_end();
-
- val = game_mode_get_ioprio(getpid());
- if (val != IOPRIO_DEFAULT) {
- LOG_ERROR("ioprio value non-default after gamemode_request_end\nExpected: %d, Was: %d\n",
- IOPRIO_DEFAULT,
- val);
- ret = -1;
- }
-
- val = run_tests_on_process_tree(IOPRIO_DEFAULT, (int)ioprio, game_mode_get_ioprio);
- if (val != 0) {
- LOG_ERROR("Multithreaded ioprio tests failed!\n");
- ret = -1;
- }
- return ret;
- }
- static int game_mode_run_feature_tests(struct GameModeConfig *config)
- {
- int status = 0;
- LOG_MSG(":: Feature tests\n");
-
-
- {
- 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");
- LOG_MSG(" -- You may need to add your user to the gamemode group:");
- LOG_MSG(" -- $ sudo usermod -aG gamemode $(whoami)");
-
- status = -1;
- }
- }
-
- {
- LOG_MSG("::: Verifying Scripts\n");
- int scriptstatus = run_custom_scripts_tests(config);
- if (scriptstatus == 1)
- LOG_MSG("::: Passed (no scripts configured to run)\n");
- else if (scriptstatus == 0)
- LOG_MSG("::: Passed\n");
- else {
- LOG_MSG("::: Failed!\n");
-
- status = -1;
- }
- }
-
- {
- LOG_MSG("::: Verifying GPU Optimisations\n");
- 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");
-
- status = -1;
- }
- }
-
- {
- LOG_MSG("::: Verifying renice\n");
- int renicestatus = run_renice_tests(config);
- if (renicestatus == 1)
- LOG_MSG("::: Passed (no renice configured)\n");
- else if (renicestatus == 0)
- LOG_MSG("::: Passed\n");
- else {
- LOG_MSG("::: Failed!\n");
-
- status = -1;
- }
- }
-
- {
- LOG_MSG("::: Verifying ioprio\n");
- int iopriostatus = run_ioprio_tests(config);
- if (iopriostatus == 1)
- LOG_MSG("::: Passed (no ioprio configured)\n");
- else if (iopriostatus == 0)
- LOG_MSG("::: Passed\n");
- else {
- LOG_MSG("::: Failed!\n");
- status = -1;
- }
- }
-
-
-
- if (status != -1)
- LOG_MSG(":: Passed%s\n\n", status > 0 ? " (with optional failures)" : "");
- else
- LOG_ERROR(":: Failed!\n");
- return status;
- }
- static int run_supervisor_tests(void)
- {
- int supervisortests = 0;
- int ret = 0;
- LOG_MSG(":: Supervisor tests\n");
-
- pid_t pid = fork();
- if (pid == 0) {
-
- pause();
- exit(EXIT_SUCCESS);
- }
-
- ret = gamemode_request_start_for(pid);
- if (ret != 0) {
- LOG_ERROR("gamemode_request_start_for gave unexpected value %d, (expected 0)!\n", ret);
- if (ret == -1)
- LOG_ERROR("GameMode error string: %s!\n", gamemode_error_string());
- supervisortests = -1;
- }
-
- ret = gamemode_query_status();
- if (ret != 1) {
- LOG_ERROR(
- "gamemode_query_status after start request gave unexpected value %d, (expected 1)!\n",
- ret);
- if (ret == -1)
- LOG_ERROR("GameMode error string: %s!\n", gamemode_error_string());
- supervisortests = -1;
- }
-
- ret = gamemode_query_status_for(pid);
- if (ret != 2) {
- LOG_ERROR(
- "gamemode_query_status_for after start request gave unexpected value %d, (expected "
- "2)!\n",
- ret);
- if (ret == -1)
- LOG_ERROR("GameMode error string: %s!\n", gamemode_error_string());
- supervisortests = -1;
- }
-
- ret = gamemode_request_end_for(pid);
- if (ret != 0) {
- LOG_ERROR("gamemode_request_end_for gave unexpected value %d, (expected 0)!\n", ret);
- if (ret == -1)
- LOG_ERROR("GameMode error string: %s!\n", gamemode_error_string());
- supervisortests = -1;
- }
-
- ret = gamemode_query_status();
- if (ret != 0) {
- LOG_ERROR(
- "gamemode_query_status after end request gave unexpected value %d, (expected 0)!\n",
- ret);
- if (ret == -1)
- LOG_ERROR("GameMode error string: %s!\n", gamemode_error_string());
- supervisortests = -1;
- }
-
- if (kill(pid, SIGUSR1) == -1) {
- LOG_ERROR("failed to send continue signal to other child process: %s\n", strerror(errno));
- supervisortests = -1;
- }
-
- int wstatus;
- usleep(100000);
- while (waitpid(pid, &wstatus, WNOHANG) == 0) {
- LOG_MSG("...Waiting for child to quit...\n");
- usleep(100000);
- }
- if (supervisortests == 0)
- LOG_MSG(":: Passed\n\n");
- else
- LOG_ERROR(":: Failed!\n");
- return supervisortests;
- }
- int game_mode_run_client_tests(void)
- {
- int status = 0;
- LOG_MSG(": Loading config\n");
-
-
- GameModeConfig *config = config_create();
- config_init(config);
- LOG_MSG(": Running tests\n\n");
-
- if (verify_gamemode_initial(config) != 0)
- return -1;
-
- if (config_get_require_supervisor(config) != 0) {
- LOG_ERROR("Tests currently unsupported when require_supervisor is set\n");
- return -1;
- }
-
-
- if (run_basic_client_tests() != 0)
- status = -1;
-
- if (run_dual_client_tests() != 0)
- status = -1;
-
- if (run_gamemoderun_and_reaper_tests(config) != 0)
- status = -1;
-
- if (run_supervisor_tests() != 0)
- status = -1;
- if (status != 0) {
- LOG_MSG(": Client tests failed, skipping feature tests\n");
- } else {
-
- status = game_mode_run_feature_tests(config);
- }
- if (status >= 0)
- LOG_MSG(": All Tests Passed%s!\n", status > 0 ? " (with optional failures)" : "");
- else
- LOG_MSG(": Tests Failed!\n");
- return status;
- }
|