00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include <config.h>
00034 #endif
00035
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <assert.h>
00039 #include <cpl.h>
00040
00041
00042 #include "irplib_plugin.h"
00043
00044
00054
00055
00056
00057
00058
00059
00060
00061 #ifndef LINE_LEN_MAX
00062 #define LINE_LEN_MAX 1024
00063 #endif
00064
00065
00066 #define DEV_RANDOM "/dev/urandom"
00067
00068
00069 #define recipe_assert(bool) \
00070 ((bool) ? (cpl_msg_debug(cpl_func, \
00071 "OK in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s",__LINE__, \
00072 cpl_error_get_message(), cpl_error_get_where(), #bool), 0) \
00073 : (cpl_msg_error(cpl_func, \
00074 "Failure in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s", \
00075 __LINE__, cpl_error_get_message(), cpl_error_get_where(), #bool), 1))
00076
00077
00078
00079
00080
00081
00082
00083 static const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist *,
00084 const char *,
00085 const char *,
00086 const char *);
00087
00088 static void recipe_msg_set_level_from_env(void);
00089 static void recipe_parameterlist_set_defaults(cpl_parameterlist *);
00090 static void recipe_frameset_load(cpl_frameset *, const char *);
00091
00092 static int recipe_sof_test_random(cpl_plugin *, size_t, const char *[]);
00093 static int recipe_sof_test_image_empty(cpl_plugin *, size_t, const char *[]);
00094 static int recipe_sof_test_local(cpl_plugin *);
00095 static int recipe_sof_test_from_env(cpl_plugin *);
00096 static void recipe_frameset_empty(cpl_frameset *);
00097
00098 static cpl_errorstate inistate;
00099
00102
00103
00104
00105
00106
00116
00117 const char * irplib_parameterlist_get_string(const cpl_parameterlist * self,
00118 const char * instrume,
00119 const char * recipe,
00120 const char * parameter)
00121 {
00122
00123 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00124 recipe, parameter);
00125 const char * value;
00126
00127 cpl_ensure(par != NULL, cpl_error_get_code(), NULL);
00128
00129 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_STRING,
00130 CPL_ERROR_TYPE_MISMATCH, NULL);
00131
00132 value = cpl_parameter_get_string(par);
00133
00134 cpl_ensure(value != NULL, cpl_error_get_code(), NULL);
00135
00136 return value;
00137
00138 }
00139
00140
00150
00151 cpl_boolean irplib_parameterlist_get_bool(const cpl_parameterlist * self,
00152 const char * instrume,
00153 const char * recipe,
00154 const char * parameter)
00155 {
00156
00157 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00158 recipe, parameter);
00159 cpl_errorstate prestate = cpl_errorstate_get();
00160 cpl_boolean value;
00161
00162 cpl_ensure(par != NULL, cpl_error_get_code(), CPL_FALSE);
00163
00164 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_BOOL,
00165 CPL_ERROR_TYPE_MISMATCH, CPL_FALSE);
00166
00167 value = cpl_parameter_get_bool(par);
00168
00169 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00170
00171 return value;
00172
00173 }
00174
00175
00176
00186
00187 int irplib_parameterlist_get_int(const cpl_parameterlist * self,
00188 const char * instrume,
00189 const char * recipe,
00190 const char * parameter)
00191 {
00192
00193 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00194 recipe, parameter);
00195 cpl_errorstate prestate = cpl_errorstate_get();
00196 int value;
00197
00198 cpl_ensure(par != NULL, cpl_error_get_code(), 0);
00199
00200 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_INT,
00201 CPL_ERROR_TYPE_MISMATCH, 0);
00202
00203 value = cpl_parameter_get_int(par);
00204
00205 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00206
00207 return value;
00208 }
00209
00210
00220
00221 double irplib_parameterlist_get_double(const cpl_parameterlist * self,
00222 const char * instrume,
00223 const char * recipe,
00224 const char * parameter)
00225 {
00226
00227 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00228 recipe, parameter);
00229 cpl_errorstate prestate = cpl_errorstate_get();
00230 double value;
00231
00232 cpl_ensure(par != NULL, cpl_error_get_code(), 0.0);
00233
00234 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_DOUBLE,
00235 CPL_ERROR_TYPE_MISMATCH, 0.0);
00236
00237 value = cpl_parameter_get_double(par);
00238
00239 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00240
00241 return value;
00242 }
00243
00244
00258
00259 cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist * self,
00260 const char * instrume,
00261 const char * recipe,
00262 const char * parameter,
00263 const char * defvalue,
00264 const char * alias,
00265 const char * context,
00266 const char * man)
00267 {
00268
00269 cpl_error_code error;
00270 cpl_parameter * par;
00271 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00272 parameter);
00273
00274 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00275
00276 par = cpl_parameter_new_value(paramname, CPL_TYPE_STRING, man, context,
00277 defvalue);
00278 cpl_free(paramname);
00279
00280 cpl_ensure_code(par != NULL, cpl_error_get_code());
00281
00282 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00283 cpl_ensure_code(!error, error);
00284
00285 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00286 cpl_ensure_code(!error, error);
00287
00288 error = cpl_parameterlist_append(self, par);
00289 cpl_ensure_code(!error, error);
00290
00291 return CPL_ERROR_NONE;
00292 }
00293
00294
00295
00309
00310 cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist * self,
00311 const char * instrume,
00312 const char * recipe,
00313 const char * parameter,
00314 cpl_boolean defvalue,
00315 const char * alias,
00316 const char * context,
00317 const char * man)
00318 {
00319
00320 cpl_error_code error;
00321 cpl_parameter * par;
00322 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00323 parameter);
00324
00325 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00326
00327 par = cpl_parameter_new_value(paramname, CPL_TYPE_BOOL, man, context,
00328 defvalue);
00329 cpl_free(paramname);
00330
00331 cpl_ensure_code(par != NULL, cpl_error_get_code());
00332
00333 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00334 cpl_ensure_code(!error, error);
00335
00336 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00337 cpl_ensure_code(!error, error);
00338
00339 error = cpl_parameterlist_append(self, par);
00340 cpl_ensure_code(!error, error);
00341
00342 return CPL_ERROR_NONE;
00343 }
00344
00345
00346
00347
00361
00362 cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist * self,
00363 const char * instrume,
00364 const char * recipe,
00365 const char * parameter,
00366 int defvalue,
00367 const char * alias,
00368 const char * context,
00369 const char * man)
00370 {
00371
00372 cpl_error_code error;
00373 cpl_parameter * par;
00374 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00375 parameter);
00376
00377 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00378
00379 par = cpl_parameter_new_value(paramname, CPL_TYPE_INT, man, context,
00380 defvalue);
00381 cpl_free(paramname);
00382
00383 cpl_ensure_code(par != NULL, cpl_error_get_code());
00384
00385 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00386 cpl_ensure_code(!error, error);
00387
00388 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00389 cpl_ensure_code(!error, error);
00390
00391 error = cpl_parameterlist_append(self, par);
00392 cpl_ensure_code(!error, error);
00393
00394 return CPL_ERROR_NONE;
00395 }
00396
00397
00398
00412
00413 cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist * self,
00414 const char * instrume,
00415 const char * recipe,
00416 const char * parameter,
00417 double defvalue,
00418 const char * alias,
00419 const char * context,
00420 const char * man)
00421 {
00422
00423 cpl_error_code error;
00424 cpl_parameter * par;
00425 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00426 parameter);
00427
00428 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00429
00430 par = cpl_parameter_new_value(paramname, CPL_TYPE_DOUBLE, man, context,
00431 defvalue);
00432 cpl_free(paramname);
00433
00434 cpl_ensure_code(par != NULL, cpl_error_get_code());
00435
00436 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00437 cpl_ensure_code(!error, error);
00438
00439 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00440 cpl_ensure_code(!error, error);
00441
00442 error = cpl_parameterlist_append(self, par);
00443 cpl_ensure_code(!error, error);
00444
00445 return CPL_ERROR_NONE;
00446 }
00447
00448
00449
00461
00462 int irplib_plugin_test(cpl_pluginlist * self, size_t nstr, const char *astr[]) {
00463
00464 cpl_plugin * plugin;
00465 cpl_recipe * recipe;
00466 int (*recipe_create) (cpl_plugin *);
00467 int (*recipe_exec ) (cpl_plugin *);
00468 int (*recipe_deinit) (cpl_plugin *);
00469 const cpl_msg_severity msg_level = cpl_msg_get_level();
00470
00471 int recipe_nfail = 0;
00472 cpl_errorstate prestate;
00473 cpl_boolean is_debug;
00474
00475
00476 cpl_msg_set_level(CPL_MSG_OFF);
00477 recipe_msg_set_level_from_env();
00478
00479 is_debug = cpl_msg_get_level() <= CPL_MSG_DEBUG ? CPL_TRUE : CPL_FALSE;
00480
00481 inistate = cpl_errorstate_get();
00482
00483 assert( nstr == 0 || astr != NULL );
00484
00485 plugin = cpl_pluginlist_get_first(self);
00486
00487 if (plugin == NULL) {
00488 cpl_msg_warning(cpl_func, "With an empty pluginlist, "
00489 "no tests can be made");
00490 cpl_msg_set_level(msg_level);
00491 return 0;
00492 }
00493
00494 if (is_debug) cpl_plugin_dump(plugin, stdout);
00495
00496 recipe_create = cpl_plugin_get_init(plugin);
00497 recipe_exec = cpl_plugin_get_exec(plugin);
00498 recipe_deinit = cpl_plugin_get_deinit(plugin);
00499
00500
00501 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00502 cpl_msg_warning(cpl_func, "This plugin is not of type recipe, "
00503 "cannot test further");
00504 cpl_msg_set_level(msg_level);
00505 return 0;
00506 }
00507
00508 recipe_nfail += recipe_assert( recipe_create(plugin) == 0);
00509
00510 recipe = (cpl_recipe *) plugin;
00511
00512 recipe_nfail += recipe_assert( recipe->parameters != NULL);
00513
00514 recipe_parameterlist_set_defaults(recipe->parameters);
00515
00516 if (is_debug) cpl_parameterlist_dump(recipe->parameters, stdout);
00517
00518 recipe->frames = cpl_frameset_new();
00519
00520 cpl_msg_info(cpl_func,"Checking handling of pre-existing CPL error state - "
00521 "may produce warning(s)/error(s):");
00522 cpl_error_set(cpl_func, CPL_ERROR_UNSPECIFIED);
00523 prestate = cpl_errorstate_get();
00524
00525 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00526
00527 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_UNSPECIFIED );
00528
00529 if (!cpl_errorstate_is_equal(prestate)) {
00530 recipe_nfail += recipe_assert( cpl_errorstate_is_equal(prestate) );
00531 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
00532 cpl_msg_debug(cpl_func, "Resetting error state");
00533 cpl_errorstate_set(prestate);
00534 }
00535
00536 cpl_errorstate_set(inistate);
00537
00538 cpl_msg_info(cpl_func,"Checking handling of empty frameset - "
00539 "may produce warning(s)/error(s):");
00540
00541 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00542
00543 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00544
00545 if (cpl_errorstate_is_equal(inistate)) {
00546 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00547 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00548 } else if (is_debug) {
00549 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00550 }
00551 cpl_msg_debug(cpl_func, "Resetting error state");
00552 cpl_errorstate_set(inistate);
00553
00554 cpl_msg_info(cpl_func,"Checking handling of dummy frameset - "
00555 "may produce warning(s)/error(s):");
00556 do {
00557 cpl_frame * f = cpl_frame_new();
00558 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, "/dev/null") == 0);
00559 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, "RECIPE_DUMMY_TAG") == 0);
00560 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00561
00562 if (!cpl_errorstate_is_equal(inistate)) {
00563 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
00564 cpl_msg_debug(cpl_func, "Resetting error state");
00565 cpl_errorstate_set(inistate);
00566 }
00567
00568
00569 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00570
00571 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00572
00573 if (cpl_errorstate_is_equal(inistate)) {
00574 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00575 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00576 } else if (is_debug) {
00577 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00578 }
00579 cpl_msg_debug(cpl_func, "Resetting error state");
00580 cpl_errorstate_set(inistate);
00581
00582 recipe_nfail += recipe_assert( cpl_frameset_erase_frame(recipe->frames, f)
00583 == CPL_ERROR_NONE );
00584
00585 } while (0);
00586
00587 recipe_nfail += recipe_sof_test_random(plugin, nstr, astr);
00588
00589 recipe_nfail += recipe_sof_test_image_empty(plugin, nstr, astr);
00590
00591 recipe_nfail += recipe_sof_test_local(plugin);
00592
00593 recipe_nfail += recipe_sof_test_from_env(plugin);
00594
00595 cpl_frameset_delete(recipe->frames);
00596
00597 recipe_nfail += recipe_assert( recipe_deinit(plugin) == 0 );
00598
00599 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00600
00601 if (recipe_nfail) cpl_msg_error(cpl_func, "%d test(s) failed", recipe_nfail);
00602
00603 cpl_msg_set_level(msg_level);
00604 return recipe_nfail;
00605 }
00606
00609
00626
00627 static void recipe_msg_set_level_from_env(void)
00628 {
00629
00630 const char * level = getenv("RECIPE_MSG_LEVEL");
00631
00632 if (level == NULL) return;
00633
00634 if (!strcmp(level, "debug"))
00635 cpl_msg_set_level(CPL_MSG_DEBUG);
00636 else if (!strcmp(level, "info"))
00637 cpl_msg_set_level(CPL_MSG_INFO);
00638 else if (!strcmp(level, "warning"))
00639 cpl_msg_set_level(CPL_MSG_WARNING);
00640 else if (!strcmp(level, "error"))
00641 cpl_msg_set_level(CPL_MSG_ERROR);
00642 else if (!strcmp(level, "off"))
00643 cpl_msg_set_level(CPL_MSG_OFF);
00644
00645 return;
00646
00647 }
00648
00649
00650
00651
00661
00662 static void recipe_parameterlist_set_defaults(cpl_parameterlist *parlist)
00663 {
00664
00665 cpl_parameter * p = cpl_parameterlist_get_first(parlist);
00666
00667 for (; p != NULL; p = cpl_parameterlist_get_next(parlist)) {
00668
00669 if (cpl_parameter_get_default_flag(p)) continue;
00670
00671 cpl_msg_debug(cpl_func, __FILE__ " line %u: OK", __LINE__);
00672
00673 switch (cpl_parameter_get_type(p)) {
00674 case CPL_TYPE_BOOL:
00675 cpl_parameter_set_bool(p, cpl_parameter_get_default_bool(p));
00676 break;
00677 case CPL_TYPE_INT:
00678 cpl_parameter_set_int(p, cpl_parameter_get_default_int(p));
00679 break;
00680 case CPL_TYPE_DOUBLE:
00681 cpl_parameter_set_double(p, cpl_parameter_get_default_double(p));
00682 break;
00683 case CPL_TYPE_STRING:
00684 {
00685 const char * s_default = cpl_parameter_get_default_string(p);
00686
00687 cpl_parameter_set_string(p, s_default != NULL ? s_default : "");
00688 break;
00689 }
00690
00691 default:
00692 assert( 0 );
00693 }
00694 }
00695 }
00696
00697
00698
00705
00706 static int recipe_sof_test_random(cpl_plugin * plugin, size_t nstr,
00707 const char *astr[])
00708 {
00709 cpl_recipe * recipe = (cpl_recipe*)plugin;
00710
00711 int (*recipe_exec) (cpl_plugin *);
00712
00713
00714 int recipe_nfail = 0;
00715 size_t i;
00716
00717
00718 if (nstr < 1) return recipe_nfail;
00719
00720 cpl_msg_info(cpl_func, "Testing recipe with %u " DEV_RANDOM " as input ",
00721 (unsigned)nstr);
00722
00723 for (i = 0; i < nstr; i++) {
00724 cpl_frame * f = cpl_frame_new();
00725
00726 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, DEV_RANDOM) == 0);
00727 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, astr[i]) == 0);
00728 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00729 }
00730
00731 recipe_exec = cpl_plugin_get_exec(plugin);
00732
00733 if (!cpl_errorstate_is_equal(inistate)) {
00734 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00735 cpl_msg_debug(cpl_func, "Resetting error state");
00736 cpl_errorstate_set(inistate);
00737 }
00738
00739
00740 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00741
00742 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00743
00744 if (cpl_errorstate_is_equal(inistate)) {
00745 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00746 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00747 } else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
00748 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00749 }
00750 cpl_msg_debug(cpl_func, "Resetting error state");
00751 cpl_errorstate_set(inistate);
00752
00753 recipe_frameset_empty(recipe->frames);
00754
00755 return recipe_nfail;
00756 }
00757
00758
00759
00766
00767 static int recipe_sof_test_image_empty(cpl_plugin * plugin, size_t nstr,
00768 const char *astr[])
00769 {
00770 cpl_recipe * recipe = (cpl_recipe*)plugin;
00771
00772 int (*recipe_exec) (cpl_plugin *);
00773
00774
00775 int recipe_nfail = 0;
00776 size_t i;
00777 cpl_frame * frame;
00778 cpl_image * iempty;
00779
00780
00781 if (nstr < 1) return recipe_nfail;
00782
00783 cpl_msg_info(cpl_func, "Testing recipe with %u empty images as input ",
00784 (unsigned)nstr);
00785
00786 iempty = cpl_image_new(13, 17, CPL_TYPE_FLOAT);
00787
00788 for (i = 0; i < nstr; i++) {
00789 cpl_frame * f = cpl_frame_new();
00790 char * rawname = cpl_sprintf("raw%05u.fits", (unsigned)(i+1));
00791
00792 recipe_nfail += recipe_assert( cpl_image_save(iempty, rawname,
00793 CPL_BPP_IEEE_FLOAT, NULL,
00794 CPL_IO_DEFAULT) == 0);
00795
00796 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, rawname) == 0);
00797 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, astr[i]) == 0);
00798 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00799
00800 cpl_free(rawname);
00801 }
00802 cpl_image_delete(iempty);
00803
00804 recipe_exec = cpl_plugin_get_exec(plugin);
00805
00806 if (!cpl_errorstate_is_equal(inistate)) {
00807 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00808 cpl_msg_debug(cpl_func, "Resetting error state");
00809 cpl_errorstate_set(inistate);
00810 }
00811
00812
00813 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00814
00815 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00816
00817 if (cpl_errorstate_is_equal(inistate)) {
00818 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00819 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00820 } else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
00821 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00822 }
00823 cpl_msg_debug(cpl_func, "Resetting error state");
00824 cpl_errorstate_set(inistate);
00825
00826 for (frame = cpl_frameset_get_first(recipe->frames); frame != NULL;
00827 frame = cpl_frameset_get_first(recipe->frames))
00828 {
00829 recipe_nfail +=
00830 recipe_assert( remove(cpl_frame_get_filename(frame)) == 0);
00831 cpl_frameset_erase_frame(recipe->frames, frame);
00832 }
00833
00834 return recipe_nfail;
00835 }
00836
00837
00838
00845
00846 static int recipe_sof_test_from_env(cpl_plugin * plugin)
00847 {
00848 cpl_recipe * recipe = (cpl_recipe*)plugin;
00849 const char * recipename = cpl_plugin_get_name(plugin);
00850 const char * var_name = "RECIPE_SOF_PATH";
00851 const char * sof_path = getenv(var_name);
00852
00853
00854 int recipe_nfail = 0;
00855
00856 char * sof_name;
00857
00858 if (sof_path == NULL) {
00859 cpl_msg_warning(cpl_func, "Environment variable %s is unset: "
00860 "No SOFs to check", var_name);
00861 return recipe_nfail;
00862 }
00863
00864 cpl_msg_debug(cpl_func, "Checking for SOFs in %s", sof_path);
00865
00866 if (recipename == NULL) {
00867 recipe_nfail += recipe_assert(recipename != NULL);
00868 return recipe_nfail;
00869 }
00870
00871 sof_name = cpl_sprintf("%s/%s.sof", sof_path, recipename);
00872
00873 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00874
00875 recipe_frameset_load(recipe->frames, sof_name);
00876
00877 if (!cpl_frameset_is_empty(recipe->frames)) {
00878
00879 int (*recipe_exec ) (cpl_plugin *);
00880
00881 recipe_exec = cpl_plugin_get_exec(plugin);
00882
00883 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00884 recipe_nfail += recipe_assert( recipe_exec(plugin) == 0 );
00885 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00886
00887 if (!cpl_errorstate_is_equal(inistate)) {
00888 recipe_nfail += recipe_assert( cpl_errorstate_is_equal(inistate) );
00889 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00890 cpl_msg_debug(cpl_func, "Resetting error state");
00891 cpl_errorstate_set(inistate);
00892 }
00893
00894 recipe_frameset_empty(recipe->frames);
00895 }
00896
00897 cpl_free(sof_name);
00898
00899 return recipe_nfail;
00900 }
00901
00902
00903
00904
00911
00912 static int recipe_sof_test_local(cpl_plugin * plugin)
00913 {
00914 cpl_recipe * recipe = (cpl_recipe*)plugin;
00915 const char * recipename = cpl_plugin_get_name(plugin);
00916
00917
00918 int recipe_nfail = 0;
00919
00920 char * sof_name = cpl_sprintf("%s.sof", recipename);
00921
00922 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00923
00924 recipe_frameset_load(recipe->frames, sof_name);
00925
00926 if (!cpl_frameset_is_empty(recipe->frames)) {
00927
00928 int (*recipe_exec ) (cpl_plugin *);
00929
00930 recipe_exec = cpl_plugin_get_exec(plugin);
00931
00932 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00933 recipe_nfail += recipe_assert( recipe_exec(plugin) == 0 );
00934 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00935
00936 recipe_nfail
00937 += recipe_assert( cpl_dfs_update_product_header(recipe->frames)
00938 == CPL_ERROR_NONE );
00939
00940 if (!cpl_errorstate_is_equal(inistate)) {
00941 recipe_nfail += recipe_assert( cpl_errorstate_is_equal(inistate) );
00942 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00943 cpl_msg_debug(cpl_func, "Resetting error state");
00944 cpl_errorstate_set(inistate);
00945 }
00946
00947 recipe_frameset_empty(recipe->frames);
00948 }
00949
00950 cpl_free(sof_name);
00951
00952 return recipe_nfail;
00953 }
00954
00955
00956
00957
00958
00972
00973
00974 static void recipe_frameset_load(cpl_frameset * set, const char *name)
00975 {
00976
00977 FILE *fp;
00978 char line[LINE_LEN_MAX];
00979 char path[LINE_LEN_MAX], group[LINE_LEN_MAX], tag[LINE_LEN_MAX];
00980 int line_number;
00981
00982 assert( set != NULL );
00983 assert( name != NULL );
00984
00985 fp = fopen(name, "r");
00986 if (fp == NULL) {
00987 cpl_msg_debug(cpl_func, "Unable to open SOF file '%s'", name);
00988 return;
00989 }
00990
00991
00992 for (line_number = 0; fgets(line, LINE_LEN_MAX - 1, fp); line_number++) {
00993
00994 cpl_frame_group grp;
00995 cpl_frame * frame;
00996 int n;
00997
00998 if (line[0] == '#') continue;
00999
01000 n = sscanf(line, "%s %s %s", path, tag, group);
01001
01002 if (n < 1) {
01003 cpl_msg_warning(cpl_func, "Spurious line no. %d in %s: %s",
01004 line_number, name, line);
01005 break;
01006 }
01007
01008
01009 frame = cpl_frame_new();
01010
01011
01012 cpl_frame_set_filename(frame, path);
01013
01014
01015 cpl_frame_set_tag(frame, n == 1 ? "" : tag);
01016
01017 cpl_frameset_insert(set, frame);
01018
01019
01020 if (n < 3) continue;
01021
01022 if (!strcmp(group, CPL_FRAME_GROUP_RAW_ID))
01023 grp = CPL_FRAME_GROUP_RAW;
01024 else if (!strcmp(group, CPL_FRAME_GROUP_CALIB_ID))
01025 grp = CPL_FRAME_GROUP_CALIB;
01026 else if (!strcmp(group, CPL_FRAME_GROUP_PRODUCT_ID))
01027 grp = CPL_FRAME_GROUP_PRODUCT;
01028 else
01029 grp = CPL_FRAME_GROUP_NONE;
01030
01031 cpl_frame_set_group(frame, grp);
01032 }
01033
01034 fclose(fp);
01035
01036 return;
01037
01038 }
01039
01040
01041
01051
01052 static const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist
01053 * self,
01054 const char * instrume,
01055 const char * recipe,
01056 const char * parameter)
01057 {
01058
01059 const cpl_parameter * par;
01060 char * paramname;
01061
01062
01063 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
01064 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, NULL);
01065 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, NULL);
01066 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, NULL);
01067
01068 paramname = cpl_sprintf("%s.%s.%s", instrume, recipe, parameter);
01069
01070 cpl_ensure(paramname != NULL, cpl_error_get_code(), NULL);
01071
01072 par = cpl_parameterlist_find_const(self, paramname);
01073
01074 cpl_free(paramname);
01075
01076 return par;
01077
01078 }
01079
01080
01081
01107
01108 static void recipe_frameset_empty(cpl_frameset * self)
01109 {
01110 cpl_frame * f;
01111
01112 if (self == NULL) {
01113 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
01114 return;
01115 }
01116
01117 for (f = cpl_frameset_get_first(self); f != NULL;
01118 f = cpl_frameset_get_first(self))
01119 {
01120 cpl_frameset_erase_frame(self, f);
01121 }
01122 }