test_newlib_reent.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Test for multicore FreeRTOS. This test spins up threads, fiddles with queues etc.
  3. */
  4. #include <esp_types.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "freertos/FreeRTOS.h"
  8. #include "freertos/task.h"
  9. #include "freertos/semphr.h"
  10. #include "freertos/queue.h"
  11. #include "freertos/xtensa_api.h"
  12. #include "unity.h"
  13. volatile static int done;
  14. volatile static int error;
  15. static void tskTestRand(void *pvParameters)
  16. {
  17. int l;
  18. srand(0x1234);
  19. vTaskDelay((int)pvParameters / portTICK_PERIOD_MS);
  20. l = rand();
  21. printf("Rand1: %d\n", l);
  22. if (l != 869320854) {
  23. error++;
  24. }
  25. vTaskDelay((int)pvParameters / portTICK_PERIOD_MS);
  26. l = rand();
  27. printf("Rand2: %d\n", l);
  28. if (l != 1148737841) {
  29. error++;
  30. }
  31. done++;
  32. vTaskDelete(NULL);
  33. }
  34. // TODO: split this thing into separate orthogonal tests
  35. TEST_CASE("Test for per-task non-reentrant tasks", "[freertos]")
  36. {
  37. done = 0;
  38. error = 0;
  39. xTaskCreatePinnedToCore(tskTestRand, "tsk1", 2048, (void *)100, 3, NULL, 0);
  40. xTaskCreatePinnedToCore(tskTestRand, "tsk2", 2048, (void *)200, 3, NULL, 0);
  41. xTaskCreatePinnedToCore(tskTestRand, "tsk3", 2048, (void *)300, 3, NULL, portNUM_PROCESSORS - 1);
  42. xTaskCreatePinnedToCore(tskTestRand, "tsk4", 2048, (void *)400, 3, NULL, 0);
  43. while (done != 4) {
  44. vTaskDelay(1000 / portTICK_PERIOD_MS);
  45. }
  46. TEST_ASSERT(error == 0);
  47. }