00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <unistd.h>
00024 #include <stdlib.h>
00025 #include <inttypes.h>
00026
00027 #include "swscale.h"
00028 #include "rgb2rgb.h"
00029
00030 #define SIZE 1000
00031 #define srcByte 0x55
00032 #define dstByte 0xBB
00033
00034 #define FUNC(s,d,n) {s,d,#n,n}
00035
00036 static int cpu_caps;
00037
00038 static char *args_parse(int argc, char *argv[])
00039 {
00040 int o;
00041
00042 while ((o = getopt(argc, argv, "m23")) != -1) {
00043 switch (o) {
00044 case 'm':
00045 cpu_caps |= SWS_CPU_CAPS_MMX;
00046 break;
00047 case '2':
00048 cpu_caps |= SWS_CPU_CAPS_MMX2;
00049 break;
00050 case '3':
00051 cpu_caps |= SWS_CPU_CAPS_3DNOW;
00052 break;
00053 default:
00054 av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o);
00055 }
00056 }
00057
00058 return argv[optind];
00059 }
00060
00061 int main(int argc, char **argv)
00062 {
00063 int i, funcNum;
00064 uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
00065 uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
00066 int failedNum=0;
00067 int passedNum=0;
00068
00069 av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
00070 args_parse(argc, argv);
00071 av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps);
00072 sws_rgb2rgb_init(cpu_caps);
00073
00074 for(funcNum=0; ; funcNum++){
00075 struct func_info_s {
00076 int src_bpp;
00077 int dst_bpp;
00078 const char *name;
00079 void (*func)(const uint8_t *src, uint8_t *dst, long src_size);
00080 } func_info[] = {
00081 FUNC(2, 2, rgb15to16),
00082 FUNC(2, 3, rgb15to24),
00083 FUNC(2, 4, rgb15to32),
00084 FUNC(2, 3, rgb16to24),
00085 FUNC(2, 4, rgb16to32),
00086 FUNC(3, 2, rgb24to15),
00087 FUNC(3, 2, rgb24to16),
00088 FUNC(3, 4, rgb24to32),
00089 FUNC(4, 2, rgb32to15),
00090 FUNC(4, 2, rgb32to16),
00091 FUNC(4, 3, rgb32to24),
00092 FUNC(2, 2, rgb16to15),
00093 FUNC(2, 2, rgb15tobgr15),
00094 FUNC(2, 2, rgb15tobgr16),
00095 FUNC(2, 3, rgb15tobgr24),
00096 FUNC(2, 4, rgb15tobgr32),
00097 FUNC(2, 2, rgb16tobgr15),
00098 FUNC(2, 2, rgb16tobgr16),
00099 FUNC(2, 3, rgb16tobgr24),
00100 FUNC(2, 4, rgb16tobgr32),
00101 FUNC(3, 2, rgb24tobgr15),
00102 FUNC(3, 2, rgb24tobgr16),
00103 FUNC(3, 3, rgb24tobgr24),
00104 FUNC(3, 4, rgb24tobgr32),
00105 FUNC(4, 2, rgb32tobgr15),
00106 FUNC(4, 2, rgb32tobgr16),
00107 FUNC(4, 3, rgb32tobgr24),
00108 FUNC(4, 4, rgb32tobgr32),
00109 FUNC(0, 0, NULL)
00110 };
00111 int width;
00112 int failed=0;
00113 int srcBpp=0;
00114 int dstBpp=0;
00115
00116 if (!func_info[funcNum].func) break;
00117
00118 av_log(NULL, AV_LOG_INFO,".");
00119 memset(srcBuffer, srcByte, SIZE);
00120
00121 for(width=63; width>0; width--){
00122 int dstOffset;
00123 for(dstOffset=128; dstOffset<196; dstOffset+=4){
00124 int srcOffset;
00125 memset(dstBuffer, dstByte, SIZE);
00126
00127 for(srcOffset=128; srcOffset<196; srcOffset+=4){
00128 uint8_t *src= srcBuffer+srcOffset;
00129 uint8_t *dst= dstBuffer+dstOffset;
00130 const char *name=NULL;
00131
00132 if(failed) break;
00133
00134 srcBpp = func_info[funcNum].src_bpp;
00135 dstBpp = func_info[funcNum].dst_bpp;
00136 name = func_info[funcNum].name;
00137
00138 func_info[funcNum].func(src, dst, width*srcBpp);
00139
00140 if(!srcBpp) break;
00141
00142 for(i=0; i<SIZE; i++){
00143 if(srcBuffer[i]!=srcByte){
00144 av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
00145 i, width, srcOffset, dstOffset, name);
00146 failed=1;
00147 break;
00148 }
00149 }
00150 for(i=0; i<dstOffset; i++){
00151 if(dstBuffer[i]!=dstByte){
00152 av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
00153 i, width, srcOffset, dstOffset, name);
00154 failed=1;
00155 break;
00156 }
00157 }
00158 for(i=dstOffset + width*dstBpp; i<SIZE; i++){
00159 if(dstBuffer[i]!=dstByte){
00160 av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
00161 i, width, srcOffset, dstOffset, name);
00162 failed=1;
00163 break;
00164 }
00165 }
00166 }
00167 }
00168 }
00169 if(failed) failedNum++;
00170 else if(srcBpp) passedNum++;
00171 }
00172
00173 av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
00174 return failedNum;
00175 }