X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=tests%2Fruntc.c;h=f0649f9d727b5d6a209c620f78d3d61a3bc463e5;hp=bb2595013338c6b7698b78c79b635dfbd59ee54c;hb=98457aa731ec0e7fe5a1be9f83181354253dc566;hpb=b74823812d4106bfafc4a7fef1d4a141dac58519 diff --git a/tests/runtc.c b/tests/runtc.c index bb25950..f0649f9 100644 --- a/tests/runtc.c +++ b/tests/runtc.c @@ -94,13 +94,25 @@ void ERR(const char *format, ...) va_end(args); } +int sr_log(void *cb_data, int loglevel, const char *format, va_list args) +{ + (void)cb_data; + + if (loglevel == SR_LOG_ERR || loglevel == SR_LOG_WARN) + logmsg("Error: sr: ", stderr, format, args); + else if (debug) + logmsg("DBG: sr: ", stdout, format, args); + + return SRD_OK; +} + int srd_log(void *cb_data, int loglevel, const char *format, va_list args) { (void)cb_data; if (loglevel == SRD_LOG_ERR || loglevel == SRD_LOG_WARN) logmsg("Error: srd: ", stderr, format, args); - else if (loglevel >= SRD_LOG_DBG && debug) + else if (debug) logmsg("DBG: srd: ", stdout, format, args); return SRD_OK; @@ -251,9 +263,9 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op) struct option *option; GVariant *gvar; GHashTable *probes, *opts; - GSList *pdl, *l, *annl; + GSList *pdl, *l; int idx; - char **dec_ann; + char **decoder_class; if (op->outfile) { if ((op->outfd = open(op->outfile, O_CREAT|O_WRONLY, 0600)) == -1) { @@ -320,24 +332,21 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op) dec = srd_decoder_get_by_id(pd->name); if (op->class) { if (op->type == SRD_OUTPUT_ANN) - annl = dec->annotations; - /* TODO can't dereference this for binary yet + l = dec->annotations; else if (op->type == SRD_OUTPUT_BINARY) - annl = dec->binary; - */ + l = dec->binary; else /* Only annotations and binary for now. */ return FALSE; idx = 0; - while(annl) { - dec_ann = annl->data; - /* TODO can't dereference this for binary yet */ - if (!strcmp(dec_ann[0], op->class)) { + while(l) { + decoder_class = l->data; + if (!strcmp(decoder_class[0], op->class)) { op->class_idx = idx; break; } else idx++; - annl = annl->next; + l = l->next; } if (op->class_idx == -1) { ERR("Output class '%s' not found in decoder %s.", @@ -366,6 +375,7 @@ int main(int argc, char **argv) struct probe *probe; struct option *option; struct output *op; + int ret; char c, *opt_infile, **kv, **opstr; op = malloc(sizeof(struct output)); @@ -464,6 +474,7 @@ int main(int argc, char **argv) if (!op->pd || op->type == -1) usage(NULL); + sr_log_callback_set(sr_log, NULL); if (sr_init(&ctx) != SR_OK) return 1; @@ -471,12 +482,14 @@ int main(int argc, char **argv) if (srd_init(DECODERS_DIR) != SRD_OK) return 1; - run_testcase(opt_infile, pdlist, op); + ret = 0; + if (!run_testcase(opt_infile, pdlist, op)) + ret = 1; srd_exit(); sr_exit(ctx); - return 0; + return ret; }