make some global var static (fix a build failure with shared lib on x86_64)
[ffmpeg.git] / libswscale / cs_test.c
1 /*
2     Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20 #include <string.h>              /* for memset() */
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <inttypes.h>
24
25 #include "swscale.h"
26 #include "rgb2rgb.h"
27
28 #define SIZE 1000
29 #define srcByte 0x55
30 #define dstByte 0xBB
31
32 #ifdef __APPLE_CC__
33 #define memalign(x,y) malloc(y)
34 #endif
35
36 static int cpu_caps;
37
38 static char *args_parse(int argc, char *argv[])
39 {
40     int o;
41
42     while ((o = getopt(argc, argv, "m23")) != -1) {
43         switch (o) {
44             case 'm':
45                 cpu_caps |= SWS_CPU_CAPS_MMX;
46                 break;
47             case '2':
48                 cpu_caps |= SWS_CPU_CAPS_MMX2;
49                 break;
50             case '3':
51                 cpu_caps |= SWS_CPU_CAPS_3DNOW;
52                 break;
53             default:
54                 fprintf(stderr, "Unknown option %c\n", o);
55         }
56     }
57
58     return argv[optind];
59 }
60
61 main(int argc, char **argv)
62 {
63         int i, funcNum;
64         uint8_t *srcBuffer= (uint8_t*)memalign(128, SIZE);
65         uint8_t *dstBuffer= (uint8_t*)memalign(128, SIZE);
66         int failedNum=0;
67         int passedNum=0;
68         
69         printf("memory corruption test ...\n");
70         args_parse(argc, argv);
71         fprintf(stderr, "CPU capabilities forced to %x\n", cpu_caps);
72         sws_rgb2rgb_init(cpu_caps);
73         
74         for(funcNum=0; funcNum<100; funcNum++){
75                 int width;
76                 int failed=0;
77                 int srcBpp=0;
78                 int dstBpp=0;
79
80                 printf("."); fflush(stdout);
81                 memset(srcBuffer, srcByte, SIZE);
82
83                 for(width=32; width<64; width++){
84                         int dstOffset;
85                         for(dstOffset=128; dstOffset<196; dstOffset++){
86                                 int srcOffset;
87                                 memset(dstBuffer, dstByte, SIZE);
88
89                                 for(srcOffset=128; srcOffset<196; srcOffset++){
90                                         uint8_t *src= srcBuffer+srcOffset;
91                                         uint8_t *dst= dstBuffer+dstOffset;
92                                         char *name=NULL;
93                                         
94                                         if(failed) break; //don't fill the screen with shit ...
95
96                                         switch(funcNum){
97                                         case 0:
98                                                 srcBpp=2;
99                                                 dstBpp=2;
100                                                 name="rgb15to16";
101                                                 rgb15to16(src, dst, width*srcBpp);
102                                                 break;
103                                         case 1:
104                                                 srcBpp=2;
105                                                 dstBpp=3;
106                                                 name="rgb15to24";
107                                                 rgb15to24(src, dst, width*srcBpp);
108                                                 break;
109                                         case 2:
110                                                 srcBpp=2;
111                                                 dstBpp=4;
112                                                 name="rgb15to32";
113                                                 rgb15to32(src, dst, width*srcBpp);
114                                                 break;
115                                         case 3:
116                                                 srcBpp=2;
117                                                 dstBpp=3;
118                                                 name="rgb16to24";
119                                                 rgb16to24(src, dst, width*srcBpp);
120                                                 break;
121                                         case 4:
122                                                 srcBpp=2;
123                                                 dstBpp=4;
124                                                 name="rgb16to32";
125                                                 rgb16to32(src, dst, width*srcBpp);
126                                                 break;
127                                         case 5:
128                                                 srcBpp=3;
129                                                 dstBpp=2;
130                                                 name="rgb24to15";
131                                                 rgb24to15(src, dst, width*srcBpp);
132                                                 break;
133                                         case 6:
134                                                 srcBpp=3;
135                                                 dstBpp=2;
136                                                 name="rgb24to16";
137                                                 rgb24to16(src, dst, width*srcBpp);
138                                                 break;
139                                         case 7:
140                                                 srcBpp=3;
141                                                 dstBpp=4;
142                                                 name="rgb24to32";
143                                                 rgb24to32(src, dst, width*srcBpp);
144                                                 break;
145                                         case 8:
146                                                 srcBpp=4;
147                                                 dstBpp=2;
148                                                 name="rgb32to15";
149                                                 rgb32to15(src, dst, width*srcBpp);
150                                                 break;
151                                         case 9:
152                                                 srcBpp=4;
153                                                 dstBpp=2;
154                                                 name="rgb32to16";
155                                                 rgb32to16(src, dst, width*srcBpp);
156                                                 break;
157                                         case 10:
158                                                 srcBpp=4;
159                                                 dstBpp=3;
160                                                 name="rgb32to24";
161                                                 rgb32to24(src, dst, width*srcBpp);
162                                                 break;
163                                         case 11:
164                                                 srcBpp=2;
165                                                 dstBpp=2;
166                                                 name="rgb16to15";
167                                                 rgb16to15(src, dst, width*srcBpp);
168                                                 break;
169                                         
170                                         case 14:
171                                                 srcBpp=2;
172                                                 dstBpp=2;
173                                                 name="rgb15tobgr15";
174                                                 rgb15tobgr15(src, dst, width*srcBpp);
175                                                 break;
176                                         case 15:
177                                                 srcBpp=2;
178                                                 dstBpp=2;
179                                                 name="rgb15tobgr16";
180                                                 rgb15tobgr16(src, dst, width*srcBpp);
181                                                 break;
182                                         case 16:
183                                                 srcBpp=2;
184                                                 dstBpp=3;
185                                                 name="rgb15tobgr24";
186                                                 rgb15tobgr24(src, dst, width*srcBpp);
187                                                 break;
188                                         case 17:
189                                                 srcBpp=2;
190                                                 dstBpp=4;
191                                                 name="rgb15tobgr32";
192                                                 rgb15tobgr32(src, dst, width*srcBpp);
193                                                 break;
194                                         case 18:
195                                                 srcBpp=2;
196                                                 dstBpp=2;
197                                                 name="rgb16tobgr15";
198                                                 rgb16tobgr15(src, dst, width*srcBpp);
199                                                 break;
200                                         case 19:
201                                                 srcBpp=2;
202                                                 dstBpp=2;
203                                                 name="rgb16tobgr16";
204                                                 rgb16tobgr16(src, dst, width*srcBpp);
205                                                 break;
206                                         case 20:
207                                                 srcBpp=2;
208                                                 dstBpp=3;
209                                                 name="rgb16tobgr24";
210                                                 rgb16tobgr24(src, dst, width*srcBpp);
211                                                 break;
212                                         case 21:
213                                                 srcBpp=2;
214                                                 dstBpp=4;
215                                                 name="rgb16tobgr32";
216                                                 rgb16tobgr32(src, dst, width*srcBpp);
217                                                 break;
218                                         case 22:
219                                                 srcBpp=3;
220                                                 dstBpp=2;
221                                                 name="rgb24tobgr15";
222                                                 rgb24tobgr15(src, dst, width*srcBpp);
223                                                 break;
224                                         case 23:
225                                                 srcBpp=3;
226                                                 dstBpp=2;
227                                                 name="rgb24tobgr16";
228                                                 rgb24tobgr16(src, dst, width*srcBpp);
229                                                 break;
230                                         case 24:
231                                                 srcBpp=3;
232                                                 dstBpp=3;
233                                                 name="rgb24tobgr24";
234                                                 rgb24tobgr24(src, dst, width*srcBpp);
235                                                 break;
236                                         case 25:
237                                                 srcBpp=3;
238                                                 dstBpp=4;
239                                                 name="rgb24tobgr32";
240                                                 rgb24tobgr32(src, dst, width*srcBpp);
241                                                 break;
242                                         case 26:
243                                                 srcBpp=4;
244                                                 dstBpp=2;
245                                                 name="rgb32tobgr15";
246                                                 rgb32tobgr15(src, dst, width*srcBpp);
247                                                 break;
248                                         case 27:
249                                                 srcBpp=4;
250                                                 dstBpp=2;
251                                                 name="rgb32tobgr16";
252                                                 rgb32tobgr16(src, dst, width*srcBpp);
253                                                 break;
254                                         case 28:
255                                                 srcBpp=4;
256                                                 dstBpp=3;
257                                                 name="rgb32tobgr24";
258                                                 rgb32tobgr24(src, dst, width*srcBpp);
259                                                 break;
260                                         case 29:
261                                                 srcBpp=4;
262                                                 dstBpp=4;
263                                                 name="rgb32tobgr32";
264                                                 rgb32tobgr32(src, dst, width*srcBpp);
265                                                 break;
266
267                                         }
268                                         if(!srcBpp) break;
269
270                                         for(i=0; i<SIZE; i++){
271                                                 if(srcBuffer[i]!=srcByte){
272                                                         printf("src damaged at %d w:%d src:%d dst:%d %s\n", 
273                                                                 i, width, srcOffset, dstOffset, name);
274                                                         failed=1;
275                                                         break;
276                                                 }
277                                         }
278                                         for(i=0; i<dstOffset; i++){
279                                                 if(dstBuffer[i]!=dstByte){
280                                                         printf("dst damaged at %d w:%d src:%d dst:%d %s\n", 
281                                                                 i, width, srcOffset, dstOffset, name);
282                                                         failed=1;
283                                                         break;
284                                                 }
285                                         }
286                                         for(i=dstOffset + width*dstBpp; i<SIZE; i++){
287                                                 if(dstBuffer[i]!=dstByte){
288                                                         printf("dst damaged at %d w:%d src:%d dst:%d %s\n", 
289                                                                 i, width, srcOffset, dstOffset, name);
290                                                         failed=1;
291                                                         break;
292                                                 }
293                                         }
294                                 }
295                         }
296                 }
297                 if(failed) failedNum++;
298                 else if(srcBpp) passedNum++;
299         }
300         
301         printf("%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
302         return failedNum;
303 }