summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-10-16 16:47:21 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-10-16 16:51:41 +0900
commit577ae1debc724cb0144d903a8a1bfa4daf467475 (patch)
treed695e9aa3a306a00cd4b5b576fe42f7fb58752d3
parent0b26b1bd8950b0e385a2f96c3a123d0dee1b67b4 (diff)
downloadefl-577ae1debc724cb0144d903a8a1bfa4daf467475.tar.gz
eina: let's add some straight forward test.
-rw-r--r--src/Makefile_Eina.am3
-rw-r--r--src/tests/eina/eina_suite.c1
-rw-r--r--src/tests/eina/eina_suite.h1
-rw-r--r--src/tests/eina/eina_test_lock.c172
4 files changed, 176 insertions, 1 deletions
diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index 09264ced9d..5ad1c2096d 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -268,7 +268,8 @@ tests/eina/eina_test_simple_xml_parser.c \
tests/eina/eina_test_value.c \
tests/eina/eina_test_cow.c \
tests/eina/eina_test_barrier.c \
-tests/eina/eina_test_tmpstr.c
+tests/eina/eina_test_tmpstr.c \
+tests/eina/eina_test_lock.c
# tests/eina/eina_test_model.c
tests_eina_eina_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
diff --git a/src/tests/eina/eina_suite.c b/src/tests/eina/eina_suite.c
index 1577b3aebb..1a27503cf3 100644
--- a/src/tests/eina/eina_suite.c
+++ b/src/tests/eina/eina_suite.c
@@ -73,6 +73,7 @@ static const Eina_Test_Case etc[] = {
// { "Model", eina_test_model },
{ "Barrier", eina_test_barrier },
{ "Tmp String", eina_test_tmpstr },
+ { "Locking", eina_test_locking },
{ NULL, NULL }
};
diff --git a/src/tests/eina/eina_suite.h b/src/tests/eina/eina_suite.h
index 85a32cf556..e786309e0c 100644
--- a/src/tests/eina/eina_suite.h
+++ b/src/tests/eina/eina_suite.h
@@ -60,5 +60,6 @@ void eina_test_model(TCase *tc);
void eina_test_cow(TCase *tc);
void eina_test_barrier(TCase *tc);
void eina_test_tmpstr(TCase *tc);
+void eina_test_locking(TCase *tc);
#endif /* EINA_SUITE_H_ */
diff --git a/src/tests/eina/eina_test_lock.c b/src/tests/eina/eina_test_lock.c
new file mode 100644
index 0000000000..a813352d2a
--- /dev/null
+++ b/src/tests/eina/eina_test_lock.c
@@ -0,0 +1,172 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2013 Cedric Bail
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "eina_suite.h"
+#include "Eina.h"
+
+static Eina_Spinlock spin;
+static Eina_Thread thread;
+static unsigned int counter;
+
+static void *
+_eina_test_lock_thread(void *data, Eina_Thread t)
+{
+ unsigned int i;
+
+ fail_if(!eina_thread_equal(t, thread));
+ fail_if(strcmp("test", data));
+
+ for (i = 0; i < 10000; i++)
+ {
+ fail_if(eina_spinlock_take(&spin) != EINA_LOCK_SUCCEED);
+ counter++;
+ fail_if(eina_spinlock_release(&spin) != EINA_LOCK_SUCCEED);
+ }
+
+ return data;
+}
+
+START_TEST(eina_test_spinlock)
+{
+ unsigned int i;
+
+ fail_if(!eina_init());
+
+ counter = 0;
+ fail_if(!eina_spinlock_new(&spin));
+
+ fail_if(!eina_thread_create(&thread, EINA_THREAD_NORMAL, 0, _eina_test_lock_thread, "test"));
+
+ for (i = 0; i < 10000; i++)
+ {
+ fail_if(eina_spinlock_take(&spin) != EINA_LOCK_SUCCEED);
+ counter++;
+ fail_if(eina_spinlock_release(&spin) != EINA_LOCK_SUCCEED);
+ }
+
+ fail_if(strcmp("test", eina_thread_join(thread)));
+
+ fail_if(counter != 20000);
+
+ eina_spinlock_free(&spin);
+
+ eina_shutdown();
+}
+END_TEST
+
+static Eina_TLS key;
+
+static void *
+_eina_test_tls_thread(void *data EINA_UNUSED, Eina_Thread t EINA_UNUSED)
+{
+ unsigned int mystack = 21;
+
+ fail_if(!eina_tls_set(key, &mystack));
+ fail_if(eina_tls_get(key) != &mystack);
+
+ return NULL;
+}
+
+START_TEST(eina_test_tls)
+{
+ unsigned int ft = 42;
+
+ fail_if(!eina_init());
+
+ fail_if(!eina_tls_new(&key));
+
+ fail_if(!eina_tls_set(key, &ft));
+
+ fail_if(!eina_thread_create(&thread, EINA_THREAD_NORMAL, 0, _eina_test_tls_thread, NULL));
+
+ eina_thread_join(thread);
+
+ fail_if(eina_tls_get(key) != &ft);
+
+ eina_tls_free(key);
+
+ eina_shutdown();
+}
+END_TEST
+
+static Eina_Lock mtcond;
+static Eina_Condition cond;
+static Eina_RWLock mutex;
+
+static void *
+_eina_test_rwlock_thread(void *data EINA_UNUSED, Eina_Thread t EINA_UNUSED)
+{
+ fail_if(!eina_condition_broadcast(&cond));
+
+ fail_if(eina_rwlock_take_write(&mutex) != EINA_LOCK_SUCCEED);
+ counter = 7200;
+ fail_if(eina_rwlock_release(&mutex) != EINA_LOCK_SUCCEED);
+
+ fail_if(!eina_condition_broadcast(&cond));
+
+ return NULL;
+}
+
+START_TEST(eina_test_rwlock)
+{
+ fail_if(!eina_init());
+
+ fail_if(!eina_rwlock_new(&mutex));
+ fail_if(!eina_lock_new(&mtcond));
+ fail_if(!eina_condition_new(&cond, &mtcond));
+
+ counter = 42;
+
+ fail_if(eina_rwlock_take_read(&mutex) != EINA_LOCK_SUCCEED);
+ fail_if(eina_lock_take(&mtcond) != EINA_LOCK_SUCCEED);
+
+ fail_if(!eina_thread_create(&thread, EINA_THREAD_NORMAL, 0, _eina_test_rwlock_thread, NULL));
+
+ fail_if(!eina_condition_wait(&cond));
+ fail_if(!eina_lock_release(&mtcond));
+
+ fail_if(counter != 42);
+ fail_if(eina_rwlock_release(&mutex) != EINA_LOCK_SUCCEED);
+
+ fail_if(eina_lock_take(&mtcond) != EINA_LOCK_SUCCEED);
+ fail_if(!eina_condition_wait(&cond));
+ fail_if(eina_lock_release(&mtcond) != EINA_LOCK_SUCCEED);
+
+ fail_if(eina_rwlock_take_read(&mutex) != EINA_LOCK_SUCCEED);
+ fail_if(counter != 7200);
+ fail_if(eina_rwlock_release(&mutex) != EINA_LOCK_SUCCEED);
+
+ eina_condition_free(&cond);
+ eina_lock_free(&mtcond);
+ eina_rwlock_free(&mutex);
+
+ eina_shutdown();
+}
+END_TEST
+
+void
+eina_test_locking(TCase *tc)
+{
+ tcase_add_test(tc, eina_test_spinlock);
+ tcase_add_test(tc, eina_test_tls);
+ tcase_add_test(tc, eina_test_rwlock);
+}