1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/*
* The ManaPlus Client
* Copyright (C) 2011 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "test/testmain.h"
#include "utils/gettext.h"
#include "client.h"
#include "configuration.h"
#include "localconsts.h"
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/stringutils.h"
#include "utils/process.h"
#include <iostream>
#include "debug.h"
#ifdef WIN32
const std::string fileName = "manaplus.exe";
#else
const std::string fileName = "manaplus";
#endif
TestMain::TestMain()
{
log = new Logger;
// log->setLogFile(Client::getLocalDataDirectory()
// + std::string("/test.log"));
log->setLogFile(Client::getLocalDataDirectory()
+ std::string("/manaplustest.log"));
}
void TestMain::initConfig()
{
config.init(Client::getConfigDirectory() + "/test.xml");
// config.setDefaultValues(getConfigDefaults());
config.setValue("hwaccel", false);
config.setValue("screen", false);
config.setValue("sound", false);
config.setValue("guialpha", 0.8f);
config.setValue("remember", true);
config.setValue("sfxVolume", 50);
config.setValue("musicVolume", 60);
config.setValue("fpslimit", 0);
config.setValue("customcursor", true);
config.setValue("useScreenshotDirectorySuffix", true);
config.setValue("ChatLogLength", 128);
config.setValue("screenwidth", 800);
config.setValue("screenheight", 600);
}
int TestMain::exec()
{
initConfig();
int softwareTest = invokeSoftwareRenderTest("1");
int fastOpenGLTest = invokeFastOpenGLRenderTest("2");
int safeOpenGLTest = invokeSafeOpenGLRenderTest("3");
int soundTest = invokeTest4();
int rescaleTest[3];
int softFpsTest = -1;
int fastOpenGLFpsTest = -1;
int safeOpenGLFpsTest = -1;
int softFps = 0;
int fastOpenGLFps = 0;
int safeOpenGLFps = 0;
int openGLMode = 0;
int maxFps = 0;
rescaleTest[0] = -1;
rescaleTest[1] = -1;
rescaleTest[2] = -1;
std::string info;
info += strprintf("%d.%d,%d,%d.", soundTest, softwareTest,
fastOpenGLTest, safeOpenGLTest);
if (!softwareTest)
{
softFpsTest = invokeSoftwareRenderTest("8");
info += strprintf ("%d", softFpsTest);
if (!softFpsTest)
{
softFps = readValue(8);
info += strprintf (",%d", softFps);
if (!softFps)
{
softwareTest = -1;
softFpsTest = -1;
}
else
{
rescaleTest[0] = invokeSoftwareRenderTest("5");
info += strprintf (",%d", rescaleTest[0]);
}
}
else
{
softwareTest = -1;
}
}
info += ".";
if (!fastOpenGLTest)
{
fastOpenGLFpsTest = invokeFastOpenGLRenderTest("9");
info += strprintf ("%d", fastOpenGLFpsTest);
if (!fastOpenGLFpsTest)
{
fastOpenGLFps = readValue(9);
info += strprintf (",%d", fastOpenGLFps);
if (!fastOpenGLFps)
{
fastOpenGLTest = -1;
fastOpenGLFpsTest = -1;
}
else
{
rescaleTest[1] = invokeFastOpenGLRenderTest("6");
info += strprintf (",%d", rescaleTest[1]);
}
}
else
{
fastOpenGLTest = -1;
}
}
info += ".";
if (!safeOpenGLTest)
{
safeOpenGLFpsTest = invokeSafeOpenGLRenderTest("10");
info += strprintf ("%d", safeOpenGLFpsTest);
if (!safeOpenGLFpsTest)
{
safeOpenGLFps = readValue(10);
info += strprintf (",%d", safeOpenGLFps);
if (!safeOpenGLFps)
{
safeOpenGLTest = -1;
safeOpenGLFpsTest = -1;
}
else
{
rescaleTest[2] = invokeSafeOpenGLRenderTest("7");
info += strprintf (",%d", rescaleTest[2]);
}
}
else
{
safeOpenGLTest = -1;
}
}
info += ".";
maxFps = softFps;
if (maxFps < fastOpenGLFps)
{
openGLMode = 1;
maxFps = fastOpenGLFps;
}
if (maxFps < safeOpenGLFps)
{
openGLMode = 2;
maxFps = safeOpenGLFps;
}
writeConfig(openGLMode, rescaleTest[openGLMode], soundTest, info);
return 0;
}
void TestMain::writeConfig(int openGLMode, int rescale,
int sound, std::string info)
{
config.init(Client::getConfigDirectory() + "/config.xml");
// searched values
config.setValue("opengl", openGLMode);
config.setValue("showBackground", !rescale);
config.setValue("sound", !sound);
// better perfomance
config.setValue("hwaccel", true);
config.setValue("fpslimit", 60);
config.setValue("altfpslimit", 2);
config.setValue("safemode", false);
config.setValue("enableMapReduce", true);
// stats
config.setValue("testInfo", info);
config.write();
}
int TestMain::readValue(int ver, int def)
{
std::string tmp;
int var;
file.open((Client::getLocalDataDirectory()
+ std::string("/test.log")).c_str(), std::ios::in);
if (!getline(file, tmp))
{
file.close();
return def;
}
var = atoi(tmp.c_str());
if (ver != var || !getline(file, tmp))
{
file.close();
return def;
}
def = atoi(tmp.c_str());
file.close();
log->log("value for %d = %d", ver, def);
return def;
}
int TestMain::invokeTest(std::string test)
{
config.setValue("opengl", 0);
config.write();
int ret = execFile(fileName, fileName, "-t", test);
return ret;
}
int TestMain::invokeTest4()
{
config.setValue("sound", true);
int ret = invokeTest("4");
log->log("4: %d", ret);
return ret;
}
int TestMain::invokeSoftwareRenderTest(std::string test)
{
config.setValue("opengl", 0);
config.write();
int ret = execFile(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
return ret;
}
int TestMain::invokeFastOpenGLRenderTest(std::string test)
{
#if defined USE_OPENGL
config.setValue("opengl", 1);
#else
return -1;
#endif
config.write();
int ret = execFile(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
return ret;
}
int TestMain::invokeSafeOpenGLRenderTest(std::string test)
{
#if defined USE_OPENGL
config.setValue("opengl", 2);
#else
return -1;
#endif
config.write();
int ret = execFile(fileName, fileName, "-t", test, 30);
log->log("%s: %d", test.c_str(), ret);
return ret;
}
|