summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2018-05-18 17:23:06 +0300
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2018-05-20 21:29:45 +0300
commit7337672562154e53313aceb9d9af9fe62309682a (patch)
treea3b7444ce073e09368a942f0cdeff9ca16988b18
parenta1341ac74cf32e8893d6d69250e7fbf44cbf7548 (diff)
Compare the shots directly after the test to speed up
The problem that we try to solve is the time taken to compare the shots after all the scenarios have been run. Now, comparing the shots sequentially is done right after the test finished to run. With -j 1, it won't change anything. With more CPUs, it will compare while other tests are running, i.e when the CPU is not too much busy.
-rw-r--r--src/bin/exactness.c298
1 files changed, 152 insertions, 146 deletions
diff --git a/src/bin/exactness.c b/src/bin/exactness.c
index 87606f1..09d0bb3 100644
--- a/src/bin/exactness.c
+++ b/src/bin/exactness.c
@@ -57,6 +57,145 @@ _printf(int verbose, const char *fmt, ...)
57 va_end(ap); 57 va_end(ap);
58} 58}
59 59
60static Exactness_Image *
61_image_load(const char *filename)
62{
63 int w, h;
64 Evas_Load_Error err;
65 Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
66 Eo *e = ecore_evas_get(ee);
67
68 Eo *img = evas_object_image_add(e);
69 evas_object_image_file_set(img, filename, NULL);
70 err = evas_object_image_load_error_get(img);
71 if (err != EVAS_LOAD_ERROR_NONE)
72 {
73 fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
74 filename, evas_load_error_str(err));
75 return NULL;
76 }
77
78 Exactness_Image *ex_img = malloc(sizeof(*ex_img));
79 int len;
80 evas_object_image_size_get(img, &w, &h);
81 ex_img->w = w;
82 ex_img->h = h;
83 len = w * h * 4;
84 ex_img->pixels = malloc(len);
85 memcpy(ex_img->pixels, evas_object_image_data_get(img, EINA_FALSE), len);
86
87 ecore_evas_free(ee);
88 return ex_img;
89}
90
91static void
92_image_save(Exactness_Image *ex_img, const char *output)
93{
94 Ecore_Evas *ee;
95 Eo *e, *img;
96 ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
97 e = ecore_evas_get(ee);
98 img = evas_object_image_add(e);
99 evas_object_image_size_set(img, ex_img->w, ex_img->h);
100 evas_object_image_data_set(img, ex_img->pixels);
101 evas_object_image_save(img, output, NULL, NULL);
102 ecore_evas_free(ee);
103}
104
105static void
106_file_compare(const char *orig_dir, const char *ent_name)
107{
108 char filename1[EXACTNESS_PATH_MAX], filename2[EXACTNESS_PATH_MAX];
109 Exactness_Image *img1, *img2, *imgO = NULL;
110 snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s", orig_dir, ent_name);
111 snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ent_name);
112
113 img1 = _image_load(filename1);
114 img2 = _image_load(filename2);
115
116 if (exactness_image_compare(img1, img2, &imgO))
117 {
118 char buf[EXACTNESS_PATH_MAX];
119 snprintf(buf, EXACTNESS_PATH_MAX, "%s/%s/comp_%s", _dest_dir, CURRENT_SUBDIR, ent_name);
120 _image_save(imgO, buf);
121 _compare_errors = eina_list_append(_compare_errors, strdup(ent_name));
122 }
123 exactness_image_free(img1);
124 exactness_image_free(img2);
125 exactness_image_free(imgO);
126}
127
128static void
129_exu_imgs_unpack(const char *exu_path, const char *dir, const char *ent_name)
130{
131 Exactness_Unit *unit = exactness_unit_file_read(exu_path);
132 Exactness_Image *img;
133 Eina_List *itr;
134 Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
135 Eo *e = ecore_evas_get(ee);
136 int n = 1;
137 if (!unit) return;
138 EINA_LIST_FOREACH(unit->imgs, itr, img)
139 {
140 char filename[EXACTNESS_PATH_MAX];
141 Eo *o = evas_object_image_add(e);
142 snprintf(filename, EXACTNESS_PATH_MAX, "%s/%s%c%.3d.png",
143 dir, ent_name, SHOT_DELIMITER, n++);
144 evas_object_image_size_set(o, img->w, img->h);
145 evas_object_image_data_set(o, img->pixels);
146 if (!evas_object_image_save(o, filename, NULL, NULL))
147 {
148 printf("Cannot save widget to <%s>\n", filename);
149 }
150 efl_del(o);
151 }
152 efl_del(e);
153 ecore_evas_free(ee);
154}
155
156static void
157_run_test_compare(const List_Entry *ent)
158{
159 char path[2*EXACTNESS_PATH_MAX];
160 char origdir[EXACTNESS_PATH_MAX];
161 const char *base_dir;
162 Eina_List *itr;
163 int n = 1;
164 EINA_LIST_FOREACH(_base_dirs, itr, base_dir)
165 {
166 sprintf(path, "%s/%s.exu", base_dir, ent->name);
167 if (ecore_file_exists(path))
168 {
169 char currentdir[EXACTNESS_PATH_MAX];
170 snprintf(currentdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, CURRENT_SUBDIR);
171 _exu_imgs_unpack(path, currentdir, ent->name);
172 snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ORIG_SUBDIR);
173 mkdir(origdir, 0744);
174 _exu_imgs_unpack(path, origdir, ent->name);
175 goto found;
176 }
177 else
178 {
179 sprintf(path, "%s/%s.rec", base_dir, ent->name);
180 if (!ecore_file_exists(path)) return;
181 snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, ORIG_SUBDIR);
182 goto found;
183 }
184 }
185found:
186 do
187 {
188 sprintf(path, "%s/%s%c%.3d.png", origdir, ent->name, SHOT_DELIMITER, n);
189 if (ecore_file_exists(path))
190 {
191 sprintf(path, "%s%c%.3d.png", ent->name, SHOT_DELIMITER, n);
192 _file_compare(origdir, path);
193 }
194 else break;
195 n++;
196 } while (EINA_TRUE);
197}
198
60#define CONFIG "ELM_SCALE=1 ELM_FINGER_SIZE=10" 199#define CONFIG "ELM_SCALE=1 ELM_FINGER_SIZE=10"
61static Eina_Bool 200static Eina_Bool
62_run_command_prepare(const List_Entry *ent, char *buf) 201_run_command_prepare(const List_Entry *ent, char *buf)
@@ -140,27 +279,33 @@ _run_test_prefix_rm(const char *dir, const char *prefix)
140 eina_file_dir_list(dir, 0, _prefix_rm_cb, (void *) prefix); 279 eina_file_dir_list(dir, 0, _prefix_rm_cb, (void *) prefix);
141} 280}
142 281
282static void
283_job_compare(void *data)
284{
285 _run_test_compare(data);
286
287 /* If all jobs are done. */
288 if (!_running_jobs) ecore_main_loop_quit();
289}
290
143static Eina_Bool 291static Eina_Bool
144_job_deleted_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) 292_job_deleted_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
145{ 293{
146 Ecore_Exe_Event_Del *msg = (Ecore_Exe_Event_Del *) event; 294 Ecore_Exe_Event_Del *msg = (Ecore_Exe_Event_Del *) event;
295 List_Entry *ent = ecore_exe_data_get(msg->exe);
147 296
148 if ((msg->exit_code != 0) || (msg->exit_signal != 0)) 297 if ((msg->exit_code != 0) || (msg->exit_signal != 0))
149 { 298 {
150 List_Entry *ent = ecore_exe_data_get(msg->exe);
151 _errors = eina_list_append(_errors, ent); 299 _errors = eina_list_append(_errors, ent);
152 } 300 }
153 301
302 ecore_job_add(_job_compare, ent);
154 _running_jobs--; 303 _running_jobs--;
155 304
156 _job_consume(); 305 _job_consume();
157 306
158 /* If all jobs are done. */ 307 /* If all jobs are done. */
159 if (!_running_jobs) 308 if (!_running_jobs) return ECORE_CALLBACK_DONE;
160 {
161 ecore_main_loop_quit();
162 return ECORE_CALLBACK_DONE;
163 }
164 309
165 return ECORE_CALLBACK_RENEW; 310 return ECORE_CALLBACK_RENEW;
166} 311}
@@ -220,145 +365,6 @@ _scheduler_run()
220 while (_job_consume()); 365 while (_job_consume());
221} 366}
222 367
223static Exactness_Image *
224_image_load(const char *filename)
225{
226 int w, h;
227 Evas_Load_Error err;
228 Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
229 Eo *e = ecore_evas_get(ee);
230
231 Eo *img = evas_object_image_add(e);
232 evas_object_image_file_set(img, filename, NULL);
233 err = evas_object_image_load_error_get(img);
234 if (err != EVAS_LOAD_ERROR_NONE)
235 {
236 fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
237 filename, evas_load_error_str(err));
238 return NULL;
239 }
240
241 Exactness_Image *ex_img = malloc(sizeof(*ex_img));
242 int len;
243 evas_object_image_size_get(img, &w, &h);
244 ex_img->w = w;
245 ex_img->h = h;
246 len = w * h * 4;
247 ex_img->pixels = malloc(len);
248 memcpy(ex_img->pixels, evas_object_image_data_get(img, EINA_FALSE), len);
249
250 ecore_evas_free(ee);
251 return ex_img;
252}
253
254static void
255_image_save(Exactness_Image *ex_img, const char *output)
256{
257 Ecore_Evas *ee;
258 Eo *e, *img;
259 ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
260 e = ecore_evas_get(ee);
261 img = evas_object_image_add(e);
262 evas_object_image_size_set(img, ex_img->w, ex_img->h);
263 evas_object_image_data_set(img, ex_img->pixels);
264 evas_object_image_save(img, output, NULL, NULL);
265 ecore_evas_free(ee);
266}
267
268static void
269_file_compare(const char *orig_dir, const char *ent_name)
270{
271 char filename1[EXACTNESS_PATH_MAX], filename2[EXACTNESS_PATH_MAX];
272 Exactness_Image *img1, *img2, *imgO = NULL;
273 snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s", orig_dir, ent_name);
274 snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ent_name);
275
276 img1 = _image_load(filename1);
277 img2 = _image_load(filename2);
278
279 if (exactness_image_compare(img1, img2, &imgO))
280 {
281 char buf[EXACTNESS_PATH_MAX];
282 snprintf(buf, EXACTNESS_PATH_MAX, "%s/%s/comp_%s", _dest_dir, CURRENT_SUBDIR, ent_name);
283 _image_save(imgO, buf);
284 _compare_errors = eina_list_append(_compare_errors, strdup(ent_name));
285 }
286 exactness_image_free(img1);
287 exactness_image_free(img2);
288 exactness_image_free(imgO);
289}
290
291static void
292_exu_imgs_unpack(const char *exu_path, const char *dir, const char *ent_name)
293{
294 Exactness_Unit *unit = exactness_unit_file_read(exu_path);
295 Exactness_Image *img;
296 Eina_List *itr;
297 Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
298 Eo *e = ecore_evas_get(ee);
299 int n = 1;
300 if (!unit) return;
301 EINA_LIST_FOREACH(unit->imgs, itr, img)
302 {
303 char filename[EXACTNESS_PATH_MAX];
304 Eo *o = evas_object_image_add(e);
305 snprintf(filename, EXACTNESS_PATH_MAX, "%s/%s%c%.3d.png",
306 dir, ent_name, SHOT_DELIMITER, n++);
307 evas_object_image_size_set(o, img->w, img->h);
308 evas_object_image_data_set(o, img->pixels);
309 if (!evas_object_image_save(o, filename, NULL, NULL))
310 {
311 printf("Cannot save widget to <%s>\n", filename);
312 }
313 efl_del(o);
314 }
315 efl_del(e);
316 ecore_evas_free(ee);
317}
318
319static void
320_run_test_compare(const List_Entry *ent)
321{
322 char path[2*EXACTNESS_PATH_MAX];
323 char origdir[EXACTNESS_PATH_MAX];
324 const char *base_dir;
325 Eina_List *itr;
326 int n = 1;
327 EINA_LIST_FOREACH(_base_dirs, itr, base_dir)
328 {
329 sprintf(path, "%s/%s.exu", base_dir, ent->name);
330 if (ecore_file_exists(path))
331 {
332 char currentdir[EXACTNESS_PATH_MAX];
333 snprintf(currentdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, CURRENT_SUBDIR);
334 _exu_imgs_unpack(path, currentdir, ent->name);
335 snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s/%s", _dest_dir, CURRENT_SUBDIR, ORIG_SUBDIR);
336 mkdir(origdir, 0744);
337 _exu_imgs_unpack(path, origdir, ent->name);
338 goto found;
339 }
340 else
341 {
342 sprintf(path, "%s/%s.rec", base_dir, ent->name);
343 if (!ecore_file_exists(path)) return;
344 snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", _dest_dir, ORIG_SUBDIR);
345 goto found;
346 }
347 }
348found:
349 do
350 {
351 sprintf(path, "%s/%s%c%.3d.png", origdir, ent->name, SHOT_DELIMITER, n);
352 if (ecore_file_exists(path))
353 {
354 sprintf(path, "%s%c%.3d.png", ent->name, SHOT_DELIMITER, n);
355 _file_compare(origdir, path);
356 }
357 else break;
358 n++;
359 } while (EINA_TRUE);
360}
361
362static List_Entry * 368static List_Entry *
363_list_file_load(const char *filename) 369_list_file_load(const char *filename)
364{ 370{
@@ -582,7 +588,7 @@ main(int argc, char *argv[])
582 588
583 /* Results */ 589 /* Results */
584 printf("*******************************************************\n"); 590 printf("*******************************************************\n");
585 if (mode_play) 591 if (mode_play && EINA_FALSE)
586 { 592 {
587 List_Entry *list_itr; 593 List_Entry *list_itr;
588 594