backend: Add basic transform module sanity checks.

This commit is contained in:
Uwe Hermann 2015-02-10 22:55:41 +01:00
parent 8677e4e7be
commit 187cfc604e
1 changed files with 54 additions and 0 deletions

View File

@ -306,6 +306,55 @@ static int sanity_check_all_output_modules(void)
return ret;
}
/**
* Sanity-check all libsigrok transform modules.
*
* @retval SR_OK All modules are OK
* @retval SR_ERR One or more modules have issues.
*/
static int sanity_check_all_transform_modules(void)
{
int i, errors, ret = SR_OK;
const struct sr_transform_module **transforms;
const char *d;
sr_spew("Sanity-checking all transform modules.");
transforms = sr_transform_list();
for (i = 0; transforms[i]; i++) {
errors = 0;
d = (transforms[i]->id) ? transforms[i]->id : "NULL";
if (!transforms[i]->id) {
sr_err("No ID in module %d ('%s').", i, d);
errors++;
}
if (!transforms[i]->name) {
sr_err("No name in module %d ('%s').", i, d);
errors++;
}
if (!transforms[i]->desc) {
sr_err("No description in module '%s'.", d);
errors++;
}
/* Note: options() is optional. */
/* Note: init() is optional. */
if (!transforms[i]->receive) {
sr_err("No receive in module '%s'.", d);
errors++;
}
/* Note: cleanup() is optional. */
if (errors == 0)
continue;
ret = SR_ERR;
}
return ret;
}
/**
* Initialize libsigrok.
*
@ -347,6 +396,11 @@ SR_API int sr_init(struct sr_context **ctx)
return ret;
}
if (sanity_check_all_transform_modules() < 0) {
sr_err("Internal transform module error(s), aborting.");
return ret;
}
/* + 1 to handle when struct sr_context has no members. */
context = g_malloc0(sizeof(struct sr_context) + 1);