eio-model: Fix Eio model races in tests

Removed sleep and implemented a deterministic way to test if the test has really finished.
This commit is contained in:
Felipe Magno de Almeida 2015-04-09 22:46:24 -03:00
parent 668fcab941
commit d02f99ee21
3 changed files with 65 additions and 44 deletions

View File

@ -122,7 +122,7 @@ _eio_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
{
if (error != 0)
{
ERR("%d: %s.", error, strerror(error));
WRN("%d: %s.", error, strerror(error));
}
}
@ -131,7 +131,7 @@ _eio_prop_set_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, in
{
if (error != 0)
{
ERR("%d: %s.", error, strerror(error));
WRN("%d: %s.", error, strerror(error));
}
}
@ -432,7 +432,7 @@ _eio_error_children_load_cb(void *data, Eio_File *handler EINA_UNUSED, int error
Eio_Model_Data *priv = data;
Eo *child;
ERR("%d: %s.", error, strerror(error));
WRN("%d: %s.", error, strerror(error));
EINA_LIST_FREE(priv->children_list, child)
eo_unref(child);
@ -545,11 +545,6 @@ _eio_model_efl_model_base_child_del(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, E
Eio_Model_Data *child_priv;
EINA_SAFETY_ON_NULL_RETURN_VAL(child, EFL_MODEL_LOAD_STATUS_ERROR);
if (priv->children_list != NULL)
{
priv->children_list = eina_list_remove(priv->children_list, child);
}
child_priv = eo_data_scope_get(child, MY_CLASS);
EINA_SAFETY_ON_NULL_RETURN_VAL(child_priv, EFL_MODEL_LOAD_STATUS_ERROR);

View File

@ -16,14 +16,6 @@
#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
#define EFL_MODEL_MAX_TEST_CHILDS 16
/**
* The following test works however
* it is going to rename (move) the original directory to
* new one so '/tmp' as root dir doesn't work , you'll need to use
* '/tmp/some_other_dir' as root instead.
*/
//#define _RUN_LOCAL_TEST
struct reqs_t {
/* property change */
int changed_is_dir;
@ -44,6 +36,9 @@ struct reqs_t {
int children;
int child_add;
int child_del;
/* load status */
int properties_loaded;
};
static struct reqs_t reqs;
@ -72,7 +67,12 @@ _load_status_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *des
printf("Children is Loaded\n");
if (st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES)
printf("Properties is Loaded\n");
{
fprintf(stderr, "Properties are Loaded\n"); fflush(stderr);
if(!reqs.properties_loaded)
ecore_main_loop_quit();
reqs.properties_loaded = 1;
}
if ((st->status & EFL_MODEL_LOAD_STATUS_LOADED) == EFL_MODEL_LOAD_STATUS_LOADED)
{
@ -104,8 +104,6 @@ _load_status_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *des
/**< get full list */
eo_do(obj, status = efl_model_children_slice_get(0 ,0 ,(Eina_Accessor **)&accessor));
eina_accessor_free(accessor);
eo_do(obj, status = efl_model_children_slice_get(5 ,5 ,(Eina_Accessor **)&accessor));
eina_accessor_free(accessor);
ecore_main_loop_quit();
}
return EINA_TRUE;
@ -155,15 +153,12 @@ START_TEST(eio_model_test_test_file)
Eo *filemodel = NULL;
const Eina_Value *value_prop;
Efl_Model_Load_Status status;
#ifdef _RUN_LOCAL_TEST
Eina_Value nameset_value;
#endif
Eina_Array *properties_list;
Eina_Array_Iterator iterator;
char *str;
unsigned int i;
memset(&reqs, -1, sizeof(struct reqs_t));
memset(&reqs, 0, sizeof(struct reqs_t));
fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
@ -180,6 +175,8 @@ START_TEST(eio_model_test_test_file)
handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
ecore_main_loop_begin();
eo_do(filemodel, status = efl_model_property_get("filename", &value_prop));
str = eina_value_to_string(value_prop);
printf("efl_model_test filename %s, load status %d\n", str, status);
@ -207,16 +204,6 @@ START_TEST(eio_model_test_test_file)
ecore_main_loop_begin();
#ifdef _RUN_LOCAL_TEST
eina_value_setup(&nameset_value, EINA_VALUE_TYPE_STRING);
eina_value_setup(&value_prop, EINA_VALUE_TYPE_STRING);
eina_value_set(&nameset_value, "/tmp/efl_model_test");
eo_do(filemodel, efl_model_property_set("path", &nameset_value));
eina_value_flush(&nameset_value);
eo_do(filemodel, status = efl_model_property_get("path", &value_prop));
#endif
sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */
eo_unref(filemodel);
ecore_shutdown();
eina_shutdown();

View File

@ -13,9 +13,9 @@
#include <check.h>
#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
Eina_Bool children_added = EINA_FALSE;
Eina_Tmpstr* temp_filename = NULL;
const char* tmpdir = NULL;
static Eina_Bool
_load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
@ -28,24 +28,49 @@ _load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EI
if (!(st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES))
return EINA_TRUE;
eo_do(obj, efl_model_property_get("filename", &value_prop));
eo_do(obj, efl_model_property_get("path", &value_prop));
fail_if(!value_prop, "ERROR: Cannot get property!\n");
str = eina_value_to_string(value_prop);
fail_if(!str, "ERROR: Cannot convert value to string!\n");
fprintf(stderr, "new children filename %s\n", str);
if(strcmp(str, "test_file_monitor_add") == 0)
if(strcmp(str, temp_filename) == 0)
{
fprintf(stderr, "is child that we want\n");
eo_do(obj, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_monitor_status_cb, data));
children_added = EINA_TRUE;
eo_do(parent, efl_model_child_del(obj));
ecore_main_loop_quit();
}
return EINA_FALSE;
}
static Eina_Bool
_children_removed_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void* event_info EINA_UNUSED)
{
if(children_added)
{
Efl_Model_Children_Event* evt = event_info;
Eina_Bool b;
eo_do(evt->child, b = efl_model_load_status_get() & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES);
if(b)
{
const Eina_Value* value_prop = NULL;
const char* str = NULL;
eo_do(evt->child, efl_model_property_get("path", &value_prop));
fail_if(!value_prop, "ERROR: Cannot get property!\n");
str = eina_value_to_string(value_prop);
fail_if(!str, "ERROR: Cannot convert value to string!\n");
if(strcmp(str, temp_filename) == 0)
ecore_main_loop_quit();
}
}
return EINA_TRUE;
}
static Eina_Bool
_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
@ -67,6 +92,7 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *
Efl_Model_Load_Status status;
Eo *child;
unsigned int i = 0;
int fd = 0;
fprintf(stderr, "Children count number=%d\n", *len);
@ -78,7 +104,10 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *
fprintf(stdout, "Got %d childs from Accessor. status=%d\n", i, status);
}
fclose(fopen(EFL_MODEL_TEST_FILENAME_PATH "/test_file_monitor_add", "w+"));
if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0)
{
close(fd);
}
return EINA_TRUE;
}
@ -93,20 +122,30 @@ START_TEST(eio_model_test_test_monitor_add)
fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(EFL_MODEL_TEST_FILENAME_PATH));
#ifndef HAVE_EVIL
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
if (getuid() == geteuid())
#endif
{
tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR");
}
if (!tmpdir) tmpdir = "/tmp";
#else
tmpdir = (char *)evil_tmpdir_get();
#endif /* ! HAVE_EVIL */
filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(tmpdir));
fail_if(!filemodel, "ERROR: Cannot init model!\n");
eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_ADDED, _children_added_cb, NULL));
eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_REMOVED, _children_removed_cb, NULL));
eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
eo_do(filemodel, efl_model_load());
ecore_main_loop_begin();
sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */
ecore_main_loop_iterate(); /**< Give time to unlink file */
eo_unref(filemodel);
eio_shutdown();