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_parameterlist_set_defaults(cpl_parameterlist *);
00089 static void recipe_frameset_load(cpl_frameset *, const char *);
00090
00091 static int recipe_sof_test_random(cpl_plugin *, size_t, const char *[]);
00092 static int recipe_sof_test_image_empty(cpl_plugin *, size_t, const char *[]);
00093 static int recipe_sof_test_local(cpl_plugin *);
00094 static int recipe_sof_test_from_env(cpl_plugin *);
00095 static void recipe_frameset_empty(cpl_frameset *);
00096
00097 static cpl_errorstate inistate;
00098
00101
00102
00103
00104
00105
00115
00116 const char * irplib_parameterlist_get_string(const cpl_parameterlist * self,
00117 const char * instrume,
00118 const char * recipe,
00119 const char * parameter)
00120 {
00121
00122 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00123 recipe, parameter);
00124 const char * value;
00125
00126 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00127 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00128 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00129 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00130
00131 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(NULL),
00132 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00133 parameter);
00134
00135 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_STRING,
00136 CPL_ERROR_TYPE_MISMATCH, NULL);
00137
00138 value = cpl_parameter_get_string(par);
00139
00140 cpl_ensure(value != NULL, cpl_error_get_code(), NULL);
00141
00142 return value;
00143
00144 }
00145
00146
00156
00157 cpl_boolean irplib_parameterlist_get_bool(const cpl_parameterlist * self,
00158 const char * instrume,
00159 const char * recipe,
00160 const char * parameter)
00161 {
00162
00163 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00164 recipe, parameter);
00165 cpl_errorstate prestate = cpl_errorstate_get();
00166 cpl_boolean value;
00167
00168 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00169 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00170 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00171 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00172
00173 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(CPL_FALSE),
00174 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00175 parameter);
00176
00177 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_BOOL,
00178 CPL_ERROR_TYPE_MISMATCH, CPL_FALSE);
00179
00180 value = cpl_parameter_get_bool(par);
00181
00182 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00183
00184 return value;
00185
00186 }
00187
00188
00189
00199
00200 int irplib_parameterlist_get_int(const cpl_parameterlist * self,
00201 const char * instrume,
00202 const char * recipe,
00203 const char * parameter)
00204 {
00205
00206 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00207 recipe, parameter);
00208 cpl_errorstate prestate = cpl_errorstate_get();
00209 int value;
00210
00211 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00212 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00213 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00214 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00215
00216 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(0),
00217 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00218 parameter);
00219
00220 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_INT,
00221 CPL_ERROR_TYPE_MISMATCH, 0);
00222
00223 value = cpl_parameter_get_int(par);
00224
00225 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00226
00227 return value;
00228 }
00229
00230
00240
00241 double irplib_parameterlist_get_double(const cpl_parameterlist * self,
00242 const char * instrume,
00243 const char * recipe,
00244 const char * parameter)
00245 {
00246
00247 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00248 recipe, parameter);
00249 cpl_errorstate prestate = cpl_errorstate_get();
00250 double value;
00251
00252 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00253 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00254 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00255 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00256
00257 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(0.0),
00258 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00259 parameter);
00260
00261 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_DOUBLE,
00262 CPL_ERROR_TYPE_MISMATCH, 0.0);
00263
00264 value = cpl_parameter_get_double(par);
00265
00266 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00267
00268 return value;
00269 }
00270
00271
00285
00286 cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist * self,
00287 const char * instrume,
00288 const char * recipe,
00289 const char * parameter,
00290 const char * defvalue,
00291 const char * alias,
00292 const char * context,
00293 const char * man)
00294 {
00295
00296 cpl_error_code error;
00297 cpl_parameter * par;
00298 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00299 parameter);
00300
00301 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00302
00303 par = cpl_parameter_new_value(paramname, CPL_TYPE_STRING, man, context,
00304 defvalue);
00305 cpl_free(paramname);
00306
00307 cpl_ensure_code(par != NULL, cpl_error_get_code());
00308
00309 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00310 cpl_ensure_code(!error, error);
00311
00312 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00313 cpl_ensure_code(!error, error);
00314
00315 error = cpl_parameterlist_append(self, par);
00316 cpl_ensure_code(!error, error);
00317
00318 return CPL_ERROR_NONE;
00319 }
00320
00321
00322
00336
00337 cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist * self,
00338 const char * instrume,
00339 const char * recipe,
00340 const char * parameter,
00341 cpl_boolean defvalue,
00342 const char * alias,
00343 const char * context,
00344 const char * man)
00345 {
00346
00347 cpl_error_code error;
00348 cpl_parameter * par;
00349 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00350 parameter);
00351
00352 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00353
00354 par = cpl_parameter_new_value(paramname, CPL_TYPE_BOOL, man, context,
00355 defvalue);
00356 cpl_free(paramname);
00357
00358 cpl_ensure_code(par != NULL, cpl_error_get_code());
00359
00360 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00361 cpl_ensure_code(!error, error);
00362
00363 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00364 cpl_ensure_code(!error, error);
00365
00366 error = cpl_parameterlist_append(self, par);
00367 cpl_ensure_code(!error, error);
00368
00369 return CPL_ERROR_NONE;
00370 }
00371
00372
00373
00374
00388
00389 cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist * self,
00390 const char * instrume,
00391 const char * recipe,
00392 const char * parameter,
00393 int defvalue,
00394 const char * alias,
00395 const char * context,
00396 const char * man)
00397 {
00398
00399 cpl_error_code error;
00400 cpl_parameter * par;
00401 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00402 parameter);
00403
00404 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00405
00406 par = cpl_parameter_new_value(paramname, CPL_TYPE_INT, man, context,
00407 defvalue);
00408 cpl_free(paramname);
00409
00410 cpl_ensure_code(par != NULL, cpl_error_get_code());
00411
00412 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00413 cpl_ensure_code(!error, error);
00414
00415 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00416 cpl_ensure_code(!error, error);
00417
00418 error = cpl_parameterlist_append(self, par);
00419 cpl_ensure_code(!error, error);
00420
00421 return CPL_ERROR_NONE;
00422 }
00423
00424
00425
00439
00440 cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist * self,
00441 const char * instrume,
00442 const char * recipe,
00443 const char * parameter,
00444 double defvalue,
00445 const char * alias,
00446 const char * context,
00447 const char * man)
00448 {
00449
00450 cpl_error_code error;
00451 cpl_parameter * par;
00452 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00453 parameter);
00454
00455 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00456
00457 par = cpl_parameter_new_value(paramname, CPL_TYPE_DOUBLE, man, context,
00458 defvalue);
00459 cpl_free(paramname);
00460
00461 cpl_ensure_code(par != NULL, cpl_error_get_code());
00462
00463 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00464 cpl_ensure_code(!error, error);
00465
00466 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00467 cpl_ensure_code(!error, error);
00468
00469 error = cpl_parameterlist_append(self, par);
00470 cpl_ensure_code(!error, error);
00471
00472 return CPL_ERROR_NONE;
00473 }
00474
00475
00476
00488
00489 int irplib_plugin_test(cpl_pluginlist * self, size_t nstr, const char *astr[]) {
00490
00491 cpl_plugin * plugin;
00492 cpl_recipe * recipe;
00493 int (*recipe_create) (cpl_plugin *);
00494 int (*recipe_exec ) (cpl_plugin *);
00495 int (*recipe_deinit) (cpl_plugin *);
00496 const cpl_msg_severity msg_level = cpl_msg_get_level();
00497
00498 int recipe_nfail = 0;
00499 cpl_errorstate prestate;
00500 FILE * stream;
00501 cpl_boolean is_debug;
00502
00503
00504
00505
00506 if (getenv("CPL_MSG_LEVEL") == NULL) cpl_msg_set_level(CPL_MSG_OFF);
00507
00508 is_debug = cpl_msg_get_level() <= CPL_MSG_DEBUG ? CPL_TRUE : CPL_FALSE;
00509
00510
00511 stream = is_debug ? stdout : fopen("/dev/null", "a");
00512
00513 inistate = cpl_errorstate_get();
00514
00515 assert( nstr == 0 || astr != NULL );
00516
00517 plugin = cpl_pluginlist_get_first(self);
00518
00519 if (plugin == NULL) {
00520 cpl_msg_warning(cpl_func, "With an empty pluginlist, "
00521 "no tests can be made");
00522 cpl_msg_set_level(msg_level);
00523 return 0;
00524 }
00525
00526 cpl_plugin_dump(plugin, stream);
00527
00528 recipe_create = cpl_plugin_get_init(plugin);
00529 recipe_exec = cpl_plugin_get_exec(plugin);
00530 recipe_deinit = cpl_plugin_get_deinit(plugin);
00531
00532
00533 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00534 cpl_msg_warning(cpl_func, "This plugin is not of type recipe, "
00535 "cannot test further");
00536 cpl_msg_set_level(msg_level);
00537 return 0;
00538 }
00539
00540 recipe_nfail += recipe_assert( recipe_create(plugin) == 0);
00541
00542 recipe = (cpl_recipe *) plugin;
00543
00544 recipe_nfail += recipe_assert( recipe->parameters != NULL);
00545
00546 recipe_parameterlist_set_defaults(recipe->parameters);
00547
00548 cpl_parameterlist_dump(recipe->parameters, stream);
00549
00550 recipe->frames = cpl_frameset_new();
00551
00552 cpl_msg_info(cpl_func,"Checking handling of pre-existing CPL error state - "
00553 "may produce warning(s)/error(s):");
00554 cpl_error_set(cpl_func, CPL_ERROR_UNSPECIFIED);
00555 prestate = cpl_errorstate_get();
00556
00557 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00558
00559 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_UNSPECIFIED );
00560
00561 if (!cpl_errorstate_is_equal(prestate)) {
00562 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
00563 cpl_msg_debug(cpl_func, "Resetting error state");
00564 cpl_errorstate_set(prestate);
00565 }
00566
00567 cpl_errorstate_set(inistate);
00568
00569 cpl_msg_info(cpl_func,"Checking handling of empty frameset - "
00570 "may produce warning(s)/error(s):");
00571
00572 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00573
00574 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00575
00576 if (cpl_errorstate_is_equal(inistate)) {
00577 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00578 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00579 } else if (is_debug) {
00580 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00581 }
00582 cpl_msg_debug(cpl_func, "Resetting error state");
00583 cpl_errorstate_set(inistate);
00584
00585 cpl_msg_info(cpl_func,"Checking handling of dummy frameset - "
00586 "may produce warning(s)/error(s):");
00587 do {
00588 cpl_frame * f = cpl_frame_new();
00589 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, "/dev/null") == 0);
00590 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, "RECIPE_DUMMY_TAG") == 0);
00591 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00592
00593 if (!cpl_errorstate_is_equal(inistate)) {
00594 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
00595 cpl_msg_debug(cpl_func, "Resetting error state");
00596 cpl_errorstate_set(inistate);
00597 }
00598
00599
00600 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00601
00602 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00603
00604 if (cpl_errorstate_is_equal(inistate)) {
00605 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00606 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00607 } else if (is_debug) {
00608 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00609 }
00610 cpl_msg_debug(cpl_func, "Resetting error state");
00611 cpl_errorstate_set(inistate);
00612
00613 recipe_nfail += recipe_assert( cpl_frameset_erase_frame(recipe->frames, f)
00614 == CPL_ERROR_NONE );
00615
00616 } while (0);
00617
00618 recipe_nfail += recipe_sof_test_random(plugin, nstr, astr);
00619
00620 recipe_nfail += recipe_sof_test_image_empty(plugin, nstr, astr);
00621
00622 recipe_nfail += recipe_sof_test_local(plugin);
00623
00624 recipe_nfail += recipe_sof_test_from_env(plugin);
00625
00626 cpl_frameset_delete(recipe->frames);
00627
00628 recipe_nfail += recipe_assert( recipe_deinit(plugin) == 0 );
00629
00630 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00631
00632 if (recipe_nfail) cpl_msg_error(cpl_func, "%d test(s) failed", recipe_nfail);
00633
00634 cpl_msg_set_level(msg_level);
00635
00636 if (stream != stdout) fclose(stream);
00637
00638 return recipe_nfail;
00639 }
00640
00643
00653
00654 static void recipe_parameterlist_set_defaults(cpl_parameterlist *parlist)
00655 {
00656
00657 cpl_parameter * p = cpl_parameterlist_get_first(parlist);
00658
00659 for (; p != NULL; p = cpl_parameterlist_get_next(parlist)) {
00660
00661 if (cpl_parameter_get_default_flag(p)) continue;
00662
00663 cpl_msg_debug(cpl_func, __FILE__ " line %u: OK", __LINE__);
00664
00665 switch (cpl_parameter_get_type(p)) {
00666 case CPL_TYPE_BOOL:
00667 cpl_parameter_set_bool(p, cpl_parameter_get_default_bool(p));
00668 break;
00669 case CPL_TYPE_INT:
00670 cpl_parameter_set_int(p, cpl_parameter_get_default_int(p));
00671 break;
00672 case CPL_TYPE_DOUBLE:
00673 cpl_parameter_set_double(p, cpl_parameter_get_default_double(p));
00674 break;
00675 case CPL_TYPE_STRING:
00676 {
00677 const char * s_default = cpl_parameter_get_default_string(p);
00678
00679 cpl_parameter_set_string(p, s_default != NULL ? s_default : "");
00680 break;
00681 }
00682
00683 default:
00684 assert( 0 );
00685 }
00686 }
00687 }
00688
00689
00690
00697
00698 static int recipe_sof_test_random(cpl_plugin * plugin, size_t nstr,
00699 const char *astr[])
00700 {
00701 cpl_recipe * recipe = (cpl_recipe*)plugin;
00702
00703 int (*recipe_exec) (cpl_plugin *);
00704
00705
00706 int recipe_nfail = 0;
00707 size_t i;
00708
00709
00710 if (nstr < 1) return recipe_nfail;
00711
00712 cpl_msg_info(cpl_func, "Testing recipe with %u " DEV_RANDOM " as input ",
00713 (unsigned)nstr);
00714
00715 for (i = 0; i < nstr; i++) {
00716 cpl_frame * f = cpl_frame_new();
00717
00718 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, DEV_RANDOM) == 0);
00719 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, astr[i]) == 0);
00720 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00721 }
00722
00723 recipe_exec = cpl_plugin_get_exec(plugin);
00724
00725 if (!cpl_errorstate_is_equal(inistate)) {
00726 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00727 cpl_msg_debug(cpl_func, "Resetting error state");
00728 cpl_errorstate_set(inistate);
00729 }
00730
00731
00732 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00733
00734 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00735
00736 if (cpl_errorstate_is_equal(inistate)) {
00737 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00738 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00739 } else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
00740 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00741 }
00742 cpl_msg_debug(cpl_func, "Resetting error state");
00743 cpl_errorstate_set(inistate);
00744
00745 recipe_frameset_empty(recipe->frames);
00746
00747 return recipe_nfail;
00748 }
00749
00750
00751
00758
00759 static int recipe_sof_test_image_empty(cpl_plugin * plugin, size_t nstr,
00760 const char *astr[])
00761 {
00762 cpl_recipe * recipe = (cpl_recipe*)plugin;
00763
00764 int (*recipe_exec) (cpl_plugin *);
00765
00766
00767 int recipe_nfail = 0;
00768 size_t i;
00769 cpl_frame * frame;
00770 cpl_image * iempty;
00771
00772
00773 if (nstr < 1) return recipe_nfail;
00774
00775 cpl_msg_info(cpl_func, "Testing recipe with %u empty images as input ",
00776 (unsigned)nstr);
00777
00778 iempty = cpl_image_new(13, 17, CPL_TYPE_FLOAT);
00779
00780 for (i = 0; i < nstr; i++) {
00781 cpl_frame * f = cpl_frame_new();
00782 char * rawname = cpl_sprintf("raw%05u.fits", (unsigned)(i+1));
00783
00784 recipe_nfail += recipe_assert( cpl_image_save(iempty, rawname,
00785 CPL_BPP_IEEE_FLOAT, NULL,
00786 CPL_IO_DEFAULT) == 0);
00787
00788 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, rawname) == 0);
00789 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, astr[i]) == 0);
00790 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00791
00792 cpl_free(rawname);
00793 }
00794 cpl_image_delete(iempty);
00795
00796 recipe_exec = cpl_plugin_get_exec(plugin);
00797
00798 if (!cpl_errorstate_is_equal(inistate)) {
00799 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00800 cpl_msg_debug(cpl_func, "Resetting error state");
00801 cpl_errorstate_set(inistate);
00802 }
00803
00804
00805 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00806
00807 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00808
00809 if (cpl_errorstate_is_equal(inistate)) {
00810 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00811 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00812 } else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
00813 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00814 }
00815 cpl_msg_debug(cpl_func, "Resetting error state");
00816 cpl_errorstate_set(inistate);
00817
00818 for (frame = cpl_frameset_get_first(recipe->frames); frame != NULL;
00819 frame = cpl_frameset_get_first(recipe->frames))
00820 {
00821 recipe_nfail +=
00822 recipe_assert( remove(cpl_frame_get_filename(frame)) == 0);
00823 cpl_frameset_erase_frame(recipe->frames, frame);
00824 }
00825
00826 return recipe_nfail;
00827 }
00828
00829
00830
00837
00838 static int recipe_sof_test_from_env(cpl_plugin * plugin)
00839 {
00840 cpl_recipe * recipe = (cpl_recipe*)plugin;
00841 const char * recipename = cpl_plugin_get_name(plugin);
00842 const char * var_name = "RECIPE_SOF_PATH";
00843 const char * sof_path = getenv(var_name);
00844
00845
00846 int recipe_nfail = 0;
00847
00848 char * sof_name;
00849
00850 if (sof_path == NULL) {
00851 cpl_msg_warning(cpl_func, "Environment variable %s is unset: "
00852 "No SOFs to check", var_name);
00853 return recipe_nfail;
00854 }
00855
00856 cpl_msg_debug(cpl_func, "Checking for SOFs in %s", sof_path);
00857
00858 if (recipename == NULL) {
00859 recipe_nfail += recipe_assert(recipename != NULL);
00860 return recipe_nfail;
00861 }
00862
00863 sof_name = cpl_sprintf("%s/%s.sof", sof_path, recipename);
00864
00865 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00866
00867 recipe_frameset_load(recipe->frames, sof_name);
00868
00869 if (!cpl_frameset_is_empty(recipe->frames)) {
00870
00871 int (*recipe_exec ) (cpl_plugin *);
00872
00873 recipe_exec = cpl_plugin_get_exec(plugin);
00874
00875 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00876 recipe_nfail += recipe_assert( recipe_exec(plugin) == 0 );
00877 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00878
00879 if (!cpl_errorstate_is_equal(inistate)) {
00880 recipe_nfail += recipe_assert( cpl_errorstate_is_equal(inistate) );
00881 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00882 cpl_msg_debug(cpl_func, "Resetting error state");
00883 cpl_errorstate_set(inistate);
00884 }
00885
00886 recipe_frameset_empty(recipe->frames);
00887 }
00888
00889 cpl_free(sof_name);
00890
00891 return recipe_nfail;
00892 }
00893
00894
00895
00896
00903
00904 static int recipe_sof_test_local(cpl_plugin * plugin)
00905 {
00906 cpl_recipe * recipe = (cpl_recipe*)plugin;
00907 const char * recipename = cpl_plugin_get_name(plugin);
00908
00909
00910 int recipe_nfail = 0;
00911
00912 char * sof_name = cpl_sprintf("%s.sof", recipename);
00913
00914 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00915
00916 recipe_frameset_load(recipe->frames, sof_name);
00917
00918 if (!cpl_frameset_is_empty(recipe->frames)) {
00919
00920 int (*recipe_exec ) (cpl_plugin *);
00921
00922 recipe_exec = cpl_plugin_get_exec(plugin);
00923
00924 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00925 recipe_nfail += recipe_assert( recipe_exec(plugin) == 0 );
00926 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00927
00928 recipe_nfail
00929 += recipe_assert( cpl_dfs_update_product_header(recipe->frames)
00930 == CPL_ERROR_NONE );
00931
00932 if (!cpl_errorstate_is_equal(inistate)) {
00933 recipe_nfail += recipe_assert( cpl_errorstate_is_equal(inistate) );
00934 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00935 cpl_msg_debug(cpl_func, "Resetting error state");
00936 cpl_errorstate_set(inistate);
00937 }
00938
00939 recipe_frameset_empty(recipe->frames);
00940 }
00941
00942 cpl_free(sof_name);
00943
00944 return recipe_nfail;
00945 }
00946
00947
00948
00949
00950
00964
00965
00966 static void recipe_frameset_load(cpl_frameset * set, const char *name)
00967 {
00968
00969 FILE *fp;
00970 char line[LINE_LEN_MAX];
00971 char path[LINE_LEN_MAX], group[LINE_LEN_MAX], tag[LINE_LEN_MAX];
00972 int line_number;
00973
00974 assert( set != NULL );
00975 assert( name != NULL );
00976
00977 fp = fopen(name, "r");
00978 if (fp == NULL) {
00979 cpl_msg_debug(cpl_func, "Unable to open SOF file '%s'", name);
00980 return;
00981 }
00982
00983
00984 for (line_number = 0; fgets(line, LINE_LEN_MAX - 1, fp); line_number++) {
00985
00986 cpl_frame_group grp;
00987 cpl_frame * frame;
00988 int n;
00989
00990 if (line[0] == '#') continue;
00991
00992 n = sscanf(line, "%s %s %s", path, tag, group);
00993
00994 if (n < 1) {
00995 cpl_msg_warning(cpl_func, "Spurious line no. %d in %s: %s",
00996 line_number, name, line);
00997 break;
00998 }
00999
01000
01001 frame = cpl_frame_new();
01002
01003
01004 cpl_frame_set_filename(frame, path);
01005
01006
01007 cpl_frame_set_tag(frame, n == 1 ? "" : tag);
01008
01009 cpl_frameset_insert(set, frame);
01010
01011
01012 if (n < 3) continue;
01013
01014 if (!strcmp(group, CPL_FRAME_GROUP_RAW_ID))
01015 grp = CPL_FRAME_GROUP_RAW;
01016 else if (!strcmp(group, CPL_FRAME_GROUP_CALIB_ID))
01017 grp = CPL_FRAME_GROUP_CALIB;
01018 else if (!strcmp(group, CPL_FRAME_GROUP_PRODUCT_ID))
01019 grp = CPL_FRAME_GROUP_PRODUCT;
01020 else
01021 grp = CPL_FRAME_GROUP_NONE;
01022
01023 cpl_frame_set_group(frame, grp);
01024 }
01025
01026 fclose(fp);
01027
01028 return;
01029
01030 }
01031
01032
01033
01043
01044 static const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist
01045 * self,
01046 const char * instrume,
01047 const char * recipe,
01048 const char * parameter)
01049 {
01050
01051 const cpl_parameter * par;
01052 char * paramname;
01053
01054
01055 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
01056 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, NULL);
01057 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, NULL);
01058 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, NULL);
01059
01060 paramname = cpl_sprintf("%s.%s.%s", instrume, recipe, parameter);
01061
01062 cpl_ensure(paramname != NULL, cpl_error_get_code(), NULL);
01063
01064 par = cpl_parameterlist_find_const(self, paramname);
01065
01066 cpl_free(paramname);
01067
01068 return par;
01069
01070 }
01071
01072
01073
01099
01100 static void recipe_frameset_empty(cpl_frameset * self)
01101 {
01102 cpl_frame * f;
01103
01104 if (self == NULL) {
01105 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
01106 return;
01107 }
01108
01109 for (f = cpl_frameset_get_first(self); f != NULL;
01110 f = cpl_frameset_get_first(self))
01111 {
01112 cpl_frameset_erase_frame(self, f);
01113 }
01114 }