32tv_lt(
const struct timeval *t1,
const struct timeval *t2)
34 if (t1->tv_sec < t2->tv_sec)
38 else if (t1->tv_sec > t2->tv_sec)
44 return t1->tv_usec < t2->tv_usec;
49tv_le(
const struct timeval *t1,
const struct timeval *t2)
51 if (t1->tv_sec < t2->tv_sec)
55 else if (t1->tv_sec > t2->tv_sec)
61 return t1->tv_usec <= t2->tv_usec;
66tv_eq(
const struct timeval *t1,
const struct timeval *t2)
68 return t1->tv_sec == t2->tv_sec && t1->tv_usec == t2->tv_usec;
83 unsigned int *count,
struct timeval *least,
84 const struct timeval *min,
const struct timeval *max)
87 unsigned int maxdepth = depth;
92 assert_ptr_not_equal(e, e->
lt);
93 assert_ptr_not_equal(e, e->
gt);
94 assert_ptr_not_equal(e, e->
parent);
97 assert_true(!e->
lt || e->
lt != e->
gt);
113 assert_true(
tv_le(min, &e->
tv));
114 assert_true(
tv_le(&e->
tv, max));
121 if (least &&
tv_lt(&e->
tv, least))
150 max.tv_sec = 0x7FFFFFFF;
151 max.tv_usec = 0x7FFFFFFF;
163 tv->tv_sec +=
random() % 100;
164 tv->tv_usec =
random() % 100;
171 struct timeval least;
173 least.tv_sec = least.tv_usec = 0x7FFFFFFF;
175 unsigned int count = 0;
180 unsigned int bit_ceil_n = 1;
181 unsigned int log2n = 0;
182 while (bit_ceil_n < n)
190 assert_true(maxlev >= log2n);
195 assert_true(
tv_eq(&least, &e->
tv));
204 for (
unsigned int i = 0; i < size; ++i)
206 const unsigned int src = (
unsigned int)rand() % size;
210 array[i] = array[src];
220 for (
unsigned int i = 0; i < indent; ++i)
242 printf(
"*************************\n");
250 unsigned int n = 1000;
251 unsigned int n_mod = 25;
259 for (
unsigned int i = 0; i < n; ++i)
273 for (
unsigned int j = 1; j <= n_mod; ++j)
277 for (
unsigned int i = 0; i < n; ++i)
299 assert_null(s->
root);
301 for (
unsigned int i = 0; i < n; ++i)
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
#define ALLOC_ARRAY(dptr, type, n)
Allocate memory for an array of n elements of the given type.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
const char * tv_string(const struct timeval *tv, struct gc_arena *gc)
struct schedule * schedule_init(void)
void schedule_remove_node(struct schedule *s, struct schedule_entry *e)
struct schedule_entry * schedule_find_least(struct schedule_entry *e)
int schedule_entry_compare(const struct schedule_entry *e1, const struct schedule_entry *e2)
This method compares two schedule entries and return which one is earlier,later or equal.
void schedule_add_modify(struct schedule *s, struct schedule_entry *e)
void schedule_free(struct schedule *s)
Garbage collection arena used to keep track of dynamically allocated memory.
struct schedule_entry * lt
struct schedule_entry * parent
struct schedule_entry * gt
struct schedule_entry * root
void schedule_verify(struct schedule *s, unsigned int n)
unsigned int schedule_debug(struct schedule *s, unsigned int *count, struct timeval *least)
static bool tv_le(const struct timeval *t1, const struct timeval *t2)
static bool tv_eq(const struct timeval *t1, const struct timeval *t2)
void tv_randomize(struct timeval *tv)
static struct schedule_entry * schedule_find_earliest_wakeup(struct schedule *s)
void schedule_randomize_array(struct schedule_entry **array, unsigned int size)
static bool tv_lt(const struct timeval *t1, const struct timeval *t2)
void schedule_test(void **state)
Runs the schedule test.
void schedule_print_work(struct schedule_entry *e, unsigned int indent)
unsigned int schedule_debug_entry(const struct schedule_entry *e, unsigned int depth, unsigned int *count, struct timeval *least, const struct timeval *min, const struct timeval *max)
void schedule_print(struct schedule *s)