aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am12
-rw-r--r--src/util/test_scheduler_hogging_cancel.c51
-rw-r--r--src/util/test_scheduler_hogging_priority.c55
3 files changed, 118 insertions, 0 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index ed01558eb..81b8a93b7 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -174,6 +174,8 @@ endif
174noinst_PROGRAMS = \ 174noinst_PROGRAMS = \
175 gnunet-config-diff \ 175 gnunet-config-diff \
176 test_common_logging_dummy \ 176 test_common_logging_dummy \
177 test_scheduler_hogging_cancel \
178 test_scheduler_hogging_priority \
177 gnunet-crypto-tvg 179 gnunet-crypto-tvg
178 180
179if ENABLE_TEST_RUN 181if ENABLE_TEST_RUN
@@ -587,6 +589,16 @@ test_scheduler_delay_SOURCES = \
587test_scheduler_delay_LDADD = \ 589test_scheduler_delay_LDADD = \
588 libgnunetutil.la 590 libgnunetutil.la
589 591
592test_scheduler_hogging_cancel_SOURCES = \
593 test_scheduler_hogging_cancel.c
594test_scheduler_hogging_cancel_LDADD = \
595 libgnunetutil.la
596
597test_scheduler_hogging_priority_SOURCES = \
598 test_scheduler_hogging_priority.c
599test_scheduler_hogging_priority_LDADD = \
600 libgnunetutil.la
601
590test_service_SOURCES = \ 602test_service_SOURCES = \
591 test_service.c 603 test_service.c
592test_service_LDADD = \ 604test_service_LDADD = \
diff --git a/src/util/test_scheduler_hogging_cancel.c b/src/util/test_scheduler_hogging_cancel.c
new file mode 100644
index 000000000..7611338b3
--- /dev/null
+++ b/src/util/test_scheduler_hogging_cancel.c
@@ -0,0 +1,51 @@
1#include "gnunet_util_lib.h"
2#include <unistd.h>
3
4static int count = 0;
5static int final_count;
6static struct GNUNET_SCHEDULER_Task *t4;
7
8static void end (void *cls)
9{
10 final_count = count;
11 count = 5000;
12 GNUNET_SCHEDULER_shutdown ();
13}
14
15static void self_rescheduling (void *cls)
16{
17 if (0 == count)
18 {
19 GNUNET_SCHEDULER_cancel (t4);
20 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_MILLISECONDS,
21 GNUNET_SCHEDULER_PRIORITY_URGENT,
22 &end,
23 NULL);
24 sleep (1);
25 /* end should be added to ready queue on next scheduler pass for certain
26 now */
27 }
28 if (++count < 5000)
29 {
30 GNUNET_SCHEDULER_add_now (&self_rescheduling, NULL);
31 }
32}
33
34static void to_be_canceled (void *cls)
35{
36 /* Don't run me! */
37}
38
39
40static void init (void *cls)
41{
42 GNUNET_SCHEDULER_add_now (&self_rescheduling, NULL);
43 t4 = GNUNET_SCHEDULER_add_now (&to_be_canceled, NULL);
44}
45
46
47int main (int argc, char **argv)
48{
49 GNUNET_SCHEDULER_run (&init, NULL);
50 return final_count < 5000 ? 0 : 1;
51}
diff --git a/src/util/test_scheduler_hogging_priority.c b/src/util/test_scheduler_hogging_priority.c
new file mode 100644
index 000000000..217a39ce7
--- /dev/null
+++ b/src/util/test_scheduler_hogging_priority.c
@@ -0,0 +1,55 @@
1#include "gnunet_util_lib.h"
2#include <unistd.h>
3
4static int count = 0;
5static int final_count;
6
7static void end (void *cls)
8{
9 final_count = count;
10 count = 5000;
11 GNUNET_SCHEDULER_shutdown ();
12}
13
14static void self_rescheduling (void *cls)
15{
16 if (count == 0)
17 {
18 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_MILLISECONDS,
19 GNUNET_SCHEDULER_PRIORITY_URGENT,
20 &end,
21 NULL);
22 sleep(1);
23 /* end should be added to ready queue on next scheduler pass for certain
24 now */
25 }
26 if (++count < 5000)
27 {
28 GNUNET_SCHEDULER_add_now (&self_rescheduling, NULL);
29 }
30}
31
32
33static void noop (void *cls)
34{
35}
36
37static void indirection (void *cls)
38{
39 GNUNET_SCHEDULER_add_with_reason_and_priority (&self_rescheduling, NULL,
40 GNUNET_SCHEDULER_REASON_STARTUP,
41 GNUNET_SCHEDULER_PRIORITY_HIGH);
42}
43
44static void init (void *cls)
45{
46 GNUNET_SCHEDULER_add_now (&indirection, NULL);
47 GNUNET_SCHEDULER_add_now (&noop, NULL);
48}
49
50
51int main (int argc, char **argv)
52{
53 GNUNET_SCHEDULER_run (&init, NULL);
54 return final_count < 5000 ? 0 : 1;
55}