test_index.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 TESTS_TAG "UNIT_TESTS"
  10. int run_minunit();
  11. int run_minunit_test_irda_decoder_encoder();
  12. int run_minunit_test_rpc();
  13. void minunit_print_progress(void) {
  14. static char progress[] = {'\\', '|', '/', '-'};
  15. static uint8_t progress_counter = 0;
  16. static TickType_t last_tick = 0;
  17. TickType_t current_tick = xTaskGetTickCount();
  18. if(current_tick - last_tick > 20) {
  19. last_tick = current_tick;
  20. printf("[%c]\033[3D", progress[++progress_counter % COUNT_OF(progress)]);
  21. }
  22. }
  23. void minunit_print_fail(const char* str) {
  24. printf("%s\n", str);
  25. }
  26. void unit_tests_cli(Cli* cli, string_t args, void* context) {
  27. uint32_t test_result = 0;
  28. minunit_run = 0;
  29. minunit_assert = 0;
  30. minunit_fail = 0;
  31. minunit_status = 0;
  32. Loader* loader = furi_record_open("loader");
  33. furi_record_close("loader");
  34. NotificationApp* notification = furi_record_open("notification");
  35. furi_record_close("notification");
  36. if(loader_is_locked(loader)) {
  37. FURI_LOG_E(TESTS_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. test_result |= run_minunit();
  43. test_result |= run_minunit_test_irda_decoder_encoder();
  44. test_result |= run_minunit_test_rpc();
  45. if(test_result == 0) {
  46. delay(200); /* wait for tested services and apps to deallocate */
  47. uint32_t heap_after = memmgr_get_free_heap();
  48. notification_message(notification, &sequence_success);
  49. if(heap_after != heap_before) {
  50. FURI_LOG_E(TESTS_TAG, "Leaked: %d", heap_before - heap_after);
  51. } else {
  52. FURI_LOG_I(TESTS_TAG, "No leaks");
  53. }
  54. FURI_LOG_I(TESTS_TAG, "PASSED");
  55. } else {
  56. notification_message(notification, &sequence_error);
  57. FURI_LOG_E(TESTS_TAG, "FAILED");
  58. }
  59. }
  60. }
  61. void unit_tests_cli_init() {
  62. Cli* cli = furi_record_open("cli");
  63. cli_add_command(cli, "unit_tests", CliCommandFlagParallelSafe, unit_tests_cli, NULL);
  64. furi_record_close("cli");
  65. }