test-prioq.c revision b826ab586c9e0a9c0d438a75c28cf3a8ab485929
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering This file is part of systemd.
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering Copyright 2013 Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering (at your option) any later version.
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering systemd is distributed in the hope that it will be useful, but
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering Lesser General Public License for more details.
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1d22e9068c52c1cf935bcdff70b9b9654e3c939eLennart Poetteringstatic int unsigned_compare(const void *a, const void *b) {
1d22e9068c52c1cf935bcdff70b9b9654e3c939eLennart Poettering const unsigned *x = a, *y = b;
1d22e9068c52c1cf935bcdff70b9b9654e3c939eLennart Poetteringstatic void test_unsigned(void) {
4e2f8d27781731021aa6b96c0ee18a8966eefe1cLennart Poettering for (i = 0; i < ELEMENTSOF(buffer); i++) {
1d22e9068c52c1cf935bcdff70b9b9654e3c939eLennart Poettering u = (unsigned) rand();
4e2f8d27781731021aa6b96c0ee18a8966eefe1cLennart Poettering assert_se(prioq_put(q, UINT_TO_PTR(u), NULL) >= 0);
a911bb9ab27ac0eb3bbf4e8b4109e5da9b88eee3Lennart Poettering qsort(buffer, ELEMENTSOF(buffer), sizeof(buffer[0]), unsigned_compare);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering for (i = 0; i < ELEMENTSOF(buffer); i++) {
2d4a39e759c4ab846ad8a546abeddd40bc8d736eLennart Poettering assert_se(prioq_size(q) == ELEMENTSOF(buffer) - i);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringstatic int test_compare(const void *a, const void *b) {
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering const struct test *x = a, *y = b;
718db96199eb307751264e4163555662c9a389faLennart Poetteringstatic void test_hash(const void *a, struct siphash *state) {
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering const struct test *x = a;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering siphash24_compress(&x->value, sizeof(x->value), state);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringstatic const struct hash_ops test_hash_ops = {
adb3a45d9a1cebdec30406cc2c04503fc5e735beLennart Poetteringstatic void test_struct(void) {
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering unsigned previous = 0, i;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering for (i = 0; i < SET_SIZE; i++) {
2d4a39e759c4ab846ad8a546abeddd40bc8d736eLennart Poettering if (i % 4 == 0) {
718db96199eb307751264e4163555662c9a389faLennart Poettering assert_se(prioq_size(q) == (SET_SIZE * 3 / 4) - i);