test-event.c revision 9da4cb2be260ed123f2676cb85cb350c527b1492
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
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.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-event.h"
#include "log.h"
#include "util.h"
#include "macro.h"
#include "signal-util.h"
return 1;
}
static unsigned got_d;
got_unref = true;
return 0;
}
got_a = true;
got_b = true;
got_d++;
if (got_d < 2)
else
} else
assert_not_reached("Yuck!");
return 1;
}
assert_se(s);
return 1;
}
sd_event_source *p = NULL;
assert_se(s);
if (pid == 0)
_exit(0);
assert_se(sd_event_add_child(sd_event_source_get_event(s), &p, pid, WEXITED, child_handler, INT_TO_PTR('f')) >= 0);
return 1;
}
sd_event_source *p = NULL;
assert_se(s);
assert_se(sd_event_add_signal(sd_event_source_get_event(s), &p, SIGUSR1, signal_handler, INT_TO_PTR('e')) >= 0);
return 1;
}
static bool do_quit = false;
if (do_quit) {
sd_event_source *p;
assert_se(sd_event_add_defer(sd_event_source_get_event(s), &p, defer_handler, INT_TO_PTR('d')) >= 0);
} else {
got_c = true;
}
} else
assert_not_reached("Huh?");
return 2;
}
static bool got_exit = false;
got_exit = true;
return 3;
}
static void test_basic(void) {
static const char ch = 'x';
int a[2] = { -1, -1 }, b[2] = { -1, -1}, d[2] = { -1, -1}, k[2] = { -1, -1 };
assert_se(sd_event_default(&e) >= 0);
assert_se(sd_event_set_watchdog(e, true) >= 0);
/* Test whether we cleanly can destroy an io event source from its own handler */
got_unref = false;
/* Add a oneshot handler, trigger it, re-enable it, and trigger
* it again. */
/* Test for floating event sources */
do_quit = true;
assert_se(sd_event_loop(e) >= 0);
sd_event_unref(e);
safe_close_pair(a);
safe_close_pair(b);
safe_close_pair(d);
safe_close_pair(k);
}
static int last_rtqueue_sigval = 0;
static int n_rtqueue = 0;
n_rtqueue ++;
return 0;
}
static void test_rtqueue(void) {
assert_se(sd_event_default(&e) >= 0);
assert_se(last_rtqueue_sigval == 0);
assert_se(sd_event_run(e, 0) == 0); /* the other SIGUSR2 is dropped, because the first one was still queued */
sd_event_unref(e);
}
test_basic();
test_rtqueue();
return 0;
}