exactness: switch from homegrown debug printf to eina_log

Use a full eina_log domain here for each executable. No need to have a
own half baked ex_printf version here for such things.

Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de>
Differential Revision: https://phab.enlightenment.org/D11558
This commit is contained in:
Stefan Schmidt 2020-03-23 17:46:10 +01:00
parent 9da0235d74
commit 912fbe79a2
6 changed files with 78 additions and 65 deletions

View File

@ -4,19 +4,6 @@
#include "common.h"
static int _verbose = 0;
void
ex_printf(int verbose, const char *fmt, ...)
{
va_list ap;
if (!_verbose || verbose > _verbose) return;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
int
ex_prg_invoke(const char *full_path, int argc, char **argv, Eina_Bool player)
{

View File

@ -276,6 +276,5 @@ Exactness_Unit *exactness_unit_file_read(const char *filename);
Eina_Bool exactness_unit_file_write(Exactness_Unit *unit, const char *filename);
void exactness_image_free(Exactness_Image *img);
void ex_printf(int verbose, const char *fmt, ...);
int ex_prg_invoke(const char *full_path, int argc, char **argv, Eina_Bool player);
Eina_Stringshare *ex_prg_full_path_guess(const char *prg);

View File

@ -255,7 +255,7 @@ ok:
}
strncpy(buf, eina_strbuf_string_get(sbuf), SCHEDULER_CMD_SIZE-1);
eina_strbuf_free(sbuf);
ex_printf(1, "Command: %s\n", buf);
printf("Command: %s\n", buf);
return EINA_TRUE;
}

View File

