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 <stdlib.h>
00024 #include <inttypes.h>
00025
00026 #include "swscale.h"
00027 #include "rgb2rgb.h"
00028 #include "libavutil/mem.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 = av_malloc(SIZE);
00040 uint8_t *dstBuffer = 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, rgb12to15),
00058 FUNC(2, 2, rgb15to16),
00059 FUNC(2, 3, rgb15to24),
00060 FUNC(2, 4, rgb15to32),
00061 FUNC(2, 3, rgb16to24),
00062 FUNC(2, 4, rgb16to32),
00063 FUNC(3, 2, rgb24to15),
00064 FUNC(3, 2, rgb24to16),
00065 FUNC(3, 4, rgb24to32),
00066 FUNC(4, 2, rgb32to15),
00067 FUNC(4, 2, rgb32to16),
00068 FUNC(4, 3, rgb32to24),
00069 FUNC(2, 2, rgb16to15),
00070 FUNC(2, 2, rgb12tobgr12),
00071 FUNC(2, 2, rgb15tobgr15),
00072 FUNC(2, 2, rgb15tobgr16),
00073 FUNC(2, 3, rgb15tobgr24),
00074 FUNC(2, 4, rgb15tobgr32),
00075 FUNC(2, 2, rgb16tobgr15),
00076 FUNC(2, 2, rgb16tobgr16),
00077 FUNC(2, 3, rgb16tobgr24),
00078 FUNC(2, 4, rgb16tobgr32),
00079 FUNC(3, 2, rgb24tobgr15),
00080 FUNC(3, 2, rgb24tobgr16),
00081 FUNC(3, 3, rgb24tobgr24),
00082 FUNC(3, 4, rgb24tobgr32),
00083 FUNC(4, 2, rgb32tobgr15),
00084 FUNC(4, 2, rgb32tobgr16),
00085 FUNC(4, 3, rgb32tobgr24),
00086 FUNC(4, 4, shuffle_bytes_2103),
00087 FUNC(6, 6, rgb48tobgr48_nobswap),
00088 FUNC(6, 6, rgb48tobgr48_bswap),
00089 FUNC(8, 6, rgb64to48_nobswap),
00090 FUNC(8, 6, rgb64to48_bswap),
00091 FUNC(8, 6, rgb64tobgr48_nobswap),
00092 FUNC(8, 6, rgb64tobgr48_bswap),
00093 FUNC(0, 0, NULL)
00094 };
00095 int width;
00096 int failed = 0;
00097 int srcBpp = 0;
00098 int dstBpp = 0;
00099
00100 if (!func_info[funcNum].func)
00101 break;
00102
00103 av_log(NULL, AV_LOG_INFO, ".");
00104 memset(srcBuffer, srcByte, SIZE);
00105
00106 for (width = 63; width > 0; width--) {
00107 int dstOffset;
00108 for (dstOffset = 128; dstOffset < 196; dstOffset += 4) {
00109 int srcOffset;
00110 memset(dstBuffer, dstByte, SIZE);
00111
00112 for (srcOffset = 128; srcOffset < 196; srcOffset += 4) {
00113 uint8_t *src = srcBuffer + srcOffset;
00114 uint8_t *dst = dstBuffer + dstOffset;
00115 const char *name = NULL;
00116
00117
00118 if (failed)
00119 break;
00120
00121 srcBpp = func_info[funcNum].src_bpp;
00122 dstBpp = func_info[funcNum].dst_bpp;
00123 name = func_info[funcNum].name;
00124
00125 func_info[funcNum].func(src, dst, width * srcBpp);
00126
00127 if (!srcBpp)
00128 break;
00129
00130 for (i = 0; i < SIZE; i++) {
00131 if (srcBuffer[i] != srcByte) {
00132 av_log(NULL, AV_LOG_INFO,
00133 "src damaged at %d w:%d src:%d dst:%d %s\n",
00134 i, width, srcOffset, dstOffset, name);
00135 failed = 1;
00136 break;
00137 }
00138 }
00139 for (i = 0; i < dstOffset; i++) {
00140 if (dstBuffer[i] != dstByte) {
00141 av_log(NULL, AV_LOG_INFO,
00142 "dst damaged at %d w:%d src:%d dst:%d %s\n",
00143 i, width, srcOffset, dstOffset, name);
00144 failed = 1;
00145 break;
00146 }
00147 }
00148 for (i = dstOffset + width * dstBpp; i < SIZE; i++) {
00149 if (dstBuffer[i] != dstByte) {
00150 av_log(NULL, AV_LOG_INFO,
00151 "dst damaged at %d w:%d src:%d dst:%d %s\n",
00152 i, width, srcOffset, dstOffset, name);
00153 failed = 1;
00154 break;
00155 }
00156 }
00157 }
00158 }
00159 }
00160 if (failed)
00161 failedNum++;
00162 else if (srcBpp)
00163 passedNum++;
00164 }
00165
00166 av_log(NULL, AV_LOG_INFO,
00167 "\n%d converters passed, %d converters randomly overwrote memory\n",
00168 passedNum, failedNum);
00169 return failedNum;
00170 }