Changeset 5587 for trunk/psModules/test
- Timestamp:
- Nov 23, 2005, 1:54:30 PM (21 years ago)
- Location:
- trunk/psModules/test
- Files:
-
- 2 edited
-
astrom/tst_pmAstrometry.c (modified) (8 diffs)
-
imsubtract/tst_pmSubtractBias.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/test/astrom/tst_pmAstrometry.c
r5543 r5587 1 1 /** @file tst_pmAstrometry.c 2 2 * 3 * @brief Contains the tests: pmAstrometry.[ch]. Only the pmxxxAlloc()3 * @brief Contains the tests: pmAstrometry.[ch]. The pmxxxAlloc() 4 4 * and psFree() functionality are used here. 5 5 * 6 * @author G eorge Gusciora, MHPCC6 * @author GLG, MHPCC 7 7 * 8 * XXX: Significant work needed: must test the variout coordinate transformation function.8 * XXX: Untested: pmFPACheckParents() 9 9 * 10 * 11 * 12 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-11-18 19:43:14 $ 10 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-11-23 23:54:30 $ 14 12 * 15 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 38 36 #define CHIP_ALLOC_NAME "ChipName" 39 37 #define CELL_ALLOC_NAME "CellName" 38 #define MISC_NUM 32 39 #define MISC_NAME "META00" 40 #define MISC_NAME2 "META01" 41 #define NUM_BIAS_DATA 10 42 #define TEST_NUM_ROWS 32 43 #define TEST_NUM_COLS 32 44 45 psPlaneTransform *PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM() 46 { 47 psPlaneTransform *pt = psPlaneTransformAlloc(1, 1); 48 pt->x->coeff[1][0] = 1.0; 49 pt->y->coeff[0][1] = 1.0; 50 return(pt); 51 } 52 53 psPlaneDistort *PS_CREATE_4D_IDENTITY_PLANE_DISTORT() 54 { 55 psPlaneDistort *pd = psPlaneDistortAlloc(1, 1, 1, 1); 56 pd->x->coeff[1][0][0][0] = 1.0; 57 pd->y->coeff[0][1][0][0] = 1.0; 58 return(pd); 59 } 60 61 /****************************************************************************** 62 generateSimpleFPA(): This function generates a pmFPA data structure and then 63 populates its members with real data. We do this to ensure that the data is 64 later being psFree()'ed correctly. 65 *****************************************************************************/ 66 pmFPA *generateSimpleFPA() 67 { 68 psBool rc; 69 pmFPA* fpa = pmFPAAlloc(psMetadataAlloc()); 70 71 if (fpa == NULL) { 72 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc() returned a NULL."); 73 return(NULL); 74 } 75 76 // 77 // Test and create camera metadata. 78 // 79 if (fpa->camera == NULL) { 80 psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: fpa->camera is NULL."); 81 psFree(fpa); 82 return(NULL); 83 } else { 84 rc = psMetadataAddS32((psMetadata *) fpa->camera, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 85 if (rc == false) { 86 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add metadata to fpa->camera."); 87 psFree(fpa); 88 return(NULL); 89 } 90 psS32 tmpS32 = psMetadataLookupS32(&rc, fpa->camera, MISC_NAME); 91 if ((rc == false) || (tmpS32 != MISC_NUM)) { 92 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not read metadata from fpa->camera."); 93 psFree(fpa); 94 return(NULL); 95 } 96 } 97 98 // 99 // Create various transforms and projections. 100 // 101 fpa->fromTangentPlane = PS_CREATE_4D_IDENTITY_PLANE_DISTORT(); 102 fpa->toTangentPlane = PS_CREATE_4D_IDENTITY_PLANE_DISTORT(); 103 fpa->projection = psProjectionAlloc(0.0,0.0,10.0,10.0,PS_PROJ_TAN); 104 105 // 106 // Ensure fpa concepts metadata was allocated properly. 107 // 108 if (fpa->concepts == NULL) { 109 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set fpa->concepts."); 110 psFree(fpa); 111 return(NULL); 112 } else { 113 rc = psMetadataAddS32(fpa->concepts, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 114 if (rc == false) { 115 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add data to fpa->concepts."); 116 psFree(fpa); 117 return(NULL); 118 } 119 psS32 tmpS32 = psMetadataLookupS32(&rc, fpa->concepts, MISC_NAME); 120 if ((rc == false) || (tmpS32 != MISC_NUM)) { 121 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not read metadata from fpa->concepts."); 122 psFree(fpa); 123 return(NULL); 124 } 125 } 126 127 // 128 // Create ->analysis metadata. 129 // 130 fpa->analysis = psMetadataAlloc(); 131 rc = psMetadataAddS32(fpa->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 132 133 // 134 // We test the fpa->chips array later. 135 // 136 137 // 138 // How to test the p_pmHDU *private member? 139 // 140 141 // 142 // Create ->phu metadata. 143 // 144 fpa->phu = psMetadataAlloc(); 145 rc = psMetadataAddS32(fpa->phu, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 146 147 return(fpa); 148 } 149 40 150 41 151 psS32 main(psS32 argc, char* argv[]) … … 47 157 } 48 158 159 /****************************************************************************** 160 testFPAAlloc() 161 1: We ensure that pmFPAAlloc() properly allocates a pmFPA struct. 162 2: We populate the members with real data to ensure they are being 163 free'ed correctly. 164 *****************************************************************************/ 49 165 static psS32 testFPAAlloc(void) 50 166 { 51 // XXX: Do something more with these arguments. 52 const psMetadata *camera = psMetadataAlloc(); 167 psMetadata *camera = psMetadataAlloc(); 53 168 pmFPA* fpa = pmFPAAlloc(camera); 54 169 55 170 if (fpa == NULL) { 56 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.");171 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc() returned a NULL."); 57 172 return 1; 58 173 } … … 96 211 return 9; 97 212 } 98 99 psFree(fpa); 100 psFree(camera); 101 102 return 0; 213 psFree(fpa); 214 215 // 216 // Populate the pmFPA struct with real data to ensure they were 217 // psFree()'ed correctly. 218 // 219 fpa = generateSimpleFPA(); 220 if (fpa == NULL) { 221 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: generateSimpleFPA() returned NULL."); 222 return(15); 223 } 224 psFree(fpa); 225 226 return(0); 227 } 228 229 /****************************************************************************** 230 generateSimpleChip(): This function generates a pmChip data structure and then 231 populates its members with real data. We do this to ensure that the data is 232 later being psFree()'ed correctly. 233 *****************************************************************************/ 234 pmChip *generateSimpleChip(pmFPA *fpa) 235 { 236 psBool rc; 237 pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME); 238 if (chip == NULL) { 239 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL."); 240 return(NULL); 241 } 242 chip->toFPA = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(); 243 chip->fromFPA = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(); 244 // 245 // We already ensured that chip->concepts was working properly. 246 // 247 248 // 249 // Create ->analysis metadata. 250 // 251 chip->analysis = psMetadataAlloc(); 252 rc = psMetadataAddS32(chip->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 253 254 // 255 // We test the chip->cells array later. 256 // 257 258 // 259 // How to test the p_pmHDU *private member? 260 // 261 262 return(chip); 103 263 } 104 264 105 265 static psS32 testChipAlloc(void) 106 266 { 107 const psMetadata *camera = psMetadataAlloc(); 108 pmFPA* fpa = pmFPAAlloc(camera); 109 if (fpa == NULL) { 110 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL."); 111 return 1; 112 } 113 267 pmFPA* fpa = generateSimpleFPA(); 114 268 pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME); 115 269 if (chip == NULL) { … … 174 328 return 25; 175 329 } 176 177 psFree(fpa); 178 // psFree(chip); 179 psFree(camera); 180 181 return 0; 330 psFree(fpa); 331 332 // 333 // Populate the pmChip struct with real data to ensure they were 334 // psFree()'ed correctly. 335 // 336 fpa = generateSimpleFPA(); 337 chip = generateSimpleChip(fpa); 338 psFree(fpa); 339 340 return(0); 341 } 342 343 /****************************************************************************** 344 generateSimpleCell(): This function generates a pmCell data structure and then 345 populates its members with real data. We do this to ensure that the data is 346 later being psFree()'ed correctly. 347 *****************************************************************************/ 348 pmCell *generateSimpleCell(pmFPA *fpa, pmChip *chip) 349 { 350 psBool rc; 351 pmCell *cell = pmCellAlloc(chip, (psMetadata *) fpa->camera, CELL_ALLOC_NAME); 352 if (cell == NULL) { 353 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL."); 354 return(NULL); 355 } 356 cell->toChip = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(); 357 cell->toFPA = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(); 358 cell->toSky = PS_CREATE_2D_IDENTITY_PLANE_TRANSFORM(); 359 // 360 // We already ensured that cell->concepts was working properly. 361 // 362 363 // 364 // Test camera metadata. 365 // 366 if (cell->camera == NULL) { 367 psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->camera is NULL."); 368 psFree(fpa); 369 return(NULL); 370 } else { 371 rc = psMetadataAddS32((psMetadata *) cell->camera, PS_LIST_HEAD, MISC_NAME2, 0, NULL, MISC_NUM); 372 if (rc == false) { 373 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add metadata to cell->camera."); 374 psFree(fpa); 375 return(NULL); 376 } 377 psS32 tmpS32 = psMetadataLookupS32(&rc, cell->camera, MISC_NAME2); 378 if ((rc == false) || (tmpS32 != MISC_NUM)) { 379 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not read metadata from cell->camera."); 380 psFree(fpa); 381 return(NULL); 382 } 383 } 384 385 // 386 // Create ->analysis metadata. 387 // 388 cell->analysis = psMetadataAlloc(); 389 rc = psMetadataAddS32(cell->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 390 391 // 392 // We test the cell->readouts array later. 393 // 394 395 // 396 // How to test the p_pmHDU *private member? 397 // 398 399 return(cell); 182 400 } 183 401 184 402 static psS32 testCellAlloc(void) 185 403 { 186 const psMetadata *camera = psMetadataAlloc(); 187 pmFPA* fpa = pmFPAAlloc(camera); 188 if (fpa == NULL) { 189 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.n"); 190 return 1; 191 } 192 404 pmFPA* fpa = generateSimpleFPA(); 193 405 pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME); 194 if (chip == NULL) { 195 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.n"); 196 return 2; 197 } 198 199 pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, CELL_ALLOC_NAME); 406 pmCell *cell = pmCellAlloc(chip, (psMetadata *) fpa->camera, CELL_ALLOC_NAME); 200 407 if (cell == NULL) { 201 408 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.n"); … … 240 447 } 241 448 242 if (cell->camera != camera) {449 if (cell->camera != fpa->camera) { 243 450 psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->camera set improperly.\n"); 244 451 return 20; … … 269 476 return 27; 270 477 } 271 272 psFree(fpa); 273 // psFree(chip); 274 // psFree(cell); 275 psFree(camera); 276 277 return 0; 278 } 478 psFree(fpa); 479 480 // 481 // Populate the pmCell struct with real data to ensure they were 482 // psFree()'ed correctly. 483 // 484 fpa = generateSimpleFPA(); 485 chip = generateSimpleChip(fpa); 486 cell = generateSimpleCell(fpa, chip); 487 psFree(fpa); 488 489 return(0); 490 } 491 492 /****************************************************************************** 493 generateSimpleReadout(): This function generates a pmReadout data structure and then 494 populates its members with real data. We do this to ensure that the data is 495 later being psFree()'ed correctly. 496 *****************************************************************************/ 497 pmReadout *generateSimpleReadout(pmFPA *fpa, pmChip *chip, pmCell *cell) 498 { 499 psBool rc; 500 pmReadout *readout = pmReadoutAlloc(cell); 501 if (readout == NULL) { 502 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmReadoutAlloc returned a NULL."); 503 return(NULL); 504 } 505 readout->image = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32); 506 readout->mask = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_U8); 507 readout->weight = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32); 508 509 // 510 // Create a psList of bias data. 511 // 512 for (psS32 i = 0 ; i < NUM_BIAS_DATA ; i++) { 513 psImage *tmpImage = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32); 514 if (readout->bias == NULL) { 515 readout->bias = psListAlloc(tmpImage); 516 } else { 517 psListAdd(readout->bias, PS_LIST_HEAD, tmpImage); 518 } 519 } 520 521 // 522 // Test readout->analysis metadata. 523 // 524 if (readout->analysis == NULL) { 525 psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: readout->analysis is NULL."); 526 psFree(fpa); 527 return(NULL); 528 } else { 529 rc = psMetadataAddS32((psMetadata *) readout->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 530 if (rc == false) { 531 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: could not add metadata to readout->analysis."); 532 psFree(fpa); 533 return(NULL); 534 } 535 } 536 537 return(readout); 538 } 539 279 540 280 541 static psS32 testReadoutAlloc(void) 281 542 { 282 const psMetadata *camera = psMetadataAlloc(); 283 pmFPA* fpa = pmFPAAlloc(camera); 284 285 if (fpa == NULL) { 286 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.\n"); 287 return 1; 288 } 289 290 pmChip *chip = pmChipAlloc(fpa, "ChipName"); 291 if (chip == NULL) { 292 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.\n"); 293 return 2; 294 } 295 296 pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, "CellName"); 297 if (cell == NULL) { 298 psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.\n"); 299 return 3; 300 } 301 543 pmFPA* fpa = generateSimpleFPA(); 544 pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME); 545 pmCell *cell = pmCellAlloc(chip, (psMetadata *) fpa->camera, CELL_ALLOC_NAME); 302 546 pmReadout *readout = pmReadoutAlloc(cell); 303 547 if (readout == NULL) { … … 355 599 return 20; 356 600 } 357 358 psFree(fpa); 359 // psFree(chip); 360 // psFree(cell); 361 // psFree(readout); 362 psFree(camera); 363 364 return 0; 365 } 601 psFree(fpa); 602 603 // 604 // Populate the pmReadout struct with real data to ensure they were 605 // psFree()'ed correctly. 606 // 607 fpa = generateSimpleFPA(); 608 chip = generateSimpleChip(fpa); 609 cell = generateSimpleCell(fpa, chip); 610 readout = generateSimpleReadout(fpa, chip, cell); 611 psFree(fpa); 612 613 return(0); 614 } -
trunk/psModules/test/imsubtract/tst_pmSubtractBias.c
r5552 r5587 25 25 * XXX: Memory leaks are not being detected. 26 26 * 27 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $28 * @date $Date: 2005-11- 19 00:55:18$27 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 28 * @date $Date: 2005-11-23 23:54:30 $ 29 29 * 30 30 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 52 52 }; 53 53 54 psS32 currentId = 0; 55 psS32 memLeaks = 0; // XXX: remove 54 56 55 57 int main(int argc, char* argv[]) … … 67 69 psTraceSetLevel("psSpline1DEval", 0); 68 70 psTraceSetLevel("psSpline1DEvalVector", 0); 71 72 psS32 currentId = psMemGetId(); // XXX: remove 73 psS32 memLeaks = 0; // XXX: remove 74 if (0) { 75 PRINT_MEMLEAKS(0); 76 } 69 77 70 78 return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv); … … 661 669 } 662 670 oAverage/= (psF32) numOverscans; 663 664 665 if (fit == PM_FIT_NONE) { 666 myReadout = pmSubtractBias(myReadout, NULL, PM_FIT_NONE, overscanaxis, 667 stat, nBin, NULL, NULL); 668 } else if (fit == PM_FIT_POLYNOMIAL) { 669 myReadout = pmSubtractBias(myReadout, myPoly, PM_FIT_POLYNOMIAL, overscanaxis, 670 stat, nBin, NULL, NULL); 671 } else if (fit == PM_FIT_SPLINE) { 672 // mySpline = psSpline1DAlloc(); 673 myReadout = pmSubtractBias(myReadout, mySpline, PM_FIT_SPLINE, overscanaxis, 674 stat, nBin, NULL, NULL); 675 } 676 677 for (i=0;i<imageNumRows;i++) { 678 for (j=0;j<imageNumCols;j++) { 679 expect = ((float) (i + j)) - oAverage; 680 actual = myReadout->image->data.F32[i][j]; 681 if (FLT_EPSILON < fabs(expect - actual)) { 682 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 683 testStatus = 1; 684 } else { 685 //printf("COOL: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 671 if (0) { 672 if (fit == PM_FIT_NONE) { 673 myReadout = pmSubtractBias(myReadout, NULL, PM_FIT_NONE, overscanaxis, 674 stat, nBin, NULL, NULL); 675 } else if (fit == PM_FIT_POLYNOMIAL) { 676 myReadout = pmSubtractBias(myReadout, myPoly, PM_FIT_POLYNOMIAL, overscanaxis, 677 stat, nBin, NULL, NULL); 678 } else if (fit == PM_FIT_SPLINE) { 679 // mySpline = psSpline1DAlloc(); 680 myReadout = pmSubtractBias(myReadout, mySpline, PM_FIT_SPLINE, overscanaxis, 681 stat, nBin, NULL, NULL); 682 } 683 if (myReadout == NULL ) { 684 printf("TEST ERROR: pmSubtractBias() returned NULL.\n"); 685 testStatus = 1; 686 } else { 687 for (i=0;i<imageNumRows;i++) { 688 for (j=0;j<imageNumCols;j++) { 689 expect = ((float) (i + j)) - oAverage; 690 actual = myReadout->image->data.F32[i][j]; 691 if (FLT_EPSILON < fabs(expect - actual)) { 692 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 693 testStatus = 1; 694 } else { 695 //printf("GOOD: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 696 } 697 } 686 698 } 687 699 } 688 700 } 689 // XXX: Figure out memory deallocation 701 702 // HEY 690 703 psFree(fpa); 691 // psFree(chip);692 // psFree(cell);693 /*694 psListElem *tmpElem = (psListElem *) myReadout->bias->head;695 while (NULL != tmpElem) {696 psFree((psImage *) tmpElem->data);697 tmpElem = tmpElem->next;698 }699 psFree(myReadout);700 */701 psFree(camera);702 704 psFree(stat); 703 705 psFree(myPoly); … … 1126 1128 } 1127 1129 1128 1129 // This code will
Note:
See TracChangeset
for help on using the changeset viewer.
