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 int main(int argc, char **argv)
00037 {
00038 int i, funcNum;
00039 uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE);
00040 uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE);
00041 int failedNum=0;
00042 int passedNum=0;
00043
00044 if (!srcBuffer || !dstBuffer)
00045 return -1;
00046
00047 av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n");
00048 sws_rgb2rgb_init();
00049
00050 for(funcNum=0; ; funcNum++) {
00051 struct func_info_s {
00052 int src_bpp;
00053 int dst_bpp;
00054 const char *name;
00055 void (*func)(const uint8_t *src, uint8_t *dst, int src_size);
00056 } func_info[] = {
00057 FUNC(2, 2, rgb15to16),
00058 FUNC(2, 3, rgb15to24),
00059 FUNC(2, 4, rgb15to32),
00060 FUNC(2, 3, rgb16to24),
00061 FUNC(2, 4, rgb16to32),
00062 FUNC(3, 2, rgb24to15),
00063 FUNC(3, 2, rgb24to16),
00064 FUNC(3, 4, rgb24to32),
00065 FUNC(4, 2, rgb32to15),
00066 FUNC(4, 2, rgb32to16),
00067 FUNC(4, 3, rgb32to24),
00068 FUNC(2, 2, rgb16to15),
00069 FUNC(2, 2, rgb15tobgr15),
00070 FUNC(2, 2, rgb15tobgr16),
00071 FUNC(2, 3, rgb15tobgr24),
00072 FUNC(2, 4, rgb15tobgr32),
00073 FUNC(2, 2, rgb16tobgr15),
00074 FUNC(2, 2, rgb16tobgr16),
00075 FUNC(2, 3, rgb16tobgr24),
00076 FUNC(2, 4, rgb16tobgr32),
00077 FUNC(3, 2, rgb24tobgr15),
00078 FUNC(3, 2, rgb24tobgr16),
00079 FUNC(3, 3, rgb24tobgr24),
00080 FUNC(3, 4, rgb24tobgr32),
00081 FUNC(4, 2, rgb32tobgr15),
00082 FUNC(4, 2, rgb32tobgr16),
00083 FUNC(4, 3, rgb32tobgr24),
00084 FUNC(4, 4, shuffle_bytes_2103),
00085 FUNC(0, 0, NULL)
00086 };
00087 int width;
00088 int failed=0;
00089 int srcBpp=0;
00090 int dstBpp=0;
00091
00092 if (!func_info[funcNum].func) break;
00093
00094 av_log(NULL, AV_LOG_INFO,".");
00095 memset(srcBuffer, srcByte, SIZE);
00096
00097 for(width=63; width>0; width--) {
00098 int dstOffset;
00099 for(dstOffset=128; dstOffset<196; dstOffset+=4) {
00100 int srcOffset;
00101 memset(dstBuffer, dstByte, SIZE);
00102
00103 for(srcOffset=128; srcOffset<196; srcOffset+=4) {
00104 uint8_t *src= srcBuffer+srcOffset;
00105 uint8_t *dst= dstBuffer+dstOffset;
00106 const char *name=NULL;
00107
00108 if(failed) break;
00109
00110 srcBpp = func_info[funcNum].src_bpp;
00111 dstBpp = func_info[funcNum].dst_bpp;
00112 name = func_info[funcNum].name;
00113
00114 func_info[funcNum].func(src, dst, width*srcBpp);
00115
00116 if(!srcBpp) break;
00117
00118 for(i=0; i<SIZE; i++) {
00119 if(srcBuffer[i]!=srcByte) {
00120 av_log(NULL, AV_LOG_INFO, "src damaged at %d w:%d src:%d dst:%d %s\n",
00121 i, width, srcOffset, dstOffset, name);
00122 failed=1;
00123 break;
00124 }
00125 }
00126 for(i=0; i<dstOffset; i++) {
00127 if(dstBuffer[i]!=dstByte) {
00128 av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
00129 i, width, srcOffset, dstOffset, name);
00130 failed=1;
00131 break;
00132 }
00133 }
00134 for(i=dstOffset + width*dstBpp; i<SIZE; i++) {
00135 if(dstBuffer[i]!=dstByte) {
00136 av_log(NULL, AV_LOG_INFO, "dst damaged at %d w:%d src:%d dst:%d %s\n",
00137 i, width, srcOffset, dstOffset, name);
00138 failed=1;
00139 break;
00140 }
00141 }
00142 }
00143 }
00144 }
00145 if(failed) failedNum++;
00146 else if(srcBpp) passedNum++;
00147 }
00148
00149 av_log(NULL, AV_LOG_INFO, "\n%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
00150 return failedNum;
00151 }