Changeset 15987 for trunk/psModules/test/camera/tap_pmFPA.c
- Timestamp:
- Jan 2, 2008, 10:53:30 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/test/camera/tap_pmFPA.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/test/camera/tap_pmFPA.c
r14881 r15987 1 /** @file tst_pmAstrometry.c2 *3 * XXX: Untested: pmFPACheckParents()4 *5 void pmCellFreeReadouts(pmCell *cell)6 void pmCellFreeData(pmCell *cell)7 void pmChipFreeCells(pmChip *chip)8 void pmChipFreeData(pmChip *chip)9 void pmFPAFreeData(pmFPA *fpa)10 void pmReadoutFreeData(pmReadout *readout)11 12 * pmReadout *pmReadoutAlloc(pmCell *cell)13 * pmCell *pmCellAlloc(pmChip *chip, const char *name)14 * pmChip *pmChipAlloc(pmFPA *fpa, const char *name)15 * pmFPA *pmFPAAlloc(const psMetadata *camera)16 17 bool pmFPACheckParents(pmFPA *fpa)18 *19 * @version $Revision: 1.1 $ $Name: not supported by cvs2svn $20 * @date $Date: 2007-09-18 18:57:18 $21 *22 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii23 */24 1 #include <stdio.h> 25 2 #include <string.h> … … 28 5 #include "tap.h" 29 6 #include "pstap.h" 7 /* STATUS: 8 All functions are tested. 9 */ 30 10 31 11 #define CHIP_ALLOC_NAME "ChipName" … … 89 69 psArrayRealloc(cell->readouts, NUM_READOUTS); 90 70 for (int i = 0 ; i < NUM_READOUTS ; i++) { 91 cell->readouts->data[i] = generateSimpleReadout(cell);71 cell->readouts->data[i] = psMemDecrRefCounter((psPtr) generateSimpleReadout(cell)); 92 72 } 93 73 return(cell); … … 108 88 psArrayRealloc(chip->cells, NUM_CELLS); 109 89 for (int i = 0 ; i < NUM_CELLS ; i++) { 110 chip->cells->data[i] = generateSimpleCell(chip);90 chip->cells->data[i] = psMemDecrRefCounter((psPtr) generateSimpleCell(chip)); 111 91 } 112 92 return(chip); … … 129 109 psArrayRealloc(fpa->chips, NUM_CHIPS); 130 110 for (int i = 0 ; i < NUM_CHIPS ; i++) { 131 fpa->chips->data[i] = generateSimpleChip(fpa);111 fpa->chips->data[i] = psMemDecrRefCounter((psPtr) generateSimpleChip(fpa)); 132 112 } 133 113 … … 135 115 } 136 116 137 // XXX: This should only be necessary until the psFree() functions for138 // FPA/chip/cell/readout correctly free all child chips/cells/readouts139 void myFreeCell(pmCell *cell)140 {141 for (int k = 0 ; k < cell->readouts->n ; k++) {142 psFree(cell->readouts->data[k]);143 }144 psFree(cell);145 }146 147 void myFreeChip(pmChip *chip) {148 for (int j = 0 ; j < chip->cells->n ; j++) {149 myFreeCell(chip->cells->data[j]);150 }151 psFree(chip);152 }153 154 void myFreeFPA(pmFPA *fpa)155 {156 for (int i = 0 ; i < fpa->chips->n ; i++) {157 myFreeChip(fpa->chips->data[i]);158 }159 psFree(fpa);160 }161 117 162 118 psS32 main(psS32 argc, char* argv[]) … … 164 120 psLogSetFormat("HLNM"); 165 121 psLogSetLevel(PS_LOG_INFO); 166 plan_tests( 56);122 plan_tests(92); 167 123 168 124 // ------------------------------------------------------------------------ 169 125 // pmFPAAlloc() tests 170 // XXX: Add tests for NULL inputs. 126 // Call pmFPAAlloc() with NULL pmCamera input. 127 { 128 psMemId id = psMemGetId(); 129 pmFPA* fpa = pmFPAAlloc(NULL); 130 ok(fpa != NULL && psMemCheckFPA(fpa), "pmFPAAlloc() returned a non-NULL pmFPA with a NULL pmCamera input"); 131 psFree(fpa); 132 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 133 } 134 135 // Call pmFPAAlloc() with acceptable input parameters. 171 136 { 172 137 psMemId id = psMemGetId(); … … 186 151 psMemCheckArray(fpa->chips), "pmFPAAlloc() set ->chips correctly"); 187 152 ok(fpa->hdu == NULL, "pmFPAAlloc() set ->hdu to NULL"); 188 // ok(fpa->wrote_phu == false, "pmFPAAlloc() set ->wrote_phu to FALSE");189 153 psFree(fpa); 190 154 psFree(camera); … … 192 156 } 193 157 158 194 159 // Populate the pmFPA struct with real data to ensure they were psFree()'ed correctly. 195 160 { 196 161 psMemId id = psMemGetId(); 197 162 pmFPA* fpa = generateSimpleFPA(NULL); 198 199 myFreeFPA(fpa); 200 /* 201 if (1) { 202 for (int i = 0 ; i < fpa->chips->n ; i++) { 203 pmChip *chip = fpa->chips->data[i]; 204 for (int j = 0 ; j < chip->cells->n ; j++) { 205 pmCell *cell = chip->cells->data[j]; 206 for (int k = 0 ; k < cell->readouts->n ; k++) { 207 pmReadout *readout = cell->readouts->data[k]; 208 psFree(readout); 209 } 210 psFree(cell); 211 } 212 psFree(chip); 213 } 214 psFree(fpa); 215 } else { 216 for (int i = 0 ; i < fpa->chips->n ; i++) { 217 pmChip *chip = fpa->chips->data[i]; 218 pmChipFreeCells(chip); 219 pmChipFreeData(chip); 220 psFree(chip); 221 } 222 psFree(fpa); 223 } 224 */ 225 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 226 } 163 psFree(fpa); 164 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Populate the pmFPA struct with real data)"); 165 } 166 227 167 228 168 // ------------------------------------------------------------------------ 229 169 // pmFPAFreeData() tests 230 // XXX: pmFPAAlloc(), pmChipAlloc(), etc, allocate much of the members of 231 // those data structures. We don't really check that those members were 232 // actually psFree()'ed; we merely ensure that they were set to NULL. 233 { 234 psMemId id = psMemGetId(); 235 psMetadata *camera = psMetadataAlloc(); 236 pmFPA* fpa = generateSimpleFPA(camera); 237 // pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME); 238 // pmCell *cell = pmCellAlloc(chip, CELL_ALLOC_NAME); 239 // pmReadout *readout = pmReadoutAlloc(cell); 170 // Call pmFPAFreeData() with NULL pmFPA input parameter 171 { 172 psMemId id = psMemGetId(); 173 pmFPAFreeData(NULL); 174 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmFPAFreeData() with NULL pmFPA input parameter)"); 175 } 176 177 178 // Call pmFPAFreeData() with acceptable input parameters 179 { 180 psMemId id = psMemGetId(); 181 pmFPA* fpa = generateSimpleFPA(NULL); 182 fpa->hdu->images = psArrayAlloc(10); 183 fpa->hdu->weights = psArrayAlloc(10); 184 fpa->hdu->masks = psArrayAlloc(10); 240 185 pmFPAFreeData(fpa); 241 186 ok(fpa->hdu->images == NULL, "pmFPAFreeData() correctly set fpa->hdu->images to NULL"); 242 187 ok(fpa->hdu->weights == NULL, "pmFPAFreeData() correctly set fpa->hdu->weights to NULL"); 243 188 ok(fpa->hdu->masks == NULL, "pmFPAFreeData() correctly set fpa->hdu->masks to NULL"); 244 245 // ok(chip->hdu->images == NULL, "pmFPAFreeData() correctly set chip->hdu->images to NULL"); 246 // ok(chip->hdu->weights == NULL, "pmFPAFreeData() correctly set chip->hdu->weights to NULL"); 247 // ok(chip->hdu->masks == NULL, "pmFPAFreeData() correctly set chip->hdu->masks to NULL"); 248 // ok(cell->hdu->images == NULL, "pmFPAFreeData() correctly set cell->hdu->images to NULL"); 249 // ok(cell->hdu->weights == NULL, "pmFPAFreeData() correctly set cell->hdu->weights to NULL"); 250 // ok(cell->hdu->masks == NULL, "pmFPAFreeData() correctly set cell->hdu->masks to NULL"); 251 psFree(camera); 252 psFree(fpa); 253 // psFree(chip); 254 // psFree(cell); 255 // psFree(readout); 256 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 257 } 258 259 // ------------------------------------------------------------------------ 189 psFree(fpa); 190 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 191 } 192 193 194 // ------------------------------------------------------------------------ 195 // pmChipAlloc() tests 196 // Call pmChipAlloc() with NULL input parameters 197 { 198 psMemId id = psMemGetId(); 199 pmChip *chip = pmChipAlloc(NULL, CHIP_ALLOC_NAME); 200 ok(chip != NULL, "pmChipAlloc() returned non-NULL with NULL pmFPA input parameter"); 201 psFree(chip); 202 pmFPA* fpa = generateSimpleFPA(NULL); 203 chip = pmChipAlloc(fpa, NULL); 204 ok(chip != NULL, "pmChipAlloc() returned non-NULL with NULL chip name input parameter"); 205 psFree(fpa); 206 psFree(chip); 207 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 208 } 209 210 260 211 // pmChipAlloc() tests 261 212 // XXX: Add tests for NULL inputs. 262 213 { 263 214 psMemId id = psMemGetId(); 264 psMetadata *camera = psMetadataAlloc(); 265 pmFPA* fpa = generateSimpleFPA(camera); 215 pmFPA* fpa = generateSimpleFPA(NULL); 266 216 pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME); 267 217 ok(chip != NULL, "pmChipAlloc() returned non-NULL"); … … 280 230 ok(chip->data_exists == false, "pmChipAlloc() set ->data_exists correctly"); 281 231 ok(chip->hdu == NULL, "pmChipAlloc() set ->hdu to NULL"); 282 // ok(chip->wrote_phu == false, "pmChipAlloc() set ->wrote_phu correctly"); 283 psFree(camera); 284 psFree(fpa); 285 psFree(chip); 286 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 287 } 232 psFree(fpa); 233 psFree(chip); 234 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 235 } 236 288 237 289 238 // Populate the pmChip struct with real data to ensure they were free'ed correctly. … … 292 241 pmChip *chip = generateSimpleChip(NULL); 293 242 psFree(chip); 243 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Populate the pmChip struct with real data)"); 244 } 245 246 247 // ------------------------------------------------------------------------ 248 // pmChipFreeData() tests 249 // Call pmChipFreeData() with NULL pmFPA input parameter 250 { 251 psMemId id = psMemGetId(); 252 pmChipFreeData(NULL); 253 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmChipFreeData() with NULL pmFPA input parameter)"); 254 } 255 256 257 // Call pmChipFreeData() with acceptable input parameters 258 { 259 psMemId id = psMemGetId(); 260 pmChip* chip = generateSimpleChip(NULL); 261 chip->hdu->images = psArrayAlloc(10); 262 chip->hdu->weights = psArrayAlloc(10); 263 chip->hdu->masks = psArrayAlloc(10); 264 pmChipFreeData(chip); 265 ok(chip->hdu->images == NULL, "pmChipFreeData() correctly set chip->hdu->images to NULL"); 266 ok(chip->hdu->weights == NULL, "pmChipFreeData() correctly set chip->hdu->weights to NULL"); 267 ok(chip->hdu->masks == NULL, "pmChipFreeData() correctly set chip->hdu->masks to NULL"); 268 psFree(chip); 269 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 270 } 271 272 273 // ------------------------------------------------------------------------ 274 // pmChipFreeCells() tests 275 // Call pmChipFreeCells() with NULL pmFPA input parameter 276 { 277 psMemId id = psMemGetId(); 278 pmChipFreeCells(NULL); 279 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmChipFreeCells() with NULL pmFPA input parameter)"); 280 } 281 282 283 // Call pmChipFreeCells() with acceptable input parameters 284 { 285 psMemId id = psMemGetId(); 286 pmChip* chip = generateSimpleChip(NULL); 287 pmChipFreeCells(chip); 288 ok(chip->cells->n == 0, "pmChipFreeCells() free'ed chip->cells correctly"); 289 psFree(chip); 294 290 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 295 291 } … … 298 294 // ------------------------------------------------------------------------ 299 295 // pmCellAlloc() tests 300 // XXX: Add tests for NULL inputs. 296 // Call pmCellAlloc() with NULL input parameters 297 { 298 psMemId id = psMemGetId(); 299 pmCell *cell = pmCellAlloc(NULL, CELL_ALLOC_NAME); 300 ok(cell != NULL, "pmCellAlloc returned non-NULL with NULL pmChip input parameter"); 301 psFree(cell); 302 303 pmChip *chip = pmChipAlloc(NULL, NULL); 304 cell = pmCellAlloc(chip, NULL); 305 ok(cell != NULL, "pmCellAlloc returned non-NULL with NULL cell name input parameter"); 306 psFree(chip); 307 psFree(cell); 308 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 309 } 310 311 312 // pmCellAlloc() tests 313 // Call pmCellAlloc() with acceptable input parameters 301 314 { 302 315 psMemId id = psMemGetId(); … … 319 332 ok(cell->data_exists == false, "pmCellAlloc() set ->data_exists correctly"); 320 333 ok(cell->hdu == NULL, "pmCellAlloc() set ->hdu to NULL"); 321 // ok(cell->wrote_phu == false, "pmCellAlloc() set ->wrote_phu correctly");322 334 psFree(camera); 323 335 psFree(fpa); … … 326 338 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 327 339 } 340 328 341 329 342 // Populate the pmCell struct with real data to ensure they were … … 333 346 pmCell *cell = generateSimpleCell(NULL); 334 347 psFree(cell); 335 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 336 } 337 338 348 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Populate the pmCell struct with real data)"); 349 } 350 351 352 // ------------------------------------------------------------------------ 353 // pmCellFreeData() tests 354 // Call pmCellFreeData() with NULL pmFPA input parameter 355 { 356 psMemId id = psMemGetId(); 357 pmCellFreeData(NULL); 358 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmCellFreeData() with NULL pmFPA input parameter)"); 359 } 360 361 362 // Call pmCellFreeData() with acceptable input parameters 363 { 364 psMemId id = psMemGetId(); 365 pmCell *cell = generateSimpleCell(NULL); 366 cell->hdu->images = psArrayAlloc(10); 367 cell->hdu->weights = psArrayAlloc(10); 368 cell->hdu->masks = psArrayAlloc(10); 369 pmCellFreeData(cell); 370 ok(cell->hdu->images == NULL, "pmCellFreeData() correctly set cell->hdu->images to NULL"); 371 ok(cell->hdu->weights == NULL, "pmCellFreeData() correctly set cell->hdu->weights to NULL"); 372 ok(cell->hdu->masks == NULL, "pmCellFreeData() correctly set cell->hdu->masks to NULL"); 373 psFree(cell); 374 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 375 } 376 377 378 // ------------------------------------------------------------------------ 339 379 // test pmCellFreeReadouts() 340 380 { … … 350 390 // ------------------------------------------------------------------------ 351 391 // pmReadoutAlloc() tests 352 // XXX: Add tests for NULL inputs. 392 // Call pmReadoutAlloc() with NULL input parameters 393 { 394 psMemId id = psMemGetId(); 395 pmReadout *readout = pmReadoutAlloc(NULL); 396 ok(readout != NULL, "pmReadoutAlloc() returned non-NULL with NULL pmCell input parameter"); 397 psFree(readout); 398 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 399 } 400 401 402 // Call pmReadoutAlloc() with acceptable parameters 353 403 { 354 404 psMemId id = psMemGetId(); … … 380 430 } 381 431 432 382 433 // Populate the pmReadout struct with real data to ensure they were 383 434 // psFree()'ed correctly. … … 390 441 } 391 442 392 /* 393 { 394 psMemId id = psMemGetId(); 395 pmReadout *readout = pmReadoutAlloc(NULL); 396 readout->image = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32); 397 readout->mask = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_U8); 398 readout->weight = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32); 399 for (psS32 i = 0 ; i < NUM_BIAS_DATA ; i++) { 400 psImage *tmpImage = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32); 401 psListAdd(readout->bias, PS_LIST_HEAD, tmpImage); 402 } 403 psMetadataAddS32(readout->analysis, PS_LIST_HEAD, MISC_NAME, 0, NULL, MISC_NUM); 404 return(readout); 405 } 406 */ 407 408 409 } 443 444 // ------------------------------------------------------------------------ 445 // pmReadoutFreeData() tests 446 // Call pmReadoutFreeData() with NULL pmFPA input parameter 447 { 448 psMemId id = psMemGetId(); 449 pmReadoutFreeData(NULL); 450 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks (Call pmReadoutFreeData() with NULL pmFPA input parameter)"); 451 } 452 453 454 // Call pmReadoutFreeData() with acceptable input parameters 455 { 456 psMemId id = psMemGetId(); 457 pmReadout *readout = generateSimpleReadout(NULL); 458 pmReadoutFreeData(readout); 459 ok(readout->image == NULL, "pmReadoutFreeData() correctly set readout->image to NULL"); 460 ok(readout->weight == NULL, "pmReadoutFreeData() correctly set readout->weight to NULL"); 461 ok(readout->mask == NULL, "pmReadoutFreeData() correctly set readout->mask to NULL"); 462 psFree(readout); 463 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 464 } 465 466 467 // ------------------------------------------------------------------------ 468 // pmFPACheckParents() tests 469 // psBool pmFPACheckParents(pmFPA *fpa) 470 // Call pmFPACheckParents() with NULL pmFPA input parameter 471 { 472 psMemId id = psMemGetId(); 473 bool rc = pmFPACheckParents(NULL); 474 ok(rc == false, "pmFPACheckParents() returned FALSE with NULL pmFPA input parameter"); 475 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 476 } 477 478 479 // pmFPACheckParents() tests 480 // Call pmFPACheckParents() with acceptable input parameters 481 { 482 psMemId id = psMemGetId(); 483 pmFPA* fpa = generateSimpleFPA(NULL); 484 bool rc = pmFPACheckParents(fpa); 485 ok(rc == true, "pmFPACheckParents() returned FALSE with acceptable input parameters"); 486 psFree(fpa); 487 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 488 } 489 490 }
Note:
See TracChangeset
for help on using the changeset viewer.
