summaryrefslogtreecommitdiff
path: root/xc/unsupported/test/suspex/testcases/rnd_hp/rnd_valid.c
blob: d353b1fe2c41532c02a2136b3ca17d122808824d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/* $XConsortium$ */

/******************************************************************************/
/*                                                                            */
/*  (c) Copyright Hewlett-Packard Company, 1993, Fort Collins, Colorado       */
/*                                                                            */
/*                            All Rights Reserved                             */
/*                                                                            */
/*  Permission to use, copy, modify, and distribute this software and its     */
/*  documentation for any purpose and without fee is hereby granted,          */
/*  provided that the above copyright notices appear in all copies and that   */
/*  both the copyright notices and this permission notice appear in           */
/*  supporting documentation, and that the name of Hewlett-Packard not be     */
/*  used in advertising or publicity pertaining to distribution of the        */
/*  software without specific, written prior permission.                      */
/*                                                                            */
/*  HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS         */
/*  SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
/*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  Hewlett-Packard    */
/*  shall not be liable for errors contained herein or direct, indirect,      */
/*  special, incidental or consequential damages in connection with the       */
/*  furnishing, performance or use of this software.                          */
/*                                                                            */
/******************************************************************************/


/*
******************************************************************************
** Renderer/Structure/OC API state validation test
******************************************************************************
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/PEX5/PEXlib.h>

#ifdef XSYSTEM
#include <XSystemTest.h>
#endif

#include <pexutcmap.h>
#include <misc.h>
#include <common_hp.h>
#include <err_handler.h>

#include "rnd_utils.h"

#ifdef XSYSTEM
XSystemTestingControlStructure xtc;
#endif


#ifdef XSYSTEM
#define WIDTH 256
#define HEIGHT 256
#else
#define WIDTH 200
#define HEIGHT 200
#endif

#define HORIZONTAL_SPACING 20
#define VERTICAL_SPACING 40

#define NUM_COLUMNS 10
#define NUM_ROWS 10
#define X_INCREMENT (1.0/NUM_COLUMNS)
#define Y_INCREMENT (1.0/NUM_ROWS)

#define NUM_CONNECTIONS 2
#define NUM_WINDOWS 3
#define NUM_RENDERERS 2
#define NUM_STRUCTURES 3

#define NUM_ITERATIONS (NUM_COLUMNS *		\
						NUM_ROWS *			\
						NUM_CONNECTIONS *	\
						NUM_WINDOWS *		\
						NUM_RENDERERS *		\
						NUM_STRUCTURES/2)

/* possible targets */
#define RENDERER 0
#define STRUCTURE 1
#define NUM_TARGETS 2

/* possible operations (OCs) */
#define ATTR 0
#define PRIM 1
#define NUM_OPERATIONS 2

#define NUM_COLORS 7

#define SEED_RANDOM 		{ srand48(1L); }
#define RANDOM_CONNECTION	((int) (drand48() * NUM_CONNECTIONS))
#define RANDOM_OPERATION	((int) (drand48() * NUM_OPERATIONS))
#define RANDOM_TARGET		((int) (drand48() * NUM_TARGETS))
#define RANDOM_RENDERER		((int) (drand48() * NUM_RENDERERS))
#define RANDOM_WINDOW		((int) (drand48() * NUM_WINDOWS))
#define RANDOM_STRUCTURE	((int) (drand48() * NUM_STRUCTURES))


typedef struct {
	int color_index;
} attr_state;

typedef struct {
	int row, col;
} prim_state;

typedef struct {
	attr_state attr;
	prim_state prim;
	int elem_count;
} attr_prim_state;



