test3.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include <software_watchdog.h>
  3. // in this test it is expected that the watchdog_timeout_cb1 is called, but not watchdog_timeout_cb2
  4. int test_result = -1;
  5. bool cb1called = false;
  6. bool cb2called = false;
  7. void watchdog_timeout_cb1(void *data)
  8. {
  9. SoftwareWatchdog *watchdog = data;
  10. printf("!! watchdog_timeout_cb1 called !! \n");
  11. fflush(stdout);
  12. cb1called = true;
  13. }
  14. void watchdog_timeout_cb2(void *data)
  15. {
  16. SoftwareWatchdog *watchdog = data;
  17. printf("!! watchdog_timeout_cb2 called !! \n");
  18. fflush(stdout);
  19. cb2called = true;
  20. }
  21. int main(void){
  22. printHelloWorld();
  23. SoftwareWatchdog watchdog1;
  24. struct timespec timeout1;
  25. timeout1.tv_nsec = 500*1000000;
  26. timeout1.tv_sec = 1;
  27. swd_setup(&watchdog1, "watchdog1", watchdog_timeout_cb1, timeout1, NULL);
  28. swd_enable(&watchdog1);
  29. SoftwareWatchdog watchdog2;
  30. struct timespec timeout2;
  31. timeout2.tv_nsec = 500*1000000;
  32. timeout2.tv_sec = 1;
  33. swd_setup(&watchdog2, "watchdog2", watchdog_timeout_cb2, timeout2, NULL);
  34. swd_enable(&watchdog2);
  35. printf("Main: Sleeping for some seconds:\n");
  36. for (int i = 3; i > 0; i--) {
  37. swd_kick(&watchdog2);
  38. printf("%d\n", i);
  39. fflush(stdout);
  40. sleep(1);
  41. }
  42. if(cb1called && !cb2called)
  43. return 0;
  44. return -1;
  45. }