1 /*
2 Copyright (c) 2010, Lawrence Livermore National Security, LLC.
3 Produced at the Lawrence Livermore National Laboratory
4 Written by Stewart Brown (brown50@llnl.gov).
5 CODE-422942.
6 All rights reserved.
7
8 This file was adapted for PDB Lite from the 11_09_21 version of
9 PACT by Mark Miller (miller86@llnl.gov). For details on PACT, see
10 pact.llnl.gov
11
12 This file is part of Silo. For details, see silo.llnl.gov.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions
16 are met:
17
18 * Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the disclaimer below.
20 * Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the disclaimer (as noted
22 below) in the documentation and/or other materials provided with
23 the distribution.
24 * Neither the name of the LLNS/LLNL nor the names of its
25 contributors may be used to endorse or promote products derived
26 from this software without specific prior written permission.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE
32 LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
33 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41 This work was produced at Lawrence Livermore National Laboratory under
42 Contract No. DE-AC52-07NA27344 with the DOE. Neither the United
43 States Government nor Lawrence Livermore National Security, LLC nor
44 any of their employees, makes any warranty, express or implied, or
45 assumes any liability or responsibility for the accuracy,
46 completeness, or usefulness of any information, apparatus, product, or
47 process disclosed, or represents that its use would not infringe
48 privately-owned rights. Any reference herein to any specific
49 commercial products, process, or services by trade name, trademark,
50 manufacturer or otherwise does not necessarily constitute or imply its
51 endorsement, recommendation, or favoring by the United States
52 Government or Lawrence Livermore National Security, LLC. The views and
53 opinions of authors expressed herein do not necessarily state or
54 reflect those of the United States Government or Lawrence Livermore
55 National Security, LLC, and shall not be used for advertising or
56 product endorsement purposes.
57 */
58
59 /*
60 Mark C. Miller, Wed Dec 19 20:06:37 PST 2012
61 This file was taken from the 11_09_21 version of PACT and adpated to
62 be used as a test of PDB Lite, part of the Silo library. To the
63 extent possible, the adaption here was to retain the original code
64 and intentions of tests as much as possible and use the CPP to re-map
65 any methods from the original code to their equivalents in PDB Lite.
66 In cases where there were no equivalents, a few different strategies
67 were employed...
68 * Existing functionality was disabled; this works fine for cosmetic
69 things such as memory utilization and performance tracking as
70 similar data can be obtained from tools like valgrind.
71 * Customized alternative methods were coded here in this file.
72 * The logic of the original test was altered slightly.
73 * Some tests were completely disabled.
74 There is no "lite_" pre-pending any symbol names here becasue part of
75 the intention of this test is to test the exported lite_pdb.h and
76 lite_score.h header files. Those files included CPP macros to remap
77 PDB Proper symbol names to their PDB Lite equivalents.
78
79 In some tests, we leak memory for certain data ('ca' in test 2 and
80 'tab4_r' in test 4.
81
82 Note that in PDB Lite, by default, we compile it with a reduced SCORE
83 memory header to save memory useage for some libraries. Nonetheless,
84 this test will passes with these reduced SCORE headers. If you are
85 running into problems with this test, you can always re-configure to
86 --enable-normal-sclite-mem-headers and see if that fixes the problems.
87 */
88 #ifdef PDB_LITE
89
90 #include <lite_pdb.h>
91
92 #include <assert.h>
93 #include <dirent.h>
94 #include <math.h>
95 #include <signal.h>
96 #include <stdarg.h>
97 #include <stdio.h>
98 #include <stdlib.h>
99 #include <string.h>
100 #include <sys/stat.h>
101 #include <sys/time.h>
102 #include <sys/types.h>
103 #include <unistd.h>
104
105 /* Constant and macro definitions taken from PDB proper */
106 #define SC_HA_NAME_KEY "by-name"
107 #define N_PRIMITIVE_FP 2 /* float and double but not long double */
108 #define PD_MD5_FILE 1
109 #define TOLERANCE 1.0e-10
110 #define SMALL 1.0e-100
111 #define ABS fabs
112 #define min(a, b) ((a) < (b) ? (a) : (b))
113
114 /* Typename differences between PDB proper and PDB Lite */
115 #define hasharr HASHTAB
116 #define hasharrstr "hashtab"
117 #define haelem hashel
118 #define haelemstr "hashel"
119
120 /* Methods mapped to PDB Lite / SCORE Lite (or system) equivalents */
121 #define SC_hasharr_dump(A,B,C,D) SC_dump_hash(A,B,D)
122 #define SC_hasharr_get_n(A) (A->nelements)
123 #define SC_hasharr_def_lookup(A,B) SC_def_lookup(B,A)
124 #define SC_make_hasharr(A, B, C, D) SC_make_hash_table(A,B)
125 #define SC_hasharr_install(A, B, C, D, E, F) SC_install(B, C, D, A)
126 #define SC_free_hasharr(A, B, C) SC_rl_hash_table(A)
127 #define PD_target_n_platforms() NSTD
128 #define _PD_lookup_size _lite_PD_lookup_size
129 #define SC_ASSERT assert
130 #define SC_signal signal
131 #define SC_VA_START(A) va_list ap; va_start(ap, A);
132 #define SC_VSNPRINTF(A,B,C) vsnprintf(A,B,C,ap);
133 #define SC_VA_END va_end(ap);
134 #define SC_sleep sleep
135 #define STDOUT stdout
136 #define CSTRSAVE(A) SC_strsavef(A,foo_str())
137 #define CFREE SFREE
138 #define REMOVE unlink
139 #define POW pow
140 #ifdef PRINT
141 #undef PRINT
142 #define PRINT fprintf
143 #endif
144 #define CMAKE(A) FMAKE(A,foo_str())
145 #define CMAKE_N(A,B) FMAKE_N(A,B,foo_str())
146
147 /* Methods mapped to customized equivalents coded here in this file */
148 #define SC_free_strings free_strings
149 #define SC_wall_clock_time wall_clock_time
150 #define PD_fp_toler fp_toler
151 #define PD_def_hash_types(A,B) def_hash_types(A)
152 #define PD_target_platform target_platform
153 #define PD_target_platform_n target_platform_n
154 #define PD_target_platform_name target_platform_name
155
156 /* Methods completely disabled here */
157 #define SC_bf_set_hooks() /*void*/
158 #define SC_zero_space_n(A,B) /*void*/
159 #define SC_mem_stats(A,B,C,D) /*void*/
160 #define SC_mem_monitor(A,B,C,D) /*void*/0
161 #define PD_init_threads(A,B) /*void*/
162 #define PD_read_as_dwim(A,B,C,D,E) /*void*/1
163 #define PD_activate_cksum(A,B) /*void*/
164 #define PD_verify(A) /*void*/0
165 #define PD_verify_writes(A) /*void*/
166 #define PD_set_io_hooks(A) /*void*/
167 #define PD_open_vif(A) /*void*/
168 #define PD_set_fmt_version(A) /*void*/
169 #define PD_set_track_pointers(A,B) /*void*/
170 #define PD_set_buffer_size(A) /*void*/
171 #define SC_hasharr_rekey(A,B) /*void*/
172
173 static int last = 0;
174
175 /* ensures the tag names used in SCORE allocations are unique */
foo_str()176 static char *foo_str()
177 {
178 static char retval[32];
179 static int i = 0;
180 sprintf(retval, "foo%d", i++);
181 return retval;
182 }
183
free_strings(char ** strs)184 static void free_strings(char **strs)
185 {
186 int i = 0;
187 if (!strs) return;
188 SFREE(strs);
189 }
190
wall_clock_time()191 static double wall_clock_time()
192 {
193 struct timeval tv;
194 gettimeofday(&tv, 0);
195 return (double) tv.tv_sec + (double) tv.tv_usec / 1e+6;
196 }
197
target_platform_n(int i)198 static int target_platform_n(int i) {return 1;};
199
target_platform_name(int i)200 static char *target_platform_name(int i)
201 {
202 switch (i)
203 {
204 case 1: return "IEEE_32_64";
205 case 2: return "INTEL_X86";
206 case 3: return "CRAY_64";
207 case 4: return "VAX_11";
208 case 6: return "IEEE_32_96";
209 default: return "default";
210 }
211 }
212
target_platform(const char * tgt)213 static int target_platform(const char *tgt)
214 {
215 if (!strcmp(tgt, "IEEE_32_64"))
216 return PD_target(&lite_IEEEA_STD, &lite_M68000_ALIGNMENT);
217 else if (!strcmp(tgt, "IEEE_32_96"))
218 return PD_target(&lite_IEEEB_STD, &lite_M68000_ALIGNMENT);
219 else if (!strcmp(tgt, "INTEL_X86"))
220 return PD_target(&lite_INTELA_STD, &lite_INTELA_ALIGNMENT);
221 else if (!strcmp(tgt, "CRAY_64"))
222 return PD_target(&lite_CRAY_STD, &lite_UNICOS_ALIGNMENT);
223 else if (!strcmp(tgt, "VAX_11"))
224 return PD_target(&lite_VAX_STD, &lite_DEF_ALIGNMENT);
225 else
226 return PD_target(&lite_DEF_STD, &lite_DEF_ALIGNMENT);
227 }
228
fp_toler(PDBfile * file,long double * fptol)229 static void fp_toler(PDBfile *file, long double *fptol)
230 {int i, fpmn[N_PRIMITIVE_FP];
231 data_standard *fstd, *hstd;
232 long *fformat, *hformat;
233
234 fstd = file->std;
235 hstd = file->host_std;
236
237 for (i = 0; i < N_PRIMITIVE_FP; i++)
238 {
239 switch (i)
240 {
241 case 0:
242 fformat = fstd->float_format;
243 hformat = hstd->float_format;
244 break;
245 case 1:
246 fformat = fstd->double_format;
247 hformat = hstd->double_format;
248 break;
249 }
250
251 {fpmn[i] = min(fformat[2], hformat[2]);
252 fptol[i] = powl(2.0, -((long double) fpmn[i]));};
253 }
254
255 return;}
256
257 /* taken directly from PDB in PACT December, 2012 */
PM_value_compare(double x1,double x2,double tol)258 static int PM_value_compare(double x1, double x2, double tol)
259 {int rv;
260 double dx;
261
262 if (tol < 0.0)
263 tol = TOLERANCE;
264
265 dx = (x1 - x2)/(ABS(x1) + ABS(x2) + SMALL);
266 if (dx < -tol)
267 rv = -1;
268 else if (tol < dx)
269 rv = 1;
270 else
271 rv = 0;
272
273 return(rv);}
274
def_hash_types(PDBfile * file)275 static void def_hash_types(PDBfile *file)
276 {
277 PD_defstr(file, haelemstr,
278 "char *name",
279 "char *type",
280 "char *def",
281 "hashel *next",
282 LAST);
283
284 PD_defstr(file, hasharrstr,
285 "int size",
286 "int nelements",
287 "int docp",
288 "hashel **table",
289 LAST);
290 }
291
292
293 #else
294
295 #include <pdb.h>
296 #define hasharrstr "hasharr"
297 #define haelemstr "hashel"
298
299 #endif
300
301 #define DATDIR "pdbtst-data"
302 #define DATFILE "nat"
303
304 #define N_DOUBLE 3
305 #define N_INT 5
306 #define N_CHAR 10
307 #define N_FLOAT 4
308
309 #define FLOAT_EQUAL(d1, d2) (PM_value_compare(d1, d2, fptol[0]) == 0)
310 #define DOUBLE_EQUAL(d1, d2) (PM_value_compare(d1, d2, fptol[1]) == 0)
311
312 struct s_l_frame
313 {float x_min;
314 float x_max;
315 float y_min;
316 float y_max;};
317
318 typedef struct s_l_frame l_frame;
319
320 struct s_plot
321 {float x_axis[N_CHAR];
322 float y_axis[N_CHAR];
323 int npts;
324 char *label;
325 l_frame view;};
326
327 typedef struct s_plot plot;
328
329 struct s_lev2
330 {char **s;
331 int type;};
332
333 typedef struct s_lev2 lev2;
334
335 struct s_lev1
336 {int *a;
337 double *b;
338 lev2 *c;};
339
340 typedef struct s_lev1 lev1;
341
342 struct s_st3
343 {char a;
344 short b;
345 char c[2];
346 int d;
347 char e[3];
348 float f;
349 char g[4];
350 double h;
351 char i[5];
352 char *j;
353 char k[6];};
354
355 typedef struct s_st3 st3;
356
357 struct s_st4
358 {short a;
359 char b;};
360
361 typedef struct s_st4 st4;
362
363 struct s_st61
364 {int n;
365 double a[10];};
366
367 typedef struct s_st61 st61;
368
369 struct s_st62
370 {int n;
371 double *a;};
372
373 typedef struct s_st62 st62;
374
375 typedef int (*PFTest)(char *base, char *tgt, int n);
376
377 extern long _PD_lookup_size(char *s, hasharr *tab);
378
379 static st61
380 *d61_w = NULL;
381
382 static st62
383 *d62_w = NULL;
384
385 static st62
386 d71_w,
387 d71_w_save,
388 d72_w,
389 d71_r,
390 d72_r;
391
392 static st4
393 *vr4_w,
394 *vr4_r;
395
396 static st3
397 vr1_w,
398 vr1_r;
399
400 static lev1
401 tar5_t[4],
402 tar5_r[4],
403 *tar_r,
404 *tar_w;
405
406 static hasharr
407 *tab4_r,
408 *tab4_w;
409
410 static char
411 *CHAR_S,
412 *SHORT_S,
413 *INT_S,
414 *LONG_S,
415 *FLOAT_S,
416 *DOUBLE_S,
417 *HASHEL_S,
418 cs_w,
419 cs_r,
420 ca_w[N_CHAR],
421 ca_r[N_CHAR],
422 *cap_w[N_DOUBLE],
423 *cap_r[N_DOUBLE];
424
425 static short
426 ss_w,
427 ss_r,
428 sa_w[N_INT],
429 sa_r[N_INT];
430
431 static int
432 debug_mode = FALSE,
433 native_only = FALSE,
434 read_only = FALSE,
435 is_w,
436 is_r,
437 ia_w[N_INT],
438 ia_r[N_INT],
439 do_r,
440 do_w,
441 p_w[N_INT],
442 p_r[N_INT],
443 len;
444
445 static float
446 d61_a[10],
447 d62_a[10],
448 d62_s[8],
449 fs_w,
450 fs_r,
451 fs_app_w,
452 fs_app_r,
453 fs_p1_r,
454 fs_p2_r,
455 fs_p3_r,
456 fa1_r[N_FLOAT],
457 fa2_w[N_FLOAT][N_DOUBLE],
458 fa2_r[N_FLOAT][N_DOUBLE],
459 fa2_app_w[N_FLOAT][N_DOUBLE],
460 fa2_app_r[N_FLOAT][N_DOUBLE];
461
462 static double
463 ds_w,
464 ds_r,
465 da_w[N_FLOAT],
466 da_r[N_FLOAT],
467 *d8_w,
468 *d8a_r,
469 *d8b_r,
470 *d8c_r,
471 *d8d_r;
472
473 #ifdef HAVE_ANSI_FLOAT16
474
475 static long double
476 qs_w,
477 qs_r,
478 qa_w[N_FLOAT],
479 qa_r[N_FLOAT];
480
481 #endif
482
483 static plot
484 graph_w,
485 graph_r;
486
487 static l_frame
488 view_w,
489 view_r;
490
491 /* variables for partial and member reads in test #2 */
492
493 static int
494 *ap1,
495 *ap2,
496 aa[4];
497
498 static double
499 *bp1,
500 *bp2,
501 ba[4];
502
503 static lev2
504 *cp1,
505 *cp2,
506 ca[4];
507
508 static char
509 **sp1,
510 **sp2,
511 **sp3,
512 **sp4,
513 *tp1,
514 *tp2,
515 *tp3,
516 *tp4,
517 *tp5,
518 *tp6,
519 *tp7,
520 *tp8,
521 ta[8];
522
523 /*--------------------------------------------------------------------------*/
524
525 /* GENERAL PURPOSE ROUTINES */
526
527 /*--------------------------------------------------------------------------*/
528
529 /* TEST_TARGET - set up the target for the data file */
530
test_target(char * tgt,char * base,int n,char * fname,char * datfile)531 static void test_target(char *tgt, char *base, int n,
532 char *fname, char *datfile)
533 {int rv;
534
535 if (tgt != NULL)
536 {rv = PD_target_platform(tgt);
537 SC_ASSERT(rv == TRUE);
538
539 sprintf(fname, "%s-%s.rs%d", base, tgt, n);
540 sprintf(datfile, "%s-%s.db%d", base, tgt, n);}
541
542 else
543 {sprintf(fname, "%s-nat.rs%d", base, n);
544 sprintf(datfile, "%s-nat.db%d", base, n);};
545
546 return;}
547
548 /*--------------------------------------------------------------------------*/
549 /*--------------------------------------------------------------------------*/
550
551 /* DUMP_TEST_SYMBOL_TABLE - dump the symbol table */
552
dump_test_symbol_table(FILE * fp,hasharr * tab,int n)553 static void dump_test_symbol_table(FILE *fp, hasharr *tab, int n)
554 {int i, ne;
555 char **names;
556
557 PRINT(fp, "\nTest %d Symbol table:\n", n);
558
559 ne = SC_hasharr_get_n(tab);
560 names = SC_hasharr_dump(tab, NULL, NULL, FALSE);
561 for (i = 0; i < ne; i++)
562 PRINT(fp, "%s\n", names[i]);
563 SC_free_strings(names);
564
565 PRINT(fp, "\n");
566
567 return;}
568
569 /*--------------------------------------------------------------------------*/
570 /*--------------------------------------------------------------------------*/
571
572 /* ERROR - get out on an error */
573
error(int n,FILE * fp,char * fmt,...)574 static void error(int n, FILE *fp, char *fmt, ...)
575 {char t[MAXLINE];
576
577 SC_VA_START(fmt);
578 SC_VSNPRINTF(t, MAXLINE, fmt);
579 SC_VA_END;
580
581 io_printf(fp, "%s", t);
582
583 exit(1);
584
585 return;}
586
587 /*--------------------------------------------------------------------------*/
588
589 /* TEST #0 ROUTINES */
590
591 /*--------------------------------------------------------------------------*/
592
593 /* PRINT_TEST_0_DATA - print it out to STDOUT */
594
print_test_0_data(PDBfile * strm,FILE * fp)595 static void print_test_0_data(PDBfile *strm, FILE *fp)
596 {int nbp;
597
598 /* print scalars */
599 nbp = _PD_lookup_size("char", strm->chart);
600 PRINT(fp, "size(char) = %d\n", nbp);
601
602 nbp = _PD_lookup_size("short", strm->chart);
603 PRINT(fp, "size(short) = %d\n", nbp);
604
605 nbp = _PD_lookup_size("int", strm->chart);
606 PRINT(fp, "size(int) = %d\n", nbp);
607
608 nbp = _PD_lookup_size("long", strm->chart);
609 PRINT(fp, "size(long) = %d\n", nbp);
610
611 nbp = _PD_lookup_size("long_long", strm->chart);
612 PRINT(fp, "size(long_long) = %d\n", nbp);
613
614 nbp = _PD_lookup_size("float", strm->chart);
615 PRINT(fp, "size(float) = %d\n", nbp);
616
617 nbp = _PD_lookup_size("double", strm->chart);
618 PRINT(fp, "size(double) = %d\n", nbp);
619
620 #ifdef HAVE_ANSI_FLOAT16
621 nbp = _PD_lookup_size("long_double", strm->chart);
622 PRINT(fp, "size(long double) = %d\n", nbp);
623 #endif
624
625 nbp = _PD_lookup_size("*", strm->chart);
626 PRINT(fp, "size(char *) = %d\n", nbp);
627
628 PRINT(fp, "\n");
629
630 /* whole struct test */
631 nbp = _PD_lookup_size("l_frame", strm->chart);
632 PRINT(fp, "size(l_frame) = %d\n", nbp);
633
634 nbp = _PD_lookup_size("plot", strm->chart);
635 PRINT(fp, "size(plot) = %d\n", nbp);
636
637 PRINT(fp, "\n");
638
639 return;}
640
641 /*--------------------------------------------------------------------------*/
642 /*--------------------------------------------------------------------------*/
643
644 /* COMPARE_TEST_0_DATA - compare the test data */
645
compare_test_0_data(PDBfile * strm,FILE * fp)646 static int compare_test_0_data(PDBfile *strm, FILE *fp)
647 {int nbp, nbc, err, err_tot;
648
649 err = TRUE;
650 err_tot = TRUE;
651
652 /* compare primitive types */
653 nbp = _PD_lookup_size("char", strm->host_chart);
654 nbc = sizeof(char);
655 err &= (nbp == nbc);
656
657 nbp = _PD_lookup_size("short", strm->host_chart);
658 nbc = sizeof(short);
659 err &= (nbp == nbc);
660
661 nbp = _PD_lookup_size("int", strm->host_chart);
662 nbc = sizeof(int);
663 err &= (nbp == nbc);
664
665 nbp = _PD_lookup_size("long", strm->host_chart);
666 nbc = sizeof(long);
667 err &= (nbp == nbc);
668
669 nbp = _PD_lookup_size("long_long", strm->host_chart);
670 nbc = sizeof(int64_t);
671 err &= (nbp == nbc);
672
673 nbp = _PD_lookup_size("float", strm->host_chart);
674 nbc = sizeof(float);
675 err &= (nbp == nbc);
676
677 nbp = _PD_lookup_size("double", strm->host_chart);
678 nbc = sizeof(double);
679 err &= (nbp == nbc);
680
681 #ifdef HAVE_ANSI_FLOAT16
682 nbp = _PD_lookup_size("long_double", strm->host_chart);
683 nbc = sizeof(long double);
684 err &= (nbp == nbc);
685 #endif
686
687 nbp = _PD_lookup_size("*", strm->host_chart);
688 nbc = sizeof(char *);
689 err &= (nbp == nbc);
690
691 if (err)
692 PRINT(fp, "Primitive types compare\n");
693 else
694 PRINT(fp, "Primitive types differ\n");
695 err_tot &= err;
696
697 /* compare structures */
698 nbp = _PD_lookup_size("l_frame", strm->host_chart);
699 nbc = sizeof(l_frame);
700 err &= (nbp == nbc);
701
702 nbp = _PD_lookup_size("plot", strm->host_chart);
703 nbc = sizeof(plot);
704 err &= (nbp == nbc);
705
706 if (err)
707 PRINT(fp, "Structs compare\n");
708 else
709 PRINT(fp, "Structs differ\n");
710 err_tot &= err;
711
712 return(err_tot);}
713
714 /*--------------------------------------------------------------------------*/
715 /*--------------------------------------------------------------------------*/
716
717 /* TEST_0 - test PDB calculation of type and struct sizes */
718
test_0(char * base,char * tgt,int n)719 static int test_0(char *base, char *tgt, int n)
720 {int err;
721 char datfile[MAXLINE], fname[MAXLINE];
722 PDBfile *strm;
723 FILE *fp;
724
725 /* target the file as asked */
726 test_target(tgt, base, n, fname, datfile);
727
728 fp = io_open(fname, "w");
729
730 /* create the named file */
731 strm = PD_create(datfile);
732 if (strm == NULL)
733 error(1, fp, "Test couldn't create file %s\r\n", datfile);
734
735 PRINT(fp, "File %s created\n", datfile);
736
737 /* make a few defstructs */
738 PD_defstr(strm, "l_frame",
739 "float x_min",
740 "float x_max",
741 "float y_min",
742 "float y_max",
743 LAST);
744
745 PD_defstr(strm, "plot",
746 "float x_axis(10)",
747 "float y_axis(10)",
748 "integer npts",
749 "char * label",
750 "l_frame view",
751 LAST);
752
753 /* compare the original data with that read in */
754 err = compare_test_0_data(strm, fp);
755
756 /* print it out to STDOUT */
757 print_test_0_data(strm, fp);
758
759 /* close the file */
760 if (PD_close(strm) == FALSE)
761 error(1, fp, "Test couldn't close file %s\r\n", datfile);
762
763 PRINT(fp, "File %s closed\n", datfile);
764
765 io_close(fp);
766
767 return(err);}
768
769 /*--------------------------------------------------------------------------*/
770
771 /* TEST #1 ROUTINES */
772
773 /*--------------------------------------------------------------------------*/
774
775 /* PREP_TEST_1_DATA - prepare the test data */
776
prep_test_1_data(void)777 static void prep_test_1_data(void)
778 {int i, k;
779
780 /* set scalars */
781 cs_r = 0;
782 ss_r = 0;
783 is_r = 0;
784 fs_r = 0.0;
785 fs_p1_r = 0.0;
786 fs_p2_r = 0.0;
787 fs_p3_r = 0.0;
788 ds_r = 0.0;
789
790 cs_w = 'Q';
791 ss_w = -514;
792 is_w = 10;
793 fs_w = 3.14159;
794 fs_app_w = -3.14159;
795 ds_w = exp(1.0);
796
797 /* set char array */
798 for (i = 0; i < N_CHAR; i++)
799 {ca_w[i] = '\0';
800 ca_r[i] = '\0';};
801
802 /* set short array */
803 for (i = 0; i < N_INT; i++)
804 {sa_w[i] = 2 - i;
805 sa_r[i] = 0;};
806
807 /* set int array */
808 for (i = 0; i < N_INT; i++)
809 {ia_w[i] = i - 2;
810 ia_r[i] = 0;};
811
812 /* set float array */
813 for (i = 0; i < N_FLOAT; i++)
814 for (k = 0; k < N_DOUBLE; k++)
815 {fa2_w[i][k] = POW((double) (i+1), (double) (k+1));
816 fa2_app_w[i][k] = POW((double) (k+1), (double) (i+1));
817 fa2_r[i][k] = 0.0;
818 fa2_app_r[i][k] = 0.0;};
819
820 /* set double array */
821 for (i = 0; i < N_FLOAT; i++)
822 {da_w[i] = POW(ds_w, (double) (i+1));
823 da_r[i] = 0.0;};
824
825 /* set strings */
826 strcpy(ca_w, "Hi there!");
827 len = strlen(ca_w) + 1;
828
829 cap_w[0] = CSTRSAVE("lev1");
830 cap_w[1] = CSTRSAVE("lev2");
831 cap_w[2] = CSTRSAVE("tar fu blat");
832 cap_r[0] = NULL;
833 cap_r[1] = NULL;
834 cap_r[2] = NULL;
835
836 /* set structures */
837 for (i = 0; i < N_CHAR; i++)
838 {graph_w.x_axis[i] = ((float) i)/10.0;
839 graph_w.y_axis[i] = 0.5 - graph_w.x_axis[i];
840 graph_r.x_axis[i] = -1000.0;
841 graph_r.y_axis[i] = -1000.0;};
842
843 view_w.x_min = 0.1;
844 view_w.x_max = 1.0;
845 view_w.y_min = -0.5;
846 view_w.y_max = 0.5;
847
848 view_r.x_min = -1.e-10;
849 view_r.x_max = -1.e-10;
850 view_r.y_min = -1.e-10;
851 view_r.y_max = -1.e-10;
852
853 graph_w.npts = N_CHAR;
854 graph_w.label = CSTRSAVE("test graph");
855 graph_w.view = view_w;
856
857 graph_r.npts = 0;
858 graph_r.label = NULL;
859
860 graph_r.view.x_min = -1.e-10;
861 graph_r.view.x_max = -1.e-10;
862 graph_r.view.y_min = -1.e-10;
863 graph_r.view.y_max = -1.e-10;
864
865 return;}
866
867 /*--------------------------------------------------------------------------*/
868 /*--------------------------------------------------------------------------*/
869
870 /* CLEANUP_TEST_1 - free all known test data memory */
871
cleanup_test_1(void)872 static void cleanup_test_1(void)
873 {
874
875 CFREE(cap_w[0]);
876 CFREE(cap_w[1]);
877 CFREE(cap_w[2]);
878
879 CFREE(cap_r[0]);
880 CFREE(cap_r[1]);
881 CFREE(cap_r[2]);
882
883 CFREE(graph_w.label);
884 CFREE(graph_r.label);
885
886 return;}
887
888 /*--------------------------------------------------------------------------*/
889 /*--------------------------------------------------------------------------*/
890
891 /* WRITE_TEST_1_DATA - write out the data into the PDB file */
892
write_test_1_data(PDBfile * strm)893 static void write_test_1_data(PDBfile *strm)
894 {long ind[6];
895
896 /* write scalars into the file */
897 if (PD_write(strm, "cs", "char", &cs_w) == 0)
898 error(1, STDOUT, "CS WRITE FAILED - WRITE_TEST_1_DATA\n");
899 if (PD_write(strm, "ss", "short", &ss_w) == 0)
900 error(1, STDOUT, "SS WRITE FAILED - WRITE_TEST_1_DATA\n");
901 if (PD_write(strm, "is", "integer", &is_w) == 0)
902 error(1, STDOUT, "IS WRITE FAILED - WRITE_TEST_1_DATA\n");
903 if (PD_write(strm, "fs", "float", &fs_w) == 0)
904 error(1, STDOUT, "FS WRITE FAILED - WRITE_TEST_1_DATA\n");
905 if (PD_write(strm, "ds", "double", &ds_w) == 0)
906 error(1, STDOUT, "DS WRITE FAILED - WRITE_TEST_1_DATA\n");
907
908 /* write primitive arrays into the file */
909 ind[0] = 0L;
910 ind[1] = len - 1;
911 ind[2] = 1L;
912 if (PD_write_alt(strm, "ca", "char", ca_w, 1, ind) == 0)
913 error(1, STDOUT, "CA WRITE FAILED - WRITE_TEST_1_DATA\n");
914 if (PD_write(strm, "sa(5)", "short", sa_w) == 0)
915 error(1, STDOUT, "SA WRITE FAILED - WRITE_TEST_1_DATA\n");
916 if (PD_write(strm, "ia(5)", "integer", ia_w) == 0)
917 error(1, STDOUT, "IA WRITE FAILED - WRITE_TEST_1_DATA\n");
918
919 ind[0] = 0L;
920 ind[1] = N_FLOAT - 1;
921 ind[2] = 1L;
922 ind[3] = 0L;
923 ind[4] = N_DOUBLE - 1;
924 ind[5] = 1L;
925 if (PD_write_alt(strm, "fa2", "float", fa2_w, 2, ind) == 0)
926 error(1, STDOUT, "FA2 WRITE FAILED - WRITE_TEST_1_DATA\n");
927
928 ind[0] = 0L;
929 ind[1] = N_FLOAT - 1;
930 ind[2] = 1L;
931 if (PD_write_alt(strm, "da", "double", da_w, 1, ind) == 0)
932 error(1, STDOUT, "DA WRITE FAILED - WRITE_TEST_1_DATA\n");
933
934 ind[0] = 0L;
935 ind[1] = N_DOUBLE - 1;
936 ind[2] = 1L;
937 if (PD_write_alt(strm, "cap", "char *", cap_w, 1, ind) == 0)
938 error(1, STDOUT, "CAP WRITE FAILED - WRITE_TEST_1_DATA\n");
939
940 /* write structures into the file */
941 if (PD_write(strm, "view", "l_frame", &view_w) == 0)
942 error(1, STDOUT, "VIEW WRITE FAILED - WRITE_TEST_1_DATA\n");
943
944 if (PD_write(strm, "graph", "plot", &graph_w) == 0)
945 error(1, STDOUT, "GRAPH WRITE FAILED - WRITE_TEST_1_DATA\n");
946
947 return;}
948
949 /*--------------------------------------------------------------------------*/
950 /*--------------------------------------------------------------------------*/
951
952 /* APPEND_TEST_1_DATA - append some test data to the file */
953
append_test_1_data(PDBfile * strm)954 static void append_test_1_data(PDBfile *strm)
955 {long ind[6];
956
957 if (PD_write(strm, "fs_app", "float", &fs_app_w) == 0)
958 error(1, STDOUT, "FS_APP WRITE FAILED - APPEND_TEST_1_DATA\n");
959
960 ind[0] = 0L;
961 ind[1] = N_FLOAT - 1;
962 ind[2] = 1L;
963 ind[3] = 0L;
964 ind[4] = N_DOUBLE - 1;
965 ind[5] = 1L;
966 if (PD_write_alt(strm, "fa2_app", "float", fa2_app_w, 2, ind) == 0)
967 error(1, STDOUT, "FA2_APP WRITE FAILED - APPEND_TEST_1_DATA\n");
968
969 return;}
970
971 /*--------------------------------------------------------------------------*/
972 /*--------------------------------------------------------------------------*/
973
974 /* READ_TEST_1_DATA - read the test data from the file */
975
read_test_1_data(PDBfile * strm)976 static int read_test_1_data(PDBfile *strm)
977 {int err;
978 long ind[6];
979
980 /* read the scalar data from the file */
981 err = PD_read(strm, "cs", &cs_r);
982 err = PD_read(strm, "ss", &ss_r);
983 err = PD_read(strm, "is", &is_r);
984 err = PD_read(strm, "fs", &fs_r);
985 err = PD_read(strm, "ds", &ds_r);
986
987 /* read the primitive arrays from the file */
988 err = PD_read(strm, "ca", ca_r);
989 err = PD_read(strm, "sa", sa_r);
990 err = PD_read(strm, "ia", ia_r);
991 err = PD_read(strm, "fa2", fa2_r);
992 err = PD_read(strm, "da", da_r);
993 err = PD_read(strm, "cap", cap_r);
994
995 /* read the entire structures from the file */
996 err = PD_read(strm, "view", &view_r);
997 err = PD_read(strm, "graph", &graph_r);
998
999 /* read the appended data from the file */
1000 err = PD_read(strm, "fs_app", &fs_app_r);
1001 err = PD_read(strm, "fa2_app", fa2_app_r);
1002
1003 /* partial array read */
1004 ind[0] = 1;
1005 ind[1] = 2;
1006 ind[2] = 1;
1007 ind[3] = 0;
1008 ind[4] = 1;
1009 ind[5] = 1;
1010 err = PD_read_alt(strm, "fa2", fa1_r, ind);
1011
1012 /* struct member test */
1013 ind[0] = 8;
1014 ind[1] = 8;
1015 ind[2] = 1;
1016 err = PD_read_alt(strm, "graph.x_axis", &fs_p1_r, ind);
1017 err = PD_read( strm, "graph.view.x_max", &fs_p2_r);
1018 err = PD_read( strm, "view.y_max", &fs_p3_r);
1019
1020 return(err);}
1021
1022 /*--------------------------------------------------------------------------*/
1023 /*--------------------------------------------------------------------------*/
1024
1025 /* PRINT_TEST_1_DATA - print it out to STDOUT */
1026
print_test_1_data(FILE * fp)1027 static void print_test_1_data(FILE *fp)
1028 {int i, k;
1029
1030 /* print scalars */
1031 PRINT(fp, "short scalar: ss = %d\n", ss_r);
1032 PRINT(fp, "integer scalar: is = %d\n", is_r);
1033 PRINT(fp, "float scalar: fs = %14.6e\n", fs_r);
1034 PRINT(fp, "double scalar: ds = %14.6e\n", ds_r);
1035
1036 PRINT(fp, "\n");
1037
1038 /* print char array */
1039 PRINT(fp, "static char array:\n ca = %s\n", ca_r);
1040
1041 /* print short array */
1042 PRINT(fp, "short array:\n");
1043 for (i = 0; i < N_INT; i++)
1044 PRINT(fp, " sa[%d] = %d\n", i, sa_r[i]);
1045
1046 /* print int array */
1047 PRINT(fp, "integer array:\n");
1048 for (i = 0; i < N_INT; i++)
1049 PRINT(fp, " ia[%d] = %d\n", i, ia_r[i]);
1050
1051 /* print float array */
1052 PRINT(fp, "float array:\n");
1053 for (i = 0; i < N_FLOAT; i++)
1054 for (k = 0; k < N_DOUBLE; k++)
1055 PRINT(fp, " fa2[%d][%d] = %14.6e\n", i, k, fa2_r[i][k]);
1056
1057 /* print double array */
1058 PRINT(fp, "double array:\n");
1059 for (i = 0; i < N_FLOAT; i++)
1060 PRINT(fp, " da[%d] = %14.6e\n", i, da_r[i]);
1061
1062 /* print character pointer array */
1063 PRINT(fp, "string array:\n");
1064 for (i = 0; i < N_DOUBLE; i++)
1065 PRINT(fp, " cap[%d] = %s\n", i, cap_r[i]);
1066
1067 PRINT(fp, "\n");
1068
1069 /* print appended scalars */
1070 PRINT(fp, "appended float scalar: fs_app = %14.6e\n", fs_app_r);
1071
1072 /* print float array */
1073 PRINT(fp, "appended float array:\n");
1074 for (i = 0; i < N_FLOAT; i++)
1075 for (k = 0; k < N_DOUBLE; k++)
1076 PRINT(fp, " fa2_app[%d][%d] = %14.6e\n",
1077 i, k, fa2_app_r[i][k]);
1078
1079 PRINT(fp, "\n");
1080
1081 /* whole struct test */
1082 PRINT(fp, "struct view:\n");
1083 PRINT(fp, " x-min = %14.6e\n", view_r.x_min);
1084 PRINT(fp, " x-max = %14.6e\n", view_r.x_max);
1085 PRINT(fp, " y-min = %14.6e\n", view_r.y_min);
1086 PRINT(fp, " y-max = %14.6e\n", view_r.y_max);
1087
1088 PRINT(fp, "\n");
1089
1090 PRINT(fp, "struct graph:\n");
1091 PRINT(fp, " #pts = %d\n", graph_r.npts);
1092 PRINT(fp, " x-min = %14.6e\n", graph_r.view.x_min);
1093 PRINT(fp, " x-max = %14.6e\n", graph_r.view.x_max);
1094 PRINT(fp, " y-min = %14.6e\n", graph_r.view.y_min);
1095 PRINT(fp, " y-max = %14.6e\n", graph_r.view.y_max);
1096
1097 PRINT(fp, " x values y values\n");
1098 for (i = 0; i < N_CHAR; i++)
1099 PRINT(fp, " %14.6e %14.6e\n",
1100 graph_r.x_axis[i], graph_r.y_axis[i]);
1101
1102 PRINT(fp, "\n");
1103
1104 /* partial read single elements */
1105 PRINT(fp, "\npartial read scalars:\n");
1106 PRINT(fp, " graph.x_axis[8] = %14.6e\n", fs_p1_r);
1107 PRINT(fp, " graph.view.x_max = %14.6e\n", fs_p2_r);
1108 PRINT(fp, " view.y_max = %14.6e\n", fs_p3_r);
1109
1110 PRINT(fp, "\n");
1111
1112 /* partial read arrays */
1113 PRINT(fp, "partial read float array:\n");
1114 for (i = 0; i < N_FLOAT; i++)
1115 PRINT(fp, " fa2_p[%d] = %14.6e\n", i, fa1_r[i]);
1116
1117 PRINT(fp, "\n");
1118
1119 return;}
1120
1121 /*--------------------------------------------------------------------------*/
1122 /*--------------------------------------------------------------------------*/
1123
1124 /* COMPARE_TEST_1_DATA - compare the test data */
1125
compare_test_1_data(PDBfile * strm,FILE * fp)1126 static int compare_test_1_data(PDBfile *strm, FILE *fp)
1127 {int i, k, err, err_tot;
1128 long double fptol[N_PRIMITIVE_FP];
1129
1130 PD_fp_toler(strm, fptol);
1131
1132 err_tot = TRUE;
1133
1134 /* compare scalars */
1135 err = TRUE;
1136 err &= (cs_r == cs_w);
1137 err &= (ss_r == ss_w);
1138 err &= (is_r == is_w);
1139 err &= FLOAT_EQUAL(fs_r, fs_w);
1140 err &= FLOAT_EQUAL(fs_app_r, fs_app_w);
1141 err &= DOUBLE_EQUAL(ds_r, ds_w);
1142
1143 if (err)
1144 PRINT(fp, "Scalars compare\n");
1145 else
1146 PRINT(fp, "Scalars differ\n");
1147 err_tot &= err;
1148
1149 /* compare char array */
1150 err = TRUE;
1151 for (i = 0; i < N_CHAR; i++)
1152 err &= (ca_r[i] == ca_w[i]);
1153
1154 /* compare short array */
1155 for (i = 0; i < N_INT; i++)
1156 err &= (sa_r[i] == sa_w[i]);
1157
1158 /* compare int array */
1159 for (i = 0; i < N_INT; i++)
1160 err &= (ia_r[i] == ia_w[i]);
1161
1162 /* compare float array */
1163 for (i = 0; i < N_FLOAT; i++)
1164 for (k = 0; k < N_DOUBLE; k++)
1165 {err &= FLOAT_EQUAL(fa2_r[i][k], fa2_w[i][k]);
1166 err &= FLOAT_EQUAL(fa2_app_r[i][k], fa2_app_w[i][k]);}
1167
1168 /* compare double array */
1169 for (i = 0; i < N_FLOAT; i++)
1170 err &= DOUBLE_EQUAL(da_r[i], da_w[i]);
1171
1172 if (err)
1173 PRINT(fp, "Arrays compare\n");
1174 else
1175 PRINT(fp, "Arrays differ\n");
1176 err_tot &= err;
1177
1178 /* compare strings */
1179 err = TRUE;
1180 for (i = 0; i < N_DOUBLE; i++)
1181 err &= (strcmp(cap_r[i], cap_w[i]) == 0);
1182
1183 if (err)
1184 PRINT(fp, "Strings compare\n");
1185 else
1186 PRINT(fp, "Strings differ\n");
1187 err_tot &= err;
1188
1189 /* compare structures */
1190 err = TRUE;
1191 for (i = 0; i < N_CHAR; i++)
1192 {err &= FLOAT_EQUAL(graph_r.x_axis[i], graph_w.x_axis[i]);
1193 err &= FLOAT_EQUAL(graph_r.y_axis[i], graph_w.y_axis[i]);};
1194
1195 err &= FLOAT_EQUAL(view_r.x_min, view_w.x_min);
1196 err &= FLOAT_EQUAL(view_r.x_max, view_w.x_max);
1197 err &= FLOAT_EQUAL(view_r.y_min, view_w.y_min);
1198 err &= FLOAT_EQUAL(view_r.y_max, view_w.y_max);
1199
1200 err &= (graph_r.npts == graph_w.npts);
1201 err &= (strcmp(graph_r.label, graph_w.label) == 0);
1202
1203 err &= FLOAT_EQUAL(graph_r.view.x_min, graph_w.view.x_min);
1204 err &= FLOAT_EQUAL(graph_r.view.x_max, graph_w.view.x_max);
1205 err &= FLOAT_EQUAL(graph_r.view.y_min, graph_w.view.y_min);
1206 err &= FLOAT_EQUAL(graph_r.view.y_max, graph_w.view.y_max);
1207
1208 if (err)
1209 PRINT(fp, "Structs compare\n");
1210 else
1211 PRINT(fp, "Structs differ\n");
1212 err_tot &= err;
1213
1214 /* compare partial read results */
1215 err = TRUE;
1216 err &= FLOAT_EQUAL(fs_p1_r, graph_w.x_axis[8]);
1217 err &= FLOAT_EQUAL(fs_p2_r, graph_w.view.x_max);
1218 err &= FLOAT_EQUAL(fs_p3_r, view_w.y_max);
1219
1220 if (err)
1221 PRINT(fp, "Partial reads compare\n");
1222 else
1223 PRINT(fp, "Partial reads differ\n");
1224 err_tot &= err;
1225
1226 return(err_tot);}
1227
1228 /*--------------------------------------------------------------------------*/
1229 /*--------------------------------------------------------------------------*/
1230
1231 /* TEST_1 - test the fundamental PDBLib functions
1232 * -
1233 * - read and write scalars of all primitive types
1234 * - read and write structures with no indirections
1235 * - append data to a file and read it back
1236 * - read structure members
1237 * - read parts of arrays
1238 * -
1239 * - tests can be targeted
1240 */
1241
test_1(char * base,char * tgt,int n)1242 static int test_1(char *base, char *tgt, int n)
1243 {int err;
1244 char datfile[MAXLINE], fname[MAXLINE];
1245 PDBfile *strm;
1246 FILE *fp;
1247
1248 /* target the file as asked */
1249 test_target(tgt, base, n, fname, datfile);
1250
1251 fp = io_open(fname, "w");
1252
1253 prep_test_1_data();
1254
1255 if (read_only == FALSE)
1256
1257 /* create the named file */
1258 {strm = PD_create(datfile);
1259 if (strm == NULL)
1260 error(1, fp, "Test couldn't create file %s\r\n", datfile);
1261 PRINT(fp, "File %s created\n", datfile);
1262
1263 /* make a few defstructs */
1264 PD_defstr(strm, "l_frame",
1265 " float x_min",
1266 "float x_max",
1267 "float y_min",
1268 "float y_max",
1269 LAST);
1270 PD_defstr(strm, "plot",
1271 "float x_axis(10)",
1272 "float y_axis(10)",
1273 "integer npts",
1274 "char * label",
1275 "l_frame view",
1276 LAST);
1277
1278 /* write the test data */
1279 write_test_1_data(strm);
1280
1281 /* close the file */
1282 if (PD_close(strm) == FALSE)
1283 error(1, fp, "Test couldn't close file %s\r\n", datfile);
1284 PRINT(fp, "File %s closed\n", datfile);
1285
1286 /* reopen the file to append */
1287 strm = PD_open(datfile, "a");
1288 if (strm == NULL)
1289 error(1, fp, "Test couldn't open file %s to append\r\n", datfile);
1290 PRINT(fp, "File %s opened to append\n", datfile);
1291
1292 append_test_1_data(strm);
1293
1294 /* close the file after append */
1295 if (PD_close(strm) == FALSE)
1296 error(1, fp, "Test couldn't close file %s after append\r\n",
1297 datfile);
1298 PRINT(fp, "File %s closed after append\n", datfile);};
1299
1300 /* reopen the file */
1301 strm = PD_open(datfile, "r");
1302 if (strm == NULL)
1303 error(1, fp, "Test couldn't open file %s\r\n", datfile);
1304 PRINT(fp, "File %s opened\n", datfile);
1305
1306 /* dump the symbol table */
1307 dump_test_symbol_table(fp, strm->symtab, 1);
1308
1309 /* read the data from the file */
1310 read_test_1_data(strm);
1311
1312 /* compare the original data with that read in */
1313 err = compare_test_1_data(strm, fp);
1314
1315 /* close the file */
1316 if (PD_close(strm) == FALSE)
1317 error(1, fp, "Test couldn't close file %s\r\n", datfile);
1318 PRINT(fp, "File %s closed\n", datfile);
1319
1320 /* print it out to STDOUT */
1321 print_test_1_data(fp);
1322
1323 /* free known test data memory */
1324 cleanup_test_1();
1325
1326 io_close(fp);
1327 if (err)
1328 REMOVE(fname);
1329
1330 return(err);}
1331
1332 /*--------------------------------------------------------------------------*/
1333
1334 /* TEST #2 ROUTINES */
1335
1336 /*--------------------------------------------------------------------------*/
1337
1338 /* PREP_TEST_2_DATA - prepare the test data */
1339
prep_test_2_data(void)1340 static void prep_test_2_data(void)
1341 {int i, *p1, *p2;
1342 double *p3, *p4;
1343
1344 /* do_w = -1; */
1345
1346 for (i = 0; i < N_INT; i++)
1347 {p_w[i] = i;
1348 p_r[i] = 0;};
1349
1350 tar_w = CMAKE_N(lev1, 2);
1351
1352 p1 = tar_w[0].a = CMAKE_N(int, N_INT);
1353 p2 = tar_w[1].a = CMAKE_N(int, N_INT);
1354 for (i = 0; i < N_INT; i++)
1355 {p1[i] = i;
1356 p2[i] = i + 10;};
1357
1358 p3 = tar_w[0].b = CMAKE_N(double, N_DOUBLE);
1359 p4 = tar_w[1].b = CMAKE_N(double, N_DOUBLE);
1360 for (i = 0; i < N_DOUBLE; i++)
1361 {p3[i] = exp((double) i);
1362 p4[i] = log(1.0 + (double) i);};
1363
1364 tar_w[0].c = CMAKE_N(lev2, 2);
1365 tar_w[1].c = CMAKE_N(lev2, 2);
1366
1367 tar_w[0].c[0].s = CMAKE_N(char *, 2);
1368 tar_w[0].c[0].s[0] = CSTRSAVE("Hello");
1369 tar_w[0].c[0].s[1] = CSTRSAVE(" ");
1370 tar_w[0].c[1].s = CMAKE_N(char *, 2);
1371 tar_w[0].c[1].s[0] = CSTRSAVE("world");
1372 tar_w[0].c[1].s[1] = CSTRSAVE("!");
1373
1374 tar_w[1].c[0].s = CMAKE_N(char *, 2);
1375 tar_w[1].c[0].s[0] = CSTRSAVE("Foo");
1376 tar_w[1].c[0].s[1] = CSTRSAVE(" ");
1377 tar_w[1].c[1].s = CMAKE_N(char *, 2);
1378 tar_w[1].c[1].s[0] = CSTRSAVE("Bar");
1379 tar_w[1].c[1].s[1] = CSTRSAVE("!!!");
1380
1381 tar_w[0].c[0].type = 1;
1382 tar_w[0].c[1].type = 2;
1383 tar_w[1].c[0].type = 3;
1384 tar_w[1].c[1].type = 4;
1385
1386 tar_r = NULL;
1387
1388 ap1 = NULL;
1389 ap2 = NULL;
1390 for (i = 0; i < 4; i++)
1391 aa[i] = 0;
1392
1393 bp1 = NULL;
1394 bp2 = NULL;
1395 for (i = 0; i < 4; i++)
1396 ba[i] = 0.0;
1397
1398 cp1 = NULL;
1399 cp2 = NULL;
1400 for (i = 0; i < 4; i++)
1401 {ca[i].s = NULL;
1402 ca[i].type = 0;};
1403
1404 sp1 = NULL;
1405 sp2 = NULL;
1406 sp3 = NULL;
1407 sp4 = NULL;
1408
1409 tp1 = NULL;
1410 tp2 = NULL;
1411 tp3 = NULL;
1412 tp4 = NULL;
1413 tp5 = NULL;
1414 tp6 = NULL;
1415 tp7 = NULL;
1416 tp8 = NULL;
1417 for (i = 0; i < 4; i++)
1418 ta[i] = 0;
1419
1420 return;}
1421
1422 /*--------------------------------------------------------------------------*/
1423 /*--------------------------------------------------------------------------*/
1424
1425 /* CLEANUP_TEST_2 - free all know test data memory */
1426
cleanup_test_2(void)1427 static void cleanup_test_2(void)
1428 {int i;
1429
1430 if (tar_w != NULL)
1431 {CFREE(tar_w[0].c[0].s[0]);
1432 CFREE(tar_w[0].c[0].s[1]);
1433 CFREE(tar_w[0].c[1].s[0]);
1434 CFREE(tar_w[0].c[1].s[1]);
1435
1436 CFREE(tar_w[1].c[0].s[0]);
1437 CFREE(tar_w[1].c[0].s[1]);
1438 CFREE(tar_w[1].c[1].s[0]);
1439 CFREE(tar_w[1].c[1].s[1]);
1440
1441 CFREE(tar_w[0].c[0].s);
1442 CFREE(tar_w[0].c[1].s);
1443 CFREE(tar_w[1].c[0].s);
1444 CFREE(tar_w[1].c[1].s);
1445
1446 CFREE(tar_w[0].c);
1447 CFREE(tar_w[1].c);
1448
1449 CFREE(tar_w[0].a);
1450 CFREE(tar_w[1].a);
1451
1452 CFREE(tar_w[0].b);
1453 CFREE(tar_w[1].b);
1454
1455 CFREE(tar_w);};
1456
1457 if (tar_r != NULL)
1458 {CFREE(tar_r[0].c[0].s[0]);
1459 CFREE(tar_r[0].c[0].s[1]);
1460 CFREE(tar_r[0].c[1].s[0]);
1461 CFREE(tar_r[0].c[1].s[1]);
1462
1463 CFREE(tar_r[1].c[0].s[0]);
1464 CFREE(tar_r[1].c[0].s[1]);
1465 CFREE(tar_r[1].c[1].s[0]);
1466 CFREE(tar_r[1].c[1].s[1]);
1467
1468 CFREE(tar_r[0].c[0].s);
1469 CFREE(tar_r[0].c[1].s);
1470 CFREE(tar_r[1].c[0].s);
1471 CFREE(tar_r[1].c[1].s);
1472
1473 CFREE(tar_r[0].c);
1474 CFREE(tar_r[1].c);
1475
1476 CFREE(tar_r[0].a);
1477 CFREE(tar_r[1].a);
1478
1479 CFREE(tar_r[0].b);
1480 CFREE(tar_r[1].b);
1481
1482 CFREE(tar_r);};
1483
1484 CFREE(ap1);
1485 CFREE(ap2);
1486
1487 CFREE(bp1);
1488 CFREE(bp2);
1489
1490 if (cp1 != NULL)
1491 {if (cp1[0].s != NULL)
1492 {CFREE(cp1[0].s[0]);
1493 CFREE(cp1[0].s[1]);
1494 CFREE(cp1[0].s);};
1495
1496 if (cp1[1].s != NULL)
1497 {CFREE(cp1[1].s[0]);
1498 CFREE(cp1[1].s[1]);
1499 CFREE(cp1[1].s);};
1500
1501 CFREE(cp1);};
1502
1503 if (cp2 != NULL)
1504 {if (cp2[0].s != NULL)
1505 {CFREE(cp2[0].s[0]);
1506 CFREE(cp2[0].s[1]);
1507 CFREE(cp2[0].s);};
1508
1509 if (cp2[1].s != NULL)
1510 {CFREE(cp2[1].s[0]);
1511 CFREE(cp2[1].s[1]);
1512 CFREE(cp2[1].s);};
1513
1514 CFREE(cp2);};
1515
1516 #ifndef PDB_LITE /* we'll leak these with PDB Lite */
1517 for (i = 0; i < 4; i++)
1518 {CFREE(ca[i].s[0]);
1519 CFREE(ca[i].s[1]);
1520 CFREE(ca[i].s);};
1521 #endif
1522
1523 if (sp1 != NULL)
1524 {CFREE(sp1[0]);
1525 CFREE(sp1[1]);
1526 CFREE(sp1);};
1527
1528 if (sp2 != NULL)
1529 {CFREE(sp2[0]);
1530 CFREE(sp2[1]);
1531 CFREE(sp2);};
1532
1533 if (sp3 != NULL)
1534 {CFREE(sp3[0]);
1535 CFREE(sp3[1]);
1536 CFREE(sp3);};
1537
1538 if (sp4 != NULL)
1539 {CFREE(sp4[0]);
1540 CFREE(sp4[1]);
1541 CFREE(sp4);};
1542
1543 CFREE(tp1);
1544 CFREE(tp2);
1545 CFREE(tp3);
1546 CFREE(tp4);
1547 CFREE(tp5);
1548 CFREE(tp6);
1549 CFREE(tp7);
1550 CFREE(tp8);
1551
1552 return;}
1553
1554 /*--------------------------------------------------------------------------*/
1555 /*--------------------------------------------------------------------------*/
1556
1557 /* WRITE_TEST_2_DATA - write out the data into the PDB file */
1558
write_test_2_data(PDBfile * strm)1559 static void write_test_2_data(PDBfile *strm)
1560 {long ind[3];
1561
1562 ind[0] = 1L;
1563 ind[1] = N_INT;
1564 ind[2] = 1L;
1565 if (PD_write_alt(strm, "p", "integer", p_w, 1, ind) == 0)
1566 error(1, STDOUT, "P WRITE FAILED - WRITE_TEST_2_DATA\n");
1567
1568 if (PD_write(strm, "tar", "lev1 *", &tar_w) == 0)
1569 error(1, STDOUT, "TAR WRITE FAILED - WRITE_TEST_2_DATA\n");
1570
1571 return;}
1572
1573 /*--------------------------------------------------------------------------*/
1574 /*--------------------------------------------------------------------------*/
1575
1576 /* READ_TEST_2_DATA - read the test data from the file */
1577
read_test_2_data(PDBfile * strm)1578 static int read_test_2_data(PDBfile *strm)
1579 {int err;
1580
1581 do_r = strm->default_offset;
1582
1583 err = PD_read(strm, "tar", &tar_r);
1584 err = PD_read(strm, "p", p_r);
1585
1586 err = PD_read(strm, "tar(0).a", &ap1);
1587 err = PD_read(strm, "tar(1).a", &ap2);
1588
1589 err = PD_read(strm, "tar(0).a(0)", &aa[0]);
1590 err = PD_read(strm, "tar(0).a(1)", &aa[1]);
1591 err = PD_read(strm, "tar(1).a(0)", &aa[2]);
1592 err = PD_read(strm, "tar(1).a(1)", &aa[3]);
1593
1594 err = PD_read(strm, "tar(0).b", &bp1);
1595 err = PD_read(strm, "tar(1).b", &bp2);
1596
1597 err = PD_read(strm, "tar(0).b(0)", &ba[0]);
1598 err = PD_read(strm, "tar(0).b(1)", &ba[1]);
1599 err = PD_read(strm, "tar(1).b(0)", &ba[2]);
1600 err = PD_read(strm, "tar(1).b(1)", &ba[3]);
1601
1602 err = PD_read(strm, "tar(0).c", &cp1);
1603 err = PD_read(strm, "tar(1).c", &cp2);
1604
1605 err = PD_read(strm, "tar(0).c(0)", &ca[0]);
1606 err = PD_read(strm, "tar(0).c(1)", &ca[1]);
1607 err = PD_read(strm, "tar(1).c(0)", &ca[2]);
1608 err = PD_read(strm, "tar(1).c(1)", &ca[3]);
1609
1610 err = PD_read(strm, "tar(0).c(0).s", &sp1);
1611 err = PD_read(strm, "tar(0).c(1).s", &sp2);
1612 err = PD_read(strm, "tar(1).c(0).s", &sp3);
1613 err = PD_read(strm, "tar(1).c(1).s", &sp4);
1614
1615 err = PD_read(strm, "tar(0).c(0).s(0)", &tp1);
1616 err = PD_read(strm, "tar(0).c(0).s(1)", &tp2);
1617 err = PD_read(strm, "tar(0).c(1).s(0)", &tp3);
1618 err = PD_read(strm, "tar(0).c(1).s(1)", &tp4);
1619
1620 err = PD_read(strm, "tar(1).c(0).s(0)", &tp5);
1621 err = PD_read(strm, "tar(1).c(0).s(1)", &tp6);
1622 err = PD_read(strm, "tar(1).c(1).s(0)", &tp7);
1623 err = PD_read(strm, "tar(1).c(1).s(1)", &tp8);
1624
1625 err = PD_read(strm, "tar(0).c(0).s(0)(2)", &ta[0]);
1626 err = PD_read(strm, "tar(0).c(0).s(1)(1)", &ta[1]);
1627 err = PD_read(strm, "tar(0).c(1).s(0)(3)", &ta[2]);
1628 err = PD_read(strm, "tar(0).c(1).s(1)(2)", &ta[3]);
1629
1630 err = PD_read(strm, "tar(1).c(0).s(0)(2)", &ta[4]);
1631 err = PD_read(strm, "tar(1).c(0).s(1)(1)", &ta[5]);
1632 err = PD_read(strm, "tar(1).c(1).s(0)(3)", &ta[6]);
1633 err = PD_read(strm, "tar(1).c(1).s(1)(2)", &ta[7]);
1634
1635 return(err);}
1636
1637 /*--------------------------------------------------------------------------*/
1638 /*--------------------------------------------------------------------------*/
1639
1640 /* PRINT_TEST_2_DATA - print it out to the file */
1641
print_test_2_data(FILE * fp)1642 static void print_test_2_data(FILE *fp)
1643 {int i;
1644 int *p1, *p2;
1645 double *p3, *p4;
1646
1647 PRINT(fp, "\n");
1648
1649 p1 = tar_r[0].a;
1650 p2 = tar_r[1].a;
1651 PRINT(fp, "TAR struct member A:\n");
1652 PRINT(fp, " TAR[0].A TAR[1].A\n");
1653 for (i = 0; i < N_INT; i++)
1654 PRINT(fp, " %d %d\n", p1[i], p2[i]);
1655 PRINT(fp, "\n");
1656
1657 p3 = tar_r[0].b;
1658 p4 = tar_r[1].b;
1659 PRINT(fp, "TAR struct member B:\n");
1660 PRINT(fp, " TAR[0].B TAR[1].B\n");
1661 for (i = 0; i < N_DOUBLE; i++)
1662 PRINT(fp, " %f %f\n", p3[i], p4[i]);
1663 PRINT(fp, "\n");
1664
1665
1666 PRINT(fp, "TAR struct member C:\n");
1667 PRINT(fp, " TAR[0].C[0] TAR[0].C[1]\n");
1668 PRINT(fp, " S[0] S[1] S[0] S[1]\n");
1669 PRINT(fp, " %s %s %s %s\n",
1670 tar_r[0].c[0].s[0], tar_r[0].c[0].s[1],
1671 tar_r[0].c[1].s[0], tar_r[0].c[1].s[1]);
1672 PRINT(fp, "\n TYPE\n");
1673 PRINT(fp, " %d %d\n",
1674 tar_r[0].c[0].type, tar_r[0].c[1].type);
1675
1676
1677 PRINT(fp, "\n TAR[1].C[0] TAR[1].C[1]\n");
1678 PRINT(fp, " S[0] S[1] S[0] S[1]\n");
1679 PRINT(fp, " %s %s %s %s\n",
1680 tar_r[1].c[0].s[0], tar_r[1].c[0].s[1],
1681 tar_r[1].c[1].s[0], tar_r[1].c[1].s[1]);
1682
1683 PRINT(fp, " TYPE\n");
1684 PRINT(fp, " %d %d\n",
1685 tar_r[1].c[0].type, tar_r[1].c[1].type);
1686
1687 PRINT(fp, "\n");
1688
1689 /* print the offset */
1690 PRINT(fp, "file array index offset: %d\n\n", do_r);
1691
1692 PRINT(fp, "\n");
1693
1694 /* read the an array which has offsets */
1695 PRINT(fp, "array p: \n");
1696 for (i = 0; i < N_INT; i++)
1697 PRINT(fp, " %d\n", p_r[i]);
1698
1699 PRINT(fp, "\n");
1700
1701 /* print the partial and member read stuff */
1702 if (ap1 != NULL)
1703 {PRINT(fp, "member read TAR[0].A TAR[1].A\n");
1704 for (i = 0; i < N_INT; i++)
1705 PRINT(fp, " %d %d\n", ap1[i], ap2[i]);
1706 PRINT(fp, "\n");};
1707
1708 if (bp1 != NULL)
1709 {PRINT(fp, "member read TAR[0].B TAR[1].B\n");
1710 for (i = 0; i < N_DOUBLE; i++)
1711 PRINT(fp, " %f %f\n", bp1[i], bp2[i]);
1712 PRINT(fp, "\n");};
1713
1714 if (cp1 != NULL)
1715 {PRINT(fp, "member read TAR[0].C:\n");
1716 PRINT(fp, " TAR[0].C[0] TAR[0].C[1]\n");
1717 PRINT(fp, " S[0] S[1] S[0] S[1]\n");
1718 PRINT(fp, " %s %s %s %s\n",
1719 cp1[0].s[0], cp1[0].s[1],
1720 cp1[1].s[0], cp1[1].s[1]);
1721 PRINT(fp, "\n TYPE\n");
1722 PRINT(fp, " %d %d\n",
1723 cp1[0].type, cp1[1].type);
1724
1725 PRINT(fp, "\nmember read TAR[1].C:\n");
1726 PRINT(fp, " TAR[1].C[0] TAR[1].C[1]\n");
1727 PRINT(fp, " S[0] S[1] S[0] S[1]\n");
1728 PRINT(fp, " %s %s %s %s\n",
1729 cp2[0].s[0], cp2[0].s[1],
1730 cp2[1].s[0], cp2[1].s[1]);
1731 PRINT(fp, "\n TYPE\n");
1732 PRINT(fp, " %d %d\n",
1733 cp2[0].type, cp2[1].type);};
1734
1735 /*
1736 PRINT(fp, "member read TAR[0].C[0]:\n");
1737 PRINT(fp, " S[0] S[1]\n");
1738 PRINT(fp, " %s %s\n", ca[0].s[0], ca[0].s[1]);
1739
1740 PRINT(fp, "member read TAR[0].C[1]:\n");
1741 PRINT(fp, " S[0] S[1]\n");
1742 PRINT(fp, " %s %s\n", ca[1].s[0], ca[1].s[1]);
1743
1744 PRINT(fp, "member read TAR[1].C[1]:\n");
1745 PRINT(fp, " S[0] S[1]\n");
1746 PRINT(fp, " %s %s\n", ca[2].s[0], ca[2].s[1]);
1747
1748 PRINT(fp, "member read TAR[1].C[1]:\n");
1749 PRINT(fp, " S[0] S[1]\n");
1750 PRINT(fp, " %s %s\n", ca[3].s[0], ca[3].s[1]);
1751 */
1752 /* TAR.C.S read */
1753
1754 if (sp1 != NULL)
1755 {PRINT(fp, "\nmember read TAR[0].C[0].S:\n");
1756 PRINT(fp, " S[0] S[1]\n");
1757 PRINT(fp, " %s %s\n", sp1[0], sp1[1]);
1758
1759 PRINT(fp, "\nmember read TAR[0].C[1].S:\n");
1760 PRINT(fp, " S[0] S[1]\n");
1761 PRINT(fp, " %s %s\n", sp2[0], sp2[1]);
1762
1763 PRINT(fp, "\nmember read TAR[1].C[0].S:\n");
1764 PRINT(fp, " S[0] S[1]\n");
1765 PRINT(fp, " %s %s\n", sp3[0], sp3[1]);
1766
1767 PRINT(fp, "\nmember read TAR[1].C[1].S:\n");
1768 PRINT(fp, " S[0] S[1]\n");
1769 PRINT(fp, " %s %s\n", sp4[0], sp4[1]);};
1770
1771 /* TAR.C.S[i] read */
1772
1773 if (tp1 != NULL)
1774 {PRINT(fp, "\nmember read TAR[0].C[0].S[0]:\n");
1775 PRINT(fp, " S[0] S[1]\n");
1776 PRINT(fp, " %s %s\n", tp1, tp1);
1777
1778 PRINT(fp, "\nmember read TAR[0].C[1].S[1]:\n");
1779 PRINT(fp, " S[0] S[1]\n");
1780 PRINT(fp, " %s %s\n", tp2, tp2);
1781
1782 PRINT(fp, "\nmember read TAR[0].C[1].S[0]:\n");
1783 PRINT(fp, " S[0] S[1]\n");
1784 PRINT(fp, " %s %s\n", tp3, tp3);
1785
1786 PRINT(fp, "\nmember read TAR[0].C[1].S[1]:\n");
1787 PRINT(fp, " S[0] S[1]\n");
1788 PRINT(fp, " %s %s\n", tp4, tp4);
1789
1790 PRINT(fp, "\nmember read TAR[1].C[0].S[0]:\n");
1791 PRINT(fp, " S[0] S[1]\n");
1792 PRINT(fp, " %s %s\n", tp5, tp5);
1793
1794 PRINT(fp, "\nmember read TAR[1].C[0].S[1]:\n");
1795 PRINT(fp, " S[0] S[1]\n");
1796 PRINT(fp, " %s %s\n", tp6, tp6);
1797
1798 PRINT(fp, "\nmember read TAR[1].C[1].S[0]:\n");
1799 PRINT(fp, " S[0] S[1]\n");
1800 PRINT(fp, " %s %s\n", tp7, tp7);
1801
1802 PRINT(fp, "\nmember read TAR[1].C[1].S[1]:\n");
1803 PRINT(fp, " S[0] S[1]\n");
1804 PRINT(fp, " %s %s\n", tp8, tp8);
1805
1806 /* TAR.C.S[i][j] read */
1807
1808 PRINT(fp, "\nmember read from TAR[0]:\n");
1809 PRINT(fp, "C[0].S[0][2] C[0].S[1][1] C[1].S[0][3] C[1].S[1][2]\n");
1810 PRINT(fp, " %c %c %c %c\n",
1811 ta[0], ta[1], ta[2], ta[3]);};
1812
1813 return;}
1814
1815 /*--------------------------------------------------------------------------*/
1816 /*--------------------------------------------------------------------------*/
1817
1818 /* COMPARE_TEST_2_DATA - compare the test data */
1819
compare_test_2_data(PDBfile * strm,FILE * fp)1820 static int compare_test_2_data(PDBfile *strm, FILE *fp)
1821 {int i, err, err_tot;
1822 int *p1w, *p2w, *p1r, *p2r;
1823 double *p3w, *p4w, *p3r, *p4r;
1824 long double fptol[N_PRIMITIVE_FP];
1825
1826 PD_fp_toler(strm, fptol);
1827
1828 err_tot = TRUE;
1829
1830 /* compare offset and array */
1831 err = TRUE;
1832 err &= (do_r == do_w);
1833
1834 for (i = 0; i < N_INT; i++)
1835 err &= (p_w[i] == p_r[i]);
1836
1837 if (err)
1838 PRINT(fp, "Offset compare\n");
1839 else
1840 PRINT(fp, "Offset differ\n");
1841 err_tot &= err;
1842
1843 err = TRUE;
1844 p1w = tar_w[0].a;
1845 p2w = tar_w[1].a;
1846 p1r = tar_r[0].a;
1847 p2r = tar_r[1].a;
1848 for (i = 0; i < N_INT; i++)
1849 {err &= (p1w[i] == p1r[i]);
1850 err &= (p2w[i] == p2r[i]);};
1851
1852 p3w = tar_w[0].b;
1853 p4w = tar_w[1].b;
1854 p3r = tar_r[0].b;
1855 p4r = tar_r[1].b;
1856 for (i = 0; i < N_DOUBLE; i++)
1857 {err &= DOUBLE_EQUAL(p3w[i], p3r[i]);
1858 err &= DOUBLE_EQUAL(p4w[i], p4r[i]);};
1859
1860 err &= (strcmp(tar_w[0].c[0].s[0], tar_r[0].c[0].s[0]) == 0);
1861 err &= (strcmp(tar_w[0].c[0].s[1], tar_r[0].c[0].s[1]) == 0);
1862 err &= (strcmp(tar_w[0].c[1].s[0], tar_r[0].c[1].s[0]) == 0);
1863 err &= (strcmp(tar_w[0].c[1].s[1], tar_r[0].c[1].s[1]) == 0);
1864
1865 err &= (strcmp(tar_w[1].c[0].s[0], tar_r[1].c[0].s[0]) == 0);
1866 err &= (strcmp(tar_w[1].c[0].s[1], tar_r[1].c[0].s[1]) == 0);
1867 err &= (strcmp(tar_w[1].c[1].s[0], tar_r[1].c[1].s[0]) == 0);
1868 err &= (strcmp(tar_w[1].c[1].s[1], tar_r[1].c[1].s[1]) == 0);
1869
1870 err &= (tar_w[0].c[0].type == tar_r[0].c[0].type);
1871 err &= (tar_w[0].c[1].type == tar_r[0].c[1].type);
1872 err &= (tar_w[1].c[0].type == tar_r[1].c[0].type);
1873 err &= (tar_w[1].c[1].type == tar_r[1].c[1].type);
1874
1875 if (err)
1876 PRINT(fp, "Indirects compare\n");
1877 else
1878 PRINT(fp, "Indirects differ\n");
1879 err_tot &= err;
1880
1881 PRINT(fp, "\n");
1882
1883 if (err)
1884 PRINT(fp, "Offset compare\n");
1885 else
1886 PRINT(fp, "Offset differ\n");
1887 err_tot &= err;
1888
1889 err = TRUE;
1890
1891 if (ap1 != NULL)
1892 {p1w = tar_w[0].a;
1893 p2w = tar_w[1].a;
1894 for (i = 0; i < N_INT; i++)
1895 {err &= (p1w[i] == ap1[i]);
1896 err &= (p2w[i] == ap2[i]);};};
1897
1898 if (bp1 != NULL)
1899 {p3w = tar_w[0].b;
1900 p4w = tar_w[1].b;
1901 for (i = 0; i < N_DOUBLE; i++)
1902 {err &= DOUBLE_EQUAL(p3w[i], bp1[i]);
1903 err &= DOUBLE_EQUAL(p4w[i], bp2[i]);};};
1904
1905 if (cp1 != NULL)
1906 {err &= (strcmp(tar_w[0].c[0].s[0], cp1[0].s[0]) == 0);
1907 err &= (strcmp(tar_w[0].c[0].s[1], cp1[0].s[1]) == 0);
1908 err &= (strcmp(tar_w[0].c[1].s[0], cp1[1].s[0]) == 0);
1909 err &= (strcmp(tar_w[0].c[1].s[1], cp1[1].s[1]) == 0);
1910
1911 err &= (strcmp(tar_w[1].c[0].s[0], cp2[0].s[0]) == 0);
1912 err &= (strcmp(tar_w[1].c[0].s[1], cp2[0].s[1]) == 0);
1913 err &= (strcmp(tar_w[1].c[1].s[0], cp2[1].s[0]) == 0);
1914 err &= (strcmp(tar_w[1].c[1].s[1], cp2[1].s[1]) == 0);
1915
1916 err &= (tar_w[0].c[0].type == cp1[0].type);
1917 err &= (tar_w[0].c[1].type == cp1[1].type);
1918 err &= (tar_w[1].c[0].type == cp2[0].type);
1919 err &= (tar_w[1].c[1].type == cp2[1].type);};
1920 /*
1921 err &= (strcmp(tar_w[0].c[0].s[0], ca[0].s[0]) == 0);
1922 err &= (strcmp(tar_w[0].c[0].s[1], ca[0].s[1]) == 0);
1923 err &= (strcmp(tar_w[0].c[1].s[0], ca[1].s[0]) == 0);
1924 err &= (strcmp(tar_w[0].c[1].s[1], ca[1].s[1]) == 0);
1925
1926 err &= (strcmp(tar_w[1].c[0].s[0], ca[2].s[0]) == 0);
1927 err &= (strcmp(tar_w[1].c[0].s[1], ca[2].s[1]) == 0);
1928 err &= (strcmp(tar_w[1].c[1].s[0], ca[3].s[0]) == 0);
1929 err &= (strcmp(tar_w[1].c[1].s[1], ca[3].s[1]) == 0);
1930 */
1931 if (sp1 != NULL)
1932 {err &= (strcmp(tar_w[0].c[0].s[0], sp1[0]) == 0);
1933 err &= (strcmp(tar_w[0].c[0].s[1], sp1[1]) == 0);
1934 err &= (strcmp(tar_w[0].c[1].s[0], sp2[0]) == 0);
1935 err &= (strcmp(tar_w[0].c[1].s[1], sp2[1]) == 0);
1936
1937 err &= (strcmp(tar_w[1].c[0].s[0], sp3[0]) == 0);
1938 err &= (strcmp(tar_w[1].c[0].s[1], sp3[1]) == 0);
1939 err &= (strcmp(tar_w[1].c[1].s[0], sp4[0]) == 0);
1940 err &= (strcmp(tar_w[1].c[1].s[1], sp4[1]) == 0);};
1941
1942 if (tp1 != NULL)
1943 {err &= (strcmp(tar_w[0].c[0].s[0], tp1) == 0);
1944 err &= (strcmp(tar_w[0].c[0].s[1], tp2) == 0);
1945 err &= (strcmp(tar_w[0].c[1].s[0], tp3) == 0);
1946 err &= (strcmp(tar_w[0].c[1].s[1], tp4) == 0);
1947
1948 err &= (strcmp(tar_w[1].c[0].s[0], tp5) == 0);
1949 err &= (strcmp(tar_w[1].c[0].s[1], tp6) == 0);
1950 err &= (strcmp(tar_w[1].c[1].s[0], tp7) == 0);
1951 err &= (strcmp(tar_w[1].c[1].s[1], tp8) == 0);
1952
1953 err &= (tar_w[0].c[0].s[0][2] == ta[0]);
1954 err &= (tar_w[0].c[0].s[1][1] == ta[1]);
1955 err &= (tar_w[0].c[1].s[0][3] == ta[2]);
1956 err &= (tar_w[0].c[1].s[1][2] == ta[3]);};
1957
1958 if (err)
1959 PRINT(fp, "Indirects compare\n");
1960 else
1961 PRINT(fp, "Indirects differ\n");
1962 err_tot &= err;
1963
1964 PRINT(fp, "\n");
1965
1966 return(err_tot);}
1967
1968 /*--------------------------------------------------------------------------*/
1969 /*--------------------------------------------------------------------------*/
1970
1971 /* TEST_2 - test the PDBLib functions handling indirections
1972 * -
1973 * - read and write structures with pointers
1974 * - set default array base indexes
1975 * - read structure members
1976 * - read parts of arrays
1977 * -
1978 * - tests can be targeted
1979 */
1980
test_2(char * base,char * tgt,int n)1981 static int test_2(char *base, char *tgt, int n)
1982 {int err;
1983 char datfile[MAXLINE], fname[MAXLINE];
1984 PDBfile *strm;
1985 FILE *fp;
1986
1987 /* target the file is asked */
1988 test_target(tgt, base, n, fname, datfile);
1989
1990 fp = io_open(fname, "w");
1991
1992 prep_test_2_data();
1993
1994 if (read_only == FALSE)
1995
1996 /* create the named file */
1997 {strm = PD_create(datfile);
1998 if (strm == NULL)
1999 error(2, fp, "Test couldn't create file %s\r\n", datfile);
2000 PRINT(fp, "File %s created\n", datfile);
2001
2002 /* set the default offset */
2003 strm->default_offset = do_w;
2004
2005 /* make a few defstructs */
2006 PD_defstr(strm, "lev2",
2007 "char **s",
2008 "integer type",
2009 LAST);
2010
2011 PD_defstr(strm, "lev1",
2012 "integer *a",
2013 "double *b",
2014 "lev2 *c",
2015 LAST);
2016
2017 /* write the test data */
2018 write_test_2_data(strm);
2019
2020 /* close the file */
2021 if (PD_close(strm) == FALSE)
2022 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2023 PRINT(fp, "File %s closed\n", datfile);};
2024
2025 /* reopen the file */
2026 strm = PD_open(datfile, "r");
2027 if (strm == NULL)
2028 error(2, fp, "Test couldn't open file %s\r\n", datfile);
2029 PRINT(fp, "File %s opened\n", datfile);
2030
2031 /* dump the symbol table */
2032 dump_test_symbol_table(fp, strm->symtab, 2);
2033
2034 /* read the structs */
2035 read_test_2_data(strm);
2036
2037 /* compare the original data with that read in */
2038 err = compare_test_2_data(strm, fp);
2039
2040 /* print out the results */
2041 print_test_2_data(fp);
2042
2043 /* close the file */
2044 if (PD_close(strm) == FALSE)
2045 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2046 PRINT(fp, "File %s closed\n", datfile);
2047
2048 /* cleanup test data memory */
2049 cleanup_test_2();
2050
2051 io_close(fp);
2052 if (err)
2053 REMOVE(fname);
2054
2055 return(err);}
2056
2057 /*--------------------------------------------------------------------------*/
2058
2059 /* TEST #3 ROUTINES */
2060
2061 /*--------------------------------------------------------------------------*/
2062
2063 /* PREP_TEST_3_DATA - prepare the test data */
2064
prep_test_3_data(void)2065 static void prep_test_3_data(void)
2066 {
2067
2068 vr1_w.a = 'A';
2069 vr1_w.b = -10;
2070 vr1_w.c[0] = 'B';
2071 vr1_w.c[1] = 'a';
2072 vr1_w.d = 32589;
2073 vr1_w.e[0] = 'C';
2074 vr1_w.e[1] = 'a';
2075 vr1_w.e[2] = 'b';
2076 vr1_w.f = 1.523e-19;
2077 vr1_w.g[0] = 'D';
2078 vr1_w.g[1] = 'a';
2079 vr1_w.g[2] = 'b';
2080 vr1_w.g[3] = 'c';
2081 vr1_w.h = 4.2782918323832554e30;
2082 vr1_w.i[0] = 'E';
2083 vr1_w.i[1] = 'a';
2084 vr1_w.i[2] = 'b';
2085 vr1_w.i[3] = 'c';
2086 vr1_w.i[4] = 'd';
2087 vr1_w.j = CSTRSAVE("whoa there big fella!");
2088 vr1_w.k[0] = 'F';
2089 vr1_w.k[1] = 'a';
2090 vr1_w.k[2] = 'b';
2091 vr1_w.k[3] = 'c';
2092 vr1_w.k[4] = 'd';
2093 vr1_w.k[5] = 'e';
2094
2095 vr1_r.a = '\0';
2096 vr1_r.b = 0;
2097 vr1_r.c[0] = '\0';
2098 vr1_r.c[1] = '\0';
2099 vr1_r.d = 0;
2100 vr1_r.e[0] = '\0';
2101 vr1_r.e[1] = '\0';
2102 vr1_r.e[2] = '\0';
2103 vr1_r.f = 0.0;
2104 vr1_r.g[0] = '\0';
2105 vr1_r.g[1] = '\0';
2106 vr1_r.g[2] = '\0';
2107 vr1_r.g[3] = '\0';
2108 vr1_r.h = 0.0;
2109 vr1_r.i[0] = '\0';
2110 vr1_r.i[1] = '\0';
2111 vr1_r.i[2] = '\0';
2112 vr1_r.i[3] = '\0';
2113 vr1_r.i[4] = '\0';
2114 vr1_r.j = NULL;
2115 vr1_r.k[0] = '\0';
2116 vr1_r.k[1] = '\0';
2117 vr1_r.k[2] = '\0';
2118 vr1_r.k[3] = '\0';
2119 vr1_r.k[4] = '\0';
2120 vr1_r.k[5] = '\0';
2121
2122 return;}
2123
2124 /*--------------------------------------------------------------------------*/
2125 /*--------------------------------------------------------------------------*/
2126
2127 /* CLEANUP_TEST_3 - free all known test data memory */
2128
cleanup_test_3(void)2129 static void cleanup_test_3(void)
2130 {
2131
2132 CFREE(vr1_w.j);
2133 CFREE(vr1_r.j);
2134
2135 return;}
2136
2137 /*--------------------------------------------------------------------------*/
2138 /*--------------------------------------------------------------------------*/
2139
2140 /* WRITE_TEST_3_DATA - write out the data into the PDB file */
2141
write_test_3_data(PDBfile * strm)2142 static void write_test_3_data(PDBfile *strm)
2143 {
2144
2145 if (PD_write(strm, "vr1", "st3", &vr1_w) == 0)
2146 error(1, STDOUT, "VR1 WRITE FAILED - WRITE_TEST_3_DATA\n");
2147
2148 return;}
2149
2150 /*--------------------------------------------------------------------------*/
2151 /*--------------------------------------------------------------------------*/
2152
2153 /* READ_TEST_3_DATA - read the test data from the file */
2154
read_test_3_data(PDBfile * strm)2155 static int read_test_3_data(PDBfile *strm)
2156 {int err;
2157
2158 err = PD_read(strm, "vr1", &vr1_r);
2159
2160 return(err);}
2161
2162 /*--------------------------------------------------------------------------*/
2163 /*--------------------------------------------------------------------------*/
2164
2165 /* PRINT_TEST_3_DATA - print it out to the file */
2166
print_test_3_data(FILE * fp)2167 static void print_test_3_data(FILE *fp)
2168 {
2169
2170 PRINT(fp, "struct vr1:\n");
2171 PRINT(fp, " vr1.a = %c\n", vr1_r.a);
2172 PRINT(fp, " vr1.b = %d\n", vr1_r.b);
2173 PRINT(fp, " vr1.c[0] = %c\n", vr1_r.c[0]);
2174 PRINT(fp, " vr1.c[1] = %c\n", vr1_r.c[1]);
2175 PRINT(fp, " vr1.d = %d\n", vr1_r.d);
2176 PRINT(fp, " vr1.e[0] = %c\n", vr1_r.e[0]);
2177 PRINT(fp, " vr1.e[1] = %c\n", vr1_r.e[1]);
2178 PRINT(fp, " vr1.e[2] = %c\n", vr1_r.e[2]);
2179 PRINT(fp, " vr1.f = %14.7e\n", vr1_r.f);
2180 PRINT(fp, " vr1.g[0] = %c\n", vr1_r.g[0]);
2181 PRINT(fp, " vr1.g[1] = %c\n", vr1_r.g[1]);
2182 PRINT(fp, " vr1.g[2] = %c\n", vr1_r.g[2]);
2183 PRINT(fp, " vr1.g[3] = %c\n", vr1_r.g[3]);
2184 PRINT(fp, " vr1.h = %20.13e\n", vr1_r.h);
2185 PRINT(fp, " vr1.i[0] = %c\n", vr1_r.i[0]);
2186 PRINT(fp, " vr1.i[1] = %c\n", vr1_r.i[1]);
2187 PRINT(fp, " vr1.i[2] = %c\n", vr1_r.i[2]);
2188 PRINT(fp, " vr1.i[3] = %c\n", vr1_r.i[3]);
2189 PRINT(fp, " vr1.i[4] = %c\n", vr1_r.i[4]);
2190 PRINT(fp, " vr1.j = %s\n", vr1_r.j);
2191 PRINT(fp, " vr1.k[0] = %c\n", vr1_r.k[0]);
2192 PRINT(fp, " vr1.k[1] = %c\n", vr1_r.k[1]);
2193 PRINT(fp, " vr1.k[2] = %c\n", vr1_r.k[2]);
2194 PRINT(fp, " vr1.k[3] = %c\n", vr1_r.k[3]);
2195 PRINT(fp, " vr1.k[4] = %c\n", vr1_r.k[4]);
2196 PRINT(fp, " vr1.k[5] = %c\n", vr1_r.k[5]);
2197
2198 PRINT(fp, "\n");
2199
2200 return;}
2201
2202 /*--------------------------------------------------------------------------*/
2203 /*--------------------------------------------------------------------------*/
2204
2205 /* COMPARE_TEST_3_DATA - compare the test data */
2206
compare_test_3_data(PDBfile * strm,FILE * fp)2207 static int compare_test_3_data(PDBfile *strm, FILE *fp)
2208 {int err, err_tot;
2209 long double fptol[N_PRIMITIVE_FP];
2210
2211 PD_fp_toler(strm, fptol);
2212
2213 err_tot = TRUE;
2214
2215 /* compare offset and array */
2216 err = TRUE;
2217 err &= (vr1_w.a == vr1_r.a);
2218 err &= (vr1_w.b == vr1_r.b);
2219 err &= (vr1_w.c[0] == vr1_r.c[0]);
2220 err &= (vr1_w.c[1] == vr1_r.c[1]);
2221 err &= (vr1_w.d == vr1_r.d);
2222 err &= (vr1_w.e[0] == vr1_r.e[0]);
2223 err &= (vr1_w.e[1] == vr1_r.e[1]);
2224 err &= (vr1_w.e[2] == vr1_r.e[2]);
2225 err &= FLOAT_EQUAL(vr1_w.f, vr1_r.f);
2226 err &= (vr1_w.g[0] == vr1_r.g[0]);
2227 err &= (vr1_w.g[1] == vr1_r.g[1]);
2228 err &= (vr1_w.g[2] == vr1_r.g[2]);
2229 err &= (vr1_w.g[3] == vr1_r.g[3]);
2230 err &= DOUBLE_EQUAL(vr1_w.h, vr1_r.h);
2231 err &= (vr1_w.i[0] == vr1_r.i[0]);
2232 err &= (vr1_w.i[1] == vr1_r.i[1]);
2233 err &= (vr1_w.i[2] == vr1_r.i[2]);
2234 err &= (vr1_w.i[3] == vr1_r.i[3]);
2235 err &= (vr1_w.i[4] == vr1_r.i[4]);
2236 err &= (strcmp(vr1_w.j, vr1_r.j) == 0);
2237 err &= (vr1_w.k[0] == vr1_r.k[0]);
2238 err &= (vr1_w.k[1] == vr1_r.k[1]);
2239 err &= (vr1_w.k[2] == vr1_r.k[2]);
2240 err &= (vr1_w.k[3] == vr1_r.k[3]);
2241 err &= (vr1_w.k[4] == vr1_r.k[4]);
2242 err &= (vr1_w.k[5] == vr1_r.k[5]);
2243
2244 if (err)
2245 PRINT(fp, "Alignments compare\n");
2246 else
2247 PRINT(fp, "Alignments differ\n");
2248 err_tot &= err;
2249
2250 PRINT(fp, "\n");
2251
2252 return(err_tot);}
2253
2254 /*--------------------------------------------------------------------------*/
2255 /*--------------------------------------------------------------------------*/
2256
2257 /* TEST_3 - test the PDBLib functions handling indirections
2258 * - read and write structures with alignment difficulties
2259 * - tests can be targeted
2260 */
2261
test_3(char * base,char * tgt,int n)2262 static int test_3(char *base, char *tgt, int n)
2263 {int err;
2264 char datfile[MAXLINE], fname[MAXLINE];
2265 PDBfile *strm;
2266 FILE *fp;
2267
2268 /* target the file is asked */
2269 test_target(tgt, base, n, fname, datfile);
2270
2271 fp = io_open(fname, "w");
2272
2273 prep_test_3_data();
2274
2275 if (read_only == FALSE)
2276
2277 /* create the named file */
2278 {if ((strm = PD_create(datfile)) == NULL)
2279 error(2, fp, "Test couldn't create file %s\r\n", datfile);
2280 PRINT(fp, "File %s created\n", datfile);
2281
2282 /* make a few defstructs */
2283 PD_defstr(strm, "st3",
2284 "char a",
2285 "short b",
2286 "char c[2]",
2287 "integer d",
2288 "char e[3]",
2289 "float f",
2290 "char g[4]",
2291 "double h",
2292 "char i[5]",
2293 "char *j",
2294 "char k[6]",
2295 LAST);
2296
2297 /* write the test data */
2298 write_test_3_data(strm);
2299
2300 /* close the file */
2301 if (PD_close(strm) == FALSE)
2302 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2303 PRINT(fp, "File %s closed\n", datfile);
2304
2305 #ifdef LINUX
2306 /* GOTCHA: Without this delay, the test fails about half the time,
2307 * iff the files are being accessed across the network.
2308 */
2309 SC_sleep(10);
2310 #endif
2311 };
2312
2313 /* reopen the file */
2314 if ((strm = PD_open(datfile, "r")) == NULL)
2315 error(2, fp, "Test couldn't open file %s\r\n", datfile);
2316 PRINT(fp, "File %s opened\n", datfile);
2317
2318 /* dump the symbol table */
2319 dump_test_symbol_table(fp, strm->symtab, 3);
2320
2321 /* read the structs */
2322 read_test_3_data(strm);
2323
2324 /* compare the original data with that read in */
2325 err = compare_test_3_data(strm, fp);
2326
2327 /* close the file */
2328 if (PD_close(strm) == FALSE)
2329 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2330 PRINT(fp, "File %s closed\n", datfile);
2331
2332 /* print out the results */
2333 print_test_3_data(fp);
2334
2335 /* clean up test data memory */
2336 cleanup_test_3();
2337
2338 io_close(fp);
2339 if (err)
2340 REMOVE(fname);
2341
2342 return(err);}
2343
2344 /*--------------------------------------------------------------------------*/
2345
2346 /* TEST #4 ROUTINES */
2347
2348 /*--------------------------------------------------------------------------*/
2349
2350 /* PREP_TEST_4_DATA - prepare the test data */
2351
prep_test_4_data(void)2352 static void prep_test_4_data(void)
2353 {int *pi;
2354 short *ps;
2355 long *pl;
2356 float *pf;
2357 double *pd;
2358 char *pc;
2359 haelem *hp;
2360
2361 tab4_w = SC_make_hasharr(3, NODOC, SC_HA_NAME_KEY, 0);
2362
2363 CHAR_S = CSTRSAVE("char *");
2364 SHORT_S = CSTRSAVE("short *");
2365 INT_S = CSTRSAVE("integer *");
2366 LONG_S = CSTRSAVE("long *");
2367 FLOAT_S = CSTRSAVE("float *");
2368 DOUBLE_S = CSTRSAVE("double *");
2369 HASHEL_S = CSTRSAVE(haelemstr " *");
2370
2371 pc = CMAKE(char);
2372 *pc = 'A';
2373 SC_hasharr_install(tab4_w, "pc", pc, CHAR_S, TRUE, TRUE);
2374
2375 ps = CMAKE(short);
2376 *ps = -1024;
2377 SC_hasharr_install(tab4_w, "ps", ps, SHORT_S, TRUE, TRUE);
2378
2379 pi = CMAKE(int);
2380 *pi = 16384;
2381 SC_hasharr_install(tab4_w, "pi", pi, INT_S, TRUE, TRUE);
2382
2383 pl = CMAKE(long);
2384 *pl = -1048576;
2385 SC_hasharr_install(tab4_w, "pl", pl, LONG_S, TRUE, TRUE);
2386
2387 pf = CMAKE(float);
2388 *pf = 3.141596;
2389 SC_hasharr_install(tab4_w, "pf", pf, FLOAT_S, TRUE, TRUE);
2390
2391 pd = CMAKE(double);
2392 *pd = -1.0e-30;
2393 hp = SC_hasharr_install(tab4_w, "pd", pd, DOUBLE_S, TRUE, TRUE);
2394
2395 SC_hasharr_install(tab4_w, "ph", hp, HASHEL_S, TRUE, TRUE);
2396
2397 tab4_r = NULL;
2398
2399 vr4_w = CMAKE_N(st4, 3);
2400
2401 vr4_w[0].a = 2048;
2402 vr4_w[0].b = 'G';
2403 vr4_w[1].a = -2048;
2404 vr4_w[1].b = 'H';
2405 vr4_w[2].a = 4096;
2406 vr4_w[2].b = 'I';
2407
2408 vr4_r = NULL;
2409
2410 return;}
2411
2412 /*--------------------------------------------------------------------------*/
2413 /*--------------------------------------------------------------------------*/
2414
2415 /* CLEANUP_HA_TEST_4 - free the haelem types which were read in not constant */
2416
cleanup_ha_test_4(haelem * hp,void * a)2417 static int cleanup_ha_test_4(haelem *hp, void *a)
2418 {
2419
2420 CFREE(hp->type);
2421
2422 return(TRUE);}
2423
2424 /*--------------------------------------------------------------------------*/
2425 /*--------------------------------------------------------------------------*/
2426
2427 /* CLEANUP_TEST_4 - free all known test data memory */
2428
cleanup_test_4(void)2429 static void cleanup_test_4(void)
2430 {
2431 /* PDB Lite's hash table isn't smart enough to deal with interdependencies
2432 of 'pd' and 'hp'. So, break that linkage now by null'ing hp's reference
2433 to the hashel for 'pd' */
2434 #ifdef PDB_LITE
2435 haelem *hp = SC_lookup("ph", tab4_w);
2436 hp->def = 0;
2437 #endif
2438 SC_free_hasharr(tab4_w, NULL, NULL);
2439
2440 if (tab4_r != NULL)
2441 SC_free_hasharr(tab4_r, cleanup_ha_test_4, NULL);
2442
2443 CFREE(CHAR_S);
2444 CFREE(SHORT_S);
2445 CFREE(INT_S);
2446 CFREE(LONG_S);
2447 CFREE(FLOAT_S);
2448 CFREE(DOUBLE_S);
2449 CFREE(HASHEL_S);
2450
2451 CFREE(vr4_w);
2452 CFREE(vr4_r);
2453
2454 return;}
2455
2456 /*--------------------------------------------------------------------------*/
2457 /*--------------------------------------------------------------------------*/
2458
2459 /* WRITE_TEST_4_DATA - write out the data into the PDB file */
2460
write_test_4_data(PDBfile * strm)2461 static void write_test_4_data(PDBfile *strm)
2462 {
2463
2464 if (PD_write(strm, "tab4", hasharrstr " *", &tab4_w) == 0)
2465 error(1, STDOUT, "TAB4 WRITE FAILED - WRITE_TEST_4_DATA\n");
2466
2467 if (PD_write(strm, "vr4", "st4 *", &vr4_w) == 0)
2468 error(1, STDOUT, "VR4 WRITE FAILED - WRITE_TEST_4_DATA\n");
2469
2470 return;}
2471
2472 /*--------------------------------------------------------------------------*/
2473 /*--------------------------------------------------------------------------*/
2474
2475 /* READ_TEST_4_DATA - read the test data from the file */
2476
read_test_4_data(PDBfile * strm)2477 static int read_test_4_data(PDBfile *strm)
2478 {int err;
2479
2480 err = PD_read(strm, "tab4", &tab4_r);
2481 SC_hasharr_rekey(tab4_r, SC_HA_NAME_KEY);
2482
2483 err = PD_read(strm, "vr4", &vr4_r);
2484
2485 return(err);}
2486
2487 /*--------------------------------------------------------------------------*/
2488 /*--------------------------------------------------------------------------*/
2489
2490 /* PRINT_TEST_4_DATA - print it out to the file */
2491
print_test_4_data(FILE * fp)2492 static void print_test_4_data(FILE *fp)
2493 {int i, ne, *pi;
2494 long *pl;
2495 short *ps;
2496 float *pf;
2497 double *pd;
2498 char *pc, **names;
2499 haelem *ph;
2500
2501 ne = SC_hasharr_get_n(tab4_r);
2502 names = SC_hasharr_dump(tab4_r, NULL, NULL, FALSE);
2503 for (i = 0; i < ne; i++)
2504 PRINT(fp, "%s\n", names[i]);
2505 SC_free_strings(names);
2506
2507 PRINT(fp, "\n");
2508
2509 pc = (char *) SC_hasharr_def_lookup(tab4_r, "pc");
2510 ps = (short *) SC_hasharr_def_lookup(tab4_r, "ps");
2511 pi = (int *) SC_hasharr_def_lookup(tab4_r, "pi");
2512 pl = (long *) SC_hasharr_def_lookup(tab4_r, "pl");
2513 pf = (float *) SC_hasharr_def_lookup(tab4_r, "pf");
2514 pd = (double *) SC_hasharr_def_lookup(tab4_r, "pd");
2515 ph = (haelem *) SC_hasharr_def_lookup(tab4_r, "ph");
2516
2517 PRINT(fp, "Table values:\n");
2518 PRINT(fp, " pc = %c %s\n", *pc, CHAR_S);
2519 PRINT(fp, " ps = %d %s\n", *ps, SHORT_S);
2520 PRINT(fp, " pi = %d %s\n", *pi, INT_S);
2521 PRINT(fp, " pl = %ld %s\n", *pl, LONG_S);
2522 PRINT(fp, " pf = %f %s\n", *pf, FLOAT_S);
2523 PRINT(fp, " pd = %e %s\n", *pd, DOUBLE_S);
2524
2525 PRINT(fp, "\n ph : %s %s\n\n", ph->name, ph->type);
2526
2527 PRINT(fp, "VR4[0]:\n");
2528 PRINT(fp, "VR4[0].A = %d\n", vr4_r[0].a);
2529 PRINT(fp, "VR4[0].B = %c\n", vr4_r[0].b);
2530 PRINT(fp, "VR4[1].A = %d\n", vr4_r[1].a);
2531 PRINT(fp, "VR4[1].B = %c\n", vr4_r[1].b);
2532 PRINT(fp, "VR4[2].A = %d\n", vr4_r[2].a);
2533 PRINT(fp, "VR4[2].B = %c\n", vr4_r[2].b);
2534
2535 return;}
2536
2537 /*--------------------------------------------------------------------------*/
2538 /*--------------------------------------------------------------------------*/
2539
2540 /* COMPARE_TEST_4_DATA - compare the test data */
2541
compare_test_4_data(PDBfile * strm,FILE * fp)2542 static int compare_test_4_data(PDBfile *strm, FILE *fp)
2543 {int err, err_tot;
2544 long double fptol[N_PRIMITIVE_FP];
2545 char *pc_w, *pc_r;
2546 short *ps_w, *ps_r;
2547 int *pi_w, *pi_r;
2548 long *pl_w, *pl_r;
2549 float *pf_w, *pf_r;
2550 double *pd_w, *pd_r;
2551 haelem *ph_w, *ph_r;
2552
2553 PD_fp_toler(strm, fptol);
2554
2555 err_tot = TRUE;
2556
2557 pc_r = (char *) SC_hasharr_def_lookup(tab4_r, "pc");
2558 ps_r = (short *) SC_hasharr_def_lookup(tab4_r, "ps");
2559 pi_r = (int *) SC_hasharr_def_lookup(tab4_r, "pi");
2560 pl_r = (long *) SC_hasharr_def_lookup(tab4_r, "pl");
2561 pf_r = (float *) SC_hasharr_def_lookup(tab4_r, "pf");
2562 pd_r = (double *) SC_hasharr_def_lookup(tab4_r, "pd");
2563 ph_r = (haelem *) SC_hasharr_def_lookup(tab4_r, "ph");
2564
2565 pc_w = (char *) SC_hasharr_def_lookup(tab4_w, "pc");
2566 ps_w = (short *) SC_hasharr_def_lookup(tab4_w, "ps");
2567 pi_w = (int *) SC_hasharr_def_lookup(tab4_w, "pi");
2568 pl_w = (long *) SC_hasharr_def_lookup(tab4_w, "pl");
2569 pf_w = (float *) SC_hasharr_def_lookup(tab4_w, "pf");
2570 pd_w = (double *) SC_hasharr_def_lookup(tab4_w, "pd");
2571 ph_w = (haelem *) SC_hasharr_def_lookup(tab4_w, "ph");
2572
2573 /* compare offset and array */
2574 err = TRUE;
2575 err &= (*pc_r == *pc_w);
2576 err &= (*ps_r == *ps_w);
2577 err &= (*pi_r == *pi_w);
2578 err &= (*pl_r == *pl_w);
2579 err &= FLOAT_EQUAL(*pf_r, *pf_w);
2580 err &= DOUBLE_EQUAL(*pd_r, *pd_w);
2581
2582 if (err)
2583 PRINT(fp, "Hash tables compare\n");
2584 else
2585 PRINT(fp, "Hash tables differ\n");
2586 err_tot &= err;
2587
2588 /* compare haelem info */
2589 err = TRUE;
2590 err &= (strcmp(ph_r->name, ph_w->name) == 0);
2591 err &= (strcmp(ph_r->type, ph_w->type) == 0);
2592 if (err)
2593 PRINT(fp, "Hashels compare\n");
2594 else
2595 PRINT(fp, "Hashels differ\n");
2596 err_tot &= err;
2597
2598 /* check the new alignments */
2599 err = TRUE;
2600 err &= (vr4_w[0].a == vr4_r[0].a);
2601 err &= (vr4_w[0].b == vr4_r[0].b);
2602 err &= (vr4_w[1].a == vr4_r[1].a);
2603 err &= (vr4_w[1].b == vr4_r[1].b);
2604 err &= (vr4_w[2].a == vr4_r[2].a);
2605 err &= (vr4_w[2].b == vr4_r[2].b);
2606
2607 if (err)
2608 PRINT(fp, "Alignments compare\n");
2609 else
2610 PRINT(fp, "Alignments differ\n");
2611 err_tot &= err;
2612
2613 PRINT(fp, "\n");
2614
2615 return(err_tot);}
2616
2617 /*--------------------------------------------------------------------------*/
2618 /*--------------------------------------------------------------------------*/
2619
2620 /* TEST_4 - test the PDBLib functions handling indirections
2621 * - read and write structures with alignment difficulties
2622 * - tests can be targeted
2623 */
2624
test_4(char * base,char * tgt,int n)2625 static int test_4(char *base, char *tgt, int n)
2626 {int err;
2627 char datfile[MAXLINE], fname[MAXLINE];
2628 PDBfile *strm;
2629 FILE *fp;
2630
2631 /* target the file as asked */
2632 test_target(tgt, base, n, fname, datfile);
2633
2634 fp = io_open(fname, "w");
2635
2636 prep_test_4_data();
2637
2638 if (read_only == FALSE)
2639
2640 /* create the named file */
2641 {strm = PD_create(datfile);
2642 if (strm == NULL)
2643 error(2, fp, "Test couldn't create file %s\r\n", datfile);
2644 PRINT(fp, "File %s created\n", datfile);
2645
2646 strm->previous_file = CSTRSAVE(base);
2647
2648 /* make a few defstructs */
2649 PD_def_hash_types(strm, 3);
2650
2651 PD_defstr(strm, "st4",
2652 "short a",
2653 "char b",
2654 LAST);
2655
2656 /* write the test data */
2657 write_test_4_data(strm);
2658
2659 /* close the file */
2660 if (PD_close(strm) == FALSE)
2661 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2662 PRINT(fp, "File %s closed\n", datfile);};
2663
2664 /* reopen the file */
2665 strm = PD_open(datfile, "r");
2666 if (strm == NULL)
2667 error(2, fp, "Test couldn't open file %s\r\n", datfile);
2668 PRINT(fp, "File %s opened\n", datfile);
2669
2670 /* dump the symbol table */
2671 dump_test_symbol_table(fp, strm->symtab, 4);
2672
2673 /* read the structs */
2674 read_test_4_data(strm);
2675
2676 /* compare the original data with that read in */
2677 err = compare_test_4_data(strm, fp);
2678
2679 /* print out the results */
2680 print_test_4_data(fp);
2681
2682 /* close the file */
2683 if (PD_close(strm) == FALSE)
2684 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2685 PRINT(fp, "File %s closed\n", datfile);
2686
2687 /* clean up test data memory */
2688 cleanup_test_4();
2689
2690 io_close(fp);
2691 if (err)
2692 REMOVE(fname);
2693
2694 return(err);}
2695
2696 /*--------------------------------------------------------------------------*/
2697
2698 /* TEST #5 ROUTINES */
2699
2700 /*--------------------------------------------------------------------------*/
2701
2702 /* PREP_TEST_5_DATA - prepare the test data */
2703
prep_test_5_data(void)2704 static void prep_test_5_data(void)
2705 {int i, *p1, *p2;
2706 double *p3, *p4;
2707
2708 for (i = 0; i < N_INT; i++)
2709 {p_w[i] = i;
2710 p_r[i] = 0;};
2711
2712 tar_w = CMAKE_N(lev1, 2);
2713
2714 p1 = tar_w[0].a = CMAKE_N(int, N_INT);
2715 p2 = tar_w[1].a = CMAKE_N(int, N_INT);
2716 for (i = 0; i < N_INT; i++)
2717 {p1[i] = i;
2718 p2[i] = i + 10;};
2719
2720 p3 = tar_w[0].b = CMAKE_N(double, N_DOUBLE);
2721 p4 = tar_w[1].b = CMAKE_N(double, N_DOUBLE);
2722 for (i = 0; i < N_DOUBLE; i++)
2723 {p3[i] = exp((double) i);
2724 p4[i] = log(1.0 + (double) i);};
2725
2726 tar_w[0].c = NULL;
2727 tar_w[1].c = NULL;
2728
2729 memset(tar5_t, 0, 4*sizeof(lev1));
2730 memset(tar5_r, 0, 4*sizeof(lev1));
2731
2732 return;}
2733
2734 /*--------------------------------------------------------------------------*/
2735 /*--------------------------------------------------------------------------*/
2736
2737 /* CLEANUP_TEST_5 - free all known test data memory */
2738
cleanup_test_5(void)2739 static void cleanup_test_5(void)
2740 {int l;
2741
2742 if (tar_w != NULL)
2743 {CFREE(tar_w[0].a);
2744 CFREE(tar_w[1].a);
2745
2746 CFREE(tar_w[0].b);
2747 CFREE(tar_w[1].b);
2748
2749 CFREE(tar_w);};
2750
2751 for (l = 0; l < 4; l++)
2752 {CFREE(tar5_t[l].a);
2753 CFREE(tar5_t[l].b);
2754
2755 CFREE(tar5_r[l].a);
2756 CFREE(tar5_r[l].b);};
2757
2758 return;}
2759
2760 /*--------------------------------------------------------------------------*/
2761 /*--------------------------------------------------------------------------*/
2762
2763 /* WRITE_TEST_5_DATA - write out the data into the PDB file */
2764
write_test_5_data(PDBfile * strm)2765 static void write_test_5_data(PDBfile *strm)
2766 {
2767
2768 if (PD_write(strm, "tar(2)", "lev1", tar_w) == 0)
2769 error(1, STDOUT, "TAR WRITE FAILED - WRITE_TEST_5_DATA\n");
2770
2771 if (PD_append(strm, "tar(2:3)", tar_w) == 0)
2772 error(1, STDOUT, "TAR APPEND FAILED - WRITE_TEST_5_DATA\n");
2773
2774 return;}
2775
2776 /*--------------------------------------------------------------------------*/
2777 /*--------------------------------------------------------------------------*/
2778
2779 /* READ_TEST_5_DATA - read the test data from the file */
2780
read_test_5_data(PDBfile * strm)2781 static int read_test_5_data(PDBfile *strm)
2782 {int err; long ind[3];
2783
2784 err = (PD_read(strm, "tar", tar5_t) != 4);
2785
2786 #ifdef PDB_LITE
2787 err = (PD_read(strm, "tar", tar5_r) != 4);
2788 err = (PD_read(strm, "tar(0)", tar5_r+0) != 1);
2789 err = (PD_read(strm, "tar(1)", tar5_r+1) != 1);
2790 #else
2791 err = (PD_read(strm, "tar(0)", tar5_r+0) != 1);
2792 err = (PD_read(strm, "tar(1)", tar5_r+1) != 1);
2793 err = (PD_read(strm, "tar(2)", tar5_r+2) != 1);
2794 err = (PD_read(strm, "tar(3)", tar5_r+3) != 1);
2795 #endif
2796
2797 return(err);}
2798
2799 /*--------------------------------------------------------------------------*/
2800 /*--------------------------------------------------------------------------*/
2801
2802 /* PRINT_TEST_5_DATA - print it out to the file */
2803
print_test_5_data(FILE * fp)2804 static void print_test_5_data(FILE *fp)
2805 {int i;
2806 int *p0, *p1, *p2, *p3;
2807 double *p4, *p5, *p6, *p7;
2808
2809 PRINT(fp, "\n");
2810
2811 p0 = tar5_t[0].a;
2812 p1 = tar5_t[1].a;
2813 p2 = tar5_t[2].a;
2814 p3 = tar5_t[3].a;
2815 PRINT(fp, "TAR struct member A:\n");
2816 PRINT(fp, " TAR[0].A TAR[1].A TAR[2].A TAR[3].A\n");
2817 for (i = 0; i < N_INT; i++)
2818 PRINT(fp, " %d %d %d %d\n",
2819 p0[i], p1[i], p2[i], p3[i]);
2820 PRINT(fp, "\n");
2821
2822 p4 = tar5_t[0].b;
2823 p5 = tar5_t[1].b;
2824 p6 = tar5_t[2].b;
2825 p7 = tar5_t[3].b;
2826 PRINT(fp, "TAR struct member B:\n");
2827 PRINT(fp, " TAR[0].B TAR[1].B TAR[2].B TAR[3].B\n");
2828 for (i = 0; i < N_DOUBLE; i++)
2829 PRINT(fp, " %f %f %f %f\n",
2830 p4[i], p5[i], p6[i], p7[i]);
2831 PRINT(fp, "\n");
2832
2833 return;}
2834
2835 /*--------------------------------------------------------------------------*/
2836 /*--------------------------------------------------------------------------*/
2837
2838 /* COMPARE_TEST_5_DATA - compare the test data */
2839
compare_test_5_data(PDBfile * strm,FILE * fp)2840 static int compare_test_5_data(PDBfile *strm, FILE *fp)
2841 {int i, l, *p1w, *p2w, *p1r, *p2r;
2842 int err, err_tot;
2843 double *p3w, *p4w, *p3r, *p4r;
2844 long double fptol[N_PRIMITIVE_FP];
2845
2846 PD_fp_toler(strm, fptol);
2847
2848 err_tot = TRUE;
2849
2850 err = TRUE;
2851 p1w = tar_w[0].a;
2852 p2w = tar_w[1].a;
2853 p3w = tar_w[0].b;
2854 p4w = tar_w[1].b;
2855
2856 for (l = 0; l < 2; l++)
2857 {p1r = tar5_t[2*l].a;
2858 p2r = tar5_t[2*l+1].a;
2859 for (i = 0; i < N_INT; i++)
2860 {err &= (p1w[i] == p1r[i]);
2861 err &= (p2w[i] == p2r[i]);};
2862
2863 p3r = tar5_t[2*l].b;
2864 p4r = tar5_t[2*l+1].b;
2865 for (i = 0; i < N_DOUBLE; i++)
2866 {err &= DOUBLE_EQUAL(p3w[i], p3r[i]);
2867 err &= DOUBLE_EQUAL(p4w[i], p4r[i]);};};
2868
2869 for (l = 0; l < 2; l++)
2870 {p1r = tar5_r[2*l].a;
2871 p2r = tar5_r[2*l+1].a;
2872 for (i = 0; i < N_INT; i++)
2873 {err &= (p1w[i] == p1r[i]);
2874 err &= (p2w[i] == p2r[i]);};
2875
2876 p3r = tar5_r[2*l].b;
2877 p4r = tar5_r[2*l+1].b;
2878 for (i = 0; i < N_DOUBLE; i++)
2879 {err &= DOUBLE_EQUAL(p3w[i], p3r[i]);
2880 err &= DOUBLE_EQUAL(p4w[i], p4r[i]);};};
2881
2882 PRINT(fp, "\n");
2883
2884 return(err_tot);}
2885
2886 /*--------------------------------------------------------------------------*/
2887 /*--------------------------------------------------------------------------*/
2888
2889 /* TEST_5 - test the PDBLib functions handling indirections and appends
2890 * - read and write structures with alignment difficulties
2891 * - tests can be targeted
2892 */
2893
test_5(char * base,char * tgt,int n)2894 static int test_5(char *base, char *tgt, int n)
2895 {int err;
2896 char datfile[MAXLINE], fname[MAXLINE];
2897 PDBfile *strm;
2898 FILE *fp;
2899
2900 /* target the file as asked */
2901 test_target(tgt, base, n, fname, datfile);
2902
2903 fp = io_open(fname, "w");
2904
2905 prep_test_5_data();
2906
2907 if (read_only == FALSE)
2908
2909 /* create the named file */
2910 {strm = PD_create(datfile);
2911 if (strm == NULL)
2912 error(2, fp, "Test couldn't create file %s\r\n", datfile);
2913 PRINT(fp, "File %s created\n", datfile);
2914
2915 strm->previous_file = CSTRSAVE(base);
2916
2917 /* make a few defstructs */
2918 PD_defstr(strm, "lev1",
2919 "integer *a",
2920 "double *b",
2921 "char *c",
2922 LAST);
2923
2924 /* write the test data */
2925 write_test_5_data(strm);
2926
2927 /* close the file */
2928 if (PD_close(strm) == FALSE)
2929 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2930 PRINT(fp, "File %s closed\n", datfile);};
2931
2932 /* reopen the file */
2933 strm = PD_open(datfile, "r");
2934 if (strm == NULL)
2935 error(2, fp, "Test couldn't open file %s\r\n", datfile);
2936 PRINT(fp, "File %s opened\n", datfile);
2937
2938 /* read the structs */
2939 read_test_5_data(strm);
2940
2941 /* compare the original data with that read in */
2942 err = compare_test_5_data(strm, fp);
2943
2944 /* print out the results */
2945 print_test_5_data(fp);
2946
2947 /* close the file */
2948 if (PD_close(strm) == FALSE)
2949 error(2, fp, "Test couldn't close file %s\r\n", datfile);
2950 PRINT(fp, "File %s closed\n", datfile);
2951
2952 /* clean up test data memory */
2953 cleanup_test_5();
2954
2955 io_close(fp);
2956 if (err)
2957 REMOVE(fname);
2958
2959 return(err);}
2960
2961 /*--------------------------------------------------------------------------*/
2962
2963 /* TEST #6 ROUTINES */
2964
2965 /*--------------------------------------------------------------------------*/
2966
2967 /* PREP_TEST_6_DATA - prepare the test data */
2968
prep_test_6_data(void)2969 static void prep_test_6_data(void)
2970 {int i, n;
2971 double *p1, *p2;
2972
2973 n = 10;
2974
2975 d61_w = CMAKE(st61);
2976 d61_w->n = n;
2977
2978 d62_w = CMAKE(st62);
2979 d62_w->n = n;
2980 d62_w->a = CMAKE_N(double, n);
2981
2982 p1 = d61_w->a;
2983 p2 = d62_w->a;
2984 for (i = 0; i < n; i++)
2985 {p1[i] = 0.1*((double) i);
2986 p2[i] = -0.1*((double) i);};
2987
2988 return;}
2989
2990 /*--------------------------------------------------------------------------*/
2991 /*--------------------------------------------------------------------------*/
2992
2993 /* CLEANUP_TEST_6 - free all known test data memory */
2994
cleanup_test_6(void)2995 static void cleanup_test_6(void)
2996 {
2997
2998 if (d61_w != NULL)
2999 CFREE(d61_w);
3000
3001 if (d62_w != NULL)
3002 {CFREE(d62_w->a);
3003 CFREE(d62_w);};
3004
3005 return;}
3006
3007 /*--------------------------------------------------------------------------*/
3008 /*--------------------------------------------------------------------------*/
3009
3010 /* WRITE_TEST_6_DATA - write out the data into the PDB file */
3011
write_test_6_data(PDBfile * strm)3012 static void write_test_6_data(PDBfile *strm)
3013 {
3014
3015 if (PD_write(strm, "d61", "st61", d61_w) == 0)
3016 error(1, STDOUT, "D61 WRITE FAILED - WRITE_TEST_6_DATA\n");
3017
3018 if (PD_write(strm, "d62", "st62", d62_w) == 0)
3019 error(1, STDOUT, "D62 WRITE FAILED - WRITE_TEST_6_DATA\n");
3020
3021 return;}
3022
3023 /*--------------------------------------------------------------------------*/
3024 /*--------------------------------------------------------------------------*/
3025
3026 /* READ_TEST_6_DATA - read the test data from the file */
3027
read_test_6_data(PDBfile * strm)3028 static int read_test_6_data(PDBfile *strm)
3029 {int err;
3030
3031 err = PD_read_as_dwim(strm, "d61.a", "float", 10, d61_a);
3032 err = PD_read_as_dwim(strm, "d62.a", "float", 10, d62_a);
3033 err = PD_read_as_dwim(strm, "d62.a", "float", 8, d62_s);
3034
3035 return(err);}
3036
3037 /*--------------------------------------------------------------------------*/
3038 /*--------------------------------------------------------------------------*/
3039
3040 /* PRINT_TEST_6_DATA - print it out to the file */
3041
print_test_6_data(FILE * fp)3042 static void print_test_6_data(FILE *fp)
3043 {int i, n;
3044
3045 n = d61_w->n;
3046
3047 PRINT(fp, "\n");
3048
3049 PRINT(fp, "D61 struct member A:\n");
3050 for (i = 0; i < n; i++)
3051 PRINT(fp, "%3d %5.2f\n", i, d61_a[i]);
3052 PRINT(fp, "\n");
3053
3054 PRINT(fp, "D62 struct member A:\n");
3055 for (i = 0; i < n; i++)
3056 PRINT(fp, "%3d %5.2f\n", i, d62_a[i]);
3057 PRINT(fp, "\n");
3058
3059 return;}
3060
3061 /*--------------------------------------------------------------------------*/
3062 /*--------------------------------------------------------------------------*/
3063
3064 /* COMPARE_TEST_6_DATA - compare the test data */
3065
compare_test_6_data(PDBfile * strm,FILE * fp)3066 static int compare_test_6_data(PDBfile *strm, FILE *fp)
3067 {int i, n;
3068 int err, err_tot;
3069 float fc1, fc2;
3070 double *p1w, *p2w;
3071 long double fptol[N_PRIMITIVE_FP];
3072
3073 PD_fp_toler(strm, fptol);
3074
3075 err_tot = TRUE;
3076
3077 err = TRUE;
3078 p1w = d61_w->a;
3079 p2w = d62_w->a;
3080
3081 n = d61_w->n;
3082
3083 for (i = 0; i < n; i++)
3084 {fc1 = p1w[i];
3085 fc2 = p2w[i];
3086 err &= FLOAT_EQUAL(fc1, d61_a[i]);
3087 err &= FLOAT_EQUAL(fc2, d62_a[i]);};
3088
3089 err_tot &= err;
3090
3091 n -= 2;
3092 for (i = 0; i < n; i++)
3093 {fc2 = p2w[i];
3094 err &= FLOAT_EQUAL(fc2, d62_s[i]);};
3095
3096 err_tot &= err;
3097
3098 PRINT(fp, "\n");
3099
3100 return(err_tot);}
3101
3102 /*--------------------------------------------------------------------------*/
3103 /*--------------------------------------------------------------------------*/
3104
3105 /* TEST_6 - test the PDBLib function PD_read_as_dwim */
3106
test_6(char * base,char * tgt,int n)3107 static int test_6(char *base, char *tgt, int n)
3108 {int err;
3109 char datfile[MAXLINE], fname[MAXLINE];
3110 PDBfile *strm;
3111 FILE *fp;
3112
3113 /* target the file as asked */
3114 test_target(tgt, base, n, fname, datfile);
3115
3116 fp = io_open(fname, "w");
3117
3118 prep_test_6_data();
3119
3120 if (read_only == FALSE)
3121
3122 /* create the named file */
3123 {strm = PD_create(datfile);
3124 if (strm == NULL)
3125 error(2, fp, "Test couldn't create file %s\r\n", datfile);
3126 PRINT(fp, "File %s created\n", datfile);
3127
3128 /* make a few defstructs */
3129 PD_defstr(strm, "st61",
3130 "int n",
3131 "double a[10]",
3132 LAST);
3133
3134 PD_defstr(strm, "st62",
3135 "int n",
3136 "double *a",
3137 LAST);
3138
3139 /* write the test data */
3140 write_test_6_data(strm);
3141
3142 /* close the file */
3143 if (PD_close(strm) == FALSE)
3144 error(2, fp, "Test couldn't close file %s\r\n", datfile);
3145 PRINT(fp, "File %s closed\n", datfile);};
3146
3147 /* reopen the file */
3148 strm = PD_open(datfile, "r");
3149 if (strm == NULL)
3150 error(2, fp, "Test couldn't open file %s\r\n", datfile);
3151 PRINT(fp, "File %s opened\n", datfile);
3152
3153 /* read the structs */
3154 read_test_6_data(strm);
3155
3156 /* compare the original data with that read in */
3157 err = compare_test_6_data(strm, fp);
3158
3159 /* print out the results */
3160 print_test_6_data(fp);
3161
3162 /* close the file */
3163 if (PD_close(strm) == FALSE)
3164 error(2, fp, "Test couldn't close file %s\r\n", datfile);
3165 PRINT(fp, "File %s closed\n", datfile);
3166
3167 /* clean up test data memory */
3168 cleanup_test_6();
3169
3170 io_close(fp);
3171 if (err)
3172 REMOVE(fname);
3173
3174 return(err);}
3175
3176 /*--------------------------------------------------------------------------*/
3177
3178 /* TEST #7 ROUTINES */
3179
3180 /*--------------------------------------------------------------------------*/
3181
3182 /* PREP_TEST_7_DATA - prepare the test data */
3183
prep_test_7_data(void)3184 static void prep_test_7_data(void)
3185 {int i, n;
3186
3187 n = 10;
3188
3189 d71_w.a = CMAKE_N(double, n);
3190 d71_w_save.a = CMAKE_N(double, n);
3191 d72_w.a = CMAKE_N(double, n);
3192
3193 d71_w.n = n;
3194 d71_w_save.n = n;
3195 d72_w.n = n;
3196
3197 for (i = 0; i < n; i++)
3198 {d71_w.a[i] = d71_w_save.a[i] = (double)i;
3199 d72_w.a[i] = (double)i * 10.0;}
3200
3201 return;}
3202
3203 /*--------------------------------------------------------------------------*/
3204 /*--------------------------------------------------------------------------*/
3205
3206 /* CLEANUP_TEST_7 - free all known test data memory */
3207
cleanup_test_7(void)3208 static void cleanup_test_7(void)
3209 {
3210
3211 CFREE(d71_w.a);
3212 CFREE(d71_w_save.a);
3213 CFREE(d72_w.a);
3214 CFREE(d71_r.a);
3215 CFREE(d72_r.a);
3216
3217 return;}
3218
3219 /*--------------------------------------------------------------------------*/
3220 /*--------------------------------------------------------------------------*/
3221
3222 /* WRITE_TEST_7_DATA - write out the data into the PDB file */
3223
write_test_7_data(PDBfile * strm)3224 static void write_test_7_data(PDBfile *strm)
3225 {int i;
3226
3227 if (PD_write(strm, "d71", "st62", &d71_w) == 0)
3228 error(1, STDOUT, "D71 WRITE FAILED - WRITE_TEST_7_DATA\n");
3229
3230 /* reuse an area of memory to test PD_TRACK_POINTERS */
3231 for (i = 0; i < d71_w.n; i++)
3232 d71_w.a[i] = (double) i * 10.0;
3233
3234 if (PD_write(strm, "d72", "st62", &d71_w) == 0)
3235 error(1, STDOUT, "D72 WRITE FAILED - WRITE_TEST_7_DATA\n");
3236
3237 return;}
3238
3239 /*--------------------------------------------------------------------------*/
3240 /*--------------------------------------------------------------------------*/
3241
3242 /* READ_TEST_7_DATA - read the test data from the file */
3243
read_test_7_data(PDBfile * strm)3244 static int read_test_7_data(PDBfile *strm)
3245 {int err;
3246
3247 err = PD_read(strm, "d71", &d71_r);
3248 err = PD_read(strm, "d72", &d72_r);
3249
3250 return(err);}
3251
3252 /*--------------------------------------------------------------------------*/
3253 /*--------------------------------------------------------------------------*/
3254
3255 /* PRINT_TEST_7_DATA - print it out to the file */
3256
print_test_7_data(FILE * fp)3257 static void print_test_7_data(FILE *fp)
3258 {int i, n;
3259
3260 n = d71_w.n;
3261
3262 PRINT(fp, "\n");
3263
3264 PRINT(fp, "D71 struct member A:\n");
3265 for (i = 0; i < n; i++)
3266 PRINT(fp, "%3d %5.2f\n", i, d71_r.a[i]);
3267 PRINT(fp, "\n");
3268
3269 PRINT(fp, "D72 struct member A:\n");
3270 for (i = 0; i < n; i++)
3271 PRINT(fp, "%3d %5.2f\n", i, d72_r.a[i]);
3272 PRINT(fp, "\n");
3273
3274 return;}
3275
3276 /*--------------------------------------------------------------------------*/
3277 /*--------------------------------------------------------------------------*/
3278
3279 /* COMPARE_TEST_7_DATA - compare the test data */
3280
compare_test_7_data(PDBfile * strm,FILE * fp)3281 static int compare_test_7_data(PDBfile *strm, FILE *fp)
3282 {int i, n;
3283 int err, err_tot;
3284 float fc1, fc2;
3285 double *p1w, *p2w;
3286 long double fptol[N_PRIMITIVE_FP];
3287
3288 PD_fp_toler(strm, fptol);
3289
3290 err_tot = TRUE;
3291
3292 err = TRUE;
3293 p1w = d71_w_save.a;
3294 p2w = d72_w.a;
3295
3296 n = d71_w.n;
3297
3298 for (i = 0; i < n; i++)
3299 {fc1 = p1w[i];
3300 fc2 = p2w[i];
3301 err &= FLOAT_EQUAL(fc1, d71_r.a[i]);
3302 err &= FLOAT_EQUAL(fc2, d72_r.a[i]);};
3303
3304 err_tot &= err;
3305
3306 PRINT(fp, "\n");
3307
3308 return(err_tot);}
3309
3310 /*--------------------------------------------------------------------------*/
3311 /*--------------------------------------------------------------------------*/
3312
3313 /* TEST_7 - test the PDBLib pointer tracking */
3314
test_7(char * base,char * tgt,int n)3315 static int test_7(char *base, char *tgt, int n)
3316 {int err;
3317 char datfile[MAXLINE], fname[MAXLINE];
3318 PDBfile *strm;
3319 FILE *fp;
3320
3321 /* target the file as asked */
3322 test_target(tgt, base, n, fname, datfile);
3323
3324 fp = io_open(fname, "w");
3325
3326 prep_test_7_data();
3327
3328 if (read_only == FALSE)
3329
3330 /* create the named file */
3331 {strm = PD_create(datfile);
3332 if (strm == NULL)
3333 error(2, fp, "Test couldn't create file %s\r\n", datfile);
3334 PRINT(fp, "File %s created\n", datfile);
3335
3336 /* make a few defstructs */
3337 PD_defstr(strm, "st62",
3338 "int n",
3339 "double *a",
3340 LAST);
3341
3342 /* turn off pointer tracking */
3343 PD_set_track_pointers(strm, FALSE);
3344
3345 /* write the test data */
3346 write_test_7_data(strm);
3347
3348 /* close the file */
3349 if (PD_close(strm) == FALSE)
3350 error(2, fp, "Test couldn't close file %s\r\n", datfile);
3351 PRINT(fp, "File %s closed\n", datfile);};
3352
3353 /* reopen the file */
3354 strm = PD_open(datfile, "r");
3355 if (strm == NULL)
3356 error(2, fp, "Test couldn't open file %s\r\n", datfile);
3357 PRINT(fp, "File %s opened\n", datfile);
3358
3359 /* read the structs */
3360 read_test_7_data(strm);
3361
3362 /* compare the original data with that read in */
3363 err = compare_test_7_data(strm, fp);
3364
3365 /* print out the results */
3366 print_test_7_data(fp);
3367
3368 /* close the file */
3369 if (PD_close(strm) == FALSE)
3370 error(2, fp, "Test couldn't close file %s\r\n", datfile);
3371 PRINT(fp, "File %s closed\n", datfile);
3372
3373 /* clean up test data memory */
3374 cleanup_test_7();
3375
3376 io_close(fp);
3377 if (err)
3378 REMOVE(fname);
3379
3380 return(err);}
3381
3382 /*--------------------------------------------------------------------------*/
3383
3384 /* TEST #8 ROUTINES */
3385
3386 /*--------------------------------------------------------------------------*/
3387
3388 /* PREP_TEST_8_DATA - prepare the test data */
3389
prep_test_8_data(void)3390 static void prep_test_8_data(void)
3391 {int i, j, n, m;
3392
3393 n = 10;
3394 m = 2*n;
3395
3396 d8_w = CMAKE_N(double, n);
3397 d8a_r = CMAKE_N(double, m);
3398 d8b_r = CMAKE_N(double, m);
3399 d8c_r = CMAKE_N(double, m);
3400 d8d_r = CMAKE_N(double, m);
3401
3402 for (i = 0; i < n; i++)
3403 {j = i + 1;
3404 d8_w[i] = (double) (j * j);};
3405
3406 for (i = 0; i < m; i++)
3407 {d8a_r[i] = 0.0;
3408 d8b_r[i] = 0.0;
3409 d8c_r[i] = 0.0;
3410 d8d_r[i] = 0.0;};
3411
3412 return;}
3413
3414 /*--------------------------------------------------------------------------*/
3415 /*--------------------------------------------------------------------------*/
3416
3417 /* CLEANUP_TEST_8 - free all known test data memory */
3418
cleanup_test_8(void)3419 static void cleanup_test_8(void)
3420 {
3421
3422 CFREE(d8_w);
3423 CFREE(d8a_r);
3424 CFREE(d8b_r);
3425 CFREE(d8c_r);
3426 CFREE(d8d_r);
3427
3428 return;}
3429
3430 /*--------------------------------------------------------------------------*/
3431 /*--------------------------------------------------------------------------*/
3432
3433 /* WRITE_TEST_8_DATA - write out the data into the PDB file */
3434
write_test_8_data(PDBfile * strm)3435 static void write_test_8_data(PDBfile *strm)
3436 {long ind[4];
3437
3438 if (PD_write(strm, "d8a[10]", "double", d8_w) == 0)
3439 error(1, STDOUT, "D8A WRITE FAILED - WRITE_TEST_8_DATA\n");
3440
3441 #ifdef PDB_LITE
3442 ind[0] = 1L;
3443 ind[1] = 10L;
3444 if (PD_defent_alt(strm, "d8b", "double", 1, ind) == 0)
3445 #else
3446 if (PD_defent(strm, "d8b[1,10]", "double") == 0)
3447 #endif
3448 error(1, STDOUT, "D8B DEFENT FAILED - WRITE_TEST_8_DATA\n");
3449
3450 if (PD_write(strm, "d8b[0,0:9]", "double", d8_w) == 0)
3451 error(1, STDOUT, "D8B WRITE FAILED - WRITE_TEST_8_DATA\n");
3452
3453 #ifdef PDB_LITE
3454 ind[0] = 0L;
3455 ind[1] = 10L;
3456 if (PD_defent_alt(strm, "d8c", "double", 1, ind) == 0)
3457 #else
3458 if (PD_defent(strm, "d8c[0,10]", "double") == 0)
3459 #endif
3460 error(1, STDOUT, "D8C DEFENT FAILED - WRITE_TEST_8_DATA\n");
3461
3462 ind[0] = 1L;
3463 ind[1] = 0L;
3464 ind[2] = 0L;
3465 ind[3] = 9L;
3466 if (PD_defent_alt(strm, "d8d", "double", 2, ind) == 0)
3467 error(1, STDOUT, "D8D DEFENT FAILED - WRITE_TEST_8_DATA\n");
3468
3469 return;}
3470
3471 /*--------------------------------------------------------------------------*/
3472 /*--------------------------------------------------------------------------*/
3473
3474 /* APPEND_TEST_8_DATA - append to the data in the PDB file */
3475
append_test_8_data(PDBfile * strm)3476 static void append_test_8_data(PDBfile *strm)
3477 {
3478
3479 if (PD_append(strm, "d8a[10:19]", d8_w) == 0)
3480 error(1, STDOUT, "D8A APPEND FAILED - WRITE_TEST_8_DATA\n");
3481
3482 #ifndef PDB_LITE
3483 if (PD_append(strm, "d8b[1:1,0:9]", d8_w) == 0)
3484 error(1, STDOUT, "D8B APPEND FAILED - WRITE_TEST_8_DATA\n");
3485 #endif
3486
3487 if (PD_append(strm, "d8c[0:0,0:9]", d8_w) == 0)
3488 error(1, STDOUT, "D8C APPEND FAILED - WRITE_TEST_8_DATA\n");
3489
3490 if (PD_append(strm, "d8d[0:0,0:9]", d8_w) == 0)
3491 error(1, STDOUT, "D8D APPEND FAILED - WRITE_TEST_8_DATA\n");
3492
3493 return;}
3494
3495 /*--------------------------------------------------------------------------*/
3496 /*--------------------------------------------------------------------------*/
3497
3498 /* READ_TEST_8_DATA - read the test data from the file */
3499
read_test_8_data(PDBfile * strm)3500 static int read_test_8_data(PDBfile *strm)
3501 {int err;
3502
3503 err = PD_read(strm, "d8a", d8a_r);
3504 err = PD_read(strm, "d8b", d8b_r);
3505 err = PD_read(strm, "d8c", d8c_r);
3506 err = PD_read(strm, "d8d", d8d_r);
3507
3508 return(err);}
3509
3510 /*--------------------------------------------------------------------------*/
3511 /*--------------------------------------------------------------------------*/
3512
3513 /* PRINT_TEST_8_DATA - print it out to the file */
3514
print_test_8_data(FILE * fp)3515 static void print_test_8_data(FILE *fp)
3516 {int i, n;
3517
3518 n = 20;
3519
3520 PRINT(fp, "\n");
3521
3522 PRINT(fp, "D8A:\n");
3523 for (i = 0; i < n; i++)
3524 PRINT(fp, "%3d %11.4e %11.4e %11.4e\n",
3525 i, d8a_r[i], d8b_r[i], d8c_r[i]);
3526 PRINT(fp, "\n");
3527
3528 return;}
3529
3530 /*--------------------------------------------------------------------------*/
3531 /*--------------------------------------------------------------------------*/
3532
3533 /* COMPARE_TEST_8_DATA - compare the test data */
3534
compare_test_8_data(PDBfile * strm,FILE * fp)3535 static int compare_test_8_data(PDBfile *strm, FILE *fp)
3536 {int i, n;
3537 int err, err_tot;
3538 double wc, arc, brc, crc, drc;
3539 long double fptol[N_PRIMITIVE_FP];
3540
3541 PD_fp_toler(strm, fptol);
3542
3543 err_tot = TRUE;
3544 err = TRUE;
3545 n = 10;
3546
3547 for (i = 0; i < n; i++)
3548 {wc = d8_w[i];
3549 arc = d8a_r[i];
3550 brc = d8b_r[i];
3551 crc = d8c_r[i];
3552 drc = d8d_r[i];
3553
3554 err &= DOUBLE_EQUAL(wc, arc);
3555 err &= DOUBLE_EQUAL(wc, brc);
3556 err &= DOUBLE_EQUAL(wc, crc);
3557 err &= DOUBLE_EQUAL(wc, drc);};
3558
3559 for (i = 0; i < n; i++)
3560 {wc = d8_w[i];
3561 arc = d8a_r[n+i];
3562 brc = d8b_r[n+i];
3563
3564 err &= DOUBLE_EQUAL(wc, arc);
3565 err &= DOUBLE_EQUAL(wc, brc);};
3566
3567 err_tot &= err;
3568
3569 PRINT(fp, "\n");
3570
3571 return(err_tot);}
3572
3573 /*--------------------------------------------------------------------------*/
3574 /*--------------------------------------------------------------------------*/
3575
3576 /* TEST_8 - test the PDBLib defent and append logic */
3577
test_8(char * base,char * tgt,int n)3578 static int test_8(char *base, char *tgt, int n)
3579 {int err;
3580 char datfile[MAXLINE], fname[MAXLINE];
3581 PDBfile *strm;
3582 FILE *fp;
3583
3584 /* target the file as asked */
3585 test_target(tgt, base, n, fname, datfile);
3586
3587 fp = io_open(fname, "w");
3588
3589 prep_test_8_data();
3590
3591 if (read_only == FALSE)
3592
3593 /* create the named file */
3594 {strm = PD_create(datfile);
3595 if (strm == NULL)
3596 error(2, fp, "Test couldn't create file %s\r\n", datfile);
3597 PRINT(fp, "File %s created\n", datfile);
3598
3599 /* write the test data */
3600 write_test_8_data(strm);
3601
3602 /* append the test data */
3603 append_test_8_data(strm);
3604
3605 /* close the file */
3606 if (PD_close(strm) == FALSE)
3607 error(2, fp, "Test couldn't close file %s\r\n", datfile);
3608 PRINT(fp, "File %s closed\n", datfile);};
3609
3610 /* reopen the file */
3611 strm = PD_open(datfile, "r");
3612 if (strm == NULL)
3613 error(2, fp, "Test couldn't open file %s\r\n", datfile);
3614 PRINT(fp, "File %s opened\n", datfile);
3615
3616 /* read the structs */
3617 read_test_8_data(strm);
3618
3619 /* compare the original data with that read in */
3620 err = compare_test_8_data(strm, fp);
3621
3622 /* print out the results */
3623 print_test_8_data(fp);
3624
3625 /* close the file */
3626 if (PD_close(strm) == FALSE)
3627 error(2, fp, "Test couldn't close file %s\r\n", datfile);
3628 PRINT(fp, "File %s closed\n", datfile);
3629
3630 /* clean up test data memory */
3631 cleanup_test_8();
3632
3633 io_close(fp);
3634 if (err)
3635 REMOVE(fname);
3636
3637 return(err);}
3638
3639 /*--------------------------------------------------------------------------*/
3640 /*--------------------------------------------------------------------------*/
3641
3642 /* TEST_9 - test the PDBLib checksum logic */
3643
test_9(char * base,char * tgt,int n)3644 static int test_9(char *base, char *tgt, int n)
3645 {int err, status, var;
3646 char datfile[MAXLINE], fname[MAXLINE];
3647 PDBfile *file;
3648 FILE *fp;
3649
3650 err = TRUE;
3651 var = 42;
3652
3653 /* target the file as asked */
3654 test_target(tgt, base, n, fname, datfile);
3655
3656 fp = io_open(fname, "w");
3657
3658 if (tgt != NULL)
3659 snprintf(datfile, MAXLINE, "%s-%s.db9a", base, tgt);
3660 else
3661 snprintf(datfile, MAXLINE, "%s-nat.db9a", base);
3662
3663 if (read_only == FALSE)
3664
3665 /* create the named file */
3666 {file = PD_create(datfile);
3667 if (file == NULL)
3668 error(2, fp, "Test couldn't create file %s\r\n", datfile);
3669 PRINT(fp, "File %s created\n", datfile);
3670
3671 /* turn on the checksum logic */
3672 PD_activate_cksum(file, PD_MD5_FILE);
3673 PD_write(file, "test", "int", &var);
3674 PD_close(file);};
3675
3676 /* reopen the file and see if the checksum is valid */
3677 file = PD_open(datfile, "a");
3678 if (file == NULL)
3679 error(2, fp, "Test couldn't open file %s\r\n", datfile);
3680 PRINT(fp, "File %s reopened\n", datfile);
3681
3682 PD_activate_cksum(file, PD_MD5_FILE);
3683
3684 /* make sure the checksum checks out */
3685 status = PD_verify(file);
3686
3687 if (status != TRUE)
3688 err = FALSE;
3689 else
3690 PRINT(fp, "File %s verified\n", datfile);
3691
3692 PD_close(file);
3693
3694 if (tgt != NULL)
3695 snprintf(datfile, MAXLINE, "%s-%s.db9b", base, tgt);
3696 else
3697 snprintf(datfile, MAXLINE, "%s-nat.db9b", base);
3698
3699 if (read_only == FALSE)
3700
3701 /* do it again, except this time, don't activate the checksum
3702 * create the named file
3703 */
3704 {file = PD_create(datfile);
3705 if (file == NULL)
3706 error(2, fp, "Test couldn't create file %s\r\n", datfile);
3707 PRINT(fp, "File %s created\n", datfile);
3708
3709 /* leave the checksum logic off */
3710 PD_write(file, "test", "int", &var);
3711 PD_close(file);};
3712
3713 /* reopen the file and see if the checksum is valid */
3714 file = PD_open(datfile, "a");
3715 if (file == NULL)
3716 error(2, fp, "Test couldn't open file %s\r\n", datfile);
3717 PRINT(fp, "File %s reopened\n", datfile);
3718
3719 PD_activate_cksum(file, PD_MD5_FILE);
3720
3721 /* make sure it returns -1 meaning integrity cannot be determined */
3722 status = PD_verify(file);
3723
3724 if (status != -1)
3725 err = FALSE;
3726 else
3727 PRINT(fp, "File %s cannot be verified (as expected)\n", datfile);
3728
3729 PD_close(file);
3730
3731 io_close(fp);
3732 if (err)
3733 REMOVE(fname);
3734
3735 return(err);}
3736
3737 /*--------------------------------------------------------------------------*/
3738
3739 /* TEST #10 ROUTINES */
3740
3741 #ifdef HAVE_ANSI_FLOAT16
3742
3743 #define QUAD_EQUAL(q1, q2) (PM_qvalue_compare(q1, q2, fptol[2]) == 0)
3744
3745 /*--------------------------------------------------------------------------*/
3746
3747 /* PREP_TEST_10_DATA - prepare the test data */
3748
prep_test_10_data(void)3749 static void prep_test_10_data(void)
3750 {int i;
3751
3752 /* set scalars */
3753 qs_r = 0.0L;
3754 qs_w = expl(1.0);
3755 qs_w = 2.0L;
3756
3757 /* set long double array */
3758 for (i = 0; i < N_FLOAT; i++)
3759 {qa_w[i] = POWL(qs_w, (long double) (i+1));
3760 qa_r[i] = 0.0L;};
3761
3762 return;}
3763
3764 /*--------------------------------------------------------------------------*/
3765 /*--------------------------------------------------------------------------*/
3766
3767 /* WRITE_TEST_10_DATA - write out the data into the PDB file */
3768
write_test_10_data(PDBfile * strm)3769 static void write_test_10_data(PDBfile *strm)
3770 {long ind[6];
3771
3772 /* write scalars into the file */
3773 if (PD_write(strm, "qs", "long_double", &qs_w) == 0)
3774 error(1, STDOUT, "QS WRITE FAILED - WRITE_TEST_10_DATA\n");
3775
3776 /* write primitive arrays into the file */
3777 ind[0] = 0L;
3778 ind[1] = N_FLOAT - 1;
3779 ind[2] = 1L;
3780 if (PD_write_alt(strm, "qa", "long_double", qa_w, 1, ind) == 0)
3781 error(1, STDOUT, "DA WRITE FAILED - WRITE_TEST_10_DATA\n");
3782
3783 return;}
3784
3785 /*--------------------------------------------------------------------------*/
3786 /*--------------------------------------------------------------------------*/
3787
3788 /* READ_TEST_10_DATA - read the test data from the file */
3789
read_test_10_data(PDBfile * strm)3790 static int read_test_10_data(PDBfile *strm)
3791 {int err;
3792
3793 /* read the scalar data from the file */
3794 err = PD_read(strm, "qs", &qs_r);
3795
3796 /* read the primitive arrays from the file */
3797 err = PD_read(strm, "qa", qa_r);
3798
3799 return(err);}
3800
3801 /*--------------------------------------------------------------------------*/
3802 /*--------------------------------------------------------------------------*/
3803
3804 /* PRINT_TEST_10_DATA - print it out to STDOUT */
3805
print_test_10_data(FILE * fp)3806 static void print_test_10_data(FILE *fp)
3807 {int i;
3808
3809 PRINT(fp, "long double scalar: qs = %14.6Le\n", qs_r);
3810
3811 /* print long double array */
3812 PRINT(fp, "long double array:\n");
3813 for (i = 0; i < N_FLOAT; i++)
3814 PRINT(fp, " qa[%d] = %14.6Le\n", i, qa_r[i]);
3815
3816 PRINT(fp, "\n");
3817
3818 return;}
3819
3820 /*--------------------------------------------------------------------------*/
3821 /*--------------------------------------------------------------------------*/
3822
3823 /* COMPARE_TEST_10_DATA - compare the test data */
3824
compare_test_10_data(PDBfile * strm,FILE * fp)3825 static int compare_test_10_data(PDBfile *strm, FILE *fp)
3826 {int i, err, err_tot;
3827 long double fptol[N_PRIMITIVE_FP];
3828
3829 PD_fp_toler(strm, fptol);
3830
3831 err_tot = TRUE;
3832
3833 /* compare scalars */
3834 err = TRUE;
3835
3836 err &= QUAD_EQUAL(qs_r, qs_w);
3837
3838 if (err)
3839 PRINT(fp, "Scalars compare\n");
3840 else
3841 PRINT(fp, "Scalars differ\n");
3842 err_tot &= err;
3843
3844 /* compare long double array */
3845 for (i = 0; i < N_FLOAT; i++)
3846 err &= QUAD_EQUAL(qa_r[i], qa_w[i]);
3847
3848 if (err)
3849 PRINT(fp, "Arrays compare\n");
3850 else
3851 PRINT(fp, "Arrays differ\n");
3852 err_tot &= err;
3853
3854 return(err_tot);}
3855
3856 /*--------------------------------------------------------------------------*/
3857 /*--------------------------------------------------------------------------*/
3858
3859 /* TEST_10 - test the long double support in PDBLib
3860 * -
3861 * - read and write scalars and arrays of long doubles
3862 * -
3863 * - tests can be targeted
3864 */
3865
test_10(char * base,char * tgt,int n)3866 static int test_10(char *base, char *tgt, int n)
3867 {int err;
3868 char datfile[MAXLINE], fname[MAXLINE];
3869 PDBfile *strm;
3870 FILE *fp;
3871
3872 /* target the file as asked */
3873 test_target(tgt, base, 100+n, fname, datfile);
3874
3875 fp = io_open(fname, "w");
3876
3877 prep_test_10_data();
3878
3879 if (read_only == FALSE)
3880
3881 /* create the named file */
3882 {strm = PD_create(datfile);
3883 if (strm == NULL)
3884 error(1, fp, "Test couldn't create file %s\r\n", datfile);
3885 PRINT(fp, "File %s created\n", datfile);
3886
3887 /* write the test data */
3888 write_test_10_data(strm);
3889
3890 /* close the file */
3891 if (PD_close(strm) == FALSE)
3892 error(1, fp, "Test couldn't close file %s\r\n", datfile);
3893 PRINT(fp, "File %s closed\n", datfile);};
3894
3895 /* reopen the file */
3896 strm = PD_open(datfile, "r");
3897 if (strm == NULL)
3898 error(1, fp, "Test couldn't open file %s\r\n", datfile);
3899 PRINT(fp, "File %s opened\n", datfile);
3900
3901 /* dump the symbol table */
3902 dump_test_symbol_table(fp, strm->symtab, 1);
3903
3904 /* read the data from the file */
3905 read_test_10_data(strm);
3906
3907 /* compare the original data with that read in */
3908 err = compare_test_10_data(strm, fp);
3909
3910 /* close the file */
3911 if (PD_close(strm) == FALSE)
3912 error(1, fp, "Test couldn't close file %s\r\n", datfile);
3913 PRINT(fp, "File %s closed\n", datfile);
3914
3915 /* print it out to STDOUT */
3916 print_test_10_data(fp);
3917
3918 io_close(fp);
3919 if (err)
3920 REMOVE(fname);
3921
3922 return(err);}
3923
3924 /*--------------------------------------------------------------------------*/
3925
3926 #else
3927
3928 /*--------------------------------------------------------------------------*/
3929
3930 /* TEST_10 - stub for when there is no long double support */
3931
test_10(char * base,char * tgt,int n)3932 static int test_10(char *base, char *tgt, int n)
3933 {
3934
3935 return(TRUE);}
3936
3937 /*--------------------------------------------------------------------------*/
3938
3939 #endif
3940
3941 /* DRIVER ROUTINES */
3942
3943 /*--------------------------------------------------------------------------*/
3944
3945 /* RUN_TEST - run a particular test through all targeting modes
3946 * - return the number of tests that fail
3947 */
3948
run_test(PFTest test,int n,char * host,int native)3949 static int run_test(PFTest test, int n, char *host, int native)
3950 {int i, m, rv, cs, fail;
3951 int64_t bytaa=0, bytfa=0, bytab=0, bytfb=0;
3952 char msg[MAXLINE];
3953 char *nm;
3954 double time;
3955 static int dbg = 0;
3956
3957 if (debug_mode)
3958 dbg = 2;
3959
3960 /* NOTE: under the debugger set dbg to 1 or 2 for additional
3961 * memory leak monitoring
3962 */
3963 cs = SC_mem_monitor(-1, dbg, "B", msg);
3964
3965 SC_mem_stats(&bytab, &bytfb, NULL, NULL);
3966
3967 time = SC_wall_clock_time();
3968
3969 fail = 0;
3970
3971 if (native == FALSE)
3972 {m = PD_target_n_platforms();
3973 for (i = 0; i < m; i++)
3974 {rv = PD_target_platform_n(i);
3975 SC_ASSERT(rv == TRUE);
3976
3977 nm = PD_target_platform_name(i);
3978 if ((*test)(host, nm, n) == FALSE)
3979 {PRINT(STDOUT, "Test #%d %s failed\n", n, nm);
3980 fail++;};};};
3981
3982 /* native test */
3983 if ((*test)(host, NULL, n) == FALSE)
3984 {PRINT(STDOUT, "Test #%d native failed\n", n);
3985 fail++;};
3986
3987 SC_mem_stats(&bytaa, &bytfa, NULL, NULL);
3988
3989 bytaa -= bytab;
3990 bytfa -= bytfb;
3991 time = SC_wall_clock_time() - time;
3992
3993 cs = SC_mem_monitor(cs, dbg, "B", msg);
3994
3995 #if defined PRId64
3996 PRINT(STDOUT,
3997 "\t\t %3d %8" PRId64 " %8" PRI64d " %7" PRI64d " %.2g\n",
3998 n, bytaa, bytfa, bytaa - bytfa, time);
3999 #else
4000 PRINT(STDOUT,
4001 "\t\t %3lld %8lld %8lld %7lld %.2g\n",
4002 n, bytaa, bytfa, bytaa - bytfa, time);
4003 #endif
4004
4005 return(fail);}
4006
4007 /*--------------------------------------------------------------------------*/
4008 /*--------------------------------------------------------------------------*/
4009
4010 /* PRINT_HELP - print a help message */
4011
print_help(void)4012 static void print_help(void)
4013 {
4014
4015 PRINT(STDOUT, "\nPDBTST - run basic PDB test suite\n\n");
4016 PRINT(STDOUT, "Usage: pdbtst [-b #] [-c] [-d] [-h] [-n] [-r] [-v #] [-0] [-1] [-2] [-3] [-4] [-5] [-6] [-7] [-8] [-9] [-10]\n");
4017 PRINT(STDOUT, "\n");
4018 PRINT(STDOUT, " b - set buffer size (default no buffering)\n");
4019 PRINT(STDOUT, " c - verify low level writes\n");
4020 PRINT(STDOUT, " d - turn on debug mode to display memory maps\n");
4021 PRINT(STDOUT, " h - print this help message and exit\n");
4022 PRINT(STDOUT, " n - run native mode test only\n");
4023 PRINT(STDOUT, " r - read only (assuming files from other run exist)\n");
4024 PRINT(STDOUT, " v - use format version # (default is 2)\n");
4025 PRINT(STDOUT, " 0 - do NOT run test #0\n");
4026 PRINT(STDOUT, " 1 - do NOT run test #1\n");
4027 PRINT(STDOUT, " 2 - do NOT run test #2\n");
4028 PRINT(STDOUT, " 3 - do NOT run test #3\n");
4029 PRINT(STDOUT, " 4 - do NOT run test #4\n");
4030 PRINT(STDOUT, " 5 - do NOT run test #5\n");
4031 PRINT(STDOUT, " 6 - do NOT run test #6\n");
4032 PRINT(STDOUT, " 7 - do NOT run test #7\n");
4033 PRINT(STDOUT, " 8 - do NOT run test #8\n");
4034 PRINT(STDOUT, " 9 - do NOT run test #9\n");
4035 PRINT(STDOUT, " 10 - do NOT run test #10\n");
4036 PRINT(STDOUT, "\n");
4037
4038 return;}
4039
4040 /*--------------------------------------------------------------------------*/
4041 /*--------------------------------------------------------------------------*/
4042
4043 /* MAIN - test the PDB Library system */
4044
main(int c,char ** v)4045 int main(int c, char **v)
4046 {int i, err;
4047 int test_zero, test_one, test_two, test_three;
4048 int test_four, test_five, test_six, test_seven;
4049 int test_eight, test_nine, test_ten;
4050 int use_mapped_files, check_writes;
4051 int64_t bfsz;
4052
4053 setvbuf(STDOUT, 0, _IONBF, 0);
4054
4055 if (chdir(DATDIR) == 0)
4056 {
4057 DIR *ddir;
4058 struct dirent *dent;
4059
4060 ddir = opendir(".");
4061 while ((dent = readdir(ddir)))
4062 {
4063 if (dent->d_name[0] == '.') continue;
4064 SC_ASSERT(REMOVE(dent->d_name)==0);
4065 }
4066 closedir(ddir);
4067 SC_ASSERT(chdir("..")==0);
4068 SC_ASSERT(rmdir(DATDIR)==0);
4069 }
4070 SC_ASSERT(mkdir(DATDIR,S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH)==0);
4071 SC_ASSERT(chdir(DATDIR)==0);
4072
4073 PD_init_threads(0, NULL);
4074
4075 SC_bf_set_hooks();
4076 SC_zero_space_n(1, -2);
4077
4078 bfsz = -1;
4079 bfsz = 100000;
4080 check_writes = FALSE;
4081 debug_mode = FALSE;
4082 native_only = FALSE;
4083 read_only = FALSE;
4084 use_mapped_files = FALSE;
4085 test_zero = TRUE;
4086 test_one = TRUE;
4087 test_two = TRUE;
4088 test_three = TRUE;
4089 test_four = TRUE;
4090 test_five = TRUE;
4091 test_six = TRUE;
4092 test_seven = TRUE;
4093 test_eight = TRUE;
4094 test_nine = TRUE;
4095 test_ten = TRUE;
4096 #ifdef PDB_LITE
4097 test_six = FALSE; /* PDB Lite has no read_as_dwim method */
4098 test_eight = FALSE; /* PDB Lite can't handle the append modes */
4099 test_nine = FALSE; /* PDB Lite doesn't have checksums */
4100 #endif
4101 for (i = 1; i < c; i++)
4102 {if (v[i][0] == '-')
4103 {switch (v[i][1])
4104 {case 'b' :
4105 bfsz = SC_stoi(v[++i]);
4106 break;
4107 case 'c' :
4108 check_writes = TRUE;
4109 break;
4110 case 'd' :
4111 debug_mode = TRUE;
4112 break;
4113 case 'h' :
4114 print_help();
4115 return(1);
4116 case 'm' :
4117 use_mapped_files = TRUE;
4118 break;
4119 case 'n' :
4120 native_only = TRUE;
4121 break;
4122 case 'r' :
4123 read_only = TRUE;
4124 break;
4125 case 'v' :
4126 PD_set_fmt_version(SC_stoi(v[++i]));
4127 break;
4128 case '0' :
4129 test_zero = FALSE;
4130 break;
4131 case '1' :
4132 if (v[i][2] == '0')
4133 test_ten = FALSE;
4134 else
4135 test_one = FALSE;
4136 break;
4137 case '2' :
4138 test_two = FALSE;
4139 break;
4140 case '3' :
4141 test_three = FALSE;
4142 break;
4143 case '4' :
4144 test_four = FALSE;
4145 break;
4146 case '5' :
4147 test_five = FALSE;
4148 break;
4149 case '6' :
4150 test_six = FALSE;
4151 break;
4152 case '7' :
4153 test_seven = FALSE;
4154 break;
4155 case '8' :
4156 test_eight = FALSE;
4157 break;
4158 case '9' :
4159 test_nine = FALSE;
4160 break;};}
4161 else
4162 break;};
4163
4164 PD_set_io_hooks(use_mapped_files);
4165 PD_verify_writes(check_writes);
4166
4167 PD_set_buffer_size(bfsz);
4168
4169 SC_signal(SIGINT, SIG_DFL);
4170
4171 /* force allocation of permanent memory outside of memory monitors */
4172 PD_open_vif("foo");
4173
4174 PRINT(STDOUT, "\n");
4175 PRINT(STDOUT, "\t\t Memory Time\n");
4176 PRINT(STDOUT, "\t\t (bytes) (secs)\n");
4177 PRINT(STDOUT, "\t\t Test Allocated Freed Diff\n");
4178
4179 err = 0;
4180
4181 if (test_zero)
4182 err += run_test(test_0, 0, DATFILE, TRUE);
4183 if (test_one)
4184 err += run_test(test_1, 1, DATFILE, native_only);
4185 if (test_two)
4186 err += run_test(test_2, 2, DATFILE, native_only);
4187 if (test_three)
4188 err += run_test(test_3, 3, DATFILE, native_only);
4189 if (test_four)
4190 err += run_test(test_4, 4, DATFILE, native_only);
4191 if (test_five)
4192 err += run_test(test_5, 5, DATFILE, native_only);
4193 if (test_six)
4194 err += run_test(test_6, 6, DATFILE, native_only);
4195 if (test_seven)
4196 err += run_test(test_7, 7, DATFILE, native_only);
4197 if (test_eight)
4198 err += run_test(test_8, 8, DATFILE, native_only);
4199 if (test_nine)
4200 err += run_test(test_9, 9, DATFILE, native_only);
4201 if (test_ten)
4202 err += run_test(test_10, 10, DATFILE, native_only);
4203
4204 PRINT(STDOUT, "\n");
4205
4206 return(err);}
4207
4208 /*--------------------------------------------------------------------------*/
4209 /*--------------------------------------------------------------------------*/
4210