How to perform unit testing for developed c code in Creator ?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DeAa_335316
Level 4
Level 4
First like received

Hello,

I have developed c code by using PSoc Creator and i want to know about how to test performance of developed code.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

You can measure amount of CPU clock cycles consumed by some piece of code using custom StopWatch component (attached). It uses system SysTick timer to count CPU cycles. The component is rather unfinished, but works for PSoC4, 4M and 5LP. To measure CPU clocks put StopWatch_Start() and StopWatch_Stop() in your code, and print result on terminal:

StopWatch_Start() ; // reset timer

// your code is here (function, ISR, etc.)

.....

StopWatch_Stop() ; // stop timer

uint32 BusClockTicks = StopWatch_Cycles; // read result

To add StopWatch component to you project, Import it from the demo project attached.

StopWatch_P4M_01a.png

StopWatch_P4M_01.PNG

View solution in original post

3 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Do you want to do a unit-test (as in 'testing for correctness') or a performance test (as in 'how fast is it')? For the former, I can recommend the combination of Ceedling, CMock and Unity. Note that especially mocking can be interesting since you need to abstract from your hardware.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

And for the second case (how fast...) use a logic analyzer and toggle a pin to see how fast things go on...

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

You can measure amount of CPU clock cycles consumed by some piece of code using custom StopWatch component (attached). It uses system SysTick timer to count CPU cycles. The component is rather unfinished, but works for PSoC4, 4M and 5LP. To measure CPU clocks put StopWatch_Start() and StopWatch_Stop() in your code, and print result on terminal:

StopWatch_Start() ; // reset timer

// your code is here (function, ISR, etc.)

.....

StopWatch_Stop() ; // stop timer

uint32 BusClockTicks = StopWatch_Cycles; // read result

To add StopWatch component to you project, Import it from the demo project attached.

StopWatch_P4M_01a.png

StopWatch_P4M_01.PNG