Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #27752
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Newsgroups | comp.arch.embedded |
| Subject | Unit testing for embedded development |
| Date | 2018-05-18 09:18 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <pdluoq$7rm$1@dont-email.me> (permalink) |
I'm not an expert on test-driven development. I know the general ideas
behind TDD, however I never used it in my projects.
I want to start using TDD, at least creating some unit testing on some
more critical units. However I have many difficulties.
For a module that calculates a checksum, it is very simple to create a
unit test. However an embedded firmware is more complex.
Consider a simple example. When the user press button 1, a buzzer must
be activated for 1 second.
----- Start of buzzer.c -----
#include "timer.h"
#include "bsp.h"
statis Timer tmr_buzzer;
void buzzer_on(uint16 time_ms) {
TimerSet(&tmr_buzzer, time_ms);
bsp_buzzer_on();
}
void buzzer_off(void) {
bsp_buzzer_off();
}
void buzzer_task(void) {
if (TimerExpired(&tmr_buzzer)) {
buzzer_off();
}
}
----- End of buzzer.c -----
Of course I have a bsp.c/bsp.h and a timer.c/timer.h.
Now I want to create a unit test for buzzer module, to run on PC.
----- Start of test_buzzer.c -----
#include <stdbool.h>
#include "timer.h" /* driver for PC testing */
#include "bsp.h" /* bsp_buzzer_on/off declarations */
static bool buzzer_on;
int main(int argc, char *argv[]) {
/* Test if buzzer_on() works */
buzzer_on(10000);
if (!buzzer_on) ... test failed ...
/* Wait for 10010 ms */
if (buzzer_on) ... test failed ...
...
}
void bsp_buzzer_on(void) { buzzer_on = true; }
void bsp_buzzer_off(void) { buzzer_on = false; }
----- End of test_buzzer.c -----
How do you simulate passing of the time (wait for 1010ms)? Of course, I
don't want to wait 10 seconds for the test. I need to speed up the time.
Is this the correct way to create a unit testing for a buzzer library?
Back to comp.arch.embedded | Previous | Next — Next in thread | Find similar | Unroll thread
Unit testing for embedded development pozz <pozzugno@gmail.com> - 2018-05-18 09:18 +0200 Re: Unit testing for embedded development Tobias Baumann <tobias.baumann@elpra.de> - 2018-05-18 10:10 +0200 Re: Unit testing for embedded development Tom Gardner <spamjunk@blueyonder.co.uk> - 2018-05-18 09:17 +0100 Re: Unit testing for embedded development Paul Rubin <no.email@nospam.invalid> - 2018-05-18 01:23 -0700 Re: Unit testing for embedded development StateMachineCOM <statemachineguru@gmail.com> - 2018-05-19 08:15 -0700
csiph-web