2013-05-03 03:53:37 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "scheduler.h"
|
|
|
|
#include "run_test.h"
|
|
|
|
#include "list_file.h"
|
|
|
|
#include "exactness_config.h"
|
2015-06-09 05:52:53 -07:00
|
|
|
#include "exactness_private.h"
|
2013-05-03 03:53:37 -07:00
|
|
|
|
|
|
|
#define LIBEXACTNESS_PATH PACKAGE_LIBDIR "/exactness/libexactness.so"
|
2015-07-29 14:27:19 -07:00
|
|
|
#define RED 0xffff0000
|
|
|
|
#define WHITE 0xffffffff
|
|
|
|
|
|
|
|
static Ecore_Evas *ee = NULL;
|
|
|
|
static Evas_Object *cur_img, *orig_img, *diff_img;
|
2013-05-03 03:53:37 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
run_test_simulation(const List_Entry *ent, char *buf)
|
|
|
|
{
|
2013-05-21 07:33:20 -07:00
|
|
|
snprintf(buf, SCHEDULER_CMD_SIZE, "TSUITE_VERBOSE=%d TSUITE_DEST_DIR='%s' TSUITE_FILE_NAME='%s/%s.rec' TSUITE_TEST_NAME='%s' LD_PRELOAD='%s' %s %s",
|
2013-05-17 07:47:08 -07:00
|
|
|
exactness_config.verbose,
|
2013-05-03 03:53:37 -07:00
|
|
|
exactness_config.dest_dir,
|
|
|
|
exactness_config.base_dir, ent->name,
|
|
|
|
ent->name, LIBEXACTNESS_PATH,
|
2013-05-21 07:33:20 -07:00
|
|
|
exactness_config.wrap_command,
|
2013-05-03 03:53:37 -07:00
|
|
|
ent->command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
run_test_play(const List_Entry *ent, char *buf)
|
|
|
|
{
|
2013-05-21 07:33:20 -07:00
|
|
|
snprintf(buf, SCHEDULER_CMD_SIZE, "TSUITE_VERBOSE=%d ELM_ENGINE='buffer' TSUITE_DEST_DIR='%s/" CURRENT_SUBDIR "' TSUITE_FILE_NAME='%s/%s.rec' TSUITE_TEST_NAME='%s' LD_PRELOAD='%s' %s %s",
|
2013-05-17 07:47:08 -07:00
|
|
|
exactness_config.verbose,
|
2013-05-03 03:53:37 -07:00
|
|
|
exactness_config.dest_dir,
|
|
|
|
exactness_config.base_dir, ent->name,
|
|
|
|
ent->name, LIBEXACTNESS_PATH,
|
2013-05-21 07:33:20 -07:00
|
|
|
exactness_config.wrap_command,
|
2013-05-03 03:53:37 -07:00
|
|
|
ent->command);
|
|
|
|
|
|
|
|
run_test_prefix_rm(CURRENT_SUBDIR, ent->name);
|
2013-06-10 05:44:36 -07:00
|
|
|
if (exactness_config.verbose)
|
|
|
|
{
|
|
|
|
printf("Running %s\n", ent->name);
|
|
|
|
}
|
2013-05-03 03:53:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
run_test_record(const List_Entry *ent, char *buf)
|
|
|
|
{
|
2013-05-21 07:33:20 -07:00
|
|
|
snprintf(buf, SCHEDULER_CMD_SIZE, "TSUITE_VERBOSE=%d TSUITE_RECORDING='rec' TSUITE_DEST_DIR='%s' TSUITE_FILE_NAME='%s/%s.rec' TSUITE_TEST_NAME='%s' LD_PRELOAD='%s' %s %s",
|
2013-05-17 07:47:08 -07:00
|
|
|
exactness_config.verbose,
|
2013-05-03 03:53:37 -07:00
|
|
|
exactness_config.dest_dir,
|
|
|
|
exactness_config.base_dir, ent->name,
|
|
|
|
ent->name, LIBEXACTNESS_PATH,
|
2013-05-21 07:33:20 -07:00
|
|
|
exactness_config.wrap_command,
|
2013-05-03 03:53:37 -07:00
|
|
|
ent->command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
run_test_init(const List_Entry *ent, char *buf)
|
|
|
|
{
|
2013-05-21 07:33:20 -07:00
|
|
|
snprintf(buf, SCHEDULER_CMD_SIZE, "TSUITE_VERBOSE=%d ELM_ENGINE='buffer' TSUITE_DEST_DIR='%s/" ORIG_SUBDIR "' TSUITE_FILE_NAME='%s/%s.rec' TSUITE_TEST_NAME='%s' LD_PRELOAD='%s' %s %s",
|
2013-05-17 07:47:08 -07:00
|
|
|
exactness_config.verbose,
|
2013-05-03 03:53:37 -07:00
|
|
|
exactness_config.dest_dir,
|
|
|
|
exactness_config.base_dir, ent->name,
|
|
|
|
ent->name, LIBEXACTNESS_PATH,
|
2013-05-21 07:33:20 -07:00
|
|
|
exactness_config.wrap_command,
|
2013-05-03 03:53:37 -07:00
|
|
|
ent->command);
|
|
|
|
|
|
|
|
run_test_prefix_rm(ORIG_SUBDIR, ent->name);
|
|
|
|
}
|
|
|
|
|
2015-07-29 14:27:19 -07:00
|
|
|
static Eina_Bool
|
|
|
|
compare(const char *filename1, const char *filename2, const char *diff_file)
|
|
|
|
{
|
|
|
|
Ecore_Evas *diff_ee;
|
|
|
|
Evas_Object *bg, *img;
|
|
|
|
unsigned int *pixels1 = NULL, *pixels2 = NULL, *pixels3 = NULL;
|
|
|
|
int w1, h1, w2, h2, err;
|
|
|
|
unsigned int *i1, *i2, *i3;
|
|
|
|
|
|
|
|
evas_object_image_file_set(cur_img, filename1, NULL);
|
|
|
|
err = evas_object_image_load_error_get(cur_img);
|
|
|
|
if (err != EVAS_LOAD_ERROR_NONE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot load image file %s\n", filename1);
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
evas_object_image_file_set(orig_img, filename2, NULL);
|
|
|
|
err = evas_object_image_load_error_get(orig_img);
|
|
|
|
if (err != EVAS_LOAD_ERROR_NONE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot load image file %s\n", filename2);
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixels1 = (unsigned int *)evas_object_image_data_get(cur_img, EINA_FALSE);
|
|
|
|
pixels2 = (unsigned int *)evas_object_image_data_get(orig_img, EINA_FALSE);
|
|
|
|
evas_object_image_size_get(cur_img, &w1, &h1);
|
|
|
|
evas_object_image_size_get(orig_img, &w2, &h2);
|
|
|
|
if (!pixels1 || !pixels2) goto on_error;
|
|
|
|
if (w1 != w2 || h1 != h2) goto on_error;
|
|
|
|
|
|
|
|
evas_object_image_size_set(diff_img, w1, h1);
|
|
|
|
evas_object_move(diff_img, 0, 0);
|
|
|
|
evas_object_resize(diff_img, w1, h1);
|
|
|
|
diff_ee = ecore_evas_object_ecore_evas_get(diff_img);
|
|
|
|
ecore_evas_resize(diff_ee, w1, h1);
|
|
|
|
|
|
|
|
bg = evas_object_image_add(ecore_evas_get(diff_ee));
|
|
|
|
if (!bg)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot load image object");
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
evas_object_image_filled_set(bg, EINA_TRUE);
|
|
|
|
evas_object_image_size_set(bg, w1, h1);
|
|
|
|
evas_object_image_data_set(bg, pixels2);
|
|
|
|
evas_object_move(bg, 0, 0);
|
|
|
|
evas_object_resize(bg, w1, h1);
|
|
|
|
evas_object_show(bg);
|
|
|
|
|
|
|
|
img = evas_object_image_add(ecore_evas_get(diff_ee));
|
|
|
|
if (!img)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot load image object");
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
evas_object_image_filled_set(img, EINA_TRUE);
|
|
|
|
evas_object_image_alpha_set(img, 1);
|
|
|
|
evas_object_image_size_set(img, w1, h1);
|
|
|
|
pixels3 = (unsigned int *)evas_object_image_data_get(img, EINA_TRUE);
|
|
|
|
if (!pixels3) goto on_error;
|
|
|
|
for (i1 = pixels1, i2 = pixels2, i3 = pixels3; *i1; i1++, i2++, i3++)
|
|
|
|
{
|
|
|
|
if (*i1 != *i2) *i3 = RED;
|
|
|
|
else *i3 = WHITE;
|
|
|
|
}
|
|
|
|
evas_object_move(img, 0, 0);
|
|
|
|
evas_object_resize(img, w1, h1);
|
|
|
|
evas_object_color_set(img, 128, 128, 128, 192);
|
|
|
|
evas_object_show(img);
|
|
|
|
|
|
|
|
ecore_evas_manual_render(diff_ee);
|
|
|
|
if (!evas_object_image_save(diff_img, diff_file, NULL, NULL))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to save image %s\n", diff_file);
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
on_error:
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-03 03:53:37 -07:00
|
|
|
static Eina_Bool
|
2015-05-27 03:41:28 -07:00
|
|
|
_file_sha1_get(const char *filename, unsigned char *result)
|
2013-05-03 03:53:37 -07:00
|
|
|
{
|
2015-05-27 03:41:28 -07:00
|
|
|
Eina_File *f = NULL;
|
|
|
|
const char *key = "0123456789abcde";
|
|
|
|
int key_len = strlen(key);
|
|
|
|
unsigned int size = 0;
|
|
|
|
Eina_Binbuf *buf = NULL;
|
|
|
|
void *data = NULL;
|
|
|
|
|
|
|
|
f = eina_file_open(filename, EINA_FALSE);
|
|
|
|
if (!f) goto false;
|
|
|
|
size = eina_file_size_get(f);
|
|
|
|
if (size < 1) goto false;
|
|
|
|
data = eina_file_map_all(f, EINA_FILE_POPULATE);
|
|
|
|
if (!data) goto false;
|
|
|
|
|
|
|
|
buf = eina_binbuf_manage_new(data, size, EINA_TRUE);
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Could not create Binary Buffer");
|
|
|
|
goto false;
|
|
|
|
}
|
|
|
|
if (!emile_binbuf_sha1(key, key_len, buf, result))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot generate sha1 for image");
|
|
|
|
goto false;
|
|
|
|
}
|
|
|
|
eina_binbuf_free(buf);
|
|
|
|
eina_file_close(f);
|
2013-05-03 03:53:37 -07:00
|
|
|
return EINA_TRUE;
|
2015-05-27 03:41:28 -07:00
|
|
|
|
|
|
|
false:
|
|
|
|
if (buf) eina_binbuf_free(buf);
|
|
|
|
if (f) eina_file_close(f);
|
|
|
|
return EINA_FALSE;
|
2013-05-03 03:53:37 -07:00
|
|
|
}
|
|
|
|
|
2015-05-27 03:41:28 -07:00
|
|
|
#define _DIGEST_SIZE 20
|
2013-05-03 03:53:37 -07:00
|
|
|
static Eina_Bool
|
2015-05-27 03:41:28 -07:00
|
|
|
_is_equal(const char *filename1, const char *filename2)
|
2013-05-03 03:53:37 -07:00
|
|
|
{
|
2015-05-27 03:41:28 -07:00
|
|
|
unsigned char res1[_DIGEST_SIZE], res2[_DIGEST_SIZE];
|
|
|
|
if (!_file_sha1_get(filename1, res1))
|
2013-05-03 03:53:37 -07:00
|
|
|
return EINA_FALSE;
|
2015-05-27 03:41:28 -07:00
|
|
|
if (!_file_sha1_get(filename2, res2))
|
2013-05-03 03:53:37 -07:00
|
|
|
return EINA_FALSE;
|
2015-05-27 03:41:28 -07:00
|
|
|
return !memcmp(res1, res2, _DIGEST_SIZE);
|
2013-05-03 03:53:37 -07:00
|
|
|
}
|
|
|
|
|
2015-06-09 05:52:53 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_check_prefix(const char *prefix, const char *name)
|
|
|
|
{
|
|
|
|
unsigned int len = strlen(prefix);
|
|
|
|
return (!strncmp(name, prefix, len) && (strlen(name) > len) && (name[len] == SHOT_DELIMITER));
|
|
|
|
}
|
|
|
|
|
2013-05-03 03:53:37 -07:00
|
|
|
static void
|
|
|
|
_compare_list_cb(const char *name, const char *path EINA_UNUSED, void *data)
|
|
|
|
{
|
|
|
|
const char *prefix = data;
|
2015-06-09 05:52:53 -07:00
|
|
|
if (_check_prefix(prefix, name))
|
2013-05-03 03:53:37 -07:00
|
|
|
{
|
|
|
|
char filename1[EXACTNESS_PATH_MAX], filename2[EXACTNESS_PATH_MAX];
|
2013-05-09 04:55:24 -07:00
|
|
|
snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s/%s", exactness_config.dest_dir, CURRENT_SUBDIR, name);
|
|
|
|
snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", exactness_config.dest_dir, ORIG_SUBDIR, name);
|
2015-05-27 03:41:28 -07:00
|
|
|
if (!_is_equal(filename1, filename2))
|
2013-05-03 03:53:37 -07:00
|
|
|
{
|
2015-07-29 14:27:19 -07:00
|
|
|
char diff_file[EXACTNESS_PATH_MAX];
|
2013-05-03 03:53:37 -07:00
|
|
|
exactness_ctx.compare_errors =
|
|
|
|
eina_list_append(exactness_ctx.compare_errors,
|
|
|
|
strdup(name));
|
|
|
|
|
2015-07-29 14:27:19 -07:00
|
|
|
snprintf(diff_file, EXACTNESS_PATH_MAX, "%s/%s/comp_%s", exactness_config.dest_dir,
|
|
|
|
CURRENT_SUBDIR, name);
|
|
|
|
if (compare(filename1, filename2, diff_file))
|
2013-05-03 03:53:37 -07:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed image comparing '%s'\n", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
run_test_compare(const List_Entry *ent)
|
|
|
|
{
|
2013-05-09 04:55:24 -07:00
|
|
|
char origdir[EXACTNESS_PATH_MAX];
|
2015-07-29 14:27:19 -07:00
|
|
|
|
2013-05-09 04:55:24 -07:00
|
|
|
snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", exactness_config.dest_dir, ORIG_SUBDIR);
|
2015-07-29 14:27:19 -07:00
|
|
|
ee = ecore_evas_buffer_new(1, 1);
|
|
|
|
if (!ee) goto on_error;
|
|
|
|
cur_img = evas_object_image_add(ecore_evas_get(ee));
|
|
|
|
orig_img = evas_object_image_add(ecore_evas_get(ee));
|
|
|
|
diff_img = ecore_evas_object_image_new(ee);
|
|
|
|
if (!diff_img)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot load image object\n");
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
evas_object_image_filled_set(diff_img, EINA_TRUE);
|
2013-05-09 04:55:24 -07:00
|
|
|
eina_file_dir_list(origdir, 0, _compare_list_cb, ent->name);
|
2015-07-29 14:27:19 -07:00
|
|
|
|
|
|
|
on_error:
|
|
|
|
if (ee) ecore_evas_free(ee);
|
2013-05-03 03:53:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_prefix_rm_cb(const char *name, const char *path, void *data)
|
|
|
|
{
|
|
|
|
const char *prefix = data;
|
2015-06-09 05:52:53 -07:00
|
|
|
if (_check_prefix(prefix, name))
|
2013-05-03 03:53:37 -07:00
|
|
|
{
|
|
|
|
char buf[EXACTNESS_PATH_MAX];
|
|
|
|
snprintf(buf, EXACTNESS_PATH_MAX, "%s/%s", path, name);
|
|
|
|
if (unlink(buf))
|
|
|
|
{
|
|
|
|
printf("Failed deleting '%s/%s': ", path, name);
|
|
|
|
perror("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
run_test_prefix_rm(const char *dir, const char *prefix)
|
|
|
|
{
|
|
|
|
eina_file_dir_list(dir, 0, _prefix_rm_cb, (void *) prefix);
|
|
|
|
}
|