main(argc, argv)
int argc;
char **argv;
{
	Display *display, *test_display;
	Display *displays[NUM_CONNECTIONS];
	Window window;
	Window windows[NUM_CONNECTIONS][NUM_WINDOWS];
	PEXRenderer renderer;
	PEXRenderer renderers[NUM_CONNECTIONS][NUM_RENDERERS];
	PEXLookupTable color_luts[NUM_CONNECTIONS][NUM_RENDERERS];
	PEXPipelineContext pipeline_contexts[NUM_CONNECTIONS][NUM_RENDERERS];
	PEXStructure structure;
	PEXStructure structures[NUM_CONNECTIONS][NUM_STRUCTURES];
	PEXExtensionInfo *ext_info;

	attr_state renderer_states[NUM_CONNECTIONS][NUM_RENDERERS];
	prim_state window_states[NUM_CONNECTIONS][NUM_WINDOWS];
	attr_prim_state structure_states[NUM_CONNECTIONS][NUM_STRUCTURES];
	PEXStructureInfo struct_info;

	XVisualInfo vis_info;
	XVisualInfo vis_infos[NUM_CONNECTIONS];
	XStandardColormap cmap_info;
	XStandardColormap cmap_infos[NUM_CONNECTIONS];
	PEXColorApproxEntry capx_info;
	PEXColorApproxEntry capx_infos[NUM_CONNECTIONS];

	int screen;
	XSizeHints hints;
	char title[256];

	PEXUtWindowSpecification  window_info;
	PEXUtVisualCriteria       criteria;
	Atom                      prop_atom;
	XColor                    returned_background;
	XEvent                    event;
	unsigned int              unmet;
	int                       status;

	int conn_index, window_index, resource_index, color_index, extra_index;
	int operation, target, iterations;
	int row, col;
	int image_number = 0;
	int need_to_capture;

	XID target_resource;
	PEXOCRequestType oc_target;
	attr_state *attr_ptr;
	prim_state *prim_ptr;

	PEXPCAttributes plc_attrs;
	unsigned long plc_mask[3];
	PEXColor color;
	char *display_string;

	char image_msg[256];
	char image_name[80], test_name[80];

#ifdef XSYSTEM
    int XSystemValues[20];
#endif

    int			pexmode = 0;
	int			image_depth = 0;

#ifdef XSYSTEM
	openXSystemTesting(argc, argv, &xtc, 0, 0);
	test_display = xtc.display;
	display_string = DisplayString(test_display);
#else
    /* Handle other arguments. */
    if (parse_options (argc, argv, &pexmode, &image_depth))
		exit (1);
	display_string = getenv("DISPLAY");
#endif

    _hppex_set_stderr("rnd_valid.stderr", "rnd_valid");

	describe_test ("\n\n");
	describe_test("This test stresses state switching and validation.  Several connections\n");
	describe_test("to the X server are created, and several Windows, Renderers, and Structures\n");
	describe_test("are created on each connection.  Then a pseudo-random number stream is\n");
	describe_test("used to repeatedly choose a connection, target, and OC (attribute or primitive).\n\n");
	
	describe_test("Images are generated, which are not easily verified by an operator to be\n");
	describe_test("right or wrong.  The most important thing to look for is that approximately\n");
	describe_test("an equal number of OCS (to the extent one would expect of a random number\n");
	describe_test("stream) are sent to each target.  This is a system-level stress test.\n\n");

	describe_test("Images are captured in two sets:  First, all the immediate mode rendering\n");
	describe_test("(which occurred when a renderer/window combination was randomly chosen)\n");
	describe_test("is captured.  Then, all the windows are cleared and the Structures\n");
	describe_test("that have been also receiving OCs are traversed to show their contents.\n");
	describe_test("If there are more Structures per connection than Windows, this may take more\n");
	describe_test("than one image.  The number of connections, Windows, Renderers, and Structures\n");
	describe_test("are compile-time constants that should not be varied once this test is archived.\n\n");

#ifdef XSYSTEM
	if (xtc.interactiveFramePrompt)
#else
	if (glob_verbose_mode && getenv("PAUSE"))
#endif
		prompt_user ("Hit return to continue with the test", "");

#ifndef XSYSTEM
    if (glob_verbose_mode)
	    fflush (stdout);
#endif

	for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {

		/*
			Initialize X and PEX.
		*/
		if (NULL == (displays[conn_index] = XOpenDisplay (display_string))) {

			_hppex_stderr_print( 
					"PROCESS ERROR:  XOpenDisplay failed on connection %d to %s\n", 
					conn_index, display_string);
			exit (1);
		}
		display = displays[conn_index];

		if (PEXInitialize (display, &ext_info, 0, NULL))
		{
			_hppex_stderr_print( 
					"PROCESS ERROR:  PEXInitialize failed on connection %d to %s\n", 
					conn_index, display_string);
			exit (1);
		}

#ifdef XSYSTEM
	    if (conn_index == 0) {
			/*
				Make sure all banks are cleared at the start of this test.
			*/

			_hppex_tst_init_ALL_banks (display);
		}
#endif

		/*
			Create first window.
		*/

		sprintf (title, "Validation [%d][0]", conn_index);
		screen = DefaultScreen(display);
		hints.x = HORIZONTAL_SPACING + 
				conn_index*2*(WIDTH+HORIZONTAL_SPACING);
		hints.y = VERTICAL_SPACING;
		hints.width = WIDTH;
		hints.height = HEIGHT;
		hints.flags = (USSize|USPosition);

		window_info.attr_mask             = CWEventMask;
		window_info.attrs.event_mask      = ExposureMask;
		window_info.title                 = title;
		window_info.size_hints            = hints;
		window_info.parent                = RootWindow (display, screen);
		window_info.border_width          = 0;
		window_info.background_color_name = "black";
		window_info.border_color_name     = "white";
		
		if (image_depth == 0)
		{
			char *depth;

			if (depth = getenv("TEST_IMAGE_DEPTH"))
				{
				image_depth = atoi(depth);
				}
		}

		if (image_depth == 0)
		{
			criteria.hard_criteria_mask = PEXUtMinColors;
			criteria.soft_criteria_mask = PEXUtDepth | 
						  PEXUtStandardColormapProperty;
			criteria.depth = 24;
		}
		else
		{
			criteria.hard_criteria_mask = PEXUtMinColors | PEXUtDepth;
			criteria.soft_criteria_mask = PEXUtStandardColormapProperty;
			criteria.depth = image_depth;
		}

		criteria.min_colors = 2;
		criteria.standard_colormap_property = True;

		status = PEXUtCreateWindowAndColormap (display, screen,
						   	&criteria,
						   	&window_info, 
							&(windows[conn_index][0]),
							&(vis_infos[conn_index]), 
							&(cmap_infos[conn_index]), 
							&(capx_infos[conn_index]),
						   	&unmet, &prop_atom,
						   	&returned_background);

		if ((status != PEXUtSuccess) &&
			(status != PEXUtQualifiedSuccess)) {
			fprintf (stderr,
				"PROCESS ERROR:  First window creation on connection %d failed\n", conn_index);
			exit (1);
		}

		window = windows[conn_index][0];
		XSetWindowColormap(display, window, cmap_infos[conn_index].colormap);
#ifdef XSYSTEM
		XInstallColormap(display, cmap_infos[conn_index].colormap);
#endif
		XMapWindow(display, window);
		XFlush(display);

		/* Wait for the first exposure */
		XSelectInput( display, window, ExposureMask);
		XNextEvent(display, &event);

#ifdef XSYSTEM
		XSystemValues[0] = WINDOW_SMART_HW_CONFIG;
		XSystemValues[1] = windows[conn_index][0];
		XSystemValues[2] = -1;
		defineXSystemTestControlParm(&xtc, ARCHIVE_MODE, XSystemValues);
#endif

		window_states[conn_index][0].col = 0;
		window_states[conn_index][0].row = 0;

		/*
			Create more windows using same colormap and visual.
		*/
		hints.x += WIDTH + HORIZONTAL_SPACING;

		window_info.attr_mask             = CWColormap;
		window_info.attrs.colormap = cmap_infos[conn_index].colormap;

		for (window_index=1; window_index<NUM_WINDOWS; window_index++) {

			sprintf (title, "Validation [%d][%d]", conn_index, window_index);
			window_info.size_hints = hints;

			status = PEXUtCreateWindow ( display, screen,
								&window_info,
								&(vis_infos[conn_index]),
								&(windows[conn_index][window_index]),
								&returned_background);

			if ((status != PEXUtSuccess) &&
				(status != PEXUtQualifiedSuccess)) {

				_hppex_stderr_print( 
					"PROCESS ERROR:  Window creation #%d on connection %d failed\n", 
					window_index, conn_index);
				exit (1);
			}

			XMapWindow(display, windows[conn_index][window_index]);
			XFlush(display);

#ifdef XSYSTEM
			XSetWindowColormap(display, windows[conn_index][window_index], 
								cmap_infos[conn_index].colormap);
			XInstallColormap(display, cmap_infos[conn_index].colormap);
			XSync (display, 0);
#endif

			window_states[conn_index][window_index].col = 0;
			window_states[conn_index][window_index].row = 0;

			hints.y += HEIGHT + VERTICAL_SPACING;
		}


		for (resource_index=0; resource_index<NUM_RENDERERS; resource_index++) {

			PEXRendererAttributes set_attrs;

			/*
				Create a Renderer.
			*/
			window = windows[conn_index][0];
			renderers[conn_index][resource_index] = PEXCreateRenderer (display, window, 0, NULL);
			if (renderers[conn_index][resource_index] == None) {

				_hppex_stderr_print( 
					"PROCESS ERROR: PEXCreateRenderer %d on connection %d failed\n", 
					resource_index, conn_index);
				exit (1);
			}

			/*
				Create a color LUT and a Pipeline Context 
				and attach them to the Renderer.
			*/
			color_luts[conn_index][resource_index] = 
				PEXCreateLookupTable (display, window, PEXLUTColor);

			if (color_luts[conn_index][resource_index] == None) {

				_hppex_stderr_print( 
					"PROCESS ERROR: PEXCreateLookupTable %d on connection %d failed\n", 
					resource_index, conn_index);
				exit (1);
			}

			plc_mask[0] = 0;
			plc_mask[1] = 0;
			plc_mask[2] = 0;
			pipeline_contexts[conn_index][resource_index] = 
				PEXCreatePipelineContext (display, plc_mask, &plc_attrs);

			if (pipeline_contexts[conn_index][resource_index] == None) {

				_hppex_stderr_print( 
					"PROCESS ERROR: PEXCreatePipelineContext %d on connection %d failed\n", 
					resource_index, conn_index);
				exit (1);
			}

			set_attrs.color_table = color_luts[conn_index][resource_index];
			set_attrs.pipeline_context = pipeline_contexts[conn_index][resource_index];
			PEXChangeRenderer (display, 
				renderers[conn_index][resource_index],
				PEXRAColorTable | PEXRAPipelineContext, &set_attrs);

			renderer_states[conn_index][resource_index].color_index = 1;

			PEXSetPCAttributeMask (plc_mask, PEXPCSurfaceColor);
			plc_attrs.surface_color.type = PEXColorTypeIndexed;
			plc_attrs.surface_color.value.indexed.index = 1;
			PEXSetPCAttributeMask (plc_mask, PEXPCInteriorStyle);
			plc_attrs.interior_style = PEXInteriorStyleSolid;
			PEXSetPCAttributeMask (plc_mask, PEXPCSurfaceEdgeFlag);
			plc_attrs.surface_edges = PEXOn;
			PEXSetPCAttributeMask (plc_mask, PEXPCSurfaceEdgeColor);
			plc_attrs.surface_edge_color.type = PEXColorTypeIndexed;
			plc_attrs.surface_edge_color.value.indexed.index = 1;
			PEXChangePipelineContext (display, 
				pipeline_contexts[conn_index][resource_index],
				plc_mask, &plc_attrs);
		}

		for (resource_index=0; resource_index<NUM_STRUCTURES; resource_index++) {

			structures[conn_index][resource_index] = PEXCreateStructure (display);
			if (structures[conn_index][resource_index] == None) {

				_hppex_stderr_print( 
					"PROCESS ERROR: PEXCreateStructure %d on connection %d failed\n", 
					resource_index, conn_index);
				exit (1);
			}

			structure_states[conn_index][resource_index].prim.col = 0;
			structure_states[conn_index][resource_index].prim.row = 0;
			structure_states[conn_index][resource_index].attr.color_index = 1;

			color.indexed.index = 1;
			PEXSetSurfaceColor (display, 
								structures[conn_index][resource_index], 
								PEXOCStore,
								PEXColorTypeIndexed, &color);
			PEXSetSurfaceEdgeFlag (display, 
								structures[conn_index][resource_index], 
								PEXOCStore, PEXOn);
			PEXSetSurfaceEdgeColor (display, 
								structures[conn_index][resource_index], 
								PEXOCStore,
								PEXColorTypeIndexed, &color);
			PEXSetInteriorStyle (display,
								structures[conn_index][resource_index], 
								PEXOCStore,
								PEXInteriorStyleSolid);
			structure_states[conn_index][resource_index].elem_count = 4;
		}
	} /* for connections */


	for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
		for (window_index=0; window_index<NUM_WINDOWS; window_index++) {
			for (resource_index=0; resource_index<NUM_RENDERERS; resource_index++) {

				display = displays[conn_index];
				window = windows[conn_index][window_index];
				renderer = renderers[conn_index][resource_index];

				set_renderer_clear_flags (display, renderer, True, 0.0, 0.0, 0.0);
				PEXBeginRendering (display, window, renderer);
				PEXEndRendering (display, renderer, True);
				set_renderer_clear_flags (display, renderer, False, 0.0, 0.0, 0.0);
			}
		}
	}


	for (iterations=0; iterations<NUM_ITERATIONS; iterations++) {

		conn_index = RANDOM_CONNECTION;
		operation = RANDOM_OPERATION;
		target = RANDOM_TARGET;
		if (target == RENDERER) {

			resource_index = RANDOM_RENDERER;
			window_index = RANDOM_WINDOW;

			attr_ptr = &(renderer_states[conn_index][resource_index]);
			prim_ptr = &(window_states[conn_index][window_index]);
			target_resource = renderers[conn_index][resource_index];
			oc_target = PEXOCRender;

			if (operation == ATTR) {

				color_index = ((attr_ptr->color_index + 1) % NUM_COLORS) + 1;

				plc_mask[0] = 0;
				plc_mask[1] = 0;
				plc_mask[2] = 0;
				PEXSetPCAttributeMask (plc_mask, PEXPCSurfaceColor);
				plc_attrs.surface_color.type = PEXColorTypeIndexed;
				plc_attrs.surface_color.value.indexed.index = color_index;
				PEXSetPCAttributeMask (plc_mask, PEXPCSurfaceEdgeFlag);
				plc_attrs.surface_edges = PEXOn;
				PEXSetPCAttributeMask (plc_mask, PEXPCSurfaceEdgeColor);
				plc_attrs.surface_edge_color.type = PEXColorTypeIndexed;
				plc_attrs.surface_edge_color.value.indexed.index = color_index;
				PEXChangePipelineContext (displays[conn_index], 
					pipeline_contexts[conn_index][resource_index],
					plc_mask, &plc_attrs);

				attr_ptr->color_index = color_index;
			}

			PEXBeginRendering (displays[conn_index], 
								windows[conn_index][window_index], 
								renderers[conn_index][resource_index]);
		}
		else {
			resource_index = RANDOM_STRUCTURE;

			attr_ptr = &(structure_states[conn_index][resource_index].attr);
			prim_ptr = &(structure_states[conn_index][resource_index].prim);
			target_resource = structures[conn_index][resource_index];
			oc_target = PEXOCStore;

			if (operation == ATTR) {

				color_index = ((attr_ptr->color_index + 1) % NUM_COLORS) + 1;
				color.indexed.index = color_index;
				PEXSetSurfaceColor (displays[conn_index], target_resource, oc_target,
									PEXColorTypeIndexed, &color);
				PEXSetSurfaceEdgeFlag (displays[conn_index], target_resource, oc_target, PEXOn);
				PEXSetSurfaceEdgeColor (displays[conn_index], target_resource, oc_target,
									PEXColorTypeIndexed, &color);
				attr_ptr->color_index = color_index;
				structure_states[conn_index][resource_index].elem_count += 3;
			}
			else
				structure_states[conn_index][resource_index].elem_count += 1;
		}

		if (operation == PRIM) {

			row = prim_ptr->row;
			col = prim_ptr->col;
			if (++col >= NUM_COLUMNS) {
				if (row++ >= NUM_ROWS)
					row = 0;
				col = 0;
			}

			draw_primitive (displays[conn_index], target_resource, oc_target,
							FILLED_RECTANGLE,
							col * X_INCREMENT,
							row * Y_INCREMENT,
							0.0,
							X_INCREMENT,
							Y_INCREMENT,
							0.0);
			prim_ptr->row = row;
			prim_ptr->col = col;
		}

		if (target == RENDERER) {
			PEXEndRendering (	displays[conn_index], 
								renderers[conn_index][resource_index],
								True);
		}

	} /* for iterations */

	/* capture images from all windows */
	_hppex_stderr_print( "Capturing images from immediate mode rendering\n\n");
	for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
		XSync (displays[conn_index], 0);
	}
#ifdef XSYSTEM
#ifdef IMAGE_PER_WINDOW
	for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
		XSync (displays[conn_index], 0);
		for (extra_index=0; extra_index<NUM_WINDOWS; extra_index++) {

			XSystemValues[0] = WINDOW_SMART_EXTENT;
			XSystemValues[1] = windows[conn_index][extra_index];
			defineXSystemTestControlParm(&xtc, ARCHIVE_EXTENT, XSystemValues);

			sprintf (image_msg, "ERROR: Immediate mode, conn %d, window %d",
					conn_index, extra_index);
			XSystemCheck(image_msg, &xtc);
		}
	}
	printf ("\n");
#else
	XSystemValues[0] = FULL_SCREEN;
	defineXSystemTestControlParm(&xtc, ARCHIVE_EXTENT, XSystemValues);

	XSystemCheck("ERROR: Immediate mode", &xtc);
	printf ("\n");
#endif /* IMAGE_PER_WINDOW */
#else
	for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
		XSync (displays[conn_index], 0);
		for (extra_index=0; extra_index<NUM_WINDOWS; extra_index++) {

			sprintf(image_name,"rnd_valid_%d", image_number);
			sprintf(test_name, "rnd_valid #%d", image_number);
			 image_testproc(image_name, test_name, img_desc,
							  display, 
								windows[conn_index][extra_index],
								0, 0, WIDTH, HEIGHT);
			image_number++;
		}
	}
#endif


	/*
		Now dump all the structures to appropriate windows.
	*/
	need_to_capture = False;
	_hppex_stderr_print( "Capturing images from traversal mode rendering\n\n");
	for (resource_index = 0; resource_index<NUM_STRUCTURES; resource_index++) {

		window_index = resource_index % NUM_WINDOWS;

		if ((window_index < resource_index) && (window_index == 0)) {
			/* 
				Must have wrapped around because there are more structures
				than windows, so capture the current set of windows.
			*/
			for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
				XSync (displays[conn_index], 0);
			}
#ifdef XSYSTEM
#ifdef IMAGE_PER_WINDOW
			for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
				for (extra_index=0; extra_index<NUM_WINDOWS; extra_index++) {

					XSystemValues[0] = WINDOW_SMART_EXTENT;
					XSystemValues[1] = windows[conn_index][extra_index];
					defineXSystemTestControlParm(&xtc, ARCHIVE_EXTENT, XSystemValues);

					sprintf (image_msg, "ERROR: Traversal mode, conn %d, window %d",
							conn_index, extra_index);
					XSystemCheck(image_msg, &xtc);
				}
			}
			printf ("\n");
#else
			XSystemValues[0] = FULL_SCREEN;
			defineXSystemTestControlParm(&xtc, ARCHIVE_EXTENT, XSystemValues);

			XSystemCheck("Traversal mode", &xtc);
			printf ("\n");
#endif /* IMAGE_PER_WINDOW */
#else
			for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
				for (extra_index=0; extra_index<NUM_WINDOWS; extra_index++) {

					sprintf(image_name,"rnd_valid_%d", image_number);
					sprintf(test_name, "rnd_valid #%d", image_number);
					 image_testproc(image_name, test_name, img_desc,
									  display, 
										windows[conn_index][extra_index],
										0, 0, WIDTH, HEIGHT);

					image_number++;
				}
			}
#endif
			need_to_capture = False;
		}

		for (conn_index = 0; conn_index<NUM_CONNECTIONS; conn_index++) {

			if (PEXGetStructureInfo (displays[conn_index],
								structures[conn_index][resource_index],
								PEXIEEE_754_32, PEXNumElements,
								&struct_info)) {
				if (structure_states[conn_index][resource_index].elem_count !=
					struct_info.element_count) {

					_hppex_stderr_print( "ERROR: structure %d, connection %d elem count mismatch\n",
							resource_index, conn_index);
					_hppex_stderr_print( "\texpected elem count: %d\n",
						structure_states[conn_index][resource_index].elem_count);
					_hppex_stderr_print( "\tactual elem count: %d\n", struct_info.element_count);
				}
			}

			set_renderer_clear_flags (displays[conn_index], renderers[conn_index][0], True, 0.0, 0.0, 0.0);
			PEXRenderNetwork (displays[conn_index], windows[conn_index][window_index],
							renderers[conn_index][0], structures[conn_index][resource_index]);
			XSync (displays[conn_index], 0);
			need_to_capture = True;
		}
	}

	if (need_to_capture) {
		/* capture images */
#ifdef XSYSTEM
#ifdef IMAGE_PER_WINDOW
		for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
			for (extra_index=0; extra_index<NUM_WINDOWS; extra_index++) {

				XSystemValues[0] = WINDOW_SMART_EXTENT;
				XSystemValues[1] = windows[conn_index][extra_index];
				defineXSystemTestControlParm(&xtc, ARCHIVE_EXTENT, XSystemValues);

				sprintf (image_msg, "ERROR: Traversal mode, conn %d, window %d",
						conn_index, extra_index);
				XSystemCheck(image_msg, &xtc);
			}
		}
		printf ("\n");
