EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / tests / eina_test_sched.c
1 /* EINA - EFL data type library
2  * Copyright (C) 2008 Cedric Bail
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library;
16  * if not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22
23 #if defined(EFL_HAVE_THREADS) && defined __linux__
24 #include <pthread.h>
25 #include <errno.h>
26 #include <sys/resource.h>
27 #endif
28
29 #include "eina_suite.h"
30 #include "Eina.h"
31
32 #if defined(EFL_HAVE_THREADS) && defined __linux__
33
34 /*
35  * TODO: Test if RT priorities are right. However, make check should be run as
36  * root.
37  */
38
39 static void *
40 _thread_run(void *arg __UNUSED__)
41 {
42     int niceval = getpriority(PRIO_PROCESS, 0);
43     int niceval2;
44     eina_sched_prio_drop();
45
46     niceval2 = getpriority(PRIO_PROCESS, 0);
47     fail_if((niceval2 != 19) && (niceval2 != niceval+5));
48
49     return NULL;
50 }
51
52 START_TEST(eina_test_sched_prio_drop)
53 {
54     int niceval = getpriority(PRIO_PROCESS, 0);
55     int niceval2;
56     pthread_t tid;
57
58     eina_init();
59
60     pthread_create(&tid, NULL, _thread_run, NULL);
61
62     niceval2 = getpriority(PRIO_PROCESS, 0);
63     /* niceness of main thread should not have changed */
64     fail_if(niceval2 != niceval);
65
66     pthread_join(tid, NULL);
67     /* niceness of main thread should not have changed */
68     fail_if(niceval2 != niceval);
69
70     eina_shutdown();
71 }
72 END_TEST
73 #else
74 START_TEST(eina_test_sched_prio_drop)
75 {
76    fprintf(stderr, "scheduler priority is not supported by your configuration.\n");
77 }
78 END_TEST
79 #endif
80
81 void
82 eina_test_sched(TCase *tc)
83 {
84    tcase_add_test(tc, eina_test_sched_prio_drop);
85 }