testIdmaMain.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #ifdef _XOS
  5. #define IDMA_APP_USE_XOS // will use inlined disable/enable int
  6. #endif
  7. #ifdef _XTOS
  8. #define IDMA_APP_USE_XTOS // will use inlined disable/enable int
  9. #endif
  10. //#include "CppUTest/CommandLineTestRunner.h"
  11. #include "CppUTest/TestHarness.h"
  12. #include "dmaif.h"
  13. #ifdef DSP_TEST
  14. #define IDMA_DEBUG 1
  15. // IDMA_BUFFER_DEFINE(task_write, 1, IDMA_64B_DESC);
  16. #define TCM_SIZE (32 * 1024)
  17. #define HOR_RES 4096
  18. #define VER_RES 3072
  19. #define SIZE_PER_PEX_BIT 8
  20. #define LINE_SIZE ((HOR_RES * SIZE_PER_PEX_BIT + 7) / 8)
  21. #define N_LINE 16
  22. static char temp_bufer_tcm0[TCM_SIZE] __attribute__((section(".dram0.data")));
  23. static char temp_bufer_tcm1[TCM_SIZE] __attribute__((section(".dram1.data")));
  24. #define MAX_ENTRY 256
  25. uint32_t post_isp_tick[MAX_ENTRY];
  26. uint32_t isp_int_tick[MAX_ENTRY];
  27. int32_t post_isp_cnt;
  28. int32_t isp_int_cnt;
  29. int compare(char *dst, char *src, uint32_t size) {
  30. int i;
  31. for (i = 0; i < size; i++) {
  32. if (src[i] != dst[i]) {
  33. printf("Compare fail,expect:%d,actrul:%d,at:%d\n", src[i], dst[i],
  34. i);
  35. return -1;
  36. }
  37. }
  38. return 0;
  39. }
  40. #define FRAME_NUM 2
  41. #define N_BUFFER_NUM 2
  42. char dst_pic[FRAME_NUM][VER_RES * LINE_SIZE];
  43. char source_pic[FRAME_NUM][VER_RES * LINE_SIZE];
  44. TEST_GROUP(TileIdmaTest){
  45. void setup(){
  46. int ind1, ind2,ind3;
  47. const int step=64;
  48. idma_obj =dmaif_getDMACtrl();
  49. idma_obj->init();
  50. for (ind1 = 0; ind1 < FRAME_NUM; ind1++) {
  51. for (ind2 = 0; ind2 < VER_RES; ind2++) {
  52. for(ind3 = 0;ind3 < LINE_SIZE; ind3+=step)
  53. {
  54. source_pic[ind1][LINE_SIZE * ind2+ind3] = (char)(rand() % 256);
  55. }
  56. dst_pic[ind1][LINE_SIZE * ind2] = (char)((rand() + 1) % 256);
  57. dst_pic[ind1][LINE_SIZE * (ind2 + 1) - 1] = (char)((rand() + 1) % 256);
  58. }
  59. }
  60. }
  61. int dumy_process(xvTile * out_tile,xvTile * in_tile)
  62. {
  63. if(!in_tile || !out_tile)
  64. {
  65. return -1;
  66. }
  67. uint32_t size_in = XV_TILE_GET_PITCH_IN_BYTES(in_tile)*XV_TILE_GET_HEIGHT(in_tile);
  68. uint32_t size_out = XV_TILE_GET_PITCH_IN_BYTES(out_tile)*XV_TILE_GET_HEIGHT(out_tile);
  69. uint32_t size = size_in>size_out?size_out:size_in;
  70. memcpy((void*)XV_TILE_GET_DATA_PTR(out_tile),(void*)XV_TILE_GET_DATA_PTR(in_tile),size);
  71. return 0;
  72. }
  73. void teardown() {
  74. idma_obj->uninit();
  75. idma_obj=NULL;
  76. }
  77. TMDMA * idma_obj;
  78. };
  79. TEST(TileIdmaTest, TestOneFrameTileBaseProcess_1) {
  80. uint32_t frame_counter = 0;
  81. TBOOL ret = TTRUE;
  82. unsigned int width=640;
  83. unsigned int height=480;
  84. unsigned int pitch=640;
  85. unsigned int pixRes=1;
  86. unsigned int tile_width =64;
  87. unsigned int tile_height =16;
  88. unsigned int tile_pitch=64;
  89. unsigned int x=0,y=0;
  90. xvTile *in_tile_obj;
  91. xvTile *out_tile_obj;
  92. uint32_t data_size;
  93. in_tile_obj = idma_obj->setup((uint64_t)&source_pic[0][0],VER_RES * LINE_SIZE,width,height,width,pixRes,1,0,0,
  94. tile_width*tile_height*pixRes,tile_width,tile_height,tile_width,0,0,0,XV_TILE_U8,DATA_ALIGNED_32);
  95. out_tile_obj = idma_obj->setup((uint64_t)&dst_pic[0][0],VER_RES * LINE_SIZE,width,height,width,pixRes,1,0,0,
  96. tile_width*tile_height*pixRes,tile_width,tile_height,tile_width,0,0,0,XV_TILE_U8,DATA_ALIGNED_32);
  97. do
  98. {
  99. ret =idma_obj->load(in_tile_obj, 0,0,0,0,0,0, 1);
  100. ret &=idma_obj->waitLoadDone(in_tile_obj);
  101. if(0!=dumy_process(out_tile_obj,in_tile_obj))
  102. {
  103. ret = TFALSE;
  104. break;
  105. }
  106. ret &=idma_obj->store(out_tile_obj, 0,0,0,0,0,0, 1);
  107. ret &=idma_obj->waitStoreDone(out_tile_obj);
  108. x+=tile_width;
  109. if(x>=width)
  110. {
  111. x=0;
  112. y+=tile_height;
  113. if(y>=height)
  114. {
  115. y=0;
  116. }
  117. }
  118. // XV_TILE_SET_X_COORD(in_tile_obj,x);
  119. // XV_TILE_SET_X_COORD(out_tile_obj,x);
  120. idma_obj->config(in_tile_obj,x,y);
  121. // XV_TILE_SET_Y_COORD(in_tile_obj,y);
  122. // XV_TILE_SET_Y_COORD(out_tile_obj,y);
  123. idma_obj->config(out_tile_obj,x,y);
  124. }while(!((in_tile_obj->x==0)&&(in_tile_obj->y==0)));
  125. ret &=idma_obj->release(in_tile_obj);
  126. ret &=idma_obj->release(out_tile_obj);
  127. CHECK_TRUE(ret);
  128. ret = compare((char *)dst_pic, (char *)source_pic, width * height*pixRes);
  129. CHECK_EQUAL_ZERO(ret);
  130. }
  131. TEST(TileIdmaTest, TestOneFrameNoTileBaseProcess_1) {
  132. int loop;
  133. unsigned int width=640;
  134. unsigned int height=480;
  135. unsigned int pitch=640;
  136. unsigned int pixRes=1;
  137. unsigned int tile_width =64;
  138. unsigned int tile_height =16;
  139. unsigned int tile_pitch=64;
  140. int buf_tcm_size = tile_pitch*tile_height*pixRes;
  141. int frame_size = height*pitch*pixRes;
  142. // int buf_out_tcm_size = buf_in_tcm_size;
  143. int fragment_size = frame_size % buf_tcm_size;
  144. int loop_num = frame_size / buf_tcm_size;
  145. TBOOL ret = TTRUE;
  146. int size = buf_tcm_size;
  147. loop_num = fragment_size ? loop_num + 1 : loop_num;
  148. uint32_t frame_counter = 0;
  149. uint32_t start,end;
  150. uint32_t data_size;
  151. uint32_t *buf_in_ptr;
  152. // uint32_t *buf_out_ptr;
  153. buf_in_ptr = (uint32_t *)idma_obj->allocateTcm(buf_tcm_size,0,32);
  154. for (loop = 0; loop < loop_num; loop++) {
  155. uint64_t dst1_wide =
  156. ((uint64_t)0xffffffff) & ((uint64_t)buf_in_ptr);
  157. uint64_t src1_wide = (uint64_t)source_pic + size * loop;
  158. uint64_t dst2_wide = (uint64_t)dst_pic + size * loop;
  159. if (loop == (loop_num - 1) && fragment_size) {
  160. size = fragment_size;
  161. }
  162. data_size= idma_obj->load(NULL,dst1_wide,src1_wide,size,size,1,size,1);
  163. ret &= data_size==0?TFALSE:TTRUE;
  164. data_size= idma_obj->store(NULL,dst2_wide,dst1_wide,size,size,1,size,1);
  165. ret &= data_size==0?TFALSE:TTRUE;
  166. ret &= idma_obj->waitDone(NULL,NULL);
  167. }
  168. ret &= idma_obj->freeTcm(buf_in_ptr);
  169. CHECK_TRUE(ret);
  170. ret = compare((char *)dst_pic, (char *)source_pic, width * height*pixRes);
  171. CHECK_EQUAL_ZERO(ret);
  172. }
  173. #endif
  174. //int main(int argc, char **argv) { return RUN_ALL_TESTS(argc, argv); }