diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c index ce75f00328..787a455d74 100644 --- a/src/tests/ecore/ecore_suite.c +++ b/src/tests/ecore/ecore_suite.c @@ -2,22 +2,10 @@ # include #endif -#include -#include - -#include - #include "ecore_suite.h" +#include "../efl_check.h" -typedef struct _Ecore_Test_Case Ecore_Test_Case; - -struct _Ecore_Test_Case -{ - const char *test_case; - void (*build)(TCase *tc); -}; - -static const Ecore_Test_Case etc[] = { +static const Efl_Test_Case etc[] = { { "Ecore", ecore_test_ecore }, #if HAVE_ECORE_X { "Ecore_X", ecore_test_ecore_x }, @@ -41,84 +29,18 @@ static const Ecore_Test_Case etc[] = { { NULL, NULL } }; -static void -_list_tests(void) -{ - const Ecore_Test_Case *itr; - - itr = etc; - fputs("Available Test Cases:\n", stderr); - for (; itr->test_case; itr++) - fprintf(stderr, "\t%s\n", itr->test_case); -} -static Eina_Bool -_use_test(int argc, const char **argv, const char *test_case) -{ - if (argc < 1) - return 1; - - for (; argc > 0; argc--, argv++) - if (strcmp(test_case, *argv) == 0) - return 1; - return 0; -} - -static Suite * -ecore_suite_build(int argc, const char **argv) -{ - TCase *tc; - Suite *s; - int i; - - s = suite_create("Ecore"); - - for (i = 0; etc[i].test_case; ++i) - { - if (!_use_test(argc, argv, etc[i].test_case)) continue; - tc = tcase_create(etc[i].test_case); - - etc[i].build(tc); - - suite_add_tcase(s, tc); - tcase_set_timeout(tc, 0); - } - - return s; -} - int main(int argc, char **argv) { - Suite *s; - SRunner *sr; - int i, failed_count; + int failed_count; - for (i = 1; i < argc; i++) - if ((strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0)) - { - fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", - argv[0]); - _list_tests(); - return 0; - } - else if ((strcmp(argv[i], "-l") == 0) || - (strcmp(argv[i], "--list") == 0)) - { - _list_tests(); - return 0; - } + if (!_efl_test_option_disp(argc, argv, etc)) + return 0; putenv("EFL_RUN_IN_TREE=1"); - s = ecore_suite_build(argc - 1, (const char **)argv + 1); - sr = srunner_create(s); - - srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); - - srunner_run_all(sr, CK_ENV); - failed_count = srunner_ntests_failed(sr); - srunner_free(sr); + failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1, + "Ecore", etc); return (failed_count == 0) ? 0 : 255; } diff --git a/src/tests/ecore/ecore_test_animator.c b/src/tests/ecore/ecore_test_animator.c index ed7f4ee886..98c7192a74 100644 --- a/src/tests/ecore/ecore_test_animator.c +++ b/src/tests/ecore/ecore_test_animator.c @@ -2,10 +2,11 @@ #include #endif +#include + #include #include "ecore_suite.h" -#include static double prev = 0; static Eina_Bool _anim_cb(void *data EINA_UNUSED, double pos) diff --git a/src/tests/ecore/ecore_test_ecore_audio.c b/src/tests/ecore/ecore_test_ecore_audio.c index 4be231c39c..5bceee28ae 100644 --- a/src/tests/ecore/ecore_test_ecore_audio.c +++ b/src/tests/ecore/ecore_test_ecore_audio.c @@ -2,17 +2,15 @@ #include #endif +#include #include +#include #include #include #include "ecore_suite.h" -#include -#include -#include - static Eina_Bool _failed_cb(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED) { Eina_Bool *pulse_context_failed = data; diff --git a/src/tests/ecore/ecore_test_ecore_file.c b/src/tests/ecore/ecore_test_ecore_file.c index 91003621c2..cb3928a580 100644 --- a/src/tests/ecore/ecore_test_ecore_file.c +++ b/src/tests/ecore/ecore_test_ecore_file.c @@ -9,9 +9,9 @@ #include #include -#include -#include #include +#include +#include #include "ecore_suite.h" diff --git a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c index d5bdc27f8f..fe5e32a44b 100644 --- a/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c +++ b/src/tests/ecore/ecore_test_ecore_thread_eina_thread_queue.c @@ -2,10 +2,11 @@ # include #endif -#include -#include -#include #include +#include + +#include +#include #include "ecore_suite.h" diff --git a/src/tests/ecore/ecore_test_ecore_x.c b/src/tests/ecore/ecore_test_ecore_x.c index 8baa9a560f..bb33374550 100644 --- a/src/tests/ecore/ecore_test_ecore_x.c +++ b/src/tests/ecore/ecore_test_ecore_x.c @@ -2,10 +2,10 @@ # include #endif -#include "ecore_suite.h" - #include +#include "ecore_suite.h" + /* FIXME: Currently disable these tests. They are useless ATM and they just * make buildbot complain. Once we add useful tests here we'll also bother * with getting X on the server. */ diff --git a/src/tests/efl_check.h b/src/tests/efl_check.h new file mode 100644 index 0000000000..96803122e7 --- /dev/null +++ b/src/tests/efl_check.h @@ -0,0 +1,115 @@ +#ifndef EFL_CHECK_H +#define EFL_CHECK_H + +#include /* getenv */ +#include /* fprintf, fputs */ +#include /* strcmp */ + +typedef struct _Efl_Test_Case Efl_Test_Case; +struct _Efl_Test_Case +{ + const char *test_case; + void (*build)(TCase *tc); +}; + +static void +_efl_tests_list(const Efl_Test_Case *etc) +{ + const Efl_Test_Case *itr = etc; + fputs("Available Test Cases:\n", stderr); + for (; itr->test_case; itr++) + fprintf(stderr, "\t%s\n", itr->test_case); +} + +static int +_efl_test_option_disp(int argc, char **argv, const Efl_Test_Case *etc) +{ + int i; + + for (i = 1; i < argc; i++) + if ((strcmp(argv[i], "-h") == 0) || + (strcmp(argv[i], "--help") == 0)) + { + fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n", + argv[0]); + _efl_tests_list(etc); + return 1; + } + else if ((strcmp(argv[i], "-l") == 0) || + (strcmp(argv[i], "--list") == 0)) + { + _efl_tests_list(etc); + return 1; + } + + return 0; +} + +static int +_efl_test_use(int argc, const char **argv, const char *test_case) +{ + if (argc < 1) + return 1; + + for (; argc > 0; argc--, argv++) + if (strcmp(test_case, *argv) == 0) + return 1; + return 0; +} + +static int +_efl_test_fork_has(SRunner *sr) +{ + if (srunner_fork_status(sr) == CK_FORK) + return 1; + else if (srunner_fork_status(sr) == CK_NOFORK) + return 0; + else if (srunner_fork_status(sr) == CK_FORK_GETENV) + { + char *res; + + res = getenv("CF_FORK"); + if (res && (strcmp(res, "no") == 0)) + return 0; + else + return 1; + } + + /* should never get there */ + return 0; +} + +static int +_efl_suite_build_and_run(int argc, const char **argv, const char *suite_name, const Efl_Test_Case *etc) +{ + Suite *s; + SRunner *sr; + TCase *tc; + int i, failed_count; + + s = suite_create(suite_name); + sr = srunner_create(s); + + for (i = 0; etc[i].test_case; ++i) + { + if (!_efl_test_use(argc, argv, etc[i].test_case)) + continue; + + tc = tcase_create(etc[i].test_case); + + if (_efl_test_fork_has(sr)) + tcase_set_timeout(tc, 0); + + etc[i].build(tc); + suite_add_tcase(s, tc); + } + + srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml"); + srunner_run_all(sr, CK_ENV); + failed_count = srunner_ntests_failed(sr); + srunner_free(sr); + + return failed_count; +} + +#endif