This is an old revision of the document!
Standard simulation environments
Simulating CHP programs often requires creating an environment to inject data into the circuit being tested, and an environment that reads the outputs of the circuit to check their values. actsim
comes with a simulation library that has some common functionality that can be used for this purpose.
- etest.act
import sim; defproc buffer(chan?(int) I; chan!(int) O) { int x; chp { *[ I?x; O!(x+2) ] } } defproc test() { buffer b; sim::source_sequence<32 /* 32-bit test */, 4 /* 4 data values */, {1,5,8,53} /* data values */, false /* repeat these data values forever */, 0 /* source ID for log messages */, false /* detailed log messages turned off */ > t1(b.I); sim::sink<32 /* 32-bit data */, 0 /* sink ID for log messages */, true /* detailed log messages turned on */> t2(b.O); }
Running this produces the following result:
$ actsim -p test etest.act WARNING: source_sequence<32,4,{1,5,8,53},f,0,f>: substituting chp model (requested prs, not found) WARNING: buffer<>: substituting chp model (requested prs, not found) WARNING: sink<32,0,t>: substituting chp model (requested prs, not found) actsim> cycle [ 50] <t2> Sink 0: Received value 3 (0x3) [ 80] <t2> Sink 0: Received value 7 (0x7) [ 110] <t2> Sink 0: Received value 10 (0xa) [ 140] <t1> Source 0: Sequence ended. [ 140] <t2> Sink 0: Received value 55 (0x37)