1 /*-------------------------------------------------------------------------
2 * OpenGL Conformance Test Suite
3 * -----------------------------
4 *
5 * Copyright (c) 2016 Google Inc.
6 * Copyright (c) 2016 The Khronos Group Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */ /*!
21 * \file
22 * \brief CTS Android Activity.
23 */ /*-------------------------------------------------------------------*/
24
25 #include "glcAndroidTestActivity.hpp"
26 #include "glcTestRunner.hpp"
27 #include "tcuAndroidAssets.hpp"
28 #include "tcuAndroidPlatform.hpp"
29 #include "tcuAndroidUtil.hpp"
30
31 #include <android/window.h>
32 #include <stdlib.h>
33
34 namespace glcts
35 {
36 namespace Android
37 {
38
39 using tcu::Android::AssetArchive;
40 using tcu::Android::NativeActivity;
41 using tcu::Android::Platform;
42
43 static const char *DEFAULT_LOG_PATH = "/sdcard";
44
45 static const char *DEFAULT_TEST_PARAM_FILE_NAME = "/sdcard/cts-run-params.xml";
46
getWaiverPath(ANativeActivity * activity)47 static std::string getWaiverPath(ANativeActivity *activity)
48 {
49 return tcu::Android::getIntentStringExtra(activity, "waivers");
50 }
51
getLogPath(ANativeActivity * activity)52 static std::string getLogPath(ANativeActivity *activity)
53 {
54 std::string path = tcu::Android::getIntentStringExtra(activity, "logdir");
55 return path.empty() ? std::string(DEFAULT_LOG_PATH) : path;
56 }
57
getTestRunParamFilePath(ANativeActivity * activity)58 static std::string getTestRunParamFilePath(ANativeActivity *activity)
59 {
60 std::string path = tcu::Android::getIntentStringExtra(activity, "khronosCTSTestParamFileName");
61 return path.empty() ? std::string(DEFAULT_TEST_PARAM_FILE_NAME) : path;
62 }
63
getFlags(ANativeActivity * activity)64 static uint32_t getFlags(ANativeActivity *activity)
65 {
66 uint32_t flags = 0;
67 if (tcu::Android::getIntentStringExtra(activity, "verbose") == "true")
68 flags |= TestRunner::VERBOSE_ALL;
69 else if (tcu::Android::getIntentStringExtra(activity, "summary") == "true")
70 flags |= TestRunner::PRINT_SUMMARY;
71 return flags;
72 }
73
TestThread(NativeActivity & activity,tcu::Android::AssetArchive & archive,const std::string & waiverPath,const std::string & logPath,glu::ApiType runType,uint32_t runFlags)74 TestThread::TestThread(NativeActivity &activity, tcu::Android::AssetArchive &archive, const std::string &waiverPath,
75 const std::string &logPath, glu::ApiType runType, uint32_t runFlags)
76 : RenderThread(activity)
77 , m_platform(activity)
78 , m_archive(archive)
79 , m_app(m_platform, m_archive, waiverPath.c_str(), logPath.c_str(), runType, runFlags)
80 , m_finished(false)
81 {
82 }
83
~TestThread(void)84 TestThread::~TestThread(void)
85 {
86 // \note m_testApp is managed by thread.
87 }
88
run(void)89 void TestThread::run(void)
90 {
91 RenderThread::run();
92 }
93
onWindowCreated(ANativeWindow * window)94 void TestThread::onWindowCreated(ANativeWindow *window)
95 {
96 m_platform.getWindowRegistry().addWindow(window);
97 }
98
onWindowDestroyed(ANativeWindow * window)99 void TestThread::onWindowDestroyed(ANativeWindow *window)
100 {
101 m_platform.getWindowRegistry().destroyWindow(window);
102 }
103
onWindowResized(ANativeWindow * window)104 void TestThread::onWindowResized(ANativeWindow *window)
105 {
106 // \todo [2013-05-12 pyry] Handle this in some sane way.
107 DE_UNREF(window);
108 tcu::print("Warning: Native window was resized, results may be undefined");
109 }
110
render(void)111 bool TestThread::render(void)
112 {
113 if (!m_finished)
114 m_finished = !m_app.iterate();
115 return !m_finished;
116 }
117
GetTestParamThread(NativeActivity & activity,const std::string & testParamsFilePath,glu::ApiType runType)118 GetTestParamThread::GetTestParamThread(NativeActivity &activity, const std::string &testParamsFilePath,
119 glu::ApiType runType)
120 : RenderThread(activity)
121 , m_platform(activity)
122 , m_app(m_platform, testParamsFilePath.c_str(), runType)
123 , m_finished(false)
124 {
125 }
126
~GetTestParamThread(void)127 GetTestParamThread::~GetTestParamThread(void)
128 {
129 // \note m_testApp is managed by thread.
130 }
131
run(void)132 void GetTestParamThread::run(void)
133 {
134 RenderThread::run();
135 }
136
onWindowCreated(ANativeWindow * window)137 void GetTestParamThread::onWindowCreated(ANativeWindow *window)
138 {
139 m_platform.getWindowRegistry().addWindow(window);
140 }
141
onWindowDestroyed(ANativeWindow * window)142 void GetTestParamThread::onWindowDestroyed(ANativeWindow *window)
143 {
144 m_platform.getWindowRegistry().destroyWindow(window);
145 }
146
onWindowResized(ANativeWindow * window)147 void GetTestParamThread::onWindowResized(ANativeWindow *window)
148 {
149 // \todo [2013-05-12 pyry] Handle this in some sane way.
150 DE_UNREF(window);
151 tcu::print("Warning: Native window was resized, results may be undefined");
152 }
153
render(void)154 bool GetTestParamThread::render(void)
155 {
156 if (!m_finished)
157 m_finished = !m_app.iterate();
158 return !m_finished;
159 }
160
161 // TestActivity
162
TestActivity(ANativeActivity * activity,glu::ApiType runType)163 TestActivity::TestActivity(ANativeActivity *activity, glu::ApiType runType)
164 : RenderActivity(activity)
165 , m_archive(activity->assetManager)
166 , m_cmdLine(tcu::Android::getIntentStringExtra(activity, "cmdLine"))
167 , m_testThread(*this, m_archive, getWaiverPath(activity), getLogPath(activity), runType, getFlags(activity))
168 , m_started(false)
169 {
170 // Set initial orientation.
171 tcu::Android::setRequestedOrientation(getNativeActivity(),
172 tcu::Android::mapScreenRotation(m_cmdLine.getScreenRotation()));
173
174 // Set up window flags.
175 ANativeActivity_setWindowFlags(activity,
176 AWINDOW_FLAG_KEEP_SCREEN_ON | AWINDOW_FLAG_TURN_SCREEN_ON | AWINDOW_FLAG_FULLSCREEN |
177 AWINDOW_FLAG_SHOW_WHEN_LOCKED,
178 0);
179 }
180
~TestActivity(void)181 TestActivity::~TestActivity(void)
182 {
183 }
184
onStart(void)185 void TestActivity::onStart(void)
186 {
187 if (!m_started)
188 {
189 setThread(&m_testThread);
190 m_testThread.start();
191 m_started = true;
192 }
193
194 RenderActivity::onStart();
195 }
196
onDestroy(void)197 void TestActivity::onDestroy(void)
198 {
199 if (m_started)
200 {
201 setThread(DE_NULL);
202 m_testThread.stop();
203 m_started = false;
204 }
205
206 RenderActivity::onDestroy();
207
208 // Kill this process.
209 tcu::print("Done, killing process");
210 exit(0);
211 }
212
onConfigurationChanged(void)213 void TestActivity::onConfigurationChanged(void)
214 {
215 RenderActivity::onConfigurationChanged();
216
217 // Update rotation.
218 tcu::Android::setRequestedOrientation(getNativeActivity(),
219 tcu::Android::mapScreenRotation(m_cmdLine.getScreenRotation()));
220 }
221
222 // GetTestParamActivity
223
GetTestParamActivity(ANativeActivity * activity,glu::ApiType runType)224 GetTestParamActivity::GetTestParamActivity(ANativeActivity *activity, glu::ApiType runType)
225 : RenderActivity(activity)
226 , m_testThread(*this, getTestRunParamFilePath(activity), runType)
227 , m_started(false)
228 {
229 }
230
~GetTestParamActivity(void)231 GetTestParamActivity::~GetTestParamActivity(void)
232 {
233 }
234
onStart(void)235 void GetTestParamActivity::onStart(void)
236 {
237 if (!m_started)
238 {
239 setThread(&m_testThread);
240 m_testThread.start();
241 m_started = true;
242 }
243
244 RenderActivity::onStart();
245 }
246
onDestroy(void)247 void GetTestParamActivity::onDestroy(void)
248 {
249 if (m_started)
250 {
251 setThread(DE_NULL);
252 m_testThread.stop();
253 m_started = false;
254 }
255
256 RenderActivity::onDestroy();
257
258 // Kill this process.
259 tcu::print("Done, killing GetTestParamActivity process");
260 exit(0);
261 }
262
onConfigurationChanged(void)263 void GetTestParamActivity::onConfigurationChanged(void)
264 {
265 RenderActivity::onConfigurationChanged();
266 }
267
268 } // namespace Android
269 } // namespace glcts
270