gamemode-tests.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. Copyright (c) 2017-2018, Feral Interactive
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Feral Interactive nor the names of its contributors
  12. may be used to endorse or promote products derived from this software
  13. without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #define _GNU_SOURCE
  27. #include "gamemode.h"
  28. #include "helpers.h"
  29. #include "logging.h"
  30. #include <libgen.h>
  31. #include <sys/types.h>
  32. #include <sys/wait.h>
  33. #include <unistd.h>
  34. #include "daemon_config.h"
  35. #include "gamemode_client.h"
  36. #include "governors-query.h"
  37. #include "gpu-control.h"
  38. /* Initial verify step to ensure gamemode isn't already active */
  39. static int verify_gamemode_initial(void)
  40. {
  41. int status = 0;
  42. if ((status = gamemode_query_status()) != 0 && status != -1) {
  43. LOG_ERROR("gamemode is currently active, tests require gamemode to start deactivated!\n");
  44. status = -1;
  45. } else if (status == -1) {
  46. LOG_ERROR("gamemode_query_status failed: %s!\n", gamemode_error_string());
  47. LOG_ERROR("is gamemode installed correctly?\n");
  48. status = -1;
  49. } else {
  50. status = 0;
  51. }
  52. return status;
  53. }
  54. /* Check if gamemode is active and this client is registered */
  55. static int verify_active_and_registered(void)
  56. {
  57. int status = gamemode_query_status();
  58. if (status != 2) {
  59. if (status == -1) {
  60. LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
  61. } else if (status == 1) {
  62. LOG_ERROR("gamemode was active but did not have this process registered\n");
  63. }
  64. LOG_ERROR("gamemode failed to activate correctly when requested (expected 2)!\n");
  65. status = -1;
  66. } else {
  67. status = 0;
  68. }
  69. return status;
  70. }
  71. /* Ensure gamemode is deactivated when it should be */
  72. static int verify_deactivated(void)
  73. {
  74. int status = gamemode_query_status();
  75. if (status != 0) {
  76. if (status == -1) {
  77. LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
  78. }
  79. LOG_ERROR("gamemode failed to deactivate when requested (expected 0)!\n");
  80. status = -1;
  81. } else {
  82. status = 0;
  83. }
  84. return status;
  85. }
  86. /* Ensure another client is connected */
  87. static int verify_other_client_connected(void)
  88. {
  89. int status = gamemode_query_status();
  90. if (status != 1) {
  91. if (status == -1) {
  92. LOG_ERROR("gamemode_query_status failed: %s\n", gamemode_error_string());
  93. }
  94. LOG_ERROR("gamemode_query_status failed to return other client connected (expected 1)!\n");
  95. status = -1;
  96. } else {
  97. status = 0;
  98. }
  99. return status;
  100. }
  101. /* Run basic client tests
  102. * Tests a simple request_start and request_end works
  103. */
  104. static int run_basic_client_tests(void)
  105. {
  106. LOG_MSG(":: Basic client tests\n");
  107. /* Verify that gamemode_request_start correctly start gamemode */
  108. if (gamemode_request_start() != 0) {
  109. LOG_ERROR("gamemode_request_start failed: %s\n", gamemode_error_string());
  110. return -1;
  111. }
  112. /* Verify that gamemode is now active and this client is registered*/
  113. if (verify_active_and_registered() != 0)
  114. return -1;
  115. /* Verify that gamemode_request_end corrently de-registers gamemode */
  116. if (gamemode_request_end() != 0) {
  117. LOG_ERROR("gamemode_request_end failed: %s!\n", gamemode_error_string());
  118. return -1;
  119. }
  120. /* Verify that gamemode is now innactive */
  121. if (verify_deactivated() != 0)
  122. return -1;
  123. LOG_MSG(":: Passed\n\n");
  124. return 0;
  125. }
  126. /* Run some dual client tests
  127. * This also tests that the "-r" argument works correctly and cleans up correctly
  128. */
  129. static int run_dual_client_tests(void)
  130. {
  131. int status = 0;
  132. /* Try running some process interop tests */
  133. LOG_MSG(":: Dual client tests\n");
  134. /* Get the current path to this binary */
  135. char mypath[PATH_MAX];
  136. memset(mypath, 0, sizeof(mypath));
  137. if (readlink("/proc/self/exe", mypath, PATH_MAX) == -1) {
  138. LOG_ERROR("could not read current exe path: %s\n", strerror(errno));
  139. return -1;
  140. }
  141. /* Fork so that the child can request gamemode */
  142. int child = fork();
  143. if (child == 0) {
  144. /* Relaunch self with -r (request and wait for signal) */
  145. if (execl(mypath, mypath, "-r", (char *)NULL) == -1) {
  146. LOG_ERROR("failed to re-launch self (%s) with execl: %s\n", mypath, strerror(errno));
  147. return -1;
  148. }
  149. }
  150. /* Parent process */
  151. /* None of these should early-out as we need to clean up the child */
  152. /* Give the child a chance to reqeust gamemode */
  153. usleep(1000);
  154. /* Check that when we request gamemode, it replies that the other client is connected */
  155. if (verify_other_client_connected() != 0)
  156. status = -1;
  157. /* Verify that gamemode_request_start correctly start gamemode */
  158. if (gamemode_request_start() != 0) {
  159. LOG_ERROR("gamemode_request_start failed: %s\n", gamemode_error_string());
  160. status = -1;
  161. }
  162. /* Verify that gamemode is now active and this client is registered*/
  163. if (verify_active_and_registered() != 0)
  164. status = -1;
  165. /* Request end of gamemode (de-register ourselves) */
  166. if (gamemode_request_end() != 0) {
  167. LOG_ERROR("gamemode_request_end failed: %s!\n", gamemode_error_string());
  168. status = -1;
  169. }
  170. /* Check that when we request gamemode, it replies that the other client is connected */
  171. if (verify_other_client_connected() != 0)
  172. status = -1;
  173. /* Send SIGINT to child to wake it up*/
  174. if (kill(child, SIGINT) == -1) {
  175. LOG_ERROR("failed to send continue signal to other client: %s\n", strerror(errno));
  176. status = -1;
  177. }
  178. /* Give the child a chance to finish */
  179. usleep(100000);
  180. // Wait for the child to finish up
  181. int wstatus;
  182. while (waitpid(child, &wstatus, WNOHANG) == 0) {
  183. LOG_MSG("...Waiting for child to quit...\n");
  184. usleep(100000);
  185. }
  186. /* Verify that gamemode is now innactive */
  187. if (verify_deactivated() != 0)
  188. return -1;
  189. if (status == 0)
  190. LOG_MSG(":: Passed\n\n");
  191. return status;
  192. }
  193. /* Check gamemoderun works */
  194. static int run_gamemoderun_and_reaper_tests(struct GameModeConfig *config)
  195. {
  196. int status = 0;
  197. LOG_MSG(":: Gamemoderun and reaper thread tests\n");
  198. /* Fork so that the child can request gamemode */
  199. int child = fork();
  200. if (child == 0) {
  201. /* Close stdout, we don't care if sh prints anything */
  202. fclose(stdout);
  203. /* Preload into sh and then kill it */
  204. if (execl("/usr/bin/gamemoderun", "/usr/bin/gamemoderun", "sh", (char *)NULL) == -1) {
  205. LOG_ERROR("failed to launch gamemoderun with execl: %s\n", strerror(errno));
  206. return -1;
  207. }
  208. }
  209. /* Give the child a chance to reqeust gamemode */
  210. usleep(10000);
  211. /* Check that when we request gamemode, it replies that the other client is connected */
  212. if (verify_other_client_connected() != 0)
  213. status = -1;
  214. /* Send SIGTERM to the child to stop it*/
  215. if (kill(child, SIGTERM) == -1) {
  216. LOG_ERROR("failed to send continue signal to other client: %s\n", strerror(errno));
  217. status = -1;
  218. }
  219. /* Wait for the child to clean up */
  220. int wstatus;
  221. while (waitpid(child, &wstatus, WNOHANG) == 0) {
  222. LOG_MSG("...Waiting for child to quit...\n");
  223. usleep(100000);
  224. }
  225. /* And give gamemode a chance to reap the process */
  226. long freq = config_get_reaper_frequency(config);
  227. LOG_MSG("...Waiting for reaper thread (reaper_frequency set to %ld seconds)...\n", freq);
  228. sleep((unsigned int)freq);
  229. /* Verify that gamemode is now innactive */
  230. if (verify_deactivated() != 0)
  231. return -1;
  232. if (status == 0)
  233. LOG_MSG(":: Passed\n\n");
  234. return status;
  235. }
  236. /* Check the cpu governor setting works */
  237. static int run_cpu_governor_tests(struct GameModeConfig *config)
  238. {
  239. /* get the two config parameters we care about */
  240. char desiredgov[CONFIG_VALUE_MAX] = { 0 };
  241. config_get_desired_governor(config, desiredgov);
  242. if (desiredgov[0] == '\0')
  243. strcpy(desiredgov, "performance");
  244. char defaultgov[CONFIG_VALUE_MAX] = { 0 };
  245. config_get_default_governor(config, defaultgov);
  246. if (desiredgov[0] == '\0') {
  247. const char *currentgov = get_gov_state();
  248. if (currentgov) {
  249. strncpy(desiredgov, currentgov, CONFIG_VALUE_MAX);
  250. } else {
  251. LOG_ERROR(
  252. "Could not get current CPU governor state, this indicates an error! See rest "
  253. "of log.\n");
  254. return -1;
  255. }
  256. }
  257. /* Start gamemode */
  258. gamemode_request_start();
  259. /* Verify the governor is the desired one */
  260. const char *currentgov = get_gov_state();
  261. if (strncmp(currentgov, desiredgov, CONFIG_VALUE_MAX) != 0) {
  262. LOG_ERROR("Govenor was not set to %s (was actually %s)!", desiredgov, currentgov);
  263. gamemode_request_end();
  264. return -1;
  265. }
  266. /* End gamemode */
  267. gamemode_request_end();
  268. /* Verify the governor has been set back */
  269. currentgov = get_gov_state();
  270. if (strncmp(currentgov, defaultgov, CONFIG_VALUE_MAX) != 0) {
  271. LOG_ERROR("Govenor was not set back to %s (was actually %s)!", defaultgov, currentgov);
  272. return -1;
  273. }
  274. return 0;
  275. }
  276. static int run_custom_scripts_tests(struct GameModeConfig *config)
  277. {
  278. int scriptstatus = 0;
  279. /* Grab and test the start scripts */
  280. char startscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  281. memset(startscripts, 0, sizeof(startscripts));
  282. config_get_gamemode_start_scripts(config, startscripts);
  283. if (startscripts[0][0] != '\0') {
  284. int i = 0;
  285. while (*startscripts[i] != '\0' && i < CONFIG_LIST_MAX) {
  286. LOG_MSG(":::: Running start script [%s]\n", startscripts[i]);
  287. int ret = system(startscripts[i]);
  288. if (ret == 0)
  289. LOG_MSG(":::: Passed\n");
  290. else {
  291. LOG_MSG(":::: Failed!\n");
  292. scriptstatus = -1;
  293. }
  294. i++;
  295. }
  296. }
  297. /* Grab and test the end scripts */
  298. char endscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
  299. memset(endscripts, 0, sizeof(endscripts));
  300. config_get_gamemode_end_scripts(config, endscripts);
  301. if (endscripts[0][0] != '\0') {
  302. int i = 0;
  303. while (*endscripts[i] != '\0' && i < CONFIG_LIST_MAX) {
  304. LOG_MSG(":::: Running end script [%s]\n", endscripts[i]);
  305. int ret = system(endscripts[i]);
  306. if (ret == 0)
  307. LOG_MSG(":::: Passed\n");
  308. else {
  309. LOG_MSG(":::: Failed!\n");
  310. scriptstatus = -1;
  311. }
  312. i++;
  313. }
  314. }
  315. /* Specal value for no scripts */
  316. if (endscripts[0][0] == '\0' && startscripts[0][0] == '\0')
  317. return 1;
  318. return scriptstatus;
  319. }
  320. int run_gpu_optimisation_tests(struct GameModeConfig *config)
  321. {
  322. int gpustatus = 0;
  323. /* First check if these are turned on */
  324. char apply[CONFIG_VALUE_MAX];
  325. config_get_apply_gpu_optimisations(config, apply);
  326. if (strlen(apply) == 0) {
  327. /* Special value for disabled */
  328. return 1;
  329. } else if (strncmp(apply, "accept-responsibility", CONFIG_VALUE_MAX) != 0) {
  330. LOG_ERROR(
  331. "apply_gpu_optimisations set to value other than \"accept-responsibility\" (%s), will "
  332. "not apply GPU optimisations!\n",
  333. apply);
  334. return -1;
  335. }
  336. /* Get current GPU values */
  337. GameModeGPUInfo gpuinfo;
  338. gpuinfo.device = config_get_gpu_device(config);
  339. gpuinfo.vendor = config_get_gpu_vendor(config);
  340. if (gpuinfo.vendor == Vendor_NVIDIA)
  341. gpuinfo.nv_perf_level = config_get_nv_perf_level(config);
  342. if (game_mode_get_gpu(&gpuinfo) != 0) {
  343. LOG_ERROR("Could not get current GPU info, see above!\n");
  344. return -1;
  345. }
  346. /* Store the original values */
  347. long original_core = gpuinfo.core;
  348. long original_mem = gpuinfo.mem;
  349. /* Grab the expected values */
  350. long expected_core = 0;
  351. long expected_mem = 0;
  352. switch (gpuinfo.vendor) {
  353. case Vendor_NVIDIA:
  354. expected_core = config_get_nv_core_clock_mhz_offset(config);
  355. expected_mem = config_get_nv_mem_clock_mhz_offset(config);
  356. break;
  357. case Vendor_AMD:
  358. expected_core = config_get_amd_core_clock_percentage(config);
  359. expected_mem = config_get_amd_mem_clock_percentage(config);
  360. break;
  361. default:
  362. LOG_ERROR("Configured for unsupported GPU vendor 0x%04x!\n", (unsigned int)gpuinfo.vendor);
  363. return -1;
  364. }
  365. LOG_MSG("Configured with vendor:0x%04x device:%ld core:%ld mem:%ld (nv_perf_level:%ld)\n",
  366. (unsigned int)gpuinfo.vendor,
  367. gpuinfo.device,
  368. expected_core,
  369. expected_mem,
  370. gpuinfo.nv_perf_level);
  371. /* Start gamemode and check the new values */
  372. gamemode_request_start();
  373. if (game_mode_get_gpu(&gpuinfo) != 0) {
  374. LOG_ERROR("Could not get current GPU info, see above!\n");
  375. gamemode_request_end();
  376. return -1;
  377. }
  378. if (gpuinfo.core != expected_core || gpuinfo.mem != expected_mem) {
  379. LOG_ERROR(
  380. "Current GPU clocks during gamemode do not match requested values!\n"
  381. "\tcore - expected:%ld was:%ld | mem - expected:%ld was:%ld\n",
  382. expected_core,
  383. gpuinfo.core,
  384. expected_mem,
  385. gpuinfo.mem);
  386. gpustatus = -1;
  387. }
  388. /* End gamemode and check the values have returned */
  389. gamemode_request_end();
  390. if (game_mode_get_gpu(&gpuinfo) != 0) {
  391. LOG_ERROR("Could not get current GPU info, see above!\n");
  392. return -1;
  393. }
  394. if (gpuinfo.core != original_core || gpuinfo.mem != original_mem) {
  395. LOG_ERROR(
  396. "Current GPU clocks after gamemode do not matcch original values!\n"
  397. "\tcore - original:%ld was:%ld | mem - original:%ld was:%ld\n",
  398. original_core,
  399. gpuinfo.core,
  400. original_mem,
  401. gpuinfo.mem);
  402. gpustatus = -1;
  403. }
  404. return gpustatus;
  405. }
  406. /**
  407. * game_mode_run_feature_tests runs a set of tests for each current feature (based on the current
  408. * config) returns 0 for success, -1 for failure
  409. */
  410. static int game_mode_run_feature_tests(struct GameModeConfig *config)
  411. {
  412. int status = 0;
  413. LOG_MSG(":: Feature tests\n");
  414. /* If we reach here, we should assume the basic requests and register functions are working */
  415. /* Does the CPU governor get set properly? */
  416. {
  417. LOG_MSG("::: Verifying CPU governor setting\n");
  418. int cpustatus = run_cpu_governor_tests(config);
  419. if (cpustatus == 0)
  420. LOG_MSG("::: Passed\n");
  421. else {
  422. LOG_MSG("::: Failed!\n");
  423. // Consider the CPU governor feature required
  424. status = 1;
  425. }
  426. }
  427. /* Do custom scripts run? */
  428. {
  429. LOG_MSG("::: Verifying Scripts\n");
  430. int scriptstatus = run_custom_scripts_tests(config);
  431. if (scriptstatus == 1)
  432. LOG_MSG("::: Passed (no scripts configured to run)\n");
  433. else if (scriptstatus == 0)
  434. LOG_MSG("::: Passed\n");
  435. else {
  436. LOG_MSG("::: Failed!\n");
  437. // Any custom scripts should be expected to work
  438. status = 1;
  439. }
  440. }
  441. /* Do GPU optimisations get applied? */
  442. {
  443. LOG_MSG("::: Verifying GPU Optimisations\n");
  444. int gpustatus = run_gpu_optimisation_tests(config);
  445. if (gpustatus == 1)
  446. LOG_MSG("::: Passed (gpu optimisations not configured to run)\n");
  447. else if (gpustatus == 0)
  448. LOG_MSG("::: Passed\n");
  449. else {
  450. LOG_MSG("::: Failed!\n");
  451. // Any custom scripts should be expected to work
  452. status = 1;
  453. }
  454. }
  455. /* Does the screensaver get inhibited? */
  456. /* TODO: Unknown if this is testable, org.freedesktop.ScreenSaver has no query method */
  457. /* Was the process reniced? */
  458. /* Was the scheduling applied? */
  459. /* Were io priorities changed? */
  460. /* Note: These don't get cleared up on un-register, so will have already been applied */
  461. /* TODO */
  462. if (status != -1)
  463. LOG_MSG(":: Passed%s\n\n", status > 0 ? " (with optional failures)" : "");
  464. else
  465. LOG_ERROR(":: Failed!\n");
  466. return status;
  467. }
  468. /* Run a set of tests on the supervisor code */
  469. static int run_supervisor_tests(void)
  470. {
  471. int supervisortests = 0;
  472. int ret = 0;
  473. LOG_MSG(":: Supervisor tests\n");
  474. /* Launch an external dummy process we can leave running and request gamemode for it */
  475. pid_t pid = fork();
  476. if (pid == 0) {
  477. /* Child simply pauses and exits */
  478. pause();
  479. exit(EXIT_SUCCESS);
  480. }
  481. /* Request gamemode for our dummy process */
  482. ret = gamemode_request_start_for(pid);
  483. if (ret != 0) {
  484. LOG_ERROR("gamemode_request_start_for gave unexpected value %d, (expected 0)!\n", ret);
  485. supervisortests = -1;
  486. }
  487. /* Check it's active */
  488. ret = gamemode_query_status();
  489. if (ret != 1) {
  490. LOG_ERROR(
  491. "gamemode_query_status after start request gave unexpected value %d, (expected 1)!\n",
  492. ret);
  493. supervisortests = -1;
  494. }
  495. /* Check it's active for the dummy */
  496. ret = gamemode_query_status_for(pid);
  497. if (ret != 2) {
  498. LOG_ERROR(
  499. "gamemode_query_status_for after start request gave unexpected value %d, (expected "
  500. "2)!\n",
  501. ret);
  502. supervisortests = -1;
  503. }
  504. /* request gamemode end for the client */
  505. ret = gamemode_request_end_for(pid);
  506. if (ret != 0) {
  507. LOG_ERROR("gamemode_request_end_for gave unexpected value %d, (expected 0)!\n", ret);
  508. supervisortests = -1;
  509. }
  510. /* Verify it's not active */
  511. ret = gamemode_query_status();
  512. if (ret != 0) {
  513. LOG_ERROR(
  514. "gamemode_query_status after end request gave unexpected value %d, (expected 0)!\n",
  515. ret);
  516. supervisortests = -1;
  517. }
  518. /* Wake up the child process */
  519. if (kill(pid, SIGUSR1) == -1) {
  520. LOG_ERROR("failed to send continue signal to other child process: %s\n", strerror(errno));
  521. supervisortests = -1;
  522. }
  523. // Wait for the child to finish up
  524. int wstatus;
  525. usleep(100000);
  526. while (waitpid(pid, &wstatus, WNOHANG) == 0) {
  527. LOG_MSG("...Waiting for child to quit...\n");
  528. usleep(100000);
  529. }
  530. if (supervisortests == 0)
  531. LOG_MSG(":: Passed\n\n");
  532. else
  533. LOG_ERROR(":: Failed!\n");
  534. return supervisortests;
  535. }
  536. /**
  537. * game_mode_run_client_tests runs a set of tests of the client code
  538. * we simply verify that the client can request the status and recieves the correct results
  539. *
  540. * returns 0 for success, -1 for failure
  541. */
  542. int game_mode_run_client_tests()
  543. {
  544. int status = 0;
  545. LOG_MSG(": Loading config\n");
  546. /* Grab the config */
  547. /* Note: this config may pick up a local gamemode.ini, or the daemon may have one, we may need
  548. * to cope with that */
  549. GameModeConfig *config = config_create();
  550. config_init(config);
  551. LOG_MSG(": Running tests\n\n");
  552. /* First verify that gamemode is not currently active on the system
  553. * As well as it being currently installed and queryable
  554. */
  555. if (verify_gamemode_initial() != 0)
  556. return -1;
  557. /* Controls whether we require a supervisor to actually make requests */
  558. /* TODO: This effects all tests below */
  559. if (config_get_require_supervisor(config) != 0) {
  560. LOG_ERROR("Tests currently unsupported when require_supervisor is set\n");
  561. return -1;
  562. }
  563. /* TODO: Also check blacklist/whitelist values as these may mess up the tests below */
  564. /* Run the basic tests */
  565. if (run_basic_client_tests() != 0)
  566. status = -1;
  567. /* Run the dual client tests */
  568. if (run_dual_client_tests() != 0)
  569. status = -1;
  570. /* Check gamemoderun and the reaper thread work */
  571. if (run_gamemoderun_and_reaper_tests(config) != 0)
  572. status = -1;
  573. /* Run the supervisor tests */
  574. if (run_supervisor_tests() != 0)
  575. status = -1;
  576. if (status != 0) {
  577. LOG_MSG(": Client tests failed, skipping feature tests\n");
  578. } else {
  579. /* Run the feature tests */
  580. status = game_mode_run_feature_tests(config);
  581. }
  582. if (status >= 0)
  583. LOG_MSG(": All Tests Passed%s!\n", status > 0 ? " (with optional failures)" : "");
  584. else
  585. LOG_MSG(": Tests Failed!\n");
  586. return status;
  587. }