summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-04-09 22:46:24 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-04-09 22:47:17 -0300
commitd02f99ee21f6920102ea23da5ecc438290c22752 (patch)
tree16d89bd36a200d6375a4b39026f6380040070410
parent668fcab941a3f5eb8d580d575a74cd3c5c3b78d6 (diff)
eio-model: Fix Eio model races in tests
Removed sleep and implemented a deterministic way to test if the test has really finished.
Diffstat (limited to '')
-rw-r--r--src/lib/eio/eio_model.c11
-rw-r--r--src/tests/eio/eio_model_test_file.c37
-rw-r--r--src/tests/eio/eio_model_test_monitor_add.c61
3 files changed, 65 insertions, 44 deletions
diff --git a/src/lib/eio/eio_model.c b/src/lib/eio/eio_model.c
index 0a93658331..6abddb284d 100644
--- a/src/lib/eio/eio_model.c
+++ b/src/lib/eio/eio_model.c
@@ -122,7 +122,7 @@ _eio_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int error)
122{ 122{
123 if (error != 0) 123 if (error != 0)
124 { 124 {
125 ERR("%d: %s.", error, strerror(error)); 125 WRN("%d: %s.", error, strerror(error));
126 } 126 }
127} 127}
128 128
@@ -131,7 +131,7 @@ _eio_prop_set_error_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, in
131{ 131{
132 if (error != 0) 132 if (error != 0)
133 { 133 {
134 ERR("%d: %s.", error, strerror(error)); 134 WRN("%d: %s.", error, strerror(error));
135 } 135 }
136} 136}
137 137
@@ -432,7 +432,7 @@ _eio_error_children_load_cb(void *data, Eio_File *handler EINA_UNUSED, int error
432 Eio_Model_Data *priv = data; 432 Eio_Model_Data *priv = data;
433 Eo *child; 433 Eo *child;
434 434
435 ERR("%d: %s.", error, strerror(error)); 435 WRN("%d: %s.", error, strerror(error));
436 436
437 EINA_LIST_FREE(priv->children_list, child) 437 EINA_LIST_FREE(priv->children_list, child)
438 eo_unref(child); 438 eo_unref(child);
@@ -545,11 +545,6 @@ _eio_model_efl_model_base_child_del(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, E
545 Eio_Model_Data *child_priv; 545 Eio_Model_Data *child_priv;
546 EINA_SAFETY_ON_NULL_RETURN_VAL(child, EFL_MODEL_LOAD_STATUS_ERROR); 546 EINA_SAFETY_ON_NULL_RETURN_VAL(child, EFL_MODEL_LOAD_STATUS_ERROR);
547 547
548 if (priv->children_list != NULL)
549 {
550 priv->children_list = eina_list_remove(priv->children_list, child);
551 }
552
553 child_priv = eo_data_scope_get(child, MY_CLASS); 548 child_priv = eo_data_scope_get(child, MY_CLASS);
554 EINA_SAFETY_ON_NULL_RETURN_VAL(child_priv, EFL_MODEL_LOAD_STATUS_ERROR); 549 EINA_SAFETY_ON_NULL_RETURN_VAL(child_priv, EFL_MODEL_LOAD_STATUS_ERROR);
555 550
diff --git a/src/tests/eio/eio_model_test_file.c b/src/tests/eio/eio_model_test_file.c
index af5269d033..b54ef1592b 100644
--- a/src/tests/eio/eio_model_test_file.c
+++ b/src/tests/eio/eio_model_test_file.c
@@ -16,14 +16,6 @@
16#define EFL_MODEL_TEST_FILENAME_PATH "/tmp" 16#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
17#define EFL_MODEL_MAX_TEST_CHILDS 16 17#define EFL_MODEL_MAX_TEST_CHILDS 16
18 18
19/**
20 * The following test works however
21 * it is going to rename (move) the original directory to
22 * new one so '/tmp' as root dir doesn't work , you'll need to use
23 * '/tmp/some_other_dir' as root instead.
24 */
25//#define _RUN_LOCAL_TEST
26
27struct reqs_t { 19struct reqs_t {
28 /* property change */ 20 /* property change */
29 int changed_is_dir; 21 int changed_is_dir;
@@ -44,6 +36,9 @@ struct reqs_t {
44 int children; 36 int children;
45 int child_add; 37 int child_add;
46 int child_del; 38 int child_del;
39
40 /* load status */
41 int properties_loaded;
47}; 42};
48 43
49static struct reqs_t reqs; 44static struct reqs_t reqs;
@@ -72,7 +67,12 @@ _load_status_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *des
72 printf("Children is Loaded\n"); 67 printf("Children is Loaded\n");
73 68
74 if (st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES) 69 if (st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES)
75 printf("Properties is Loaded\n"); 70 {
71 fprintf(stderr, "Properties are Loaded\n"); fflush(stderr);
72 if(!reqs.properties_loaded)
73 ecore_main_loop_quit();
74 reqs.properties_loaded = 1;
75 }
76 76
77 if ((st->status & EFL_MODEL_LOAD_STATUS_LOADED) == EFL_MODEL_LOAD_STATUS_LOADED) 77 if ((st->status & EFL_MODEL_LOAD_STATUS_LOADED) == EFL_MODEL_LOAD_STATUS_LOADED)
78 { 78 {
@@ -104,8 +104,6 @@ _load_status_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *des
104 /**< get full list */ 104 /**< get full list */
105 eo_do(obj, status = efl_model_children_slice_get(0 ,0 ,(Eina_Accessor **)&accessor)); 105 eo_do(obj, status = efl_model_children_slice_get(0 ,0 ,(Eina_Accessor **)&accessor));
106 eina_accessor_free(accessor); 106 eina_accessor_free(accessor);
107 eo_do(obj, status = efl_model_children_slice_get(5 ,5 ,(Eina_Accessor **)&accessor));
108 eina_accessor_free(accessor);
109 ecore_main_loop_quit(); 107 ecore_main_loop_quit();
110 } 108 }
111 return EINA_TRUE; 109 return EINA_TRUE;
@@ -155,15 +153,12 @@ START_TEST(eio_model_test_test_file)
155 Eo *filemodel = NULL; 153 Eo *filemodel = NULL;
156 const Eina_Value *value_prop; 154 const Eina_Value *value_prop;
157 Efl_Model_Load_Status status; 155 Efl_Model_Load_Status status;
158#ifdef _RUN_LOCAL_TEST
159 Eina_Value nameset_value;
160#endif
161 Eina_Array *properties_list; 156 Eina_Array *properties_list;
162 Eina_Array_Iterator iterator; 157 Eina_Array_Iterator iterator;
163 char *str; 158 char *str;
164 unsigned int i; 159 unsigned int i;
165 160
166 memset(&reqs, -1, sizeof(struct reqs_t)); 161 memset(&reqs, 0, sizeof(struct reqs_t));
167 162
168 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n"); 163 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
169 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n"); 164 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
@@ -180,6 +175,8 @@ START_TEST(eio_model_test_test_file)
180 175
181 handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL); 176 handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
182 177
178 ecore_main_loop_begin();
179
183 eo_do(filemodel, status = efl_model_property_get("filename", &value_prop)); 180 eo_do(filemodel, status = efl_model_property_get("filename", &value_prop));
184 str = eina_value_to_string(value_prop); 181 str = eina_value_to_string(value_prop);
185 printf("efl_model_test filename %s, load status %d\n", str, status); 182 printf("efl_model_test filename %s, load status %d\n", str, status);
@@ -207,16 +204,6 @@ START_TEST(eio_model_test_test_file)
207 204
208 ecore_main_loop_begin(); 205 ecore_main_loop_begin();
209 206
210#ifdef _RUN_LOCAL_TEST
211 eina_value_setup(&nameset_value, EINA_VALUE_TYPE_STRING);
212 eina_value_setup(&value_prop, EINA_VALUE_TYPE_STRING);
213 eina_value_set(&nameset_value, "/tmp/efl_model_test");
214 eo_do(filemodel, efl_model_property_set("path", &nameset_value));
215 eina_value_flush(&nameset_value);
216 eo_do(filemodel, status = efl_model_property_get("path", &value_prop));
217#endif
218
219 sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */
220 eo_unref(filemodel); 207 eo_unref(filemodel);
221 ecore_shutdown(); 208 ecore_shutdown();
222 eina_shutdown(); 209 eina_shutdown();
diff --git a/src/tests/eio/eio_model_test_monitor_add.c b/src/tests/eio/eio_model_test_monitor_add.c
index af95ae8f75..11d9e172a3 100644
--- a/src/tests/eio/eio_model_test_monitor_add.c
+++ b/src/tests/eio/eio_model_test_monitor_add.c
@@ -13,9 +13,9 @@
13 13
14#include <check.h> 14#include <check.h>
15 15
16#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
17
18Eina_Bool children_added = EINA_FALSE; 16Eina_Bool children_added = EINA_FALSE;
17Eina_Tmpstr* temp_filename = NULL;
18const char* tmpdir = NULL;
19 19
20static Eina_Bool 20static Eina_Bool
21_load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 21_load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
@@ -28,25 +28,50 @@ _load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EI
28 if (!(st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES)) 28 if (!(st->status & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES))
29 return EINA_TRUE; 29 return EINA_TRUE;
30 30
31 eo_do(obj, efl_model_property_get("filename", &value_prop)); 31 eo_do(obj, efl_model_property_get("path", &value_prop));
32 fail_if(!value_prop, "ERROR: Cannot get property!\n"); 32 fail_if(!value_prop, "ERROR: Cannot get property!\n");
33 33
34 str = eina_value_to_string(value_prop); 34 str = eina_value_to_string(value_prop);
35 fail_if(!str, "ERROR: Cannot convert value to string!\n"); 35 fail_if(!str, "ERROR: Cannot convert value to string!\n");
36 fprintf(stderr, "new children filename %s\n", str); 36 fprintf(stderr, "new children filename %s\n", str);
37 if(strcmp(str, "test_file_monitor_add") == 0) 37 if(strcmp(str, temp_filename) == 0)
38 { 38 {
39 fprintf(stderr, "is child that we want\n"); 39 fprintf(stderr, "is child that we want\n");
40 eo_do(obj, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_monitor_status_cb, data)); 40 eo_do(obj, eo_event_callback_del(EFL_MODEL_BASE_EVENT_LOAD_STATUS, _load_monitor_status_cb, data));
41 children_added = EINA_TRUE; 41 children_added = EINA_TRUE;
42 eo_do(parent, efl_model_child_del(obj)); 42 eo_do(parent, efl_model_child_del(obj));
43 ecore_main_loop_quit();
44 } 43 }
45 44
46 return EINA_FALSE; 45 return EINA_FALSE;
47} 46}
48 47
49static Eina_Bool 48static Eina_Bool
49_children_removed_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void* event_info EINA_UNUSED)
50{
51 if(children_added)
52 {
53 Efl_Model_Children_Event* evt = event_info;
54
55 Eina_Bool b;
56 eo_do(evt->child, b = efl_model_load_status_get() & EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES);
57 if(b)
58 {
59 const Eina_Value* value_prop = NULL;
60 const char* str = NULL;
61
62 eo_do(evt->child, efl_model_property_get("path", &value_prop));
63 fail_if(!value_prop, "ERROR: Cannot get property!\n");
64
65 str = eina_value_to_string(value_prop);
66 fail_if(!str, "ERROR: Cannot convert value to string!\n");
67 if(strcmp(str, temp_filename) == 0)
68 ecore_main_loop_quit();
69 }
70 }
71 return EINA_TRUE;
72}
73
74static Eina_Bool
50_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info) 75_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
51{ 76{
52 Efl_Model_Children_Event* evt = event_info; 77 Efl_Model_Children_Event* evt = event_info;
@@ -67,6 +92,7 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *
67 Efl_Model_Load_Status status; 92 Efl_Model_Load_Status status;
68 Eo *child; 93 Eo *child;
69 unsigned int i = 0; 94 unsigned int i = 0;
95 int fd = 0;
70 96
71 fprintf(stderr, "Children count number=%d\n", *len); 97 fprintf(stderr, "Children count number=%d\n", *len);
72 98
@@ -78,7 +104,10 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *
78 fprintf(stdout, "Got %d childs from Accessor. status=%d\n", i, status); 104 fprintf(stdout, "Got %d childs from Accessor. status=%d\n", i, status);
79 } 105 }
80 106
81 fclose(fopen(EFL_MODEL_TEST_FILENAME_PATH "/test_file_monitor_add", "w+")); 107 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0)
108 {
109 close(fd);
110 }
82 111
83 return EINA_TRUE; 112 return EINA_TRUE;
84} 113}
@@ -93,20 +122,30 @@ START_TEST(eio_model_test_test_monitor_add)
93 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n"); 122 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
94 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n"); 123 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
95 124
96 filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(EFL_MODEL_TEST_FILENAME_PATH)); 125#ifndef HAVE_EVIL
126#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
127 if (getuid() == geteuid())
128#endif
129 {
130 tmpdir = getenv("TMPDIR");
131 if (!tmpdir) tmpdir = getenv("XDG_RUNTIME_DIR");
132 }
133 if (!tmpdir) tmpdir = "/tmp";
134#else
135 tmpdir = (char *)evil_tmpdir_get();
136#endif /* ! HAVE_EVIL */
137
138 filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(tmpdir));
97 fail_if(!filemodel, "ERROR: Cannot init model!\n"); 139 fail_if(!filemodel, "ERROR: Cannot init model!\n");
98 140
99 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_ADDED, _children_added_cb, NULL)); 141 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_ADDED, _children_added_cb, NULL));
142 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILD_REMOVED, _children_removed_cb, NULL));
100 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL)); 143 eo_do(filemodel, eo_event_callback_add(EFL_MODEL_BASE_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
101 144
102 eo_do(filemodel, efl_model_load()); 145 eo_do(filemodel, efl_model_load());
103 146
104 ecore_main_loop_begin(); 147 ecore_main_loop_begin();
105 148
106 sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */
107
108 ecore_main_loop_iterate(); /**< Give time to unlink file */
109
110 eo_unref(filemodel); 149 eo_unref(filemodel);
111 150
112 eio_shutdown(); 151 eio_shutdown();