1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

increase test coverage

This commit is contained in:
Steffen Vogel 2016-10-13 22:12:06 -04:00
parent e6639cded5
commit 8017cffe2f
2 changed files with 115 additions and 3 deletions

View file

@ -7,15 +7,99 @@
*********************************************************************************/
#include <stdint.h>
#include <string.h>
#include <criterion/criterion.h>
#include "utils.h"
#include "list.h"
static char *nouns[] = { "time", "person", "year", "way", "day", "thing", "man", "world", "life", "hand", "part", "child", "eye", "woman", "place", "work", "week", "case", "point", "government", "company", "number", "group", "problem", "fact" };
struct data {
char *tag;
int data;
};
Test(list, list_lookup)
{
struct list l;
list_init(&l);
for (int i = 0; i < ARRAY_LEN(nouns); i++) {
struct data *d = malloc(sizeof(struct data));
d->tag = nouns[i];
d->data = i;
list_push(&l, d);
}
struct data *found = list_lookup(&l, "woman");
cr_assert_eq(found->data, 13);
list_destroy(&l, NULL, true);
}
Test(list, list_search)
{
struct list l;
list_init(&l);
/* Fill list */
for (int i = 0; i < ARRAY_LEN(nouns); i++)
list_push(&l, nouns[i]);
/* Declare on stack! */
char positive[] = "woman";
char negative[] = "dinosaurrier";
char *found = (char *) list_search(&l, (cmp_cb_t) strcmp, positive);
cr_assert_not_null(found);
cr_assert_eq(found, nouns[13]);
cr_assert_str_eq(found, positive);
char *not_found = (char *) list_search(&l, (cmp_cb_t) strcmp, negative);
cr_assert_null(not_found);
list_destroy(&l, NULL, false);
}
struct content {
int destroyed;
};
static void dtor(void *ptr)
{
struct content *elm = (struct content *) ptr;
elm->destroyed = 1;
}
Test(list, destructor)
{
struct list l;
struct content elm = { .destroyed = 0 };
list_init(&l);
list_push(&l, &elm);
cr_assert_eq(list_length(&l), 1);
list_destroy(&l, dtor, false);
cr_assert_eq(elm.destroyed, 1);
}
static int compare(const void *a, const void *b) {
return b - a;
}
Test(test, basics)
Test(list, basics)
{
intptr_t i;
struct list l;

View file

@ -6,6 +6,7 @@
* Unauthorized copying of this file, via any medium is strictly prohibited.
*********************************************************************************/
#include <unistd.h>
#include <criterion/criterion.h>
#include "timing.h"
@ -75,7 +76,32 @@ Test(timing, time_to_from_double)
cr_assert_float_eq(dbl, ref, 1e-9);
}
Test(timing, timerfd_wait_until) {
Test(timing, timerfd_create_rate)
{
struct timespec start, end;
double rate = 5, waited;
int tfd = timerfd_create_rate(rate);
cr_assert(tfd > 0);
for (int i = 0; i < 10; i++) {
start = time_now();
timerfd_wait(tfd);
end = time_now();
waited = time_delta(&start, &end);
cr_assert_float_eq(waited, 1.0 / rate, 10e-3, "We slept for %f instead of %f secs in round %d", waited, 1.0 / rate, i);
}
close(tfd);
}
Test(timing, timerfd_wait_until)
{
int tfd = timerfd_create(CLOCK_REALTIME, 0);
cr_assert(tfd > 0);
@ -92,5 +118,7 @@ Test(timing, timerfd_wait_until) {
double waited = time_delta(&start, &end);
cr_assert_float_eq(waited, waitfor, 1e-3, "We slept for %f instead of %f secs", waited, waitfor);
cr_assert_float_eq(waited, waitfor, 5e-3, "We slept for %f instead of %f secs", waited, waitfor);
close(tfd);
}