3 #include <time.h> /* for time() in srand() */
11 #define NEPOCHS 100000
13 /* Function prototypes */
14 void foo1(void *data
);
15 void foo2(void *data
);
25 int main(int argc
, char *argv
[])
27 state_t
*state
[NSTATES
];
28 void (*pf
[])(void *) = { foo1
, foo2
, NULL
};
33 printf("Initializing fsm\n");
34 fsm_init(&fsm
, 2<<11, 5, 0);
36 /* Initialize random number generator */
39 /* Initialize states */
40 printf("Initializing states (%u)\n", NSTATES
);
41 for (i
= 0; i
< NSTATES
; i
++) {
42 if (state_init(&state
[i
], 2<<12, 2) == ST_NOMEM
) {
43 fprintf(stderr
, "error: state_init(): ST_NOMEM\n");
44 for (j
= 0; j
< i
; j
++)
51 /* Populate states with events they can handle */
52 printf("Populating states with events (events/state = %u)\n", NEVENTS
);
53 for (i
= 0; i
< NSTATES
; i
++) {
54 for (j
= 0; j
< NEVENTS
; j
++) {
55 if (state_add_evt(state
[i
], j
, "", pf
[rand() % 3], state
[i
]) == ST_NOMEM
) {
56 fprintf(stderr
, "error: state_add_evt(): ST_NOMEM\n");
57 for (k
= 0; k
< i
; k
++)
65 /* Add states to fsm */
66 printf("Adding states to fsm (%u)\n", NSTATES
);
67 for (i
= 0; i
< NSTATES
; i
++)
68 fsm_add_state(fsm
, i
, state
[i
]);
70 /* Set initial state */
71 fsm_set_state(fsm
, 0);
74 printf("Simulating (events = %u)\n", NEPOCHS
);
75 for (i
= 0; i
< NEPOCHS
; i
++)
76 fsm_process_event(fsm
, rand() % NEVENTS
, NULL
);
79 printf("Destroying FSM\n");