summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-10-14 17:30:25 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-10-14 20:14:51 +0900
commit93298d6dc2360ef91009ef88a76e3cb0336c0235 (patch)
tree4a9a06fa9a8a13643b05b0f262ff901da1628f51
parenta23fcb8b71a6a849b429f7501b433d7dc1daf470 (diff)
Evas GL: Add a test case for Evas GL (make check)
For now this only covers SOME of Evas GL's functions. It will try to run with opengl_x11 and buffer (OSMesa). It'll also try to fail silently if the engine initialization failed, or if OSMesa could not be found. If the engines work, then Evas GL must work properly.
-rw-r--r--src/Makefile_Evas.am1
-rw-r--r--src/tests/evas/evas_suite.c1
-rw-r--r--src/tests/evas/evas_suite.h1
-rw-r--r--src/tests/evas/evas_test_evasgl.c250
4 files changed, 253 insertions, 0 deletions
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index 71cd5974be..0e08495fa4 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -2127,6 +2127,7 @@ tests/evas/evas_test_filters.c \
2127tests/evas/evas_test_image.c \ 2127tests/evas/evas_test_image.c \
2128tests/evas/evas_test_mesh.c \ 2128tests/evas/evas_test_mesh.c \
2129tests/evas/evas_test_mask.c \ 2129tests/evas/evas_test_mask.c \
2130tests/evas/evas_test_evasgl.c \
2130tests/evas/evas_tests_helpers.h \ 2131tests/evas/evas_tests_helpers.h \
2131tests/evas/evas_suite.h 2132tests/evas/evas_suite.h
2132 2133
diff --git a/src/tests/evas/evas_suite.c b/src/tests/evas/evas_suite.c
index 7b087bbaae..242215f65d 100644
--- a/src/tests/evas/evas_suite.c
+++ b/src/tests/evas/evas_suite.c
@@ -28,6 +28,7 @@ static const Evas_Test_Case etc[] = {
28 { "Images", evas_test_image_object }, 28 { "Images", evas_test_image_object },
29 { "Meshes", evas_test_mesh }, 29 { "Meshes", evas_test_mesh },
30 { "Masking", evas_test_mask }, 30 { "Masking", evas_test_mask },
31 { "Evas GL", evas_test_evasgl },
31 { NULL, NULL } 32 { NULL, NULL }
32}; 33};
33 34
diff --git a/src/tests/evas/evas_suite.h b/src/tests/evas/evas_suite.h
index 645f758081..574bdc2969 100644
--- a/src/tests/evas/evas_suite.h
+++ b/src/tests/evas/evas_suite.h
@@ -13,5 +13,6 @@ void evas_test_filters(TCase *tc);
13void evas_test_image_object(TCase *tc); 13void evas_test_image_object(TCase *tc);
14void evas_test_mesh(TCase *tc); 14void evas_test_mesh(TCase *tc);
15void evas_test_mask(TCase *tc); 15void evas_test_mask(TCase *tc);
16void evas_test_evasgl(TCase *tc);
16 17
17#endif /* _EVAS_SUITE_H */ 18#endif /* _EVAS_SUITE_H */
diff --git a/src/tests/evas/evas_test_evasgl.c b/src/tests/evas/evas_test_evasgl.c
new file mode 100644
index 0000000000..af840b5da1
--- /dev/null
+++ b/src/tests/evas/evas_test_evasgl.c
@@ -0,0 +1,250 @@
1/* Test Evas GL EAPIs.
2 *
3 * This will try with opengl_x11 and buffer (OSMesa) and silently fail if
4 * the engine or the GL library can't be initialized. This is to test Evas GL
5 * APIs when they can actually work, ie. when OSMesa exists or when the engine
6 * is GL.
7 */
8
9#ifdef HAVE_CONFIG_H
10# include "config.h"
11#endif
12
13#include <stdio.h>
14#include <dlfcn.h>
15
16#define EFL_GFX_FILTER_BETA
17#include "evas_suite.h"
18#include "Evas.h"
19#include "Evas_GL.h"
20#include "Ecore_Evas.h"
21
22static int
23_detect_osmesa(void)
24{
25 /* assume that if libOSMesa.so links, then we can create an Evas GL */
26 void *lib = dlopen("libOSMesa.so", RTLD_NOW);
27 if (!lib)
28 {
29 printf("Could not find OSMesa! Skipping Evas GL tests.\n");
30 return 0;
31 }
32 dlclose(lib);
33 return 1;
34}
35
36#define START_EVASGL_TEST(engine, options) \
37 Ecore_Evas *ee; Evas *evas; Evas_Object *im = NULL; \
38 if (!strcmp(engine, "buffer") && !_detect_osmesa()) return; \
39 putenv("EVAS_GL_API_DEBUG=1"); \
40 evas_init(); \
41 ecore_evas_init(); \
42 ee = ecore_evas_new(engine, 0, 0, 1, 1, options); \
43 if (!ee) { printf("Could not create ecore evas. Skipping Evas GL tests.\n"); \
44 goto init_failed; } \
45 ecore_evas_show(ee); \
46 ecore_evas_manual_render_set(ee, EINA_TRUE); \
47 evas = ecore_evas_get(ee); \
48 im = evas_object_image_filled_add(evas); \
49 evas_object_geometry_set(im, 0, 0, 1, 1); \
50 evas_object_show(im); \
51 ecore_evas_manual_render(ee); \
52 do {} while (0)
53
54#define END_EVASGL_TEST() \
55 init_failed: \
56 evas_object_del(im); \
57 ecore_evas_free(ee); \
58 ecore_evas_shutdown(); \
59 evas_shutdown(); \
60 do {} while (0)
61
62static void
63_test_evasgl_init(const char *engine, const char *options)
64{
65 START_EVASGL_TEST(engine, options);
66 Evas_GL_Context *ctx;
67 Evas_GL_Surface *sfc;
68 Evas_GL_Config *cfg;
69 Evas_GL_API *gl;
70 Evas_GL *evgl;
71
72 fail_if(!(evgl = evas_gl_new(evas)));
73 fail_if(!(cfg = evas_gl_config_new()));
74 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
75 fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
76
77 /* valid current states */
78 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
79 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
80 fail_if(!evas_gl_make_current(evgl, NULL, ctx));
81
82 /* no context but surface: invalid */
83 fprintf(stderr, "================ IGNORE ERRORS BEGIN ================\n");
84 fail_if(evas_gl_make_current(evgl, sfc, NULL) != EINA_FALSE);
85 fprintf(stderr, "================ IGNORE ERRORS END ================\n");
86
87 /* API verification */
88 fail_if(!(gl = evas_gl_api_get(evgl)));
89
90 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
91 evas_gl_context_destroy(evgl, ctx);
92 evas_gl_surface_destroy(evgl, sfc);
93 evas_gl_config_free(cfg);
94 evas_gl_free(evgl);
95
96 END_EVASGL_TEST();
97}
98
99static void
100_test_evasgl_current_get(const char *engine, const char *options)
101{
102 if (!_detect_osmesa())
103 return;
104
105 START_EVASGL_TEST(engine, options);
106 Evas_GL_Context *ctx, *ctx2;
107 Evas_GL_Surface *sfc, *sfc2;
108 Evas_GL_Config *cfg;
109 Evas_GL *evgl, *evgl2;
110
111 ctx2 = (void*)(intptr_t)0x1;
112 sfc2 = (void*)(intptr_t)0x1;
113 evgl2 = evas_gl_current_evas_gl_get(&ctx2, &sfc2);
114 fail_if(evgl2 || ctx2 || sfc2);
115
116 fail_if(!(evgl = evas_gl_new(evas)));
117 fail_if(!(cfg = evas_gl_config_new()));
118 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
119 fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
120
121 ctx2 = (void*)(intptr_t)0x1;
122 sfc2 = (void*)(intptr_t)0x1;
123 evgl2 = evas_gl_current_evas_gl_get(&ctx2, &sfc2);
124 fail_if(evgl2 || ctx2 || sfc2);
125
126 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
127 evgl2 = evas_gl_current_evas_gl_get(&ctx2, &sfc2);
128 fail_if(evgl2 != evgl);
129 fail_if(sfc2 != sfc);
130 fail_if(ctx2 != ctx);
131
132 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
133 evgl2 = evas_gl_current_evas_gl_get(&ctx2, &sfc2);
134 fail_if(evgl2 != evgl); /* this should not reset current Evas GL */
135 fail_if(sfc2 != NULL);
136 fail_if(ctx2 != NULL);
137
138 evas_gl_context_destroy(evgl, ctx);
139 evas_gl_surface_destroy(evgl, sfc);
140 evas_gl_free(evgl);
141 END_EVASGL_TEST();
142}
143
144static void
145_test_evasgl_context_version(const char *engine, const char *options)
146{
147 if (!_detect_osmesa())
148 return;
149
150 START_EVASGL_TEST(engine, options);
151 Evas_GL_Context *ctx, *ctx2;
152 Evas_GL_Surface *sfc;
153 Evas_GL_Config *cfg;
154 Evas_GL_API *gl;
155 Evas_GL *evgl;
156 const char *ver, *ext, *glsl;
157 int vmaj, vmin;
158
159 fail_if(!(evgl = evas_gl_new(evas)));
160 fail_if(!(cfg = evas_gl_config_new()));
161 fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
162
163 /* test only GLES 2 - GLES 3 and GLES 1 not supported yet with OSMesa */
164 fail_if(!(ctx = evas_gl_context_version_create(evgl, NULL, EVAS_GL_GLES_2_X)));
165 fail_if(!(gl = evas_gl_api_get(evgl)));
166 fail_if(gl->version != EVAS_GL_API_VERSION); /* valid for make check */
167
168 fail_if(!evas_gl_make_current(evgl, sfc, ctx));
169 fail_if(!(ver = (const char *) gl->glGetString(GL_VERSION)));
170 printf("GL_VERSION: %s\n", ver);
171 fail_if(sscanf(ver, "OpenGL ES %d.%d", &vmaj, &vmin) != 2);
172 fail_if((vmaj < 2) || (vmin < 0));
173
174 /* verify function pointers - GLES 2 only */
175 typedef void (*fptr_t)();
176 const int idx_glViewport = ((char*) &gl->glViewport - (char*) &gl->glActiveTexture) / sizeof(fptr_t);
177 fptr_t *fptr= &gl->glActiveTexture;
178 for (int i = 0; i < idx_glViewport; i++, fptr++)
179 fail_if(!*fptr);
180
181 /* mesa supports a ton of extensions but there are no extra pointers set in
182 * Evas_GL_API for those extensions */
183 fail_if(!(ext = (const char *) gl->glGetString(GL_EXTENSIONS)));
184 printf("GL_EXTENSIONS: %s\n", ext);
185
186 /* GLSL string format check */
187 fail_if(!(glsl = (const char *) gl->glGetString(GL_SHADING_LANGUAGE_VERSION)));
188 printf("GL_SHADING_LANGUAGE_VERSION: %s\n", glsl);
189 fail_if(sscanf(glsl, "OpenGL ES GLSL ES %d", &vmaj) != 1);
190
191 /* shared ctx */
192 fail_if(!(ctx2 = evas_gl_context_version_create(evgl, ctx, EVAS_GL_GLES_2_X)));
193 evas_gl_context_destroy(evgl, ctx2);
194
195 fail_if(!evas_gl_make_current(evgl, NULL, NULL));
196 evas_gl_context_destroy(evgl, ctx);
197 evas_gl_surface_destroy(evgl, sfc);
198 evas_gl_free(evgl);
199 END_EVASGL_TEST();
200}
201
202START_TEST(evas_test_evasgl_init_opengl_x11)
203{
204 _test_evasgl_init("opengl_x11", NULL);
205}
206END_TEST
207
208START_TEST(evas_test_evasgl_current_get_opengl_x11)
209{
210 _test_evasgl_current_get("opengl_x11", NULL);
211}
212END_TEST
213
214START_TEST(evas_test_evasgl_context_version_opengl_x11)
215{
216 _test_evasgl_context_version("opengl_x11", NULL);
217}
218END_TEST
219
220START_TEST(evas_test_evasgl_init_buffer)
221{
222 _test_evasgl_init("buffer", NULL);
223}
224END_TEST
225
226START_TEST(evas_test_evasgl_current_get_buffer)
227{
228 _test_evasgl_current_get("buffer", NULL);
229}
230END_TEST
231
232START_TEST(evas_test_evasgl_context_version_buffer)
233{
234 _test_evasgl_context_version("buffer", NULL);
235}
236END_TEST
237
238void evas_test_evasgl(TCase *tc)
239{
240 if (getenv("DISPLAY"))
241 {
242 tcase_add_test(tc, evas_test_evasgl_init_opengl_x11);
243 tcase_add_test(tc, evas_test_evasgl_current_get_opengl_x11);
244 tcase_add_test(tc, evas_test_evasgl_context_version_opengl_x11);
245 }
246
247 tcase_add_test(tc, evas_test_evasgl_init_buffer);
248 tcase_add_test(tc, evas_test_evasgl_current_get_buffer);
249 tcase_add_test(tc, evas_test_evasgl_context_version_buffer);
250}