@ -15,6 +15,11 @@
#include "common.h"
#define DBG(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
#define INF(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
static int _log_domain = -1;
static Eina_Stringshare *_src_filename = NULL;
static Exactness_Unit *_src_unit = NULL;
static int _verbose = 0;
@ -66,15 +71,15 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
{
case EXACTNESS_ACTION_MOUSE_IN:
{
ex_printf(1, "Mouse in\n");
ex_printf(2, "%s evas_event_feed_mouse_in n_evas=<%d>\n", __func__, n_evas);
INF("Mouse in\n");
DBG("%s evas_event_feed_mouse_in n_evas=<%d>\n", __func__, n_evas);
eina_debug_session_send(_session, _cid, _mouse_in_op, &n_evas, sizeof(int));
break;
}
case EXACTNESS_ACTION_MOUSE_OUT:
{
ex_printf(1, "Mouse out\n");
ex_printf(2, "%s evas_event_feed_mouse_out n_evas=<%d>\n", __func__, n_evas);
INF("Mouse out\n");
DBG("%s evas_event_feed_mouse_out n_evas=<%d>\n", __func__, n_evas);
eina_debug_session_send(_session, _cid, _mouse_out_op, &n_evas, sizeof(int));
break;
}
@ -83,8 +88,8 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
Exactness_Action_Mouse_Wheel *t = data;
int len = 3*sizeof(int);
char *buf = malloc(len), *tmp = buf;
ex_printf(1, "Mouse wheel\n");
ex_printf(2, "%s evas_event_feed_mouse_wheel n_evas=<%d>\n", __func__, n_evas);
INF("Mouse wheel\n");
DBG("%s evas_event_feed_mouse_wheel n_evas=<%d>\n", __func__, n_evas);
STORE_INT(tmp, n_evas);
STORE_INT(tmp, t->direction);
STORE_INT(tmp, t->z);
@ -98,7 +103,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
Exactness_Action_Multi_Event *t = data;
int len = 5*sizeof(int)+7*sizeof(double)+sizeof(int);
char *buf = malloc(len), *tmp = buf;
ex_printf(2, "%s %s n_evas=<%d>\n", __func__,
DBG("%s %s n_evas=<%d>\n", __func__,
type == EXACTNESS_ACTION_MULTI_DOWN ? "evas_event_feed_multi_down" :
"evas_event_feed_multi_up", n_evas);
STORE_INT(tmp, n_evas);
@ -125,7 +130,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
Exactness_Action_Multi_Move *t = data;
int len = 4*sizeof(int)+7*sizeof(double);
char *buf = malloc(len), *tmp = buf;
ex_printf(2, "%s evas_event_feed_multi_move n_evas=<%d>\n", __func__, n_evas);
DBG("%s evas_event_feed_multi_move n_evas=<%d>\n", __func__, n_evas);
STORE_INT(tmp, n_evas);
STORE_INT(tmp, t->d);
STORE_INT(tmp, t->x);
@ -151,7 +156,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
len += t->string ? strlen(t->string) : 0;
len += t->compose ? strlen(t->compose) : 0;
char *buf = malloc(len), *tmp = buf;
ex_printf(2, "%s %s n_evas=<%d>\n", __func__,
DBG("%s %s n_evas=<%d>\n", __func__,
type == EXACTNESS_ACTION_KEY_DOWN ? "evas_event_feed_key_down " :
"evas_event_feed_key_up", n_evas);
STORE_INT(tmp, n_evas);
@ -168,7 +173,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
}
case EXACTNESS_ACTION_TAKE_SHOT:
{
ex_printf(2, "%s take shot n_evas=<%d>\n", __func__, n_evas);
DBG("%s take shot n_evas=<%d>\n", __func__, n_evas);
eina_debug_session_send(_session, _cid, _take_shot_op, &n_evas, sizeof(int));
break;
}
@ -179,7 +184,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
len += t->wdg_name ? strlen(t->wdg_name) : 0;
len += t->event_name ? strlen(t->event_name) : 0;
char *buf = malloc(len), *tmp = buf;
ex_printf(2, "%s %s\n", __func__, "EFL event");
DBG("%s %s\n", __func__, "EFL event");
STORE_STRING(tmp, t->wdg_name);
STORE_STRING(tmp, t->event_name);
eina_debug_session_send(_session, _cid, _efl_event_op, buf, len);
@ -192,7 +197,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
int len = 0;
len += t->wdg_name ? strlen(t->wdg_name) : 0;
char *buf = malloc(len), *tmp = buf;
ex_printf(2, "%s %s\n", __func__, "Click On");
DBG("%s %s\n", __func__, "Click On");
STORE_STRING(tmp, t->wdg_name);
eina_debug_session_send(_session, _cid, _click_on_op, buf, len);
free(buf);
@ -200,7 +205,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
}
case EXACTNESS_ACTION_STABILIZE:
{
ex_printf(2, "%s stabilize\n", __func__);
DBG("%s stabilize\n", __func__);
eina_debug_session_send(_session, _cid, _stabilize_op, NULL, 0);
break;
}
@ -235,7 +240,7 @@ _src_open()
{
double diff_time = 0; /* Time to wait before feeding the first event */
ex_printf(2, "<%s> Source file is <%s>\n", __func__, _src_filename);
DBG("<%s> Source file is <%s>\n", __func__, _src_filename);
if (!strcmp(_src_filename + strlen(_src_filename) - 4,".exu"))
{
_src_unit = exactness_unit_file_read(_src_filename);
@ -246,7 +251,7 @@ _src_open()
if (act->delay_ms)
{
ex_printf(2, " Waiting <%f>\n", diff_time);
DBG(" Waiting <%f>\n", diff_time);
ecore_timer_add(act->delay_ms / 1000.0, _feed_event_timer_cb, NULL);
}
else
@ -350,6 +355,8 @@ int main(int argc, char **argv)
ECORE_GETOPT_VALUE_NONE
};
_log_domain = eina_log_domain_register("exactness_injector", NULL);
if (!ecore_evas_init())
return EXIT_FAILURE;
@ -380,5 +387,7 @@ int main(int argc, char **argv)
elm_shutdown();
end:
ecore_evas_shutdown();
eina_log_domain_unregister(_log_domain);
_log_domain = -1;
return real__;
}

View File

@ -34,6 +34,11 @@
#define IMAGE_FILENAME_EXT ".png"
#define PAUSE_KEY_STR "F2"
#define DBG(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
#define INF(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
static int _log_domain = -1;
typedef enum
{
FTYPE_UNKNOWN,
@ -136,7 +141,7 @@ _evas_render_post_cb(void *data EINA_UNUSED, const Efl_Event *event)
Eo *o = evas_object_image_add(event->object);
evas_object_image_size_set(o, ex_shot->w, ex_shot->h);
evas_object_image_data_set(o, ex_shot->pixels);
ex_printf(1, "Shot taken (%s).\n", filename);
INF("Shot taken (%s).\n", filename);
if (!evas_object_image_save(o, filename, NULL, NULL))
{
printf("Cannot save widget to <%s>\n", filename);
@ -148,7 +153,7 @@ _evas_render_post_cb(void *data EINA_UNUSED, const Efl_Event *event)
Exactness_Image *ex_img = e_data;
memcpy(ex_img, ex_shot, sizeof(Exactness_Image));
ex_shot->pixels = NULL;
ex_printf(1, "Shot taken (in %s).\n", _dest);
INF("Shot taken (in %s).\n", _dest);
}
else if (_dest_type == FTYPE_REMOTE)
{
@ -279,23 +284,23 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
{
case EXACTNESS_ACTION_MOUSE_IN:
{
ex_printf(1, "Mouse in\n");
ex_printf(2, "%s evas_event_feed_mouse_in n_evas=<%d>\n", __func__, n_evas);
INF("Mouse in\n");
DBG("%s evas_event_feed_mouse_in n_evas=<%d>\n", __func__, n_evas);
if (e) evas_event_feed_mouse_in(e, time(NULL), NULL);
break;
}
case EXACTNESS_ACTION_MOUSE_OUT:
{
ex_printf(1, "Mouse out\n");
ex_printf(2, "%s evas_event_feed_mouse_out n_evas=<%d>\n", __func__, n_evas);
INF("Mouse out\n");
DBG("%s evas_event_feed_mouse_out n_evas=<%d>\n", __func__, n_evas);
if (e) evas_event_feed_mouse_out(e, time(NULL), NULL);
break;
}
case EXACTNESS_ACTION_MOUSE_WHEEL:
{
Exactness_Action_Mouse_Wheel *t = data;
ex_printf(1, "Mouse wheel\n");
ex_printf(2, "%s evas_event_feed_mouse_wheel n_evas=<%d>\n", __func__, n_evas);
INF("Mouse wheel\n");
DBG("%s evas_event_feed_mouse_wheel n_evas=<%d>\n", __func__, n_evas);
if (e) evas_event_feed_mouse_wheel(e, t->direction, t->z, time(NULL), NULL);
break;
@ -303,7 +308,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
case EXACTNESS_ACTION_MULTI_DOWN:
{
Exactness_Action_Multi_Event *t = data;
ex_printf(2, "%s evas_event_feed_multi_down n_evas=<%d>\n", __func__, n_evas);
DBG("%s evas_event_feed_multi_down n_evas=<%d>\n", __func__, n_evas);
if (!t->d)
{
if (e) evas_event_feed_mouse_down(e, t->b, t->flags, time(NULL), NULL);
@ -322,7 +327,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
case EXACTNESS_ACTION_MULTI_UP:
{
Exactness_Action_Multi_Event *t = data;
ex_printf(2, "%s evas_event_feed_multi_up n_evas=<%d>\n", __func__, n_evas);
DBG("%s evas_event_feed_multi_up n_evas=<%d>\n", __func__, n_evas);
if (!t->d)
{
if (e) evas_event_feed_mouse_up(e, t->b, t->flags, time(NULL), NULL);
@ -341,7 +346,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
case EXACTNESS_ACTION_MULTI_MOVE:
{
Exactness_Action_Multi_Move *t = data;
ex_printf(2, "%s evas_event_feed_multi_move n_evas=<%d>\n", __func__, n_evas);
DBG("%s evas_event_feed_multi_move n_evas=<%d>\n", __func__, n_evas);
if (!t->d)
{
if (e) evas_event_feed_mouse_move(e, t->x, t->y, time(NULL), NULL);
@ -364,7 +369,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
case EXACTNESS_ACTION_KEY_DOWN:
{
Exactness_Action_Key_Down_Up *t = data;
ex_printf(2, "%s evas_event_feed_key_down n_evas=<%d>\n", __func__, n_evas);
DBG("%s evas_event_feed_key_down n_evas=<%d>\n", __func__, n_evas);
if (e)
evas_event_feed_key_down_with_keycode(e,
t->keyname, t->key, t->string,
@ -374,7 +379,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
case EXACTNESS_ACTION_KEY_UP:
{
Exactness_Action_Key_Down_Up *t = data;
ex_printf(2, "%s evas_event_feed_key_up n_evas=<%d>\n", __func__, n_evas);
DBG("%s evas_event_feed_key_up n_evas=<%d>\n", __func__, n_evas);
if (e) evas_event_feed_key_up_with_keycode(e,
t->keyname, t->key, t->string,
t->compose, time(NULL), NULL, t->keycode);
@ -383,7 +388,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
}
case EXACTNESS_ACTION_TAKE_SHOT:
{
ex_printf(2, "%s take shot n_evas=<%d>\n", __func__, n_evas);
DBG("%s take shot n_evas=<%d>\n", __func__, n_evas);
if (rect) evas_object_color_set(rect, 0, 0, 255, 255);
_cur_shot_id++;
if (_dest_type != FTYPE_UNKNOWN && e) _shot_do(e);
@ -399,7 +404,7 @@ _feed_event(Exactness_Action_Type type, unsigned int n_evas, void *data)
Eo *o = efl_name_find(e, t->wdg_name);
if (o)
{
ex_printf(2, "%s EFL event invoke %s on %s\n",
DBG("%s EFL event invoke %s on %s\n",
__func__, t->event_name, t->wdg_name);
Efl_Event_Description d;
found = EINA_TRUE;
@ -436,7 +441,7 @@ wdg_found:
Exactness_Action_Multi_Event *d_event = calloc(1, sizeof(*d_event));
Exactness_Action *act, *prev_act = eina_list_data_get(_cur_event_list);
ex_printf(2, "%s click on %s\n", __func__, t->wdg_name);
DBG("%s click on %s\n", __func__, t->wdg_name);
act = calloc(1, sizeof(*act));
act->type = EXACTNESS_ACTION_MULTI_MOVE;
act->delay_ms = 100;
@ -473,7 +478,7 @@ wdg_found:
}
case EXACTNESS_ACTION_STABILIZE:
{
ex_printf(2, "%s stabilize\n", __func__);
DBG("%s stabilize\n", __func__);
if (rect) evas_object_color_set(rect, 255, 165, 0, 255);
ecore_timer_add(0.1, _stabilization_timer_cb, NULL);
break;
@ -501,7 +506,7 @@ _feed_event_timer_cb(void *data EINA_UNUSED)
if (act->type != EXACTNESS_ACTION_STABILIZE)
{
act = eina_list_data_get(_cur_event_list);
ex_printf(2, " %s timer_time=<%f>\n", __func__, act->delay_ms / 1000.0);
DBG(" %s timer_time=<%f>\n", __func__, act->delay_ms / 1000.0);
ecore_timer_add(act->delay_ms / 1000.0, _feed_event_timer_cb, NULL);
}
}
@ -515,7 +520,7 @@ _stabilization_timer_cb(void *data EINA_UNUSED)
Evas *e;
#define STAB_MAX 5
static int need_more = STAB_MAX;
ex_printf(2, "Not stable yet!\n");
DBG("Not stable yet!\n");
EINA_LIST_FOREACH(_evas_list, itr, e)
{
if (!e) continue;
@ -539,7 +544,7 @@ _stabilization_timer_cb(void *data EINA_UNUSED)
if (_src_type != FTYPE_REMOTE && !_pause_request)
{
Exactness_Action *act = eina_list_data_get(_cur_event_list);
ex_printf(2, " %s timer_time=<%f>\n", __func__, act->delay_ms / 1000.0);
DBG(" %s timer_time=<%f>\n", __func__, act->delay_ms / 1000.0);
ecore_timer_add(act->delay_ms / 1000.0, _feed_event_timer_cb, NULL);
}
need_more = STAB_MAX;
@ -746,7 +751,7 @@ _src_feed(void *data EINA_UNUSED)
if (act && act->delay_ms)
{
ex_printf(2, " Waiting <%f>\n", act->delay_ms / 1000.0);
DBG(" Waiting <%f>\n", act->delay_ms / 1000.0);
ecore_timer_add(act->delay_ms / 1000.0, _feed_event_timer_cb, NULL);
}
else
@ -763,7 +768,7 @@ _src_open()
{
Eina_List *itr, *itr2;
Exactness_Action *act;
ex_printf(2, "<%s> Source file is <%s>\n", __func__, _src_filename);
DBG("<%s> Source file is <%s>\n", __func__, _src_filename);
if (_src_type == FTYPE_EXU)
{
_src_unit = exactness_unit_file_read(_src_filename);
@ -832,10 +837,10 @@ _event_key_cb(void *data EINA_UNUSED, const Efl_Event *event)
if (!strcmp(key, PAUSE_KEY_STR) && efl_input_key_pressed_get(evk))
{
_pause_request = !_pause_request;
if (_pause_request) ex_printf(1, "Pausing scenario\n");
if (_pause_request) INF("Pausing scenario\n");
else
{
ex_printf(1, "Playing scenario\n");
INF("Playing scenario\n");
if (!_playing_status)
_feed_event_timer_cb(NULL);
}
@ -857,7 +862,7 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
e = _evas_new();
if (e)
{
ex_printf(1, "New Evas\n");
INF("New Evas\n");
_evas_list = eina_list_append(_evas_list, e);
efl_event_callback_array_add(e, _evas_callbacks(), NULL);
}
@ -927,6 +932,8 @@ int main(int argc, char **argv)
ECORE_GETOPT_VALUE_NONE
};
_log_domain = eina_log_domain_register("exactness_player", NULL);
if (!ecore_evas_init())
return EXIT_FAILURE;
@ -1090,9 +1097,9 @@ int main(int argc, char **argv)
{
argv[i - opt_args] = argv[0] + (argv[i] - argv[opt_args]);
}
ex_printf(1, "%s ", argv[i - opt_args]);
INF("%s ", argv[i - opt_args]);
}
ex_printf(1, "\n");
INF("\n");
}
else
{
@ -1151,5 +1158,7 @@ int main(int argc, char **argv)
end:
ecore_evas_shutdown();
eina_log_domain_unregister(_log_domain);
_log_domain = -1;
return pret;
}

View File

@ -27,6 +27,11 @@
#define SHOT_KEY_STR "F2"
#define SAVE_KEY_STR "F3"
#define DBG(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
#define INF(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
static int _log_domain = -1;
static const char *_out_filename = NULL;
static const char *_test_name = NULL;
static int _verbose = 0;
@ -73,7 +78,7 @@ _add_to_list(Exactness_Action_Type type, unsigned int n_evas, unsigned int times
prev_v->n_evas == n_evas &&
(!len || !memcmp(prev_v->data, data, len))) return;
}
ex_printf(1, "Recording %s\n", _exactness_action_type_to_string_get(type));
INF("Recording %s\n", _exactness_action_type_to_string_get(type));
Exactness_Action *act = malloc(sizeof(*act));
act->type = type;
act->n_evas = n_evas;
@ -108,7 +113,7 @@ _event_pointer_cb(void *data, const Efl_Event *event)
if (!timestamp) return;
ex_printf(2, "Calling \"%s\" timestamp=<%u>\n", _exactness_action_type_to_string_get(evt), timestamp);
DBG("Calling \"%s\" timestamp=<%u>\n", _exactness_action_type_to_string_get(evt), timestamp);
switch (action)
{
@ -168,20 +173,20 @@ _event_key_cb(void *data, const Efl_Event *event)
{
if (!strcmp(key, _shot_key))
{
ex_printf(2, "Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp);
DBG("Take Screenshot: %s timestamp=<%u>\n", __func__, timestamp);
_add_to_list(EXACTNESS_ACTION_TAKE_SHOT, n_evas, timestamp, NULL, 0);
return;
}
if (!strcmp(key, STABILIZE_KEY_STR))
{
ex_printf(2, "Stabilize: %s timestamp=<%u>\n", __func__, timestamp);
DBG("Stabilize: %s timestamp=<%u>\n", __func__, timestamp);
_add_to_list(EXACTNESS_ACTION_STABILIZE, n_evas, timestamp, NULL, 0);
return;
}
if (!strcmp(key, SAVE_KEY_STR))
{
_output_write();
ex_printf(2, "Save events: %s timestamp=<%u>\n", __func__, timestamp);
DBG("Save events: %s timestamp=<%u>\n", __func__, timestamp);
return;
}
evt = EXACTNESS_ACTION_KEY_DOWN;
@ -225,7 +230,7 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
e = _evas_new();
if (e)
{
ex_printf(1, "New Evas\n");
INF("New Evas\n");
_evas_list = eina_list_append(_evas_list, e);
efl_key_data_set(e, "__evas_id", (void *)(intptr_t)_last_evas_id++);
efl_event_callback_array_add(e, _event_pointer_callbacks(), e);
@ -277,6 +282,8 @@ int main(int argc, char **argv)
ECORE_GETOPT_VALUE_NONE
};
_log_domain = eina_log_domain_register("exactness_recorder", NULL);
if (!ecore_evas_init())
return EXIT_FAILURE;
@ -385,9 +392,9 @@ int main(int argc, char **argv)
{
argv[i - opt_args] = argv[0] + (argv[i] - argv[opt_args]);
}
ex_printf(1, "%s ", argv[i - opt_args]);
INF("%s ", argv[i - opt_args]);
}
ex_printf(1, "\n");
INF("\n");
if (!_shot_key) _shot_key = getenv("SHOT_KEY");
if (!_shot_key) _shot_key = SHOT_KEY_STR;
@ -404,5 +411,7 @@ int main(int argc, char **argv)
end:
ecore_evas_shutdown();
eina_log_domain_unregister(_log_domain);
_log_domain = -1;
return pret;
}