summaryrefslogtreecommitdiff
path: root/src/tests/eet/eet_test_cache.c
diff options
context:
space:
mode:
authorVincent Torri <vincent dot torri at gmail dot com>2016-02-04 14:29:22 +0100
committerTom Hacohen <tom@stosb.com>2016-02-16 12:41:06 +0000
commit8cc995cca849033e00d0f51dff0a0d6cba46b717 (patch)
tree4b518399a60c60bd2309d8bcb2dac35de941ccb6 /src/tests/eet/eet_test_cache.c
parent885a1d2f7db673d1103f180cc517f4874067bd55 (diff)
Test rework #6: Eet
This one is big: I had to split the huge eet_suite.c into separate test files and it needs more review
Diffstat (limited to 'src/tests/eet/eet_test_cache.c')
-rw-r--r--src/tests/eet/eet_test_cache.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/tests/eet/eet_test_cache.c b/src/tests/eet/eet_test_cache.c
new file mode 100644
index 0000000000..6713c410a0
--- /dev/null
+++ b/src/tests/eet/eet_test_cache.c
@@ -0,0 +1,105 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdlib.h>
6#include <unistd.h>
7
8#include <Eina.h>
9#include <Eet.h>
10
11#include "eet_suite.h"
12#include "eet_test_common.h"
13
14static Eina_Bool open_worker_stop;
15static Eina_Condition open_worker_cond;
16static Eina_Lock open_worker_mutex;
17
18static void *
19_open_close_worker(void *path, Eina_Thread tid EINA_UNUSED)
20{
21 static Eina_Bool first = EINA_TRUE;
22
23 while (!open_worker_stop)
24 {
25 Eet_File *ef = eet_open((char const *)path, EET_FILE_MODE_READ);
26 if (ef == NULL)
27 return "eet_open() failed";
28 else
29 {
30 Eet_Error err_code = eet_close(ef);
31 if (err_code != EET_ERROR_NONE)
32 return "eet_close() failed";
33 }
34
35 if (first)
36 {
37 eina_lock_take(&open_worker_mutex);
38 eina_condition_broadcast(&open_worker_cond);
39 eina_lock_release(&open_worker_mutex);
40 first = EINA_FALSE;
41 }
42 }
43
44 return NULL;
45}
46
47START_TEST(eet_test_cache_concurrency)
48{
49 char *file;
50 const char *buffer = "test data";
51 Eet_File *ef;
52 void *thread_ret;
53 unsigned int n;
54 Eina_Thread thread;
55 Eina_Bool r;
56 int tmpfd;
57
58 file = strdup("/tmp/eet_suite_testXXXXXX");
59
60 eet_init();
61 eina_threads_init();
62
63 eina_lock_new(&open_worker_mutex);
64 eina_condition_new(&open_worker_cond, &open_worker_mutex);
65
66 /* create a file to test with */
67 fail_if(-1 == (tmpfd = mkstemp(file)));
68 fail_if(!!close(tmpfd));
69 ef = eet_open(file, EET_FILE_MODE_WRITE);
70 fail_if(!ef);
71 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
72
73 eina_lock_take(&open_worker_mutex);
74 /* start a thread that repeatedly opens and closes a file */
75 open_worker_stop = 0;
76 r = eina_thread_create(&thread, EINA_THREAD_NORMAL, -1, _open_close_worker, file);
77 fail_unless(r);
78
79 eina_condition_wait(&open_worker_cond);
80 eina_lock_release(&open_worker_mutex);
81
82 /* clear the cache repeatedly in this thread */
83 for (n = 0; n < 20000; ++n)
84 {
85 eet_clearcache();
86 }
87
88 /* join the other thread, and fail if it returned an error message */
89 open_worker_stop = 1;
90 thread_ret = eina_thread_join(thread);
91 fail_unless(thread_ret == NULL, (char const *)thread_ret);
92
93 eet_close(ef);
94
95 fail_if(unlink(file) != 0);
96
97 eina_threads_shutdown();
98 eet_shutdown();
99}
100END_TEST
101
102void eet_test_cache(TCase *tc)
103{
104 tcase_add_test(tc, eet_test_cache_concurrency);
105}