aboutsummaryrefslogtreecommitdiff
path: root/core/test/run-timer.c
blob: 75c40fe299e1959bab6f7f3dd111fbd561a16a94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

#define __TEST__
#include <timer.h>

#define mftb()	(stamp)
#define sync()

static uint64_t stamp, last;
struct lock;
static inline void lock(struct lock *l) { (void)l; }
static inline void unlock(struct lock *l) { (void)l; }

unsigned long tb_hz = 512000000;

#include "../timer.c"

#define NUM_TIMERS	100

static struct timer timers[NUM_TIMERS];
static unsigned int rand_shift, count;

static void init_rand(void)
{
	unsigned long max = RAND_MAX;

	/* Get something reasonably small */
	while(max > 0x10000) {
		rand_shift++;
		max >>= 1;
	}
}

static void expiry(struct timer *t, void *data, uint64_t now)
{
	(void)data;
	(void)now;
	assert(t->target >= last);
	count--;
}

void slw_update_timer_expiry(uint64_t new_target)
{
	(void)new_target;
	/* FIXME: do intersting SLW timer sim */
}

int main(void)
{
	unsigned int i;

	init_rand();
	for (i = 0; i < NUM_TIMERS; i++) {
		init_timer(&timers[i], expiry, NULL);
		schedule_timer(&timers[i], random() >> rand_shift);
	}
	count = NUM_TIMERS;
	while(count) {
		check_timers(false);
		stamp++;
	}
	return 0;
}