test_rma.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2002-2010 UFO: Alien Invasion.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 /* timeout version */
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 /* sequential version */
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     /* add a suite to the registry */
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     /* add the tests to the suite */
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 }

Generated by  doxygen 1.6.2