test3.c 1.4 KB

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