232 lines
6.5 KiB
C
232 lines
6.5 KiB
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "scheduler.h"
|
|
#include "run_test.h"
|
|
#include "list_file.h"
|
|
#include "exactness_config.h"
|
|
#include "exactness_private.h"
|
|
|
|
#include "tsuite_file_data.h"
|
|
|
|
#define CONFIG "ELM_SCALE=1 ELM_FINGER_SIZE=10"
|
|
|
|
typedef enum
|
|
{
|
|
RUN_SIMULATION,
|
|
RUN_PLAY,
|
|
RUN_RECORD,
|
|
RUN_INIT
|
|
} Run_Mode;
|
|
|
|
static void
|
|
_run_command_prepare(const List_Entry *ent, Run_Mode mode, char *buf)
|
|
{
|
|
Eina_Strbuf *sbuf = eina_strbuf_new();
|
|
eina_strbuf_append_printf(sbuf, "TSUITE_VERBOSE=%d ", exactness_config.verbose);
|
|
eina_strbuf_append_printf(sbuf, "TSUITE_FILE_NAME='%s/%s.rec' ",
|
|
exactness_config.base_dir, ent->name);
|
|
eina_strbuf_append_printf(sbuf, "TSUITE_TEST_NAME='%s' ", ent->name);
|
|
switch (mode)
|
|
{
|
|
case RUN_SIMULATION:
|
|
{
|
|
break;
|
|
}
|
|
case RUN_PLAY:
|
|
{
|
|
eina_strbuf_append(sbuf, "ELM_ENGINE='buffer' ");
|
|
eina_strbuf_append_printf(sbuf, "TSUITE_DEST_DIR='%s/%s' ",
|
|
exactness_config.dest_dir, CURRENT_SUBDIR);
|
|
if (exactness_config.store_objects)
|
|
eina_strbuf_append(sbuf, "TSUITE_STORE_OBJECTS=1 ");
|
|
break;
|
|
}
|
|
case RUN_INIT:
|
|
{
|
|
eina_strbuf_append(sbuf, "ELM_ENGINE='buffer' ");
|
|
eina_strbuf_append_printf(sbuf, "TSUITE_DEST_DIR='%s/%s' ",
|
|
exactness_config.dest_dir, ORIG_SUBDIR);
|
|
if (exactness_config.store_objects)
|
|
eina_strbuf_append(sbuf, "TSUITE_STORE_OBJECTS=1 ");
|
|
break;
|
|
}
|
|
case RUN_RECORD:
|
|
{
|
|
eina_strbuf_append_printf(sbuf, "TSUITE_DEST_DIR='%s' ",
|
|
exactness_config.dest_dir);
|
|
break;
|
|
}
|
|
default: break;
|
|
}
|
|
eina_strbuf_append_printf(sbuf, "LD_PRELOAD='%s/exactness/libexactness_%s.so' %s %s %s",
|
|
PACKAGE_LIBDIR, mode == RUN_RECORD ? "recorder" : "player",
|
|
CONFIG, exactness_config.wrap_command, ent->command);
|
|
strncpy(buf, eina_strbuf_string_get(sbuf), SCHEDULER_CMD_SIZE-1);
|
|
eina_strbuf_free(sbuf);
|
|
if (exactness_config.verbose) printf("Command: %s\n", buf);
|
|
}
|
|
|
|
void
|
|
run_test_simulation(const List_Entry *ent, char *buf)
|
|
{
|
|
_run_command_prepare(ent, RUN_SIMULATION, buf);
|
|
}
|
|
|
|
void
|
|
run_test_play(const List_Entry *ent, char *buf)
|
|
{
|
|
_run_command_prepare(ent, RUN_PLAY, buf);
|
|
|
|
run_test_prefix_rm(CURRENT_SUBDIR, ent->name);
|
|
if (exactness_config.verbose)
|
|
{
|
|
printf("Running %s\n", ent->name);
|
|
}
|
|
}
|
|
|
|
void
|
|
run_test_record(const List_Entry *ent, char *buf)
|
|
{
|
|
_run_command_prepare(ent, RUN_RECORD, buf);
|
|
}
|
|
|
|
void
|
|
run_test_init(const List_Entry *ent, char *buf)
|
|
{
|
|
_run_command_prepare(ent, RUN_INIT, buf);
|
|
|
|
run_test_prefix_rm(ORIG_SUBDIR, ent->name);
|
|
}
|
|
|
|
static Eina_Bool
|
|
_file_sha1_get(const char *filename, unsigned char *result)
|
|
{
|
|
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_hmac_sha1(key, key_len, buf, result))
|
|
{
|
|
fprintf(stderr, "Cannot generate sha1 for image");
|
|
goto false;
|
|
}
|
|
eina_binbuf_free(buf);
|
|
eina_file_close(f);
|
|
return EINA_TRUE;
|
|
|
|
false:
|
|
if (buf) eina_binbuf_free(buf);
|
|
if (f) eina_file_close(f);
|
|
return EINA_FALSE;
|
|
}
|
|
|
|
#define _DIGEST_SIZE 20
|
|
static Eina_Bool
|
|
_is_equal(const char *filename1, const char *filename2)
|
|
{
|
|
unsigned char res1[_DIGEST_SIZE], res2[_DIGEST_SIZE];
|
|
if (!_file_sha1_get(filename1, res1))
|
|
return EINA_FALSE;
|
|
if (!_file_sha1_get(filename2, res2))
|
|
return EINA_FALSE;
|
|
|
|
return !memcmp(res1, res2, _DIGEST_SIZE);
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
static void
|
|
_compare_list_cb(const char *name, const char *path EINA_UNUSED, void *data)
|
|
{
|
|
const char *prefix = data;
|
|
if (_check_prefix(prefix, name))
|
|
{
|
|
char filename1[EXACTNESS_PATH_MAX], filename2[EXACTNESS_PATH_MAX];
|
|
snprintf(filename1, EXACTNESS_PATH_MAX, "%s/%s/%s", exactness_config.dest_dir, ORIG_SUBDIR, name);
|
|
snprintf(filename2, EXACTNESS_PATH_MAX, "%s/%s/%s", exactness_config.dest_dir, CURRENT_SUBDIR, name);
|
|
if (!_is_equal(filename1, filename2))
|
|
{
|
|
const char *ext = strrchr(name, '.');
|
|
if (!strcmp(ext, ".eet"))
|
|
{
|
|
if (!objects_files_compare(filename1, filename2, EINA_FALSE))
|
|
{
|
|
fprintf(stderr, "Failed objects comparing '%s'\n", name);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
char buf[EXACTNESS_PATH_MAX];
|
|
exactness_ctx.compare_errors =
|
|
eina_list_append(exactness_ctx.compare_errors,
|
|
strdup(name));
|
|
|
|
/* FIXME: Clean up. */
|
|
snprintf(buf, EXACTNESS_PATH_MAX,
|
|
"compare '%s' '%s' '%s/%s/comp_%s'",
|
|
filename1, filename2,
|
|
exactness_config.dest_dir,
|
|
CURRENT_SUBDIR, name);
|
|
if (system(buf))
|
|
{
|
|
fprintf(stderr, "Failed image comparing '%s'\n", name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
run_test_compare(const List_Entry *ent)
|
|
{
|
|
char origdir[EXACTNESS_PATH_MAX];
|
|
snprintf(origdir, EXACTNESS_PATH_MAX, "%s/%s", exactness_config.dest_dir, ORIG_SUBDIR);
|
|
eina_file_dir_list(origdir, 0, _compare_list_cb, ent->name);
|
|
}
|
|
|
|
static void
|
|
_prefix_rm_cb(const char *name, const char *path, void *data)
|
|
{
|
|
const char *prefix = data;
|
|
if (_check_prefix(prefix, name))
|
|
{
|
|
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);
|
|
}
|