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