dsp_x_test.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #include <string.h>
  2. #include <stdio.h>>
  3. #include <stdlib.h>
  4. #include <sys/mman.h>
  5. #include <sys/stat.h>
  6. #include <sys/types.h>
  7. #include "csi_dsp_api.h"
  8. #include "csi_dsp_task_defs.h"
  9. #include "csi_dsp_post_process_defs.h"
  10. #define PAYLOAD_SIZE 32
  11. struct message{
  12. int cmd;
  13. char message[PAYLOAD_SIZE];
  14. };
  15. int
  16. compareBuffers(int expected, char* src, char* dst, int size)
  17. {
  18. int i;
  19. for(i = 0 ; i < size; i++) {
  20. if (dst[i] != src[i]) {
  21. if (expected) {
  22. printf("MISMATCH EXPECTED @ byte %d (dst:%x, src:%x)!!\n", i, dst[i], src[i]);
  23. }
  24. else {
  25. printf("COPY FAILED @ byte %d (dst:%x, src:%x)!!\n", i, dst[i], src[i]);
  26. return -1;
  27. }
  28. }
  29. }
  30. printf("Compare OK (src:%p, dst:%p, len:%d)\n", src, dst, size);
  31. return 0;
  32. }
  33. int load_data_from_file(char *fileInName,void* buf,size_t data_size)
  34. {
  35. // char *fileInName = NULL;
  36. // char *fileReferenceName = NULL;
  37. char fileOutName[512];
  38. int rt;
  39. FILE *file;
  40. // fileInName = "./test/obj_bits_1280.dat";
  41. // //fileOutName = argv[2];
  42. // fileReferenceName = "./test/ref_bits_1280.dat";
  43. // file = fopen(fileReferenceName, "rb");
  44. // if (file != NULL) {
  45. // fread(ref_binary, sizeof(char), 1280*1087/8, file);
  46. // fclose(file);
  47. // } else {
  48. // printf("open ref file fail: %s", fileReferenceName);
  49. // return -1;
  50. // }
  51. file = fopen(fileInName, "rb");
  52. if(file != NULL){
  53. fread(buf, sizeof(char), data_size, file);
  54. fclose(file);
  55. } else
  56. {
  57. printf("open obj file fail: %s", fileInName);
  58. return -2;
  59. }
  60. return 0;
  61. }
  62. int main(int argc, char *argv[])
  63. {
  64. printf("********************************\n");
  65. printf("[dsp ant x_test] test\n");
  66. printf("********************************\n");
  67. int en_compress = 0;
  68. if (argc < 2) {
  69. printf("[dsp test] please provide parameter in following format:\n");
  70. printf(" ./test_dsp_x_test, en_compress(0/1).");
  71. exit(-1);
  72. }
  73. if (argc >= 2)
  74. {
  75. en_compress = atoi(argv[1]);
  76. }
  77. void *instance = csi_dsp_create_instance(1);
  78. if(!instance)
  79. {
  80. printf("create fail\n");
  81. return -1;
  82. }
  83. void *task= csi_dsp_create_task(instance,CSI_DSP_TASK_SW_TO_SW);
  84. if(!task)
  85. {
  86. printf("task create fail\n");
  87. return -1;
  88. }
  89. if(csi_dsp_task_acquire_algo(task,"x_test_flo"))
  90. {
  91. printf("algo kernel load fail\n");
  92. return -1;
  93. }
  94. struct csi_sw_task_req* req=NULL;
  95. req =csi_dsp_task_create_request(task);
  96. if(req==NULL)
  97. {
  98. printf("req create fail\n");
  99. return -1;
  100. }
  101. struct csi_dsp_buffer buf2;
  102. struct csi_dsp_buffer buf1;
  103. /*****************************input buffer****************************************/
  104. if(en_compress)
  105. {
  106. buf1.buf_id = 0;
  107. buf1.dir = CSI_DSP_BUFFER_IN;
  108. buf1.type = CSI_DSP_BUF_ALLOC_DRV;
  109. buf1.plane_count = 1;
  110. buf1.width =1280;
  111. buf1.height =960;
  112. buf1.planes[0].stride= 1280;
  113. buf1.planes[0].size=1280*1180*2;
  114. if(csi_dsp_request_add_buffer(req,&buf1))
  115. {
  116. printf("%s,add buffer:%d\n",__FUNCTION__,buf1.buf_id);
  117. csi_dsp_task_release_request(req);
  118. return -1;
  119. }
  120. if(load_data_from_file("obj_bits_1280.dat",buf1.planes[0].buf_vir,buf1.planes[0].size))
  121. {
  122. return -1;
  123. }
  124. }
  125. else
  126. {
  127. buf1.buf_id = 0;
  128. buf1.dir = CSI_DSP_BUFFER_IN;
  129. buf1.type = CSI_DSP_BUF_ALLOC_DRV;
  130. buf1.plane_count = 1;
  131. buf1.width =1280;
  132. buf1.height =960;
  133. buf1.planes[0].stride= 1280/8;
  134. buf1.planes[0].size=1280*1180/8;
  135. if(csi_dsp_request_add_buffer(req,&buf1))
  136. {
  137. printf("%s,add buffer:%d\n",__FUNCTION__,buf1.buf_id);
  138. csi_dsp_task_release_request(req);
  139. return -1;
  140. }
  141. if(load_data_from_file("obj_bits_1280.dat",buf1.planes[0].buf_vir,1280*960/8))
  142. {
  143. return -1;
  144. }
  145. }
  146. /*****************************output buffer****************************************/
  147. buf2.buf_id = 1;
  148. buf2.dir = CSI_DSP_BUFFER_OUT;
  149. buf2.type = CSI_DSP_BUF_ALLOC_DRV;
  150. buf2.plane_count = 1;
  151. buf2.width =320;
  152. buf2.height =240;
  153. buf2.planes[0].stride= 320*2;
  154. buf2.planes[0].size=640*480*2;
  155. if(csi_dsp_request_add_buffer(req,&buf2))
  156. {
  157. printf("%s,add buffer:%d\n",__FUNCTION__,buf2.buf_id);
  158. csi_dsp_task_release_request(req);
  159. return -1;
  160. }
  161. memset(buf2.planes[0].buf_vir,0x00,buf2.planes[0].size);
  162. /*****************************user defineed buffer****************************************/
  163. struct csi_dsp_buffer buf3 =
  164. {
  165. .buf_id = 2,
  166. .dir = CSI_DSP_BUFFER_IN_OUT,
  167. .type = CSI_DSP_BUF_ALLOC_DRV,
  168. .plane_count = 1,
  169. .width =1280,
  170. .height =1080,
  171. .planes[0].stride= 1280/8,
  172. .planes[0].size= 1280*1180/8,
  173. };
  174. if(csi_dsp_request_add_buffer(req,&buf3))
  175. {
  176. printf("%s,add buffer:%d\n",__FUNCTION__,buf3.buf_id);
  177. csi_dsp_task_release_request(req);
  178. return -1;
  179. }
  180. if(load_data_from_file("ref_bits_1280.dat",buf3.planes[0].buf_vir,1280*1087/8))
  181. {
  182. return -1;
  183. }
  184. if(en_compress)
  185. {
  186. struct csi_dsp_buffer buf4 =
  187. {
  188. .buf_id = 2,
  189. .dir = CSI_DSP_BUFFER_IN_OUT,
  190. .type = CSI_DSP_BUF_ALLOC_DRV,
  191. .plane_count = 1,
  192. .width =1280,
  193. .height =1080,
  194. .planes[0].stride= 1280/8,
  195. .planes[0].size= 1280*1180/8,
  196. };
  197. if(csi_dsp_request_add_buffer(req,&buf4))
  198. {
  199. printf("%s,add buffer:%d\n",__FUNCTION__,buf4.buf_id);
  200. csi_dsp_task_release_request(req);
  201. return -1;
  202. }
  203. }
  204. if(csi_dsp_request_set_property(req,&en_compress,sizeof(en_compress)))
  205. {
  206. printf("%s,seting req fail:%d\n",__FUNCTION__);
  207. csi_dsp_task_release_request(req);
  208. return -1;
  209. }
  210. if(csi_dsp_request_enqueue(req))
  211. {
  212. printf("%s,req enqueu fail:%d\n",__FUNCTION__);
  213. csi_dsp_task_release_request(req);
  214. return -1;
  215. }
  216. req = csi_dsp_request_dequeue(task);
  217. if(req==NULL && req->status != CSI_DSP_SW_REQ_DONE)
  218. {
  219. printf("%s,req dequeue fail:%d\n",__FUNCTION__);
  220. return -1;
  221. }
  222. short result[320*240];
  223. load_data_from_file("result.raw",result,320*240*2);
  224. if(compareBuffers(1,(void*)buf2.planes[0].buf_vir,result,320*240*2))
  225. {
  226. printf("%s,ERR cmp fail\n",__FUNCTION__);
  227. csi_dsp_task_release_request(req);
  228. csi_dsp_destroy_task(task);
  229. csi_dsp_delete_instance(instance);
  230. printf("%s,Test FAIL!\n",__FUNCTION__);
  231. return -1;
  232. }
  233. csi_dsp_task_release_request(req);
  234. csi_dsp_destroy_task(task);
  235. csi_dsp_delete_instance(instance);
  236. printf("%s,Test Pass!\n",__FUNCTION__);
  237. return 0;
  238. }