test_index.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "m-string.h"
  2. #include <stdio.h>
  3. #include <furi.h>
  4. #include <furi-hal.h>
  5. #include "minunit_vars.h"
  6. #include <notification/notification-messages.h>
  7. #include <cli/cli.h>
  8. #include <loader/loader.h>
  9. #define TAG "UnitTests"
  10. int run_minunit();
  11. int run_minunit_test_irda_decoder_encoder();
  12. int run_minunit_test_rpc();
  13. int run_minunit_test_flipper_file();
  14. void minunit_print_progress(void) {
  15. static char progress[] = {'\\', '|', '/', '-'};
  16. static uint8_t progress_counter = 0;
  17. static TickType_t last_tick = 0;
  18. TickType_t current_tick = xTaskGetTickCount();
  19. if(current_tick - last_tick > 20) {
  20. last_tick = current_tick;
  21. printf("[%c]\033[3D", progress[++progress_counter % COUNT_OF(progress)]);
  22. }
  23. }
  24. void minunit_print_fail(const char* str) {
  25. printf("%s\n", str);
  26. }
  27. void unit_tests_cli(Cli* cli, string_t args, void* context) {
  28. uint32_t test_result = 0;
  29. minunit_run = 0;
  30. minunit_assert = 0;
  31. minunit_fail = 0;
  32. minunit_status = 0;
  33. Loader* loader = furi_record_open("loader");
  34. NotificationApp* notification = furi_record_open("notification");
  35. // TODO: lock device while test running
  36. if(loader_is_locked(loader)) {
  37. FURI_LOG_E(TAG, "RPC: stop all applications to run tests");
  38. notification_message(notification, &sequence_blink_magenta_100);
  39. } else {
  40. notification_message_block(notification, &sequence_set_only_blue_255);
  41. uint32_t heap_before = memmgr_get_free_heap();
  42. uint32_t cycle_counter = DWT->CYCCNT;
  43. test_result |= run_minunit();
  44. test_result |= run_minunit_test_irda_decoder_encoder();
  45. test_result |= run_minunit_test_rpc();
  46. test_result |= run_minunit_test_flipper_file();
  47. cycle_counter = (DWT->CYCCNT - cycle_counter);
  48. FURI_LOG_I(TAG, "Consumed: %0.2fs", (float)cycle_counter / (SystemCoreClock));
  49. if(test_result == 0) {
  50. delay(200); /* wait for tested services and apps to deallocate */
  51. uint32_t heap_after = memmgr_get_free_heap();
  52. notification_message(notification, &sequence_success);
  53. if(heap_after != heap_before) {
  54. FURI_LOG_E(TAG, "Leaked: %d", heap_before - heap_after);
  55. } else {
  56. FURI_LOG_I(TAG, "No leaks");
  57. }
  58. FURI_LOG_I(TAG, "PASSED");
  59. } else {
  60. notification_message(notification, &sequence_error);
  61. FURI_LOG_E(TAG, "FAILED");
  62. }
  63. }
  64. furi_record_close("notification");
  65. furi_record_close("loader");
  66. }
  67. void unit_tests_cli_init() {
  68. Cli* cli = furi_record_open("cli");
  69. // We need to launch apps from tests, so we cannot lock loader
  70. cli_add_command(cli, "unit_tests", CliCommandFlagParallelSafe, unit_tests_cli, NULL);
  71. furi_record_close("cli");
  72. }