LAL  7.2.0.1-a5e7375
SegmentsTest.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Peter Shawhan
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 /**
21  * \author Peter Shawhan
22  * \file
23  * \ingroup Segments_h
24  * \brief Tests the segment and segment list manipulation functions.
25  *
26  * ### Usage ###
27  *
28  * \code
29  * SegmentsTest [ lalDebugLevel ]
30  * \endcode
31  *
32  * The default value of \c lalDebugLevel is 4.
33  *
34  * ### Description ###
35  *
36  * This program tests the various XLAL functions which deal with segments
37  * and segment lists.
38  *
39  * If the \c lalDebugLevel argument is omitted, the test program sets it
40  * to 4 to turn on info messages only.
41  * Note that this default value does not enable LAL/XLAL error messages,
42  * since many of the tests intentionally create error conditions and verify that
43  * the proper error codes are generated. If you want to turn on the LAL/XLAL
44  * error and warning messages, specify a \c lalDebugLevel value of 7,
45  * or 23 if you also want informational messages related to memory checking.
46  * If you specify 0, then no messages will be printed under any circumstances.
47  * However, in all cases, the return status of the program will be 0 if all
48  * tests passed, 1 if one or more tests failed.
49  *
50  */
51 
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <lal/LALStdlib.h>
55 #include <lal/Segments.h>
56 #include <lal/Date.h>
57 
58 /** \cond DONT_DOXYGEN */
59 
60 int main( int argc, char *argv[] )
61 {
62  INT4 nfailures = 0;
63  INT4 status;
64  int compval;
65  CHAR testname[256];
66  LALSeg seg;
67  LALSeg segc1, segc2;
68  LALSeg *segptr;
69  LALSegList seglist1, seglist2;
70  INT4 seglist1ok;
71  INT4 nsegs, ilast, itime, iseg, nsearchtests;
72  INT4 nbigsize = 1000000, nfullbinary = 1000000;
73 
74  /*-- Test times --*/
75  LIGOTimeGPS time1 = { 794285000, 602350000 };
76  LIGOTimeGPS time2 = { 794285010, 902350000 };
77  LIGOTimeGPS time3 = {1794286020, 702351111 };
78  LIGOTimeGPS time3p = { 394285040, 502351234 };
79  LIGOTimeGPS time4a = { 794285020, 400000002 };
80  LIGOTimeGPS time4b = { 794285020, 555555555 };
81  LIGOTimeGPS time4c = { 794285030, 702351111 };
82 
83  LIGOTimeGPS dtime[10] = { {794000000, 0},
84  {794000000, 100000000},
85  {794000000, 220000000},
86  {794000000, 333000000},
87  {794000000, 444400000},
88  {794000000, 555550000},
89  {794000000, 666666000},
90  {794000000, 777777700},
91  {794000000, 888888880},
92  {794000000, 999999999} };
93 
94  /*-- Test segments --*/
95  LALSeg seg1 = { {794285000,602350000}, {794285010,902350000}, 1 };
96  LALSeg seg2 = { {794285020,400000002}, {794285030,702351111}, 2 };
97  /* seg3p is a point in time */
98  LALSeg seg3p = { {394285040,502351234}, {394285040,502351234}, 3 };
99  /* seg4a and seg4b touch */
100  LALSeg seg4a = { {794285050,602350000}, {794285051,300200100}, 4 };
101  LALSeg seg4b = { {794285051,300200100}, {794285055,902350000}, 44 };
102  /* seg5a and seg5b have the same start time but different end times */
103  LALSeg seg5a = { {1794285060,604350000}, {1794285061,400300200}, 5 };
104  LALSeg seg5b = { {1794285060,604350000}, {1794285061,500400300}, 55 };
105  /* seg6a and seb6c overlap with seg6b, but not with each other */
106  LALSeg seg6a = { {794285062,444444444}, {794285064,333333333}, 6 };
107  LALSeg seg6b = { {794285063,666666666}, {794285066,555555555}, 66 };
108  LALSeg seg6c = { {794285065,888888888}, {794285067,777777777}, 666 };
109  /* segbad is an invalid segment (end time earlier than start time) */
110  LALSeg segbad = { {794285020,602350000}, {794285010,902350000}, 999 };
111 
112  /* The following segments are used to build a segment list for testing
113  XLALSegListSearch. The segments are added one at a time, and the
114  search function is tested after each one is added. As the list is
115  built, it starts out disjoint, then disjoint but with touching segments,
116  then not disjoint but sorted, then not sorted. */
117  LALSeg sseg[] = { {{794285000,0}, {794285001,0}, 1},
118  {{794285002,0}, {794285003,0}, 2},
119  {{794285004,0}, {794285005,0}, 3},
120  {{794285005,0}, {794285006,0}, 4},
121  {{794285007,0}, {794285009,0}, 5},
122  {{794285008,0}, {794285010,0}, 6},
123  {{794285012,0}, {794285014,0}, 7},
124  {{794284998,0}, {794284999,0}, 8} };
125 
126  /* The following array is a list of GPS times for testing XLALSegListSearch.
127  The 'infirst' field of the structure indicates when the GPS should first
128  be found by the search, e.g. if the 'infirst' value is equal to 4, then
129  that time should be found once the segment list has been built up to the
130  point of having 4 or more segments. */
131 
132  typedef struct tagTestTime {
134  INT4 infirst;
135  } TestTime;
136 
137  TestTime lalstime[] = { {{794284997,0}, 0},
138  {{794284998,0}, 8},
139  {{794284998,5}, 8},
140  {{794284999,5}, 0},
141  {{794285000,0}, 1},
142  {{794285000,5}, 1},
143  {{794285000,999999999}, 1},
144  {{794285001,0}, 0},
145  {{794285001,5}, 0},
146  {{794285002,0}, 2},
147  {{794285002,5}, 2},
148  {{794285003,0}, 0},
149  {{794285003,5}, 0},
150  {{794285004,0}, 3},
151  {{794285004,5}, 3},
152  {{794285005,0}, 4},
153  {{794285005,5}, 4},
154  {{794285006,0}, 0},
155  {{794285006,5}, 0},
156  {{794285007,0}, 5},
157  {{794285007,5}, 5},
158  {{794285008,0}, 5},
159  {{794285008,5}, 5},
160  {{794285009,0}, 6},
161  {{794285009,5}, 6},
162  {{794285010,5}, 0},
163  {{794285011,0}, 0},
164  {{794285012,0}, 7},
165  {{794285012,5}, 7},
166  {{794285015,0}, 0} };
167 
168  /*-- Default debug level includes info messages (4), but not
169  memory checking (16), error messages (1), or warning messages (2) --*/
170 
171  /*------ Parse input line. ------*/
172  if ( argc != 1 )
173  {
174  fprintf( stderr, "Usage: %s [ lalDebugLevel ]\n", argv[0] );
175  return 0; /* so that test script won't fail */
176  }
177 
178  /*-------------------------------------------------------------------------*/
179  XLALPrintInfo("\n========== XLALSegSet tests \n");
180  /*-------------------------------------------------------------------------*/
181 
182  /*------------------------------*/
183  strcpy( testname, "XLALSegSet normal operation" );
184  xlalErrno = 0;
185  status = XLALSegSet( &seg, &time1, &time2, 5 );
186  if ( status ) {
187  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
188  } else if ( XLALGPSCmp(&seg.start,&time1) == 0 &&
189  XLALGPSCmp(&seg.end,&time2) == 0 &&
190  seg.id == 5 ) {
191  XLALPrintInfo("Pass functional check for %s\n", testname);
192  } else {
193  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Set wrong start time, end time, and/or id"); nfailures++;
194  }
195 
196  /*------------------------------*/
197  strcpy( testname, "XLALSegSet zero-length segment" );
198  xlalErrno = 0;
199  status = XLALSegSet( &seg, &time3, &time3, 6 );
200  if ( status ) {
201  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
202  } else if ( XLALGPSCmp(&seg.start,&time3) == 0 &&
203  XLALGPSCmp(&seg.end,&time3) == 0 &&
204  seg.id == 6 ) {
205  XLALPrintInfo("Pass functional check for %s\n", testname);
206  } else {
207  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Set wrong start time, end time, and/or id"); nfailures++;
208  }
209 
210  /*------------------------------*/
211  strcpy( testname, "XLALSegSet invalid segment" );
212  xlalErrno = 0;
213  status = XLALSegSet( &seg, &time2, &time1, 0 );
214  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EDOM ) {
215  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
216  } else {
217  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
218  }
219 
220  /*------------------------------*/
221  strcpy( testname, "XLALSegSet null segment pointer" );
222  xlalErrno = 0;
223  status = XLALSegSet( NULL, &time1, &time2, 0 );
224  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
225  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
226  } else {
227  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
228  }
229 
230  /*------------------------------*/
231  strcpy( testname, "XLALSegSet null time pointer 1" );
232  xlalErrno = 0;
233  status = XLALSegSet( &seg, NULL, &time3, 0 );
234  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
235  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
236  } else {
237  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
238  }
239 
240  /*------------------------------*/
241  strcpy( testname, "XLALSegSet null time pointer 2" );
242  xlalErrno = 0;
243  status = XLALSegSet( &seg, &time2, NULL, 0 );
244  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
245  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
246  } else {
247  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
248  }
249 
250  /*-------------------------------------------------------------------------*/
251  XLALPrintInfo("\n========== XLALSegCreate tests \n");
252  /*-------------------------------------------------------------------------*/
253 
254  /*------------------------------*/
255  strcpy( testname, "XLALSegCreate normal operation" );
256  xlalErrno = 0;
257  segptr = XLALSegCreate( &time1, &time2, 5 );
258  if ( segptr == NULL ) {
259  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
260  } else if ( XLALGPSCmp(&(segptr->start),&time1) == 0 &&
261  XLALGPSCmp(&(segptr->end),&time2) == 0 &&
262  segptr->id == 5 ) {
263  XLALPrintInfo("Pass functional check for %s\n", testname);
264  } else {
265  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Set wrong start time, end time, and/or id"); nfailures++;
266  }
267  if (segptr) LALFree( segptr );
268 
269  /*------------------------------*/
270  strcpy( testname, "XLALSegCreate zero-length segment" );
271  xlalErrno = 0;
272  segptr = XLALSegCreate( &time3, &time3, 6 );
273  if ( segptr == NULL ) {
274  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
275  } else if ( XLALGPSCmp(&(segptr->start),&time3) == 0 &&
276  XLALGPSCmp(&(segptr->end),&time3) == 0 &&
277  segptr->id == 6 ) {
278  XLALPrintInfo("Pass functional check for %s\n", testname);
279  } else {
280  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Set wrong start time, end time, and/or id"); nfailures++;
281  }
282  if (segptr) LALFree( segptr );
283 
284  /*------------------------------*/
285  strcpy( testname, "XLALSegCreate invalid segment" );
286  xlalErrno = 0;
287  segptr = XLALSegCreate( &time2, &time1, 0 );
288  if ( segptr == NULL && xlalErrno == XLAL_EDOM ) {
289  XLALPrintInfo("Pass return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
290  } else {
291  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
292  }
293  if (segptr) LALFree( segptr );
294 
295  /*------------------------------*/
296  strcpy( testname, "XLALSegCreate null time pointer 1" );
297  xlalErrno = 0;
298  segptr = XLALSegCreate( NULL, &time3, 0 );
299  if ( segptr == NULL && xlalErrno == XLAL_EFAULT ) {
300  XLALPrintInfo("Pass return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
301  } else {
302  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
303  }
304  if (segptr) LALFree( segptr );
305 
306  /*------------------------------*/
307  strcpy( testname, "XLALSegCreate null time pointer 2" );
308  xlalErrno = 0;
309  segptr = XLALSegCreate( &time2, NULL, 0 );
310  if ( segptr == NULL && xlalErrno == XLAL_EFAULT ) {
311  XLALPrintInfo("Pass return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
312  } else {
313  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
314  }
315  if (segptr) LALFree( segptr );
316 
317 
318  /*-------------------------------------------------------------------------*/
319  XLALPrintInfo("\n========== XLALGPSInSeg tests \n");
320  /*-------------------------------------------------------------------------*/
321 
322  /*------------------------------*/
323  strcpy( testname, "XLALGPSInSeg normal comparison 1" );
324  xlalErrno = 0;
325  compval = XLALGPSInSeg( &time1, &seg2 );
326  if ( xlalErrno == 0 ) {
327  if ( compval < 0 ) {
328  XLALPrintInfo("Pass functional check for %s\n", testname);
329  } else {
330  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
331  }
332  } else {
333  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
334  }
335 
336  /*------------------------------*/
337  strcpy( testname, "XLALGPSInSeg normal comparison 3" );
338  xlalErrno = 0;
339  compval = XLALGPSInSeg( &time3, &seg2 );
340  if ( xlalErrno == 0 ) {
341  if ( compval > 0 ) {
342  XLALPrintInfo("Pass functional check for %s\n", testname);
343  } else {
344  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
345  }
346  } else {
347  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
348  }
349 
350  /*------------------------------*/
351  strcpy( testname, "XLALGPSInSeg normal comparison 4a" );
352  xlalErrno = 0;
353  compval = XLALGPSInSeg( &time4a, &seg2 );
354  if ( xlalErrno == 0 ) {
355  if ( compval == 0 ) {
356  XLALPrintInfo("Pass functional check for %s\n", testname);
357  } else {
358  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
359  }
360  } else {
361  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
362  }
363 
364  /*------------------------------*/
365  strcpy( testname, "XLALGPSInSeg normal comparison 4b" );
366  xlalErrno = 0;
367  compval = XLALGPSInSeg( &time4b, &seg2 );
368  if ( xlalErrno == 0 ) {
369  if ( compval == 0 ) {
370  XLALPrintInfo("Pass functional check for %s\n", testname);
371  } else {
372  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
373  }
374  } else {
375  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
376  }
377 
378  /*------------------------------*/
379  strcpy( testname, "XLALGPSInSeg normal comparison 4c" );
380  xlalErrno = 0;
381  compval = XLALGPSInSeg( &time4c, &seg2 );
382  if ( xlalErrno == 0 ) {
383  if ( compval > 0 ) {
384  XLALPrintInfo("Pass functional check for %s\n", testname);
385  } else {
386  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
387  }
388  } else {
389  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
390  }
391 
392  /*------------------------------*/
393  strcpy( testname, "XLALGPSInSeg normal comparison 3p" );
394  xlalErrno = 0;
395  compval = XLALGPSInSeg( &time3p, &seg3p );
396  if ( xlalErrno == 0 ) {
397  if ( compval == 1 ) { /* seg3p is a point in time, since segment is half-open interval it cannot contain any points */
398  XLALPrintInfo("Pass functional check for %s\n", testname);
399  } else {
400  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
401  }
402  } else {
403  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
404  }
405 
406  /*------------------------------*/
407  strcpy( testname, "XLALGPSInSeg null GPS pointer" );
408  xlalErrno = 0;
409  compval = XLALGPSInSeg( NULL, &seg2 );
410  if ( compval == -1 ) { /* NULL GPS time is always compared less than a non-NULL GPS time */
411  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
412  } else {
413  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
414  }
415 
416  /*------------------------------*/
417  strcpy( testname, "XLALGPSInSeg null seg pointer" );
418  xlalErrno = 0;
419  compval = XLALGPSInSeg( &time1, NULL );
420  if ( xlalErrno == XLAL_EFAULT ) {
421  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
422  } else {
423  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
424  }
425 
426 
427  /*-------------------------------------------------------------------------*/
428  XLALPrintInfo("\n========== XLALSegCmp tests \n");
429  /*-------------------------------------------------------------------------*/
430 
431  /*------------------------------*/
432  strcpy( testname, "XLALSegCmp normal comparison (1,2)" );
433  xlalErrno = 0;
434  compval = XLALSegCmp( &seg1, &seg2 );
435  if ( xlalErrno == 0 ) {
436  if ( compval < 0 ) {
437  XLALPrintInfo("Pass functional check for %s\n", testname);
438  } else {
439  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
440  }
441  } else {
442  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
443  }
444 
445  /*------------------------------*/
446  strcpy( testname, "XLALSegCmp normal comparison (2,1)" );
447  xlalErrno = 0;
448  compval = XLALSegCmp( &seg2, &seg1 );
449  if ( xlalErrno == 0 ) {
450  if ( compval > 0 ) {
451  XLALPrintInfo("Pass functional check for %s\n", testname);
452  } else {
453  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
454  }
455  } else {
456  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
457  }
458 
459  /*------------------------------*/
460  strcpy( testname, "XLALSegCmp normal comparison (2,2)" );
461  xlalErrno = 0;
462  compval = XLALSegCmp( &seg2, &seg2 );
463  if ( xlalErrno == 0 ) {
464  if ( compval == 0 ) {
465  XLALPrintInfo("Pass functional check for %s\n", testname);
466  } else {
467  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
468  }
469  } else {
470  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
471  }
472 
473  /*------------------------------*/
474  strcpy( testname, "XLALSegCmp normal comparison (1,3p)" );
475  xlalErrno = 0;
476  compval = XLALSegCmp( &seg1, &seg3p );
477  if ( xlalErrno == 0 ) {
478  if ( compval > 0 ) {
479  XLALPrintInfo("Pass functional check for %s\n", testname);
480  } else {
481  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
482  }
483  } else {
484  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
485  }
486 
487  /*------------------------------*/
488  strcpy( testname, "XLALSegCmp normal comparison (3p,3p)" );
489  xlalErrno = 0;
490  compval = XLALSegCmp( &seg3p, &seg3p );
491  if ( xlalErrno == 0 ) {
492  if ( compval == 0 ) {
493  XLALPrintInfo("Pass functional check for %s\n", testname);
494  } else {
495  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
496  }
497  } else {
498  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
499  }
500 
501  /*------------------------------*/
502  strcpy( testname, "XLALSegCmp normal comparison (5a,5b)" );
503  xlalErrno = 0;
504  compval = XLALSegCmp( &seg5a, &seg5b );
505  if ( xlalErrno == 0 ) {
506  if ( compval < 0 ) {
507  XLALPrintInfo("Pass functional check for %s\n", testname);
508  } else {
509  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
510  }
511  } else {
512  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
513  }
514 
515  /*------------------------------*/
516  strcpy( testname, "XLALSegCmp normal comparison (5b,5a)" );
517  xlalErrno = 0;
518  compval = XLALSegCmp( &seg5b, &seg5a );
519  if ( xlalErrno == 0 ) {
520  if ( compval > 0 ) {
521  XLALPrintInfo("Pass functional check for %s\n", testname);
522  } else {
523  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Returned wrong comparison value"); nfailures++;
524  }
525  } else {
526  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
527  }
528 
529  /*------------------------------*/
530  strcpy( testname, "XLALSegCmp null seg pointer 1" );
531  xlalErrno = 0;
532  compval = XLALSegCmp( NULL, &seg5a );
533  if ( xlalErrno == XLAL_EFAULT ) {
534  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
535  } else {
536  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
537  }
538 
539  /*------------------------------*/
540  strcpy( testname, "XLALSegCmp null seg pointer 2" );
541  xlalErrno = 0;
542  compval = XLALSegCmp( &seg5b, NULL );
543  if ( xlalErrno == XLAL_EFAULT ) {
544  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
545  } else {
546  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, compval, xlalErrno);
547  }
548 
549 
550  /*-------------------------------------------------------------------------*/
551  XLALPrintInfo("\n========== XLALSegListInit tests \n");
552  /*-------------------------------------------------------------------------*/
553 
554  /*------------------------------*/
555  strcpy( testname, "XLALSegListInit normal operation" );
556  xlalErrno = 0;
557  seglist1.initMagic = -123;
558  status = XLALSegListInit( &seglist1 );
559  if ( status ) {
560  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
561  } else if ( seglist1.initMagic == SEGMENTSH_INITMAGICVAL ) {
562  XLALPrintInfo("Pass functional check for %s\n", testname);
563  } else {
564  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to set initMagic correctly"); nfailures++;
565  }
566 
567  /*------------------------------*/
568  strcpy( testname, "XLALSegListInit null seglist pointer" );
569  xlalErrno = 0;
570  status = XLALSegListInit( NULL );
571  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
572  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
573  } else {
574  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
575  }
576 
577 
578  /*-------------------------------------------------------------------------*/
579  XLALPrintInfo("\n========== XLALSegListClear tests \n");
580  /*-------------------------------------------------------------------------*/
581 
582  /*------------------------------*/
583  strcpy( testname, "XLALSegListClear normal operation (empty)" );
584  xlalErrno = 0;
585  seglist1.sorted = 0;
586  status = XLALSegListClear( &seglist1 );
587  if ( status ) {
588  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
589  } else if ( seglist1.sorted == 1 ) {
590  XLALPrintInfo("Pass functional check for %s\n", testname);
591  } else {
592  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to reset sorted correctly"); nfailures++;
593  }
594 
595  /*------------------------------*/
596  strcpy( testname, "XLALSegListClear null seglist pointer" );
597  xlalErrno = 0;
598  status = XLALSegListClear( NULL );
599  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
600  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
601  } else {
602  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
603  }
604 
605  /*------------------------------*/
606  strcpy( testname, "XLALSegListClear uninitialized seglist" );
607  xlalErrno = 0;
608  seglist1.initMagic = -444;
609  status = XLALSegListClear( &seglist1 );
610  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EINVAL ) {
611  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
612  } else {
613  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
614  }
615 
616  /*------------------------------*/
617  strcpy( testname, "XLALSegListClear normal operation (filled) - init" );
618  xlalErrno = 0;
619  status = XLALSegListInit( &seglist1 );
620  if ( status ) {
621  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
622  } else if ( seglist1.segs != NULL ) {
623  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to init segment list"); nfailures++;
624  } else {
625 
626  strcpy( testname, "XLALSegListClear normal operation (filled) - fill" );
627  xlalErrno = 0;
628  status = XLALSegListAppend( &seglist1, &seg2 );
629  if ( status ) {
630  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
631  } else if ( seglist1.segs == NULL ) {
632  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store segment 2"); nfailures++;
633  } else {
634 
635  status = XLALSegListAppend( &seglist1, &seg1 );
636  if ( status ) {
637  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
638  } else if ( seglist1.sorted == 1 ) {
639  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to clear sorted flag"); nfailures++;
640  } else {
641 
642  /*-- Finally, we're ready to test clearing --*/
643  strcpy( testname, "XLALSegListClear normal operation (filled)" );
644  status = XLALSegListClear( &seglist1 );
645  if ( status ) {
646  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
647  } else if ( seglist1.sorted == 1 ) {
648  XLALPrintInfo("Pass functional check for %s\n", testname);
649  } else {
650  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to reset sorted correctly"); nfailures++;
651  }
652 
653  }
654  }
655  }
656 
657 
658  /*-------------------------------------------------------------------------*/
659  XLALPrintInfo("\n========== XLALSegListAppend tests \n");
660  /*-------------------------------------------------------------------------*/
661 
662  /*------------------------------*/
663  strcpy( testname, "XLALSegListAppend null seglist pointer" );
664  xlalErrno = 0;
665  status = XLALSegListAppend( NULL, &seg1 );
666  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
667  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
668  } else {
669  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
670  }
671 
672  /*------------------------------*/
673  strcpy( testname, "XLALSegListAppend null seg pointer" );
674  xlalErrno = 0;
675  status = XLALSegListAppend( &seglist1, NULL );
676  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
677  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
678  } else {
679  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
680  }
681 
682  /*------------------------------*/
683  strcpy( testname, "XLALSegListAppend uninitialized seglist" );
684  xlalErrno = 0;
685  seglist1.initMagic = -444;
686  status = XLALSegListAppend( &seglist1, &seg1 );
687  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EINVAL ) {
688  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
689  } else {
690  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
691  }
692 
693  /*------------------------------*/
694  strcpy( testname, "XLALSegListAppend invalid segment - init" );
695  xlalErrno = 0;
696  status = XLALSegListInit( &seglist1 );
697  if ( status ) {
698  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
699  } else if ( seglist1.segs != NULL ) {
700  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to init segment list"); nfailures++;
701  } else {
702 
703  strcpy( testname, "XLALSegListAppend invalid segment" );
704  xlalErrno = 0;
705  status = XLALSegListAppend( &seglist1, &segbad );
706  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EDOM ) {
707  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
708  } else {
709  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
710  }
711 
712  /* Clean up */
713  XLALSegListClear( &seglist1 );
714 
715  }
716 
717  /*------------------------------*/
718  strcpy( testname, "XLALSegListAppend decimal place record - init" );
719  xlalErrno = 0;
720  status = XLALSegListInit( &seglist1 );
721  if ( status ) {
722  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
723  } else if ( seglist1.segs != NULL ) {
724  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to init segment list"); nfailures++;
725  } else if ( seglist1.dplaces != 0 ) {
726  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to init dplaces for segment list"); nfailures++;
727  } else {
728  /* Loop over segments */
729  strcpy( testname, "XLALSegListAppend decimal place record" );
730  xlalErrno = 0;
731  for ( iseg=0; iseg<=9; iseg++ ) {
732  XLALSegSet( &seg, dtime+0, dtime+iseg, 0 );
733  XLALSegListAppend( &seglist1, &seg );
734  if ( seglist1.dplaces != 3*(((UINT4)iseg+2)/3) ) {
735  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Wrong dplaces value after appending segment"); nfailures++;
736  }
737  }
738  for ( iseg=9; iseg>=0; iseg-- ) {
739  XLALSegSet( &seg, dtime+0, dtime+iseg, 0 );
740  XLALSegListAppend( &seglist1, &seg );
741  if ( seglist1.dplaces != 9 ) {
742  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Wrong dplaces value after re-appending segment"); nfailures++;
743  }
744  }
745 
746  /* Clean up */
747  XLALSegListClear( &seglist1 );
748 
749  }
750 
751  /*------------------------------*/
752  strcpy( testname, "XLALSegListAppend normal operation (empty) - init" );
753  xlalErrno = 0;
754  status = XLALSegListInit( &seglist1 );
755  if ( status ) {
756  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
757  seglist1ok = 0;
758  } else if ( seglist1.segs != NULL ) {
759  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to init segment list"); nfailures++;
760  seglist1ok = 0;
761  } else {
762  seglist1ok = 1;
763  }
764 
765  strcpy( testname, "XLALSegListAppend first segment" );
766  xlalErrno = 0;
767  if ( seglist1ok ) {
768  status = XLALSegListAppend( &seglist1, &seg1 );
769  if ( status ) {
770  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
771  seglist1ok = 0;
772  } else if ( seglist1.segs && seglist1.arraySize == SEGMENTSH_ALLOCBLOCK &&
773  seglist1.length == 1 ) {
774  XLALPrintInfo("Pass functional check for %s\n", testname);
775  } else {
776  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store first segment"); nfailures++;
777  seglist1ok = 0;
778  }
779  } else {
780  XLALPrintInfo( "Skip test: %s\n", testname );
781  }
782 
783  /*-- Continue with a second segment --*/
784  strcpy( testname, "XLALSegListAppend sorted, disjoint segment" );
785  xlalErrno = 0;
786  if ( seglist1ok ) {
787  status = XLALSegListAppend( &seglist1, &seg6a );
788  if ( status ) {
789  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
790  seglist1ok = 0;
791  } else if ( seglist1.length == 2 && seglist1.sorted &&
792  seglist1.disjoint ) {
793  XLALPrintInfo("Pass functional check for %s\n", testname);
794  } else {
795  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store second segment"); nfailures++;
796  seglist1ok = 0;
797  }
798  } else {
799  XLALPrintInfo( "Skip test: %s\n", testname );
800  }
801 
802 
803  /*-- Continue with a third segment which is not disjoint --*/
804  strcpy( testname, "XLALSegListAppend non-disjoint segment" );
805  xlalErrno = 0;
806  if ( seglist1ok ) {
807  status = XLALSegListAppend( &seglist1, &seg6b );
808  if ( status ) {
809  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
810  seglist1ok = 0;
811  } else if ( seglist1.length == 3 && seglist1.sorted &&
812  ! seglist1.disjoint ) {
813  XLALPrintInfo("Pass functional check for %s\n", testname);
814  } else {
815  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store second segment"); nfailures++;
816  seglist1ok = 0;
817  }
818  } else {
819  XLALPrintInfo( "Skip test: %s\n", testname );
820  }
821 
822  /*-- Continue with a fourth segment which is not sorted --*/
823  strcpy( testname, "XLALSegListAppend non-sorted segment" );
824  xlalErrno = 0;
825  if ( seglist1ok ) {
826  status = XLALSegListAppend( &seglist1, &seg4a );
827  if ( status ) {
828  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
829  seglist1ok = 0;
830  } else if ( seglist1.length == 4 && ! seglist1.sorted &&
831  ! seglist1.disjoint ) {
832  XLALPrintInfo("Pass functional check for %s\n", testname);
833  } else {
834  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store second segment"); nfailures++;
835  seglist1ok = 0;
836  }
837  } else {
838  XLALPrintInfo( "Skip test: %s\n", testname );
839  }
840 
841 
842  /*-------------------------------------------------------------------------*/
843  XLALPrintInfo("\n========== XLALSegListSort tests \n");
844  /*-------------------------------------------------------------------------*/
845 
846  /*------------------------------*/
847  strcpy( testname, "XLALSegListSort null seglist pointer" );
848  xlalErrno = 0;
849  status = XLALSegListSort( NULL );
850  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
851  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
852  } else {
853  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
854  }
855 
856  /*------------------------------*/
857  strcpy( testname, "XLALSegListSort uninitialized seglist" );
858  xlalErrno = 0;
859  seglist2.initMagic = -444;
860  status = XLALSegListSort( &seglist2 );
861  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EINVAL ) {
862  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
863  } else {
864  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
865  }
866 
867  /*------------------------------*/
868  strcpy( testname, "XLALSegListSort normal operation" );
869  xlalErrno = 0;
870  /*-- Sort the existing segment list --*/
871  if ( seglist1ok ) {
872  status = XLALSegListSort( &seglist1 );
873  if ( status ) {
874  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
875  seglist1ok = 0;
876  } else if ( seglist1.length == 4 &&
877  XLALSegCmp( &(seglist1.segs[0]), &seg1 ) == 0 &&
878  XLALSegCmp( &(seglist1.segs[1]), &seg4a ) == 0 &&
879  XLALSegCmp( &(seglist1.segs[2]), &seg6a ) == 0 &&
880  XLALSegCmp( &(seglist1.segs[3]), &seg6b ) == 0 &&
881  seglist1.sorted && ! seglist1.disjoint ) {
882  XLALPrintInfo("Pass functional check for %s\n", testname);
883  } else {
884  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Did not sort correctly"); nfailures++;
885  seglist1ok = 0;
886  }
887  } else {
888  XLALPrintInfo( "Skip test: %s\n", testname );
889  }
890 
891 
892  /*-------------------------------------------------------------------------*/
893  XLALPrintInfo("\n========== XLALSegListCoalesce tests \n");
894  /*-------------------------------------------------------------------------*/
895 
896  /*------------------------------*/
897  strcpy( testname, "XLALSegListCoalesce null seglist pointer" );
898  xlalErrno = 0;
899  status = XLALSegListCoalesce( NULL );
900  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EFAULT ) {
901  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
902  } else {
903  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
904  }
905 
906  /*------------------------------*/
907  strcpy( testname, "XLALSegListCoalesce uninitialized seglist" );
908  xlalErrno = 0;
909  seglist2.initMagic = -444;
910  status = XLALSegListCoalesce( &seglist2 );
911  if ( status == XLAL_FAILURE && xlalErrno == XLAL_EINVAL ) {
912  XLALPrintInfo("Pass return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
913  } else {
914  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
915  }
916 
917  /*------------------------------*/
918  strcpy( testname, "XLALSegListCoalesce normal operation 1" );
919  xlalErrno = 0;
920  /*-- Coalesce the existing segment list --*/
921  if ( seglist1ok ) {
922  status = XLALSegListCoalesce( &seglist1 );
923  /*-- Construct segment for comparison purposes --*/
924  XLALSegSet( &segc1, &(seg6a.start), &(seg6b.end), 8 );
925  if ( status ) {
926  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
927  seglist1ok = 0;
928  } else if ( seglist1.length == 3 &&
929  XLALSegCmp( &(seglist1.segs[0]), &seg1 ) == 0 &&
930  XLALSegCmp( &(seglist1.segs[1]), &seg4a ) == 0 &&
931  XLALSegCmp( &(seglist1.segs[2]), &segc1 ) == 0 &&
932  seglist1.sorted && seglist1.disjoint ) {
933  XLALPrintInfo("Pass functional check for %s\n", testname);
934  } else {
935  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Did not coalesce correctly"); nfailures++;
936  seglist1ok = 0;
937  }
938  } else {
939  XLALPrintInfo( "Skip test: %s\n", testname );
940  }
941 
942 
943  /*------------------------------*/
944  /*-- Add some segments to the existing segment list --*/
945  strcpy( testname, "XLALSegListCoalesce normal operation 2 - add 6c" );
946  xlalErrno = 0;
947  if ( seglist1ok ) {
948  status = XLALSegListAppend( &seglist1, &seg6c );
949  if ( status ) {
950  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
951  seglist1ok = 0;
952  } else if ( seglist1.length == 4 && seglist1.sorted &&
953  ! seglist1.disjoint ) {
954  XLALPrintInfo("Pass functional check for %s\n", testname);
955  } else {
956  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store second segment"); nfailures++;
957  seglist1ok = 0;
958  }
959  } else {
960  XLALPrintInfo( "Skip test: %s\n", testname );
961  }
962 
963  strcpy( testname, "XLALSegListCoalesce normal operation 2 - add 4b" );
964  xlalErrno = 0;
965  if ( seglist1ok ) {
966  status = XLALSegListAppend( &seglist1, &seg4b );
967  if ( status ) {
968  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
969  seglist1ok = 0;
970  } else if ( seglist1.length == 5 && ! seglist1.sorted &&
971  ! seglist1.disjoint ) {
972  XLALPrintInfo("Pass functional check for %s\n", testname);
973  } else {
974  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store second segment"); nfailures++;
975  seglist1ok = 0;
976  }
977  } else {
978  XLALPrintInfo( "Skip test: %s\n", testname );
979  }
980 
981  strcpy( testname, "XLALSegListCoalesce normal operation 2 - add 2" );
982  xlalErrno = 0;
983  if ( seglist1ok ) {
984  status = XLALSegListAppend( &seglist1, &seg2 );
985  if ( status ) {
986  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
987  seglist1ok = 0;
988  } else if ( seglist1.length == 6 && ! seglist1.sorted &&
989  ! seglist1.disjoint ) {
990  XLALPrintInfo("Pass functional check for %s\n", testname);
991  } else {
992  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store second segment"); nfailures++;
993  seglist1ok = 0;
994  }
995  } else {
996  XLALPrintInfo( "Skip test: %s\n", testname );
997  }
998 
999  strcpy( testname, "XLALSegListCoalesce normal operation 2 - add 2 again" );
1000  xlalErrno = 0;
1001  if ( seglist1ok ) {
1002  status = XLALSegListAppend( &seglist1, &seg2 );
1003  if ( status ) {
1004  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
1005  seglist1ok = 0;
1006  } else if ( seglist1.length == 7 && ! seglist1.sorted &&
1007  ! seglist1.disjoint ) {
1008  XLALPrintInfo("Pass functional check for %s\n", testname);
1009  } else {
1010  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to store second segment"); nfailures++;
1011  seglist1ok = 0;
1012  }
1013  } else {
1014  XLALPrintInfo( "Skip test: %s\n", testname );
1015  }
1016 
1017  strcpy( testname, "XLALSegListCoalesce normal operation 2 - coalesce" );
1018  xlalErrno = 0;
1019  if ( seglist1ok ) {
1020  status = XLALSegListCoalesce( &seglist1 );
1021  /*-- Construct segments for comparison purposes --*/
1022  XLALSegSet( &segc1, &(seg4a.start), &(seg4b.end), 8 );
1023  XLALSegSet( &segc2, &(seg6a.start), &(seg6c.end), 8 );
1024  if ( status ) {
1025  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
1026  seglist1ok = 0;
1027  } else if ( seglist1.length == 4 &&
1028  XLALSegCmp( &(seglist1.segs[0]), &seg1 ) == 0 &&
1029  XLALSegCmp( &(seglist1.segs[1]), &seg2 ) == 0 &&
1030  XLALSegCmp( &(seglist1.segs[2]), &segc1 ) == 0 &&
1031  XLALSegCmp( &(seglist1.segs[3]), &segc2 ) == 0 &&
1032  seglist1.sorted && seglist1.disjoint ) {
1033  XLALPrintInfo("Pass functional check for %s\n", testname);
1034  } else {
1035  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Did not coalesce correctly"); nfailures++;
1036  seglist1ok = 0;
1037  }
1038  } else {
1039  XLALPrintInfo( "Skip test: %s\n", testname );
1040  }
1041 
1042 
1043  /*-------------------------------------------------------------------------*/
1044  XLALPrintInfo("\n========== XLALSegListSearch tests \n");
1045  /*-------------------------------------------------------------------------*/
1046 
1047  /*------------------------------*/
1048  strcpy( testname, "XLALSegListSearch null seglist pointer" );
1049  xlalErrno = 0;
1050  segptr = XLALSegListSearch( NULL, &time1 );
1051  if ( segptr == NULL && xlalErrno == XLAL_EFAULT ) {
1052  XLALPrintInfo("Pass return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1053  } else {
1054  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1055  }
1056 
1057  /*------------------------------*/
1058  strcpy( testname, "XLALSegListSearch null GPS pointer" );
1059  xlalErrno = 0;
1060  segptr = XLALSegListSearch( &seglist1, NULL );
1061  if ( segptr == NULL && xlalErrno == XLAL_EFAULT ) {
1062  XLALPrintInfo("Pass return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1063  } else {
1064  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1065  }
1066 
1067  /*------------------------------*/
1068  strcpy( testname, "XLALSegListSearch uninitialized seglist" );
1069  xlalErrno = 0;
1070  seglist2.initMagic = -444;
1071  segptr = XLALSegListSearch( &seglist2, &time1 );
1072  if ( segptr == NULL && xlalErrno == XLAL_EINVAL ) {
1073  XLALPrintInfo("Pass return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1074  } else {
1075  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1076  }
1077 
1078  /*------------------------------*/
1079  strcpy( testname, "XLALSegListSearch empty seglist - init" );
1080  xlalErrno = 0;
1081  status = XLALSegListInit( &seglist2 );
1082  if ( status ) {
1083  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
1084  } else if ( seglist2.initMagic == SEGMENTSH_INITMAGICVAL ) {
1085  XLALPrintInfo("Pass functional check for %s\n", testname);
1086  } else {
1087  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to set initMagic correctly"); nfailures++;
1088  }
1089 
1090  strcpy( testname, "XLALSegListSearch empty seglist - search" );
1091  xlalErrno = 0;
1092  segptr = XLALSegListSearch( &seglist2, &time1 );
1093  if ( segptr == NULL && xlalErrno == 0 ) {
1094  XLALPrintInfo("Pass return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1095  } else {
1096  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1097  }
1098 
1099  nsearchtests = 0;
1100 
1101  /*------------------------------*/
1102  /* Loop over segment list length */
1103 
1104  for ( nsegs=1; nsegs<=(INT4)sizeof(sseg)/(INT4)sizeof(LALSeg); nsegs++ ) {
1105 
1106  /* Append a segment */
1107  sprintf( testname,
1108  "XLALSegListSearch - appending to make list of %d segments",
1109  nsegs );
1110  status = XLALSegListAppend( &seglist2, sseg+nsegs-1 );
1111  if ( status ) {
1112  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
1113  break;
1114  }
1115 
1116  /* Loop over test times */
1117  for ( itime=0; itime < (INT4)sizeof(lalstime)/(INT4)sizeof(TestTime); itime++ ) {
1118 
1119  /* Loop over lastFound states */
1120  for ( ilast = -1; ilast < nsegs; ilast++ ) {
1121  if ( ilast == -1 ) {
1122  seglist2.lastFound = NULL;
1123  } else {
1124  seglist2.lastFound = &(seglist2.segs[ilast]);
1125  }
1126 
1127  nsearchtests++;
1128 
1129  sprintf( testname,
1130  "XLALSegListSearch - nsegs=%d, itime=%d, ilast=%d",
1131  nsegs, itime, ilast );
1132  /* Do the search */
1133  segptr = XLALSegListSearch( &seglist2, &(lalstime[itime].gps) );
1134 
1135  /* Check whether the function had an error */
1136  if ( xlalErrno != 0 ) {
1137  XLALPrintInfo("*FAIL* return check for %s: return=%p, xlalErrno=%d\n", testname, segptr, xlalErrno);
1138  continue;
1139  }
1140 
1141  /* Check that the result is correct */
1142  if ( lalstime[itime].infirst > 0 && nsegs >= lalstime[itime].infirst ) {
1143  /* The search should have found a match */
1144  if ( ! segptr ) {
1145  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Failed to find a match"); nfailures++;
1146  continue;
1147  }
1148  /* The matched segment should contain the time */
1149  if ( XLALGPSInSeg(&(lalstime[itime].gps),segptr) != 0 ) {
1150  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Segment returned does not contain the time"); nfailures++;
1151  continue;
1152  }
1153  } else {
1154  /* The search should NOT have found a match */
1155  if ( segptr ) {
1156  XLALPrintInfo("*FAIL* functional check for %s: %s\n", testname, "Found inappropriate match"); nfailures++;
1157  continue;
1158  }
1159  }
1160 
1161  } /* End loop over lastFound states */
1162 
1163  } /* End loop over test times */
1164 
1165  } /* End loop over number of segments in list */
1166 
1167  XLALPrintInfo( "Tested %d cases for XLALSegListSearch for correctness\n",
1168  nsearchtests );
1169 
1170  /* Construct a big segment list */
1171  XLALSegListClear( &seglist2 );
1172  XLALPrintInfo( "\nConstructing a segment list with %d segments...\n",
1173  nbigsize );
1174  for ( iseg=0; iseg<nbigsize; iseg++ ) {
1175  sprintf( testname, "Appending segment %d to big list", iseg );
1176  time1.gpsSeconds = 800000000 + iseg;
1177  time1.gpsNanoSeconds = 0;
1178  time2.gpsSeconds = 800000000 + iseg;
1179  time2.gpsNanoSeconds = 500000000;
1180  status = XLALSegSet( &seg, &time1, &time2, 0 );
1181  if ( status != 0 ) {
1182  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
1183  break;
1184  }
1185  status = XLALSegListAppend( &seglist2, &seg );
1186  if ( status != 0 ) {
1187  XLALPrintInfo("*FAIL* return check for %s: return=%d, xlalErrno=%d\n", testname, status, xlalErrno);
1188  break;
1189  }
1190  }
1191 
1192  /* Do a bunch of binary searches in the big segment list */
1193  XLALPrintInfo( "\nDoing %d full binary searches in the segment list...\n",
1194  nfullbinary );
1195  time1.gpsSeconds = 800000000 + nbigsize/3 ;
1196  time1.gpsNanoSeconds = 250000000;
1197  for ( itime=0; itime<nfullbinary; itime++ ) {
1198  /* Clear the lastFound pointer, to force a full binary search */
1199  seglist2.lastFound = NULL;
1200  segptr = XLALSegListSearch( &seglist2, &time1 );
1201  }
1202 
1203 
1204  /*-------------------------------------------------------------------------*/
1205  XLALPrintInfo("\n========== XLALSegListRange tests \n");
1206  /*-------------------------------------------------------------------------*/
1207 
1208  {
1209  LIGOTimeGPS start, end;
1210 
1211  XLALPrintInfo("Check XLALSegListRange() for a sorted list ...\n");
1212  XLAL_CHECK( XLALSegListIsInitialized(&seglist1) && seglist1.sorted, XLAL_EFUNC );
1213  XLAL_CHECK( XLALSegListRange(&seglist1, &start, &end) == XLAL_SUCCESS, XLAL_EFUNC );
1214  XLAL_CHECK( XLALGPSCmp(&start, &seglist1.segs[0].start) == 0, XLAL_EFAILED );
1215  XLAL_CHECK( XLALGPSCmp(&end, &seglist1.segs[seglist1.length - 1].end) == 0, XLAL_EFAILED );
1216 
1217  XLALPrintInfo("Check XLALSegListRange() for a non-sorted list ...\n");
1219  UINT4 i = seglist1.length / 2;
1220  while (seglist2.length < seglist1.length) {
1221  XLAL_CHECK( XLALSegListAppend(&seglist2, &seglist1.segs[i]) == XLAL_SUCCESS, XLAL_EFUNC );
1222  i = (i + 1) % seglist1.length;
1223  }
1224  XLAL_CHECK( XLALSegListIsInitialized(&seglist2) && !seglist2.sorted, XLAL_EFUNC );
1225  XLAL_CHECK( XLALSegListRange(&seglist2, &start, &end) == XLAL_SUCCESS, XLAL_EFUNC );
1226  XLAL_CHECK( XLALGPSCmp(&start, &seglist1.segs[0].start) == 0, XLAL_EFAILED );
1227  XLAL_CHECK( XLALGPSCmp(&end, &seglist1.segs[seglist1.length - 1].end) == 0, XLAL_EFAILED );
1228 
1229  }
1230  XLALPrintInfo("Passed XLALSegListRange tests\n");
1231 
1232 
1233  /*-------------------------------------------------------------------------*/
1234  /* Clean up leftover seg lists */
1235  if ( seglist1.segs ) { XLALSegListClear( &seglist1 ); }
1236  if ( seglist2.segs ) { XLALSegListClear( &seglist2 ); }
1237 
1238  /*-------------------------------------------------------------------------*/
1240 
1241  /*-------------------------------------------------------------------------*/
1242  if ( nfailures == 0 ) {
1243  XLALPrintInfo("\n= = = = All tests passed = = = =\n\n");
1244  return 0;
1245  } else {
1246  XLALPrintInfo("\n= = = = %d tests FAILED = = = =\n\n", nfailures);
1247  return 1;
1248  }
1249 }
1250 
1251 
1252 /** \endcond */
int XLALSegListCoalesce(LALSegList *seglist)
The function XLALSegListCoalesce() first sorts the segments in a segment list (if not already sorted)...
Definition: Segments.c:544
UINT4 initMagic
Internal value to help ensure list was initialized.
Definition: Segments.h:195
LIGOTimeGPS start
Beginning time of the segment.
Definition: Segments.h:173
int XLALSegListRange(const LALSegList *seglist, LIGOTimeGPS *start, LIGOTimeGPS *end)
The function XLALSegListRange() returns the start and end GPS times of the segment list...
Definition: Segments.c:625
Failure return value (not an error number)
Definition: XLALError.h:403
int XLALSegSet(LALSeg *seg, const LIGOTimeGPS *start, const LIGOTimeGPS *end, const INT4 id)
This function sets the start time, the end time, and the id of a segment.
Definition: Segments.c:87
int XLALSegListInit(LALSegList *seglist)
This function must be called to initialize a segment list structure before that structure can be used...
Definition: Segments.c:255
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
Definition: XLALError.h:572
UINT4 length
Number of segments in this segment list.
Definition: Segments.h:191
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
#define SEGMENTSH_INITMAGICVAL
Distinctive value set in the &#39;initMagic&#39; field to provide a check that the structure was properly ini...
Definition: Segments.h:157
void LALCheckMemoryLeaks(void)
Definition: LALMalloc.c:784
#define LALFree(p)
Definition: LALMalloc.h:96
LALSeg * XLALSegCreate(const LIGOTimeGPS *start, const LIGOTimeGPS *end, const INT4 id)
This function is similar to XLALSegSet() except that it allocates memory for a new segment structure ...
Definition: Segments.c:131
INT4 gpsNanoSeconds
Residual nanoseconds.
Definition: LALDatatypes.h:460
int XLALSegListIsInitialized(const LALSegList *seglist)
Simple method to check whether a LALSegList is in an initialized state.
Definition: Segments.c:1055
UINT4 dplaces
Decimal places (0,3,6,9) to format GPS times.
Definition: Segments.h:192
Struct holding a single segment.
Definition: Segments.h:170
int XLALGPSInSeg(const void *pgps, const void *pseg)
This is designed to be usable as a comparison function for bsearch() and therefore returns a negative...
Definition: Segments.c:182
int XLALSegListSort(LALSegList *seglist)
This function sorts the segments in a segment list into forward time order.
Definition: Segments.c:491
int XLALSegListAppend(LALSegList *seglist, const LALSeg *seg)
This function appends a segment to a segment list.
Definition: Segments.c:375
#define fprintf
Struct holding a segment list.
Definition: Segments.h:183
UINT4 disjoint
Flag to indicate whether segment list is disjoint.
Definition: Segments.h:194
LALSeg * XLALSegListSearch(LALSegList *seglist, const LIGOTimeGPS *gps)
The function XLALSegListSearch() determines which segment in the list, if any, contains the GPS time ...
Definition: Segments.c:714
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
Definition: XLALError.h:811
int XLALPrintInfo(const char *fmt,...)
Definition: XLALError.c:90
Invalid pointer.
Definition: XLALError.h:409
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
Compares two GPS times.
Definition: XLALTime.c:174
Input domain error.
Definition: XLALError.h:411
#define SEGMENTSH_ALLOCBLOCK
Initial number of LALSeg spaces to allocate in memory at one time; this is intended to reduce the num...
Definition: Segments.h:141
LIGOTimeGPS end
Ending time of the segment.
Definition: Segments.h:174
LALSeg * segs
Pointer to array of segments (LALSeg structures)
Definition: Segments.h:189
int XLALSegCmp(const void *pseg0, const void *pseg1)
This is designed to be usable as a comparison function for qsort() and therefore returns a negative v...
Definition: Segments.c:213
Success return value (not an error number)
Definition: XLALError.h:402
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
Definition: LALDatatypes.h:459
uint32_t UINT4
Four-byte unsigned integer.
int main(int argc, char *argv[])
Definition: cache.c:25
UINT4 sorted
Flag to indicate whether segment list is sorted.
Definition: Segments.h:193
LALSeg * lastFound
Internal record of last segment found by a search.
Definition: Segments.h:196
int32_t INT4
Four-byte signed integer.
Generic failure.
Definition: XLALError.h:419
size_t arraySize
Size of array for which memory is allocated.
Definition: Segments.h:190
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:463
Invalid argument.
Definition: XLALError.h:410
int XLALSegListClear(LALSegList *seglist)
This function must be called when you are done with a segment list, in order to free memory that was ...
Definition: Segments.c:303
INT4 id
Identifier (segment ID, array index, etc.) for user.
Definition: Segments.h:175