test_rma.c
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "CUnit/Basic.h"
00026 #include "test_rma.h"
00027 #include "test_shared.h"
00028 #include "../server/sv_rma.h"
00029 #include "../ports/system.h"
00030
00031 cvar_t *sv_dumpmapassembly;
00032 cvar_t *sv_threads;
00033
00038 static int UFO_InitSuiteRandomMapAssembly (void)
00039 {
00040 TEST_Init();
00041
00042 sv_dumpmapassembly = Cvar_Get("sv_dumpassembly", "0", 0, NULL);
00043
00044 return 0;
00045 }
00046
00051 static int UFO_CleanSuiteRandomMapAssembly (void)
00052 {
00053 TEST_Shutdown();
00054 return 0;
00055 }
00056
00057 char map[MAX_TOKEN_CHARS * MAX_TILESTRINGS];
00058 char pos[MAX_TOKEN_CHARS * MAX_TILESTRINGS];
00059
00060 static void testAssembly (void)
00061 {
00062 mapInfo_t *randomMap;
00063
00064 srand(0);
00065 randomMap = SV_AssembleMap("forest", "large", map, pos);
00066 CU_ASSERT(randomMap != NULL);
00067 Mem_Free(randomMap);
00068 }
00069
00070
00071 static void testMassAssemblyTimeout (void)
00072 {
00073 int i;
00074 long time;
00075 mapInfo_t *randomMap;
00076
00077 sv_threads->integer = 1;
00078 for (i = 0; i < 10; i++) {
00079 srand(i);
00080 time = Sys_Milliseconds();
00081 randomMap = SV_AssembleMap("forest", "large", map, pos);
00082 CU_ASSERT(randomMap != NULL);
00083 time = (Sys_Milliseconds() - time);
00084 CU_ASSERT(time < 30000);
00085 TEST_Printf("%i: %i %li\n", i, randomMap->numPlaced, time);
00086 Mem_Free(randomMap);
00087 }
00088 }
00089
00090 static void testMassAssemblyParallel (void)
00091 {
00092 int i;
00093 long time;
00094 mapInfo_t *randomMap;
00095
00096 sv_threads->integer = 2;
00097 for (i = 0; i < 10; i++) {
00098 srand(i);
00099 time = Sys_Milliseconds();
00100 randomMap = SV_AssembleMap("forest", "large", map, pos);
00101 CU_ASSERT(randomMap != NULL);
00102 time = (Sys_Milliseconds() - time);
00103 CU_ASSERT(time < 30000);
00104 TEST_Printf("%i: %i %li\n", i, randomMap->numPlaced, time); fflush(stdout);
00105 Mem_Free(randomMap);
00106 }
00107
00108 }
00109
00110
00111 static void testMassAssemblySequential (void)
00112 {
00113 int i;
00114 long time;
00115 mapInfo_t *randomMap;
00116
00117 sv_threads->integer = 0;
00118 for (i = 0; i < 10; i++) {
00119 srand(i);
00120 time = Sys_Milliseconds();
00121 randomMap = SV_AssembleMap("forest", "large", map, pos);
00122 CU_ASSERT(randomMap != NULL);
00123 time = (Sys_Milliseconds() - time);
00124 CU_ASSERT(time < 30000);
00125 TEST_Printf("%i: %i %li\n", i, randomMap->numPlaced, time);
00126 Mem_Free(randomMap);
00127 }
00128 }
00129
00130 int UFO_AddRandomMapAssemblyTests (void)
00131 {
00132 static cvar_t svt;
00133 static cvar_t maxclients;
00134
00135 CU_pSuite RandomMapAssemblySuite = CU_add_suite("RandomMapAssemblyTests", UFO_InitSuiteRandomMapAssembly, UFO_CleanSuiteRandomMapAssembly);
00136
00137 if (!sv_threads) {
00138 sv_threads = &svt;
00139 sv_threads->integer = 0;
00140 }
00141
00142 if (!sv_maxclients) {
00143 sv_maxclients = &maxclients;
00144 sv_maxclients->integer = 1;
00145 }
00146
00147 if (RandomMapAssemblySuite == NULL)
00148 return CU_get_error();
00149
00150
00151 if (CU_ADD_TEST(RandomMapAssemblySuite, testAssembly) == NULL)
00152 return CU_get_error();
00153
00154 if (CU_ADD_TEST(RandomMapAssemblySuite, testMassAssemblyParallel) == NULL)
00155 return CU_get_error();
00156
00157 if (CU_ADD_TEST(RandomMapAssemblySuite, testMassAssemblyTimeout) == NULL)
00158 return CU_get_error();
00159
00160 if (CU_ADD_TEST(RandomMapAssemblySuite, testMassAssemblySequential) == NULL)
00161 return CU_get_error();
00162
00163 return CUE_SUCCESS;
00164 }