backend: Add basic transform module sanity checks.
This commit is contained in:
parent
8677e4e7be
commit
187cfc604e
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue