ManaPlus
testmain.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "test/testmain.h"
22 
23 #ifdef USE_OPENGL
24 
25 #include "logger.h"
26 #include "settings.h"
27 
28 #include "fs/paths.h"
29 
30 #include "utils/cast.h"
31 #include "utils/delete2.h"
32 #include "utils/process.h"
33 
34 #include <fstream>
35 
36 #include "debug.h"
37 
38 std::string fileName;
39 extern char *selfName;
40 
42  log(new Logger),
43  mConfig()
44 {
46  log->setLogFile(pathJoin(settings.localDataDir, "manaplustest.log"));
47 }
48 
50 {
51  delete2(log)
52 }
53 
55 {
56  mConfig.init(settings.configDir + "/test.xml",
59  mConfig.clear();
60 // setConfigDefaults(mConfig);
61 
62  mConfig.setValue("hwaccel", false);
63  mConfig.setValue("screen", false);
64  mConfig.setValue("sound", false);
65  mConfig.setValue("guialpha", 0.8F);
66 // mConfig.setValue("remember", true);
67  mConfig.setValue("sfxVolume", 50);
68  mConfig.setValue("musicVolume", 60);
69  mConfig.setValue("fpslimit", 0);
70  mConfig.setValue("customcursor", true);
71  mConfig.setValue("useScreenshotDirectorySuffix", true);
72  mConfig.setValue("ChatLogLength", 128);
73  mConfig.setValue("screenwidth", 800);
74  mConfig.setValue("screenheight", 600);
75 }
76 
77 int TestMain::exec(const bool testAudio)
78 {
79  initConfig();
80  int softwareTest = invokeSoftwareRenderTest("1");
81  int soundTest = -1;
82  int rescaleTest[6];
83  int softFps = 0;
84  int normalOpenGLFps = 0;
85  int safeOpenGLFps = 0;
86  int modernOpenGLFps = 0;
87  int textureSize[6];
88  std::string textureSizeStr;
89 
91  int detectMode = 0;
92  for (int f = 0; f < 6; f ++)
93  {
94  rescaleTest[f] = -1;
95  textureSize[f] = 1024;
96  }
97  std::string info;
98 
99  const int videoDetectTest = invokeTest("99");
100  if (videoDetectTest == 0)
101  detectMode = readValue2(99);
102 
103  int normalOpenGLTest = invokeNormalOpenGLRenderTest("2");
104  int safeOpenGLTest = invokeSafeOpenGLRenderTest("3");
105  int modernOpenGLTest = invokeModernOpenGLRenderTest("19");
106  if (testAudio)
107  soundTest = invokeTest4();
108  else
109  soundTest = 0;
110 
111  info.append(strprintf("%d.%d,%d,%d,%d.", soundTest, softwareTest,
112  normalOpenGLTest, safeOpenGLTest, modernOpenGLTest));
113 
114  if (softwareTest == 0)
115  {
116  int softFpsTest = invokeSoftwareRenderTest("8");
117  info.append(strprintf("%d", softFpsTest));
118  if (softFpsTest == 0)
119  {
120  softFps = readValue2(8);
121  info.append(strprintf(",%d", softFps));
122  if (softFps == 0)
123  {
124  softwareTest = -1;
125  softFpsTest = -1;
126  }
127  else
128  {
129  rescaleTest[0] = invokeSoftwareRenderTest("5");
130  info.append(strprintf(",%d", rescaleTest[0]));
131  }
132  }
133  else
134  {
135  softwareTest = -1;
136  }
137  }
138  info.append(".");
139  if (modernOpenGLTest == 0)
140  {
141  int modernOpenGLFpsTest = invokeModernOpenGLRenderTest("17");
142  info.append(strprintf("%d", modernOpenGLFpsTest));
143  if (modernOpenGLFpsTest == 0)
144  {
145  modernOpenGLFps = readValue2(17);
146  info.append(strprintf(",%d", modernOpenGLFps));
147  if (modernOpenGLFps == 0)
148  {
149  modernOpenGLTest = -1;
150  modernOpenGLFpsTest = -1;
151  }
152  else
153  {
154  rescaleTest[3] = invokeModernOpenGLRenderTest("18");
155  info.append(strprintf(",%d", rescaleTest[3]));
156  }
157  }
158  else
159  {
160  modernOpenGLTest = -1;
161  }
162  }
163  info.append(".");
164  if (normalOpenGLTest == 0)
165  {
166  int normalOpenGLFpsTest = invokeNormalOpenGLRenderTest("9");
167  info.append(strprintf("%d", normalOpenGLFpsTest));
168  if (normalOpenGLFpsTest == 0)
169  {
170  normalOpenGLFps = readValue2(9);
171  info.append(strprintf(",%d", normalOpenGLFps));
172  if (normalOpenGLFps == 0)
173  {
174  normalOpenGLTest = -1;
175  normalOpenGLFpsTest = -1;
176  }
177  else
178  {
179  rescaleTest[1] = invokeNormalOpenGLRenderTest("6");
180  info.append(strprintf(",%d", rescaleTest[1]));
181  }
182  }
183  else
184  {
185  normalOpenGLTest = -1;
186  }
187  }
188  info.append(".");
189  if (safeOpenGLTest == 0)
190  {
191  int safeOpenGLFpsTest = invokeSafeOpenGLRenderTest("10");
192  info.append(strprintf("%d", safeOpenGLFpsTest));
193  if (safeOpenGLFpsTest == 0)
194  {
195  safeOpenGLFps = readValue2(10);
196  info.append(strprintf(",%d", safeOpenGLFps));
197  if (safeOpenGLFps == 0)
198  {
199  safeOpenGLTest = -1;
200  safeOpenGLFpsTest = -1;
201  }
202  else
203  {
204  rescaleTest[2] = invokeSafeOpenGLRenderTest("7");
205  info.append(strprintf(",%d", rescaleTest[2]));
206  }
207  }
208  else
209  {
210  safeOpenGLTest = -1;
211  }
212  }
213  info.append(".");
214 
215  int maxFps = softFps;
216  if (maxFps < normalOpenGLFps)
217  {
219  maxFps = normalOpenGLFps;
220  }
221  if (maxFps < modernOpenGLFps)
222  {
224  maxFps = modernOpenGLFps;
225  }
226  if (maxFps < safeOpenGLFps)
227  {
229  maxFps = safeOpenGLFps;
230  }
231 
232  int batchSize = 256;
233 
234  if (invokeNormalOpenBatchTest("11") == 0)
235  batchSize = readValue2(11);
236  if (batchSize < 256)
237  batchSize = 256;
238 
239  if (invokeNormalOpenBatchTest("14") == 0)
240  {
241  textureSize[CAST_SIZE(RENDER_NORMAL_OPENGL)]
242  = readValue2(14);
243  }
244  if (invokeModernOpenBatchTest("15") == 0)
245  {
246  textureSize[CAST_SIZE(RENDER_MODERN_OPENGL)]
247  = readValue2(15);
248  }
249  if (invokeSafeOpenBatchTest("16") == 0)
250  {
251  textureSize[CAST_SIZE(RENDER_SAFE_OPENGL)]
252  = readValue2(16);
253  }
254  if (invokeMobileOpenBatchTest("20") == 0)
255  {
256  textureSize[CAST_SIZE(RENDER_GLES_OPENGL)]
257  = readValue2(20);
258  }
259  for (int f = 0; f < 6; f ++)
260  info.append(strprintf(",%d", textureSize[f]));
261  info.append(",-");
262 
263  textureSizeStr = toString(textureSize[0]);
264  for (int f = 1; f < 6; f ++)
265  textureSizeStr.append(strprintf(",%d", textureSize[f]));
266 
267  // if OpenGL implimentation is not good, disable it.
268  if ((detectMode & 15) == 0)
270 
272  soundTest, info, batchSize, textureSizeStr, detectMode);
273  return 0;
274 }
275 
277  const int rescale,
278  const int sound,
279  const std::string &info,
280  const int batchSize A_UNUSED,
281  const std::string &textureSize,
282  const int detectMode)
283 {
284  mConfig.init(settings.configDir + "/config.xml",
287 
288  log->log("set mode to %d", CAST_S32(openGLMode));
289 
290  // searched values
291  mConfig.setValue("opengl", CAST_S32(openGLMode));
292  mConfig.setValue("showBackground", rescale == 0);
293  mConfig.setValue("sound", sound == 0);
294 
295  // better performance
296  mConfig.setValue("hwaccel", true);
297  mConfig.setValue("fpslimit", 60);
298  mConfig.setValue("altfpslimit", 2);
299  mConfig.setValue("safemode", false);
300  mConfig.setValue("enableMapReduce", true);
301  mConfig.setValue("textureSize", textureSize);
302 
303  // max batch size
304 // mConfig.setValue("batchsize", batchSize);
305 
306  // additional modes
307  mConfig.setValue("useTextureSampler",
308  static_cast<bool>(detectMode & 1024));
309  mConfig.setValue("compresstextures",
310  static_cast<bool>(detectMode & 2048));
311 
312  // stats
313  mConfig.setValue("testInfo", info);
314 
315  mConfig.write();
316 }
317 
318 int TestMain::readValue2(const int ver)
319 {
320  const int def = readValue(ver, 0);
321  log->log("value for %d = %d", ver, def);
322  return def;
323 }
324 
325 int TestMain::readValue(const int ver, int def)
326 {
327  std::string tmp;
328  int var;
329  std::ifstream file;
330  file.open(pathJoin(settings.localDataDir, "test.log").c_str(),
331  std::ios::in);
332  if (!getline(file, tmp))
333  {
334  file.close();
335  return def;
336  }
337  var = atoi(tmp.c_str());
338  if (ver != var || !getline(file, tmp))
339  {
340  file.close();
341  return def;
342  }
343  def = atoi(tmp.c_str());
344  file.close();
345  return def;
346 }
347 
348 int TestMain::invokeTest(const std::string &test)
349 {
351 
352  mConfig.write();
353  const int ret = execFileWait(fileName, fileName, "-t", test, 0);
354  return ret;
355 }
356 
358 {
359  mConfig.setValue("sound", true);
360  const int ret = invokeTest("4");
361 
362  log->log("4: %d", ret);
363  return ret;
364 }
365 
366 int TestMain::invokeSoftwareRenderTest(const std::string &test)
367 {
369  mConfig.write();
370  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
371  log->log("%s: %d", test.c_str(), ret);
372  return ret;
373 }
374 
375 int TestMain::invokeNormalOpenGLRenderTest(const std::string &test)
376 {
378  mConfig.write();
379  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
380  log->log("%s: %d", test.c_str(), ret);
381  return ret;
382 }
383 
384 int TestMain::invokeModernOpenGLRenderTest(const std::string &test)
385 {
387  mConfig.write();
388  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
389  log->log("%s: %d", test.c_str(), ret);
390  return ret;
391 }
392 
393 int TestMain::invokeNormalOpenBatchTest(const std::string &test)
394 {
396  mConfig.write();
397  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
398 // log->log("%s: %d", test.c_str(), ret);
399  return ret;
400 }
401 
402 int TestMain::invokeModernOpenBatchTest(const std::string &test)
403 {
405  mConfig.write();
406  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
407 // log->log("%s: %d", test.c_str(), ret);
408  return ret;
409 }
410 
411 int TestMain::invokeMobileOpenBatchTest(const std::string &test)
412 {
414  mConfig.write();
415  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
416 // log->log("%s: %d", test.c_str(), ret);
417  return ret;
418 }
419 
420 int TestMain::invokeSafeOpenBatchTest(const std::string &test)
421 {
423  mConfig.write();
424  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
425 // log->log("%s: %d", test.c_str(), ret);
426  return ret;
427 }
428 
429 int TestMain::invokeSafeOpenGLRenderTest(const std::string &test)
430 {
432  mConfig.write();
433  const int ret = execFileWait(fileName, fileName, "-t", test, 30);
434  log->log("%s: %d", test.c_str(), ret);
435  return ret;
436 }
437 #endif // USE_OPENGL
TestMain::~TestMain
~TestMain()
Definition: testmain.cpp:49
TestMain::invokeTest
int invokeTest(const std::string &test)
Definition: testmain.cpp:348
cast.h
CAST_SIZE
#define CAST_SIZE
Definition: cast.h:33
TestMain::TestMain
TestMain()
Definition: testmain.cpp:41
settings.h
logger.h
TestMain::invokeMobileOpenBatchTest
int invokeMobileOpenBatchTest(const std::string &test)
Definition: testmain.cpp:411
selfName
char * selfName
Definition: maingui.cpp:134
TestMain::mConfig
Configuration mConfig
Definition: testmain.h:89
RenderType
RenderType
Definition: rendertype.h:24
openGLMode
RenderType openGLMode
Definition: graphicsmanager.cpp:116
settings
Settings settings
Definition: settings.cpp:31
RENDER_NORMAL_OPENGL
@ RENDER_NORMAL_OPENGL
Definition: rendertype.h:27
delete2.h
SkipError_false
const bool SkipError_false
Definition: skiperror.h:29
A_UNUSED
#define A_UNUSED
Definition: localconsts.h:159
Settings::configDir
std::string configDir
Definition: settings.h:110
pathJoin
std::string pathJoin(std::string str1, const std::string &str2)
Definition: stringutils.cpp:1036
delete2
#define delete2(var)
Definition: delete2.h:24
TestMain::invokeSoftwareRenderTest
int invokeSoftwareRenderTest(const std::string &test)
Definition: testmain.cpp:366
Catch::toString
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
process.h
ConfigurationObject::clear
void clear()
Definition: configuration.cpp:331
Configuration::setValue
void setValue(const std::string &key, const std::string &value)
Definition: configuration.cpp:238
Actions::info
bool info(InputEvent &event)
Definition: commands.cpp:56
fileName
std::string fileName
Definition: testmain.cpp:38
RENDER_GLES_OPENGL
@ RENDER_GLES_OPENGL
Definition: rendertype.h:29
TestMain::invokeSafeOpenBatchTest
int invokeSafeOpenBatchTest(const std::string &test)
Definition: testmain.cpp:420
TestMain::invokeModernOpenBatchTest
int invokeModernOpenBatchTest(const std::string &test)
Definition: testmain.cpp:402
TestMain::writeConfig
void writeConfig(const RenderType openGLMode, const int rescale, const int sound, const std::string &info, const int batchSize, const std::string &textureSize, const int detectMode)
Definition: testmain.cpp:276
TestMain::invokeSafeOpenGLRenderTest
int invokeSafeOpenGLRenderTest(const std::string &test)
Definition: testmain.cpp:429
getSelfName
std::string getSelfName()
Definition: paths.cpp:199
paths.h
strprintf
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Settings::localDataDir
std::string localDataDir
Definition: settings.h:111
RENDER_MODERN_OPENGL
@ RENDER_MODERN_OPENGL
Definition: rendertype.h:31
TestMain::invokeNormalOpenGLRenderTest
int invokeNormalOpenGLRenderTest(const std::string &test)
Definition: testmain.cpp:375
Logger::setLogFile
void setLogFile(const std::string &logFilename)
Definition: logger.cpp:119
UseVirtFs_false
const bool UseVirtFs_false
Definition: usevirtfs.h:29
TestMain::invokeTest4
int invokeTest4()
Definition: testmain.cpp:357
RENDER_SOFTWARE
@ RENDER_SOFTWARE
Definition: rendertype.h:26
TestMain::readValue
static int readValue(const int ver, int def)
Definition: testmain.cpp:325
RENDER_SAFE_OPENGL
@ RENDER_SAFE_OPENGL
Definition: rendertype.h:28
TestMain::log
Logger * log
Definition: testmain.h:87
Configuration::write
void write()
Definition: configuration.cpp:858
TestMain::invokeModernOpenGLRenderTest
int invokeModernOpenGLRenderTest(const std::string &test)
Definition: testmain.cpp:384
TestMain::initConfig
void initConfig()
Definition: testmain.cpp:54
Logger
Definition: logger.h:67
CAST_S32
#define CAST_S32
Definition: cast.h:29
new
#define new
Definition: debug_new.h:147
TestMain::invokeNormalOpenBatchTest
int invokeNormalOpenBatchTest(const std::string &test)
Definition: testmain.cpp:393
testmain.h
TestMain::exec
int exec(const bool testAudio=true)
Definition: testmain.cpp:77
TestMain::readValue2
int readValue2(const int ver)
Definition: testmain.cpp:318
Configuration::init
void init(const std::string &filename, const UseVirtFs useResManager, const SkipError skipError)
Definition: configuration.cpp:738
execFileWait
int execFileWait(const std::string &pathName, const std::string &name, const std::string &arg1, const std::string &arg2, int waitTime)
Definition: process.cpp:230
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268
debug.h