54 #include <lal/LALStdlib.h>
55 #include <lal/Segments.h>
60 int main(
int argc,
char *argv[] )
71 INT4 nsegs, ilast, itime, iseg, nsearchtests;
72 INT4 nbigsize = 1000000, nfullbinary = 1000000;
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} };
95 LALSeg seg1 = { {794285000,602350000}, {794285010,902350000}, 1 };
96 LALSeg seg2 = { {794285020,400000002}, {794285030,702351111}, 2 };
98 LALSeg seg3p = { {394285040,502351234}, {394285040,502351234}, 3 };
100 LALSeg seg4a = { {794285050,602350000}, {794285051,300200100}, 4 };
101 LALSeg seg4b = { {794285051,300200100}, {794285055,902350000}, 44 };
103 LALSeg seg5a = { {1794285060,604350000}, {1794285061,400300200}, 5 };
104 LALSeg seg5b = { {1794285060,604350000}, {1794285061,500400300}, 55 };
106 LALSeg seg6a = { {794285062,444444444}, {794285064,333333333}, 6 };
107 LALSeg seg6b = { {794285063,666666666}, {794285066,555555555}, 66 };
108 LALSeg seg6c = { {794285065,888888888}, {794285067,777777777}, 666 };
110 LALSeg segbad = { {794285020,602350000}, {794285010,902350000}, 999 };
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} };
132 typedef struct tagTestTime {
137 TestTime lalstime[] = { {{794284997,0}, 0},
143 {{794285000,999999999}, 1},
166 {{794285015,0}, 0} };
174 fprintf( stderr,
"Usage: %s [ lalDebugLevel ]\n", argv[0] );
183 strcpy( testname,
"XLALSegSet normal operation" );
193 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Set wrong start time, end time, and/or id"); nfailures++;
197 strcpy( testname,
"XLALSegSet zero-length segment" );
207 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Set wrong start time, end time, and/or id"); nfailures++;
211 strcpy( testname,
"XLALSegSet invalid segment" );
221 strcpy( testname,
"XLALSegSet null segment pointer" );
231 strcpy( testname,
"XLALSegSet null time pointer 1" );
241 strcpy( testname,
"XLALSegSet null time pointer 2" );
255 strcpy( testname,
"XLALSegCreate normal operation" );
258 if ( segptr == NULL ) {
265 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Set wrong start time, end time, and/or id"); nfailures++;
270 strcpy( testname,
"XLALSegCreate zero-length segment" );
273 if ( segptr == NULL ) {
280 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Set wrong start time, end time, and/or id"); nfailures++;
285 strcpy( testname,
"XLALSegCreate invalid segment" );
296 strcpy( testname,
"XLALSegCreate null time pointer 1" );
307 strcpy( testname,
"XLALSegCreate null time pointer 2" );
323 strcpy( testname,
"XLALGPSInSeg normal comparison 1" );
330 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
337 strcpy( testname,
"XLALGPSInSeg normal comparison 3" );
344 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
351 strcpy( testname,
"XLALGPSInSeg normal comparison 4a" );
355 if ( compval == 0 ) {
358 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
365 strcpy( testname,
"XLALGPSInSeg normal comparison 4b" );
369 if ( compval == 0 ) {
372 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
379 strcpy( testname,
"XLALGPSInSeg normal comparison 4c" );
386 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
393 strcpy( testname,
"XLALGPSInSeg normal comparison 3p" );
397 if ( compval == 1 ) {
400 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
407 strcpy( testname,
"XLALGPSInSeg null GPS pointer" );
410 if ( compval == -1 ) {
417 strcpy( testname,
"XLALGPSInSeg null seg pointer" );
432 strcpy( testname,
"XLALSegCmp normal comparison (1,2)" );
439 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
446 strcpy( testname,
"XLALSegCmp normal comparison (2,1)" );
453 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
460 strcpy( testname,
"XLALSegCmp normal comparison (2,2)" );
464 if ( compval == 0 ) {
467 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
474 strcpy( testname,
"XLALSegCmp normal comparison (1,3p)" );
481 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
488 strcpy( testname,
"XLALSegCmp normal comparison (3p,3p)" );
492 if ( compval == 0 ) {
495 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
502 strcpy( testname,
"XLALSegCmp normal comparison (5a,5b)" );
509 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
516 strcpy( testname,
"XLALSegCmp normal comparison (5b,5a)" );
523 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Returned wrong comparison value"); nfailures++;
530 strcpy( testname,
"XLALSegCmp null seg pointer 1" );
540 strcpy( testname,
"XLALSegCmp null seg pointer 2" );
555 strcpy( testname,
"XLALSegListInit normal operation" );
564 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to set initMagic correctly"); nfailures++;
568 strcpy( testname,
"XLALSegListInit null seglist pointer" );
583 strcpy( testname,
"XLALSegListClear normal operation (empty)" );
589 }
else if ( seglist1.
sorted == 1 ) {
592 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to reset sorted correctly"); nfailures++;
596 strcpy( testname,
"XLALSegListClear null seglist pointer" );
606 strcpy( testname,
"XLALSegListClear uninitialized seglist" );
617 strcpy( testname,
"XLALSegListClear normal operation (filled) - init" );
622 }
else if ( seglist1.
segs != NULL ) {
623 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to init segment list"); nfailures++;
626 strcpy( testname,
"XLALSegListClear normal operation (filled) - fill" );
631 }
else if ( seglist1.
segs == NULL ) {
632 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store segment 2"); nfailures++;
638 }
else if ( seglist1.
sorted == 1 ) {
639 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to clear sorted flag"); nfailures++;
643 strcpy( testname,
"XLALSegListClear normal operation (filled)" );
647 }
else if ( seglist1.
sorted == 1 ) {
650 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to reset sorted correctly"); nfailures++;
663 strcpy( testname,
"XLALSegListAppend null seglist pointer" );
673 strcpy( testname,
"XLALSegListAppend null seg pointer" );
683 strcpy( testname,
"XLALSegListAppend uninitialized seglist" );
694 strcpy( testname,
"XLALSegListAppend invalid segment - init" );
699 }
else if ( seglist1.
segs != NULL ) {
700 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to init segment list"); nfailures++;
703 strcpy( testname,
"XLALSegListAppend invalid segment" );
718 strcpy( testname,
"XLALSegListAppend decimal place record - init" );
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++;
729 strcpy( testname,
"XLALSegListAppend decimal place record" );
731 for ( iseg=0; iseg<=9; iseg++ ) {
735 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Wrong dplaces value after appending segment"); nfailures++;
738 for ( iseg=9; iseg>=0; iseg-- ) {
742 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Wrong dplaces value after re-appending segment"); nfailures++;
752 strcpy( testname,
"XLALSegListAppend normal operation (empty) - init" );
758 }
else if ( seglist1.
segs != NULL ) {
759 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to init segment list"); nfailures++;
765 strcpy( testname,
"XLALSegListAppend first segment" );
776 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store first segment"); nfailures++;
784 strcpy( testname,
"XLALSegListAppend sorted, disjoint segment" );
795 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store second segment"); nfailures++;
804 strcpy( testname,
"XLALSegListAppend non-disjoint segment" );
815 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store second segment"); nfailures++;
823 strcpy( testname,
"XLALSegListAppend non-sorted segment" );
830 }
else if ( seglist1.
length == 4 && ! seglist1.
sorted &&
834 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store second segment"); nfailures++;
847 strcpy( testname,
"XLALSegListSort null seglist pointer" );
857 strcpy( testname,
"XLALSegListSort uninitialized seglist" );
868 strcpy( testname,
"XLALSegListSort normal operation" );
876 }
else if ( seglist1.
length == 4 &&
884 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Did not sort correctly"); nfailures++;
897 strcpy( testname,
"XLALSegListCoalesce null seglist pointer" );
907 strcpy( testname,
"XLALSegListCoalesce uninitialized seglist" );
918 strcpy( testname,
"XLALSegListCoalesce normal operation 1" );
928 }
else if ( seglist1.
length == 3 &&
935 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Did not coalesce correctly"); nfailures++;
945 strcpy( testname,
"XLALSegListCoalesce normal operation 2 - add 6c" );
956 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store second segment"); nfailures++;
963 strcpy( testname,
"XLALSegListCoalesce normal operation 2 - add 4b" );
970 }
else if ( seglist1.
length == 5 && ! seglist1.
sorted &&
974 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store second segment"); nfailures++;
981 strcpy( testname,
"XLALSegListCoalesce normal operation 2 - add 2" );
988 }
else if ( seglist1.
length == 6 && ! seglist1.
sorted &&
992 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store second segment"); nfailures++;
999 strcpy( testname,
"XLALSegListCoalesce normal operation 2 - add 2 again" );
1006 }
else if ( seglist1.
length == 7 && ! seglist1.
sorted &&
1010 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to store second segment"); nfailures++;
1017 strcpy( testname,
"XLALSegListCoalesce normal operation 2 - coalesce" );
1027 }
else if ( seglist1.
length == 4 &&
1035 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Did not coalesce correctly"); nfailures++;
1048 strcpy( testname,
"XLALSegListSearch null seglist pointer" );
1058 strcpy( testname,
"XLALSegListSearch null GPS pointer" );
1068 strcpy( testname,
"XLALSegListSearch uninitialized seglist" );
1079 strcpy( testname,
"XLALSegListSearch empty seglist - init" );
1087 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to set initMagic correctly"); nfailures++;
1090 strcpy( testname,
"XLALSegListSearch empty seglist - search" );
1093 if ( segptr == NULL &&
xlalErrno == 0 ) {
1104 for ( nsegs=1; nsegs<=(
INT4)
sizeof(sseg)/(
INT4)
sizeof(
LALSeg); nsegs++ ) {
1108 "XLALSegListSearch - appending to make list of %d segments",
1117 for ( itime=0; itime < (
INT4)
sizeof(lalstime)/(
INT4)
sizeof(TestTime); itime++ ) {
1120 for ( ilast = -1; ilast < nsegs; ilast++ ) {
1121 if ( ilast == -1 ) {
1130 "XLALSegListSearch - nsegs=%d, itime=%d, ilast=%d",
1131 nsegs, itime, ilast );
1142 if ( lalstime[itime].infirst > 0 && nsegs >= lalstime[itime].infirst ) {
1145 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Failed to find a match"); nfailures++;
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++;
1156 XLALPrintInfo(
"*FAIL* functional check for %s: %s\n", testname,
"Found inappropriate match"); nfailures++;
1167 XLALPrintInfo(
"Tested %d cases for XLALSegListSearch for correctness\n",
1172 XLALPrintInfo(
"\nConstructing a segment list with %d segments...\n",
1174 for ( iseg=0; iseg<nbigsize; iseg++ ) {
1175 sprintf( testname,
"Appending segment %d to big list", iseg );
1193 XLALPrintInfo(
"\nDoing %d full binary searches in the segment list...\n",
1197 for ( itime=0; itime<nfullbinary; itime++ ) {
1211 XLALPrintInfo(
"Check XLALSegListRange() for a sorted list ...\n");
1217 XLALPrintInfo(
"Check XLALSegListRange() for a non-sorted list ...\n");
1222 i = (i + 1) % seglist1.
length;
1242 if ( nfailures == 0 ) {
1246 XLALPrintInfo(
"\n= = = = %d tests FAILED = = = =\n\n", nfailures);
void LALCheckMemoryLeaks(void)
int XLALPrintInfo(const char *fmt,...)
int main(int argc, char *argv[])
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
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 ...
int XLALSegListInit(LALSegList *seglist)
This function must be called to initialize a segment list structure before that structure can be used...
int XLALSegListClear(LALSegList *seglist)
This function must be called when you are done with a segment list, in order to free memory that was ...
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...
#define SEGMENTSH_INITMAGICVAL
Distinctive value set in the 'initMagic' field to provide a check that the structure was properly ini...
int XLALSegListCoalesce(LALSegList *seglist)
The function XLALSegListCoalesce() first sorts the segments in a segment list (if not already sorted)...
int XLALSegListSort(LALSegList *seglist)
This function sorts the segments in a segment list into forward time order.
int XLALSegListIsInitialized(const LALSegList *seglist)
Simple method to check whether a LALSegList is in an initialized state.
int XLALSegListAppend(LALSegList *seglist, const LALSeg *seg)
This function appends a segment to a segment list.
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.
LALSeg * XLALSegListSearch(LALSegList *seglist, const LIGOTimeGPS *gps)
The function XLALSegListSearch() determines which segment in the list, if any, contains the GPS time ...
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...
#define SEGMENTSH_ALLOCBLOCK
Initial number of LALSeg spaces to allocate in memory at one time; this is intended to reduce the num...
int XLALSegListRange(const LALSegList *seglist, LIGOTimeGPS *start, LIGOTimeGPS *end)
The function XLALSegListRange() returns the start and end GPS times of the segment list.
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
#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...
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.
@ XLAL_EFAILED
Generic failure.
@ XLAL_FAILURE
Failure return value (not an error number)
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
Compares two GPS times.
Struct holding a single segment.
LIGOTimeGPS end
Ending time of the segment.
INT4 id
Identifier (segment ID, array index, etc.) for user.
LIGOTimeGPS start
Beginning time of the segment.
Struct holding a segment list.
LALSeg * lastFound
Internal record of last segment found by a search.
UINT4 length
Number of segments in this segment list.
LALSeg * segs
Pointer to array of segments (LALSeg structures)
UINT4 sorted
Flag to indicate whether segment list is sorted.
UINT4 initMagic
Internal value to help ensure list was initialized.
UINT4 dplaces
Decimal places (0,3,6,9) to format GPS times.
size_t arraySize
Size of array for which memory is allocated.
UINT4 disjoint
Flag to indicate whether segment list is disjoint.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
INT4 gpsNanoSeconds
Residual nanoseconds.