19 #define do_random() (lcg_random(state->rng_state))
24 if (state && state->events >= COMPLETE_EVENTS) {
25 if (event_type == LP_FINI) {
26 test_printf(
"%" PRIu32
"\n", state->total_checksum);
28 state->head = deallocate_buffer(state->head, 0);
34 if (!state && event_type != LP_INIT && event_type != MODEL_INIT &&
35 event_type != MODEL_FINI) {
36 printf(
"[ERR] Requested to process an weird event\n");
52 4390023366657240769ULL);
55 unsigned buffers_to_allocate = do_random() * MAX_BUFFERS;
56 for (
unsigned i = 0; i < buffers_to_allocate; ++i) {
57 unsigned c = do_random() * MAX_BUFFER_SIZE /
sizeof(uint64_t);
58 state->head = allocate_buffer(state, NULL, c);
59 state->buffer_count++;
62 ScheduleNewEvent(me, 20 * do_random(), LOOP, NULL, 0);
67 ScheduleNewEvent(me, now + do_random() * 10, LOOP, NULL, 0);
69 if(do_random() < DOUBLING_PROBABILITY && dest != me)
70 ScheduleNewEvent(dest, now + do_random() * 10, LOOP, NULL, 0);
72 if (state->buffer_count) {
73 state->total_checksum = read_buffer(state->head, do_random() * state->buffer_count, state->total_checksum);
76 if (state->buffer_count < MAX_BUFFERS && do_random() < ALLOC_PROBABILITY) {
77 unsigned c = do_random() * MAX_BUFFER_SIZE /
sizeof(uint64_t);
78 state->head = allocate_buffer(state, NULL, c);
79 state->buffer_count++;
82 if (state->buffer_count && do_random() < DEALLOC_PROBABILITY) {
83 state->head = deallocate_buffer(state->head, do_random() * state->buffer_count);
84 state->buffer_count--;
87 if (state->buffer_count && do_random() < SEND_PROBABILITY) {
88 unsigned i = do_random() * state->buffer_count;
89 buffer *to_send = get_buffer(state->head, i);
91 dest = do_random() *
n_lps;
92 ScheduleNewEvent(dest, now + do_random() * 10, RECEIVE, to_send->data, to_send->count *
sizeof(uint64_t));
94 state->head = deallocate_buffer(state->head, i);
95 state->buffer_count--;
100 if(state->buffer_count >= MAX_BUFFERS)
102 state->head = allocate_buffer(state, event_content, event_size /
sizeof(uint64_t));
103 state->buffer_count++;
110 printf(
"[ERR] Requested to process an unknown event\n");
116 bool CanEnd(
lp_id_t me,
const void *snapshot)
120 return state->events >= COMPLETE_EVENTS;