test_newlib_reent.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "unity.h"
  12. volatile static int done;
  13. volatile static int error;
  14. static void tskTestRand(void *pvParameters)
  15. {
  16. int l;
  17. srand(0x1234);
  18. vTaskDelay((int)pvParameters / portTICK_PERIOD_MS);
  19. l = rand();
  20. printf("Rand1: %d\n", l);
  21. if (l != 869320854) {
  22. error++;
  23. }
  24. vTaskDelay((int)pvParameters / portTICK_PERIOD_MS);
  25. l = rand();
  26. printf("Rand2: %d\n", l);
  27. if (l != 1148737841) {
  28. error++;
  29. }
  30. done++;
  31. vTaskDelete(NULL);
  32. }
  33. // TODO: split this thing into separate orthogonal tests
  34. TEST_CASE("Test for per-task non-reentrant tasks", "[freertos]")
  35. {
  36. done = 0;
  37. error = 0;
  38. xTaskCreatePinnedToCore(tskTestRand, "tsk1", 2048, (void *)100, 3, NULL, 0);
  39. xTaskCreatePinnedToCore(tskTestRand, "tsk2", 2048, (void *)200, 3, NULL, 0);
  40. xTaskCreatePinnedToCore(tskTestRand, "tsk3", 2048, (void *)300, 3, NULL, portNUM_PROCESSORS - 1);
  41. xTaskCreatePinnedToCore(tskTestRand, "tsk4", 2048, (void *)400, 3, NULL, 0);
  42. while (done != 4) {
  43. vTaskDelay(1000 / portTICK_PERIOD_MS);
  44. }
  45. TEST_ASSERT(error == 0);
  46. }