#else
		XSystemValues[0] = FULL_SCREEN;
		defineXSystemTestControlParm(&xtc, ARCHIVE_EXTENT, XSystemValues);

		XSystemCheck("ERROR: Traversal mode", &xtc);
		printf ("\n");
#endif /* IMAGE_PER_WINDOW */
#else
		for (conn_index = 0; conn_index < NUM_CONNECTIONS; conn_index++) {
			for (extra_index=0; extra_index<NUM_WINDOWS; extra_index++) {

				sprintf(image_name,"rnd_valid_%d", image_number);
				sprintf(test_name, "rnd_valid #%d", image_number);
				 image_testproc(image_name, test_name, img_desc,
								  display, 
									windows[conn_index][extra_index],
									0, 0, WIDTH, HEIGHT);
				image_number++;
			}
		}
#endif
	}


	/*
		Close Structures, Renderers, windows, and connections.
	*/
	for (conn_index = 0; conn_index<NUM_CONNECTIONS; conn_index++) {

		for (resource_index=0; resource_index < NUM_STRUCTURES; resource_index++)
			PEXDestroyStructures(displays[conn_index], 1, &(structures[conn_index][resource_index]));

		for (resource_index=0; resource_index < NUM_RENDERERS; resource_index++) {
			PEXFreeRenderer(displays[conn_index], renderers[conn_index][resource_index]);
			PEXFreeLookupTable(displays[conn_index], color_luts[conn_index][resource_index]);
			PEXFreePipelineContext(displays[conn_index], pipeline_contexts[conn_index][resource_index]);
		}

		for (window_index=0; window_index < NUM_WINDOWS; window_index++)
			XDestroyWindow(displays[conn_index], windows[conn_index][window_index]);

		XCloseDisplay (displays[conn_index]);
	}

    _hppex_close_stderr();

#ifdef XSYSTEM
    closeXSystemTesting(&xtc);
#else
    file_testproc("rnd_valid.stderr", "rnd_valid");
	exit(0);
#endif

} /* renderer state validation test */