* resync without endless loop
[ffmpeg.git] / postproc / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <inttypes.h>
22
23 #include "rgb2rgb.h"
24 #include "../cpudetect.h"
25
26 #define SIZE 1000
27 #define srcByte 0x55
28 #define dstByte 0xBB
29
30 main(int argc, char **argv)
31 {
32         int i, funcNum;
33         uint8_t *srcBuffer= (uint8_t*)memalign(128, SIZE);
34         uint8_t *dstBuffer= (uint8_t*)memalign(128, SIZE);
35         int failedNum=0;
36         int passedNum=0;
37         
38         printf("memory corruption test ...\n");
39         
40         if(argc==2){
41                 GetCpuCaps(&gCpuCaps);
42                 printf("testing mmx\n");
43         }
44         
45         for(funcNum=0; funcNum<100; funcNum++){
46                 int width;
47                 int failed=0;
48                 int srcBpp=0;
49                 int dstBpp=0;
50
51                 printf("."); fflush(stdout);
52                 memset(srcBuffer, srcByte, SIZE);
53
54                 for(width=32; width<64; width++){
55                         int dstOffset;
56                         for(dstOffset=128; dstOffset<196; dstOffset++){
57                                 int srcOffset;
58                                 memset(dstBuffer, dstByte, SIZE);
59
60                                 for(srcOffset=128; srcOffset<196; srcOffset++){
61                                         uint8_t *src= srcBuffer+srcOffset;
62                                         uint8_t *dst= dstBuffer+dstOffset;
63                                         char *name=NULL;
64                                         
65                                         if(failed) break; //dont fill the screen with shit ...
66
67                                         switch(funcNum){
68                                         case 0:
69                                                 srcBpp=2;
70                                                 dstBpp=2;
71                                                 name="rgb15to16";
72                                                 rgb15to16(src, dst, width*srcBpp);
73                                                 break;
74                                         case 1:
75                                                 srcBpp=2;
76                                                 dstBpp=3;
77                                                 name="rgb15to24";
78                                                 rgb15to24(src, dst, width*srcBpp);
79                                                 break;
80                                         case 2:
81                                                 srcBpp=2;
82                                                 dstBpp=4;
83                                                 name="rgb15to32";
84                                                 rgb15to32(src, dst, width*srcBpp);
85                                                 break;
86                                         case 3:
87                                                 srcBpp=2;
88                                                 dstBpp=3;
89                                                 name="rgb16to24";
90                                                 rgb16to24(src, dst, width*srcBpp);
91                                                 break;
92                                         case 4:
93                                                 srcBpp=2;
94                                                 dstBpp=4;
95                                                 name="rgb16to32";
96                                                 rgb16to32(src, dst, width*srcBpp);
97                                                 break;
98                                         case 5:
99                                                 srcBpp=3;
100                                                 dstBpp=2;
101                                                 name="rgb24to15";
102                                                 rgb24to15(src, dst, width*srcBpp);
103                                                 break;
104                                         case 6:
105                                                 srcBpp=3;
106                                                 dstBpp=2;
107                                                 name="rgb24to16";
108                                                 rgb24to16(src, dst, width*srcBpp);
109                                                 break;
110                                         case 7:
111                                                 srcBpp=3;
112                                                 dstBpp=4;
113                                                 name="rgb24to32";
114                                                 rgb24to32(src, dst, width*srcBpp);
115                                                 break;
116                                         case 8:
117                                                 srcBpp=4;
118                                                 dstBpp=2;
119                                                 name="rgb32to15";
120                                                 rgb32to15(src, dst, width*srcBpp);
121                                                 break;
122                                         case 9:
123                                                 srcBpp=4;
124                                                 dstBpp=2;
125                                                 name="rgb32to16";
126                                                 rgb32to16(src, dst, width*srcBpp);
127                                                 break;
128                                         case 10:
129                                                 srcBpp=4;
130                                                 dstBpp=3;
131                                                 name="rgb32to24";
132                                                 rgb32to24(src, dst, width*srcBpp);
133                                                 break;
134                                         case 11:
135                                                 srcBpp=2;
136                                                 dstBpp=2;
137                                                 name="rgb16to15";
138                                                 rgb16to15(src, dst, width*srcBpp);
139                                                 break;
140                                         
141                                         case 14:
142                                                 srcBpp=2;
143                                                 dstBpp=2;
144                                                 name="rgb15tobgr15";
145                                                 rgb15tobgr15(src, dst, width*srcBpp);
146                                                 break;
147                                         case 15:
148                                                 srcBpp=2;
149                                                 dstBpp=2;
150                                                 name="rgb15tobgr16";
151                                                 rgb15tobgr16(src, dst, width*srcBpp);
152                                                 break;
153                                         case 16:
154                                                 srcBpp=2;
155                                                 dstBpp=3;
156                                                 name="rgb15tobgr24";
157                                                 rgb15tobgr24(src, dst, width*srcBpp);
158                                                 break;
159                                         case 17:
160                                                 srcBpp=2;
161                                                 dstBpp=4;
162                                                 name="rgb15tobgr32";
163                                                 rgb15tobgr32(src, dst, width*srcBpp);
164                                                 break;
165                                         case 18:
166                                                 srcBpp=2;
167                                                 dstBpp=2;
168                                                 name="rgb16tobgr15";
169                                                 rgb16tobgr15(src, dst, width*srcBpp);
170                                                 break;
171                                         case 19:
172                                                 srcBpp=2;
173                                                 dstBpp=2;
174                                                 name="rgb16tobgr16";
175                                                 rgb16tobgr16(src, dst, width*srcBpp);
176                                                 break;
177                                         case 20:
178                                                 srcBpp=2;
179                                                 dstBpp=3;
180                                                 name="rgb16tobgr24";
181                                                 rgb16tobgr24(src, dst, width*srcBpp);
182                                                 break;
183                                         case 21:
184                                                 srcBpp=2;
185                                                 dstBpp=4;
186                                                 name="rgb16tobgr32";
187                                                 rgb16tobgr32(src, dst, width*srcBpp);
188                                                 break;
189                                         case 22:
190                                                 srcBpp=3;
191                                                 dstBpp=2;
192                                                 name="rgb24tobgr15";
193                                                 rgb24tobgr15(src, dst, width*srcBpp);
194                                                 break;
195                                         case 23:
196                                                 srcBpp=3;
197                                                 dstBpp=2;
198                                                 name="rgb24tobgr16";
199                                                 rgb24tobgr16(src, dst, width*srcBpp);
200                                                 break;
201                                         case 24:
202                                                 srcBpp=3;
203                                                 dstBpp=3;
204                                                 name="rgb24tobgr24";
205                                                 rgb24tobgr24(src, dst, width*srcBpp);
206                                                 break;
207                                         case 25:
208                                                 srcBpp=3;
209                                                 dstBpp=4;
210                                                 name="rgb24tobgr32";
211                                                 rgb24tobgr32(src, dst, width*srcBpp);
212                                                 break;
213                                         case 26:
214                                                 srcBpp=4;
215                                                 dstBpp=2;
216                                                 name="rgb32tobgr15";
217                                                 rgb32tobgr15(src, dst, width*srcBpp);
218                                                 break;
219                                         case 27:
220                                                 srcBpp=4;
221                                                 dstBpp=2;
222                                                 name="rgb32tobgr16";
223                                                 rgb32tobgr16(src, dst, width*srcBpp);
224                                                 break;
225                                         case 28:
226                                                 srcBpp=4;
227                                                 dstBpp=3;
228                                                 name="rgb32tobgr24";
229                                                 rgb32tobgr24(src, dst, width*srcBpp);
230                                                 break;
231                                         case 29:
232                                                 srcBpp=4;
233                                                 dstBpp=4;
234                                                 name="rgb32tobgr32";
235                                                 rgb32tobgr32(src, dst, width*srcBpp);
236                                                 break;
237
238                                         }
239                                         if(!srcBpp) break;
240
241                                         for(i=0; i<SIZE; i++){
242                                                 if(srcBuffer[i]!=srcByte){
243                                                         printf("src damaged at %d w:%d src:%d dst:%d %s\n", 
244                                                                 i, width, srcOffset, dstOffset, name);
245                                                         failed=1;
246                                                         break;
247                                                 }
248                                         }
249                                         for(i=0; i<dstOffset; i++){
250                                                 if(dstBuffer[i]!=dstByte){
251                                                         printf("dst damaged at %d w:%d src:%d dst:%d %s\n", 
252                                                                 i, width, srcOffset, dstOffset, name);
253                                                         failed=1;
254                                                         break;
255                                                 }
256                                         }
257                                         for(i=dstOffset + width*dstBpp; i<SIZE; i++){
258                                                 if(dstBuffer[i]!=dstByte){
259                                                         printf("dst damaged at %d w:%d src:%d dst:%d %s\n", 
260                                                                 i, width, srcOffset, dstOffset, name);
261                                                         failed=1;
262                                                         break;
263                                                 }
264                                         }
265                                 }
266                         }
267                 }
268                 if(failed) failedNum++;
269                 else if(srcBpp) passedNum++;
270         }
271         
272         printf("%d converters passed, %d converters randomly overwrote memory\n", passedNum, failedNum);
273         return failedNum;
274 }