cs_test.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdio.h>
  21. #include <string.h> /* for memset() */
  22. #include <unistd.h>
  23. #include <stdlib.h>
  24. #include <inttypes.h>
  25. #include "swscale.h"
  26. #include "rgb2rgb.h"
  27. #define SIZE 1000
  28. #define srcByte 0x55
  29. #define dstByte 0xBB
  30. #define FUNC(s,d,n) {s,d,#n,n}
  31. static int cpu_caps;
  32. static char *args_parse(int argc, char *argv[])
  33. {
  34. int o;
  35. while ((o = getopt(argc, argv, "m23")) != -1) {
  36. switch (o) {
  37. case 'm':
  38. cpu_caps |= SWS_CPU_CAPS_MMX;
  39. break;
  40. case '2':
  41. cpu_caps |= SWS_CPU_CAPS_MMX2;
  42. break;
  43. case '3':
  44. cpu_caps |= SWS_CPU_CAPS_3DNOW;
  45. break;
  46. default:
  47. av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o);
  48. }
  49. }
  50. return argv[optind];
  51. }
  52. int main(int argc, char **argv)
  53. {
  54. int i, funcNum;
  55. uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
  56. uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
  57. int failedNum=0;
  58. int passedNum=0;
  59. av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
  60. args_parse(argc, argv);
  61. av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps);
  62. sws_rgb2rgb_init(cpu_caps);
  63. for(funcNum=0; ; funcNum++){
  64. struct func_info_s {
  65. int src_bpp;
  66. int dst_bpp;
  67. const char *name;
  68. void (*func)(const uint8_t *src, uint8_t *dst, long src_size);
  69. } func_info[] = {
  70. FUNC(2, 2, rgb15to16),
  71. FUNC(2, 3, rgb15to24),
  72. FUNC(2, 4, rgb15to32),
  73. FUNC(2, 3, rgb16to24),
  74. FUNC(2, 4, rgb16to32),
  75. FUNC(3, 2, rgb24to15),
  76. FUNC(3, 2, rgb24to16),
  77. FUNC(3, 4, rgb24to32),
  78. FUNC(4, 2, rgb32to15),
  79. FUNC(4, 2, rgb32to16),
  80. FUNC(4, 3, rgb32to24),
  81. FUNC(2, 2, rgb16to15),
  82. FUNC(2, 2, rgb15tobgr15),
  83. FUNC(2, 2, rgb15tobgr16),
  84. FUNC(2, 3, rgb15tobgr24),
  85. FUNC(2, 4, rgb15tobgr32),
  86. FUNC(2, 2, rgb16tobgr15),
  87. FUNC(2, 2, rgb16tobgr16),
  88. FUNC(2, 3, rgb16tobgr24),
  89. FUNC(2, 4, rgb16tobgr32),
  90. FUNC(3, 2, rgb24tobgr15),
  91. FUNC(3, 2, rgb24tobgr16),
  92. FUNC(3, 3, rgb24tobgr24),
  93. FUNC(3, 4, rgb24tobgr32),
  94. FUNC(4, 2, rgb32tobgr15),
  95. FUNC(4, 2, rgb32tobgr16),
  96. FUNC(4, 3, rgb32tobgr24),
  97. FUNC(4, 4, rgb32tobgr32),
  98. FUNC(0, 0, NULL)
  99. };
  100. int width;
  101. int failed=0;
  102. int srcBpp=0;
  103. int dstBpp=0;
  104. if (!func_info[funcNum].func) break;
  105. av_log(NULL, AV_LOG_INFO,".");
  106. memset(srcBuffer, srcByte, SIZE);
  107. for(width=63; width>0; width--){
  108. int dstOffset;
  109. for(dstOffset=128; dstOffset<196; dstOffset+=4){
  110. int srcOffset;
  111. memset(dstBuffer, dstByte, SIZE);
  112. for(srcOffset=128; srcOffset<196; srcOffset+=4){
  113. uint8_t *src= srcBuffer+srcOffset;
  114. uint8_t *dst= dstBuffer+dstOffset;
  115. const char *name=NULL;
  116. if(failed) break; //don't fill the screen with shit ...
  117. srcBpp = func_info[funcNum].src_bpp;
  118. dstBpp = func_info[funcNum].dst_bpp;
  119. name = func_info[funcNum].name;
  120. func_info[funcNum].func(src, dst, width*srcBpp);
  121. if(!srcBpp) break;
  122. for(i=0; i<SIZE; i++){
  123. if(srcBuffer[i]!=srcByte){
  124. av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
  125. i, width, srcOffset, dstOffset, name);
  126. failed=1;
  127. break;
  128. }
  129. }
  130. for(i=0; i<dstOffset; i++){
  131. if(dstBuffer[i]!=dstByte){
  132. av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
  133. i, width, srcOffset, dstOffset, name);
  134. failed=1;
  135. break;
  136. }
  137. }
  138. for(i=dstOffset + width*dstBpp; i<SIZE; i++){
  139. if(dstBuffer[i]!=dstByte){
  140. av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
  141. i, width, srcOffset, dstOffset, name);
  142. failed=1;
  143. break;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. if(failed) failedNum++;
  150. else if(srcBpp) passedNum++;
  151. }
  152. av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
  153. return failedNum;
  154. }