pico_stdio_test.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2023 Raspberry Pi (Trading) Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdio.h>
  7. #include "pico/stdlib.h"
  8. #include "pico/multicore.h"
  9. #include "pico/test.h"
  10. PICOTEST_MODULE_NAME("pico_stdio_test", "pico_stdio test harness");
  11. static volatile bool deadlock_test_done;
  12. static void deadlock_test_core1(void) {
  13. busy_wait_ms(250);
  14. for(int i=0;i<1000;i++) {
  15. if (deadlock_test_done) break;
  16. printf("Hello from core 1 - %d\n", i);
  17. busy_wait_ms(23);
  18. }
  19. }
  20. static volatile bool deadlock_test_irq_called;
  21. static int64_t deadlock_test_alarm(alarm_id_t id, void *param) {
  22. static int foo;
  23. printf("Here is a printf from the IRQ %d\n", ++foo);
  24. deadlock_test_irq_called = true;
  25. return 100;
  26. }
  27. int main() {
  28. stdio_init_all();
  29. for(int i=0;i<10;i++) {
  30. printf("Hello %d\n", i);
  31. }
  32. printf("pico_stdio_test begins\n");
  33. PICOTEST_START();
  34. // Check default config has valid data in it
  35. PICOTEST_START_SECTION("STDIO deadlock test");
  36. multicore_launch_core1(deadlock_test_core1);
  37. alarm_id_t alarm_id = add_alarm_in_ms(500, deadlock_test_alarm, NULL, false);
  38. PICOTEST_CHECK(getchar_timeout_us(2000000) < 0, "someone pressed a key!");
  39. deadlock_test_done = true;
  40. cancel_alarm(alarm_id);
  41. sleep_ms(100);
  42. PICOTEST_CHECK(deadlock_test_irq_called, "deadlock_test_irq was not called");
  43. PICOTEST_END_SECTION();
  44. PICOTEST_END_TEST();
  45. }