Skip to content

Commit e9b29fd

Browse files
committed
test/encodingstest: support more bpps and sizes
Add the options -c8, -c16, and -c32 to test with client bpps of 8, 16, and 32, respectively. Also add options -s8, s16, and -s32 to test with server bpps of 8, 16, and 32, respectively. By default, the client and server are tested with a bpp of 32, preserving the original behavior when no bpp options are passed. Also add the -large option. Normally, a 400x300 image is tested, but when -large is passed a 1024x768 image is tested.
1 parent 9e1d879 commit e9b29fd

File tree

1 file changed

+100
-19
lines changed

1 file changed

+100
-19
lines changed

test/encodingstest.c

Lines changed: 100 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#error "I need pthreads or win32 threads for that."
1111
#endif
1212

13+
#ifndef MAX
14+
#define MAX(x,y) ((x) > (y) ? (x) : (y))
15+
#endif /* MAX */
16+
1317
#define ALL_AT_ONCE
1418
/*#define VERY_VERBOSE*/
1519

@@ -39,7 +43,7 @@ static encoding_t testEncodings[]={
3943

4044
/* Here come the variables/functions to handle the test output */
4145

42-
static const int width=400,height=300;
46+
static int width=400,height=300;
4347
static unsigned int statistics[2][NUMBER_OF_ENCODINGS_TO_TEST];
4448
static unsigned int totalFailed,totalCount;
4549
static unsigned int countGotUpdate;
@@ -68,6 +72,34 @@ static void updateStatistics(int encodingIndex,rfbBool failed) {
6872
/* Here begin the functions for the client. They will be called in a
6973
* thread. */
7074

75+
static void getRGBAt(const unsigned char *buffer,
76+
int width,
77+
const rfbPixelFormat *fmt,
78+
int x, int y,
79+
unsigned int rgb[3])
80+
{
81+
int bytesPerPixel = fmt->bitsPerPixel / 8;
82+
const unsigned char *p = buffer + (y * width + x) * bytesPerPixel;
83+
84+
unsigned int pixel = 0;
85+
86+
if (fmt->bigEndian) {
87+
for (int i = 0; i < bytesPerPixel; ++i)
88+
pixel = (pixel << 8) | p[i];
89+
} else {
90+
for (int i = bytesPerPixel - 1; i >= 0; --i)
91+
pixel = (pixel << 8) | p[i];
92+
}
93+
94+
unsigned int r = (pixel >> fmt->redShift) & fmt->redMax;
95+
unsigned int g = (pixel >> fmt->greenShift) & fmt->greenMax;
96+
unsigned int b = (pixel >> fmt->blueShift) & fmt->blueMax;
97+
98+
rgb[0] = (fmt->redMax ? (r * 255u / fmt->redMax) : 0u);
99+
rgb[1] = (fmt->greenMax ? (g * 255u / fmt->greenMax) : 0u);
100+
rgb[2] = (fmt->blueMax ? (b * 255u / fmt->blueMax) : 0u);
101+
}
102+
71103
/* maxDelta=0 means they are expected to match exactly;
72104
* maxDelta>0 means that the average difference must be lower than maxDelta */
73105
static rfbBool doFramebuffersMatch(rfbScreenInfo* server,rfbClient* client,
@@ -80,19 +112,28 @@ static rfbBool doFramebuffersMatch(rfbScreenInfo* server,rfbClient* client,
80112
LOCK(frameBufferMutex);
81113
/* TODO: write unit test for colour transformation, use here, too */
82114
for(i=0;i<server->width;i++)
83-
for(j=0;j<server->height;j++)
84-
for(k=0;k<3/*server->serverFormat.bitsPerPixel/8*/;k++) {
85-
unsigned char s=server->frameBuffer[k+i*4+j*server->paddedWidthInBytes];
86-
unsigned char cl=client->frameBuffer[k+i*4+j*client->width*4];
87-
88-
if(maxDelta==0 && s!=cl) {
115+
for(j=0;j<server->height;j++) {
116+
unsigned int s[3], c[3];
117+
getRGBAt(server->frameBuffer,
118+
server->width,
119+
&server->serverFormat,
120+
i, j,
121+
s);
122+
getRGBAt(client->frameBuffer,
123+
client->width,
124+
&client->format,
125+
i, j,
126+
c);
127+
for(k=0;k<3;k++) {
128+
if(maxDelta==0 && s[k]!=c[k]) {
89129
UNLOCK(frameBufferMutex);
90130
return FALSE;
91131
} else {
92132
total++;
93-
diff+=(s>cl?s-cl:cl-s);
133+
diff+=(s[k]>c[k]?s[k]-c[k]:c[k]-s[k]);
94134
}
95135
}
136+
}
96137
UNLOCK(frameBufferMutex);
97138
if(maxDelta>0 && diff/total>=maxDelta)
98139
return FALSE;
@@ -135,14 +176,19 @@ static void update(rfbClient* client,int x,int y,int w,int h) {
135176

136177
static void update_finished(rfbClient* client) {
137178
clientData* cd = (clientData*)rfbClientGetClientData(client, clientLoop);
138-
int maxDelta=0;
179+
rfbPixelFormat *cfmt = &client->format;
180+
rfbPixelFormat *sfmt = &cd->server->serverFormat;
181+
int maxDelta = MAX(MAX(
182+
abs(256 / (cfmt->redMax+1) - 256 / (sfmt->redMax+1)),
183+
abs(256 / (cfmt->greenMax+1) - 256 / (sfmt->greenMax+1))),
184+
abs(256 / (cfmt->blueMax+1) - 256 / (sfmt->blueMax+1))) / 2;
139185

140186
#ifdef LIBVNCSERVER_HAVE_LIBZ
141187
if(testEncodings[cd->encodingIndex].id==rfbEncodingZYWRLE)
142-
maxDelta=5;
188+
maxDelta+=5;
143189
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
144190
if(testEncodings[cd->encodingIndex].id==rfbEncodingTight)
145-
maxDelta=5;
191+
maxDelta+=5;
146192
#endif
147193
#endif
148194
updateStatistics(cd->encodingIndex,
@@ -187,8 +233,15 @@ static uintptr_t all_threads[NUMBER_OF_ENCODINGS_TO_TEST];
187233
#endif
188234
static int thread_counter;
189235

190-
static void startClient(int encodingIndex,rfbScreenInfo* server) {
191-
rfbClient* client=rfbGetClient(8,3,4);
236+
static void startClient(int encodingIndex,rfbScreenInfo* server,int cbpp) {
237+
rfbClient* client;
238+
if (cbpp == 32)
239+
client=rfbGetClient(8,3,4);
240+
else if (cbpp == 16)
241+
client=rfbGetClient(5,3,2);
242+
else
243+
client=rfbGetClient(2,3,1);
244+
192245
clientData* cd;
193246

194247
cd=calloc(sizeof(clientData), 1);
@@ -237,10 +290,10 @@ static void idle(rfbScreenInfo* server)
237290
if(x1>x2) { i=x1; x1=x2; x2=i; }
238291
if(y1>y2) { i=y1; y1=y2; y2=i; }
239292
x2++; y2++;
240-
for(c=0;c<3;c++) {
293+
for(c=0;c<server->serverFormat.bitsPerPixel/8;c++) {
241294
for(i=x1;i<x2;i++)
242295
for(j=y1;j<y2;j++)
243-
server->frameBuffer[i*4+c+j*server->paddedWidthInBytes]=255*(i-x1+j-y1)/(x2-x1+y2-y1);
296+
server->frameBuffer[i*(server->bitsPerPixel/8)+c+j*server->paddedWidthInBytes]=255*(i-x1+j-y1)/(x2-x1+y2-y1);
244297
}
245298
rfbMarkRectAsModified(server,x1,y1,x2,y2);
246299

@@ -285,18 +338,46 @@ int main(int argc,char** argv)
285338

286339
rfbClientLog=rfbTestLog;
287340
rfbClientErr=rfbTestLog;
341+
int cbpp = 32;
342+
int sbpp = 32;
343+
344+
for (i = 1, j = 1; i < argc; i++)
345+
if (!strcasecmp(argv[i], "-s32"))
346+
sbpp = 32;
347+
else if (!strcasecmp(argv[i], "-s16"))
348+
sbpp = 16;
349+
else if (!strcasecmp(argv[i], "-s8"))
350+
sbpp = 8;
351+
else if (!strcasecmp(argv[i], "-c32"))
352+
cbpp = 32;
353+
else if (!strcasecmp(argv[i], "-c16"))
354+
cbpp = 16;
355+
else if (!strcasecmp(argv[i], "-c8"))
356+
cbpp = 8;
357+
else if (!strcasecmp(argv[i], "-large")) {
358+
width = 1024;
359+
height = 768;
360+
} else {
361+
fprintf(stderr, "Invalid option: %s\n", argv[i]);
362+
return 1;
363+
}
288364

289365
/* Initialize server */
290-
server=rfbGetScreen(&argc,argv,width,height,8,3,4);
366+
if (sbpp == 32)
367+
server=rfbGetScreen(&argc,argv,width,height,8,3,4);
368+
else if (sbpp == 16)
369+
server=rfbGetScreen(&argc,argv,width,height,5,3,2);
370+
else
371+
server=rfbGetScreen(&argc,argv,width,height,2,3,1);
291372
if(!server)
292373
return 1;
293374

294-
server->frameBuffer=malloc(400*300*4);
375+
server->frameBuffer=malloc(width*height*(server->bitsPerPixel/8));
295376
if (!server->frameBuffer)
296377
return 1;
297378

298379
server->cursor=NULL;
299-
for(j=0;j<400*300*4;j++)
380+
for(j=0;j<width*height*(server->bitsPerPixel/8);j++)
300381
server->frameBuffer[j]=j;
301382
rfbInitServer(server);
302383
rfbProcessEvents(server,0);
@@ -310,7 +391,7 @@ int main(int argc,char** argv)
310391
/* Initialize clients */
311392
for(i=0;i<NUMBER_OF_ENCODINGS_TO_TEST;i++)
312393
#endif
313-
startClient(i,server);
394+
startClient(i,server,cbpp);
314395

315396
t=time(NULL);
316397
/* test 20 seconds */

0 commit comments

Comments
 (0)