| 649 | } |
| 650 | |
| 651 | static void test_timer_stress(void) |
| 652 | { |
| 653 | rt_tick_t start; |
| 654 | rt_ubase_t iters = 0; |
| 655 | rt_ubase_t cur_tick; |
| 656 | rt_ubase_t next_print_time; |
| 657 | |
| 658 | LOG_I("timer stress test begin, it will take %d seconds", 3*TEST_TIME_S); |
| 659 | |
| 660 | for (int i = 0; i < sizeof(timer_flag_periodic); i++) |
| 661 | { |
| 662 | for (int j = 0; j < STRESS_TIMERS; j++) |
| 663 | { |
| 664 | rt_timer_init(&stress_timer[j], |
| 665 | "stress_timer", |
| 666 | timer_stress, |
| 667 | &stress_timer[j], |
| 668 | j + 1, |
| 669 | timer_flag_periodic[i]); |
| 670 | } |
| 671 | |
| 672 | start = rt_tick_get(); |
| 673 | cur_tick = rt_tick_get(); |
| 674 | next_print_time = cur_tick + RT_TICK_PER_SECOND; |
| 675 | while (cur_tick - start <= TEST_TIME_S * RT_TICK_PER_SECOND) |
| 676 | { |
| 677 | for (int j = 0; j < STRESS_TIMERS; j++) |
| 678 | { |
| 679 | if (rand() % 2 == 0) |
| 680 | { |
| 681 | rt_timer_start(&stress_timer[j]); |
| 682 | } |
| 683 | else |
| 684 | { |
| 685 | rt_timer_stop(&stress_timer[j]); |
| 686 | } |
| 687 | } |
| 688 | iters ++; |
| 689 | cur_tick = rt_tick_get(); |
| 690 | if (cur_tick > next_print_time) |
| 691 | { |
| 692 | PRINT_PROGRESS(next_print_time); |
| 693 | next_print_time = cur_tick + RT_TICK_PER_SECOND; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | for (int j = 0; j < STRESS_TIMERS; j++) |
| 698 | { |
| 699 | rt_timer_detach(&stress_timer[j]); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | LOG_I("success after %lu iterations", iters); |
| 704 | } |
| 705 | |
| 706 | static rt_err_t utest_tc_init(void) |
| 707 | { |
nothing calls this directly
no test coverage detected