2 * This file is part of the sigrok-test project.
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <libsigrokdecode/libsigrokdecode.h>
24 #include <libsigrok/libsigrok.h>
30 #include <sys/types.h>
35 #include <sys/resource.h>
42 static int debug = FALSE;
43 static int statistics = FALSE;
44 static char *coverage_report;
45 static struct sr_context *ctx;
57 struct initial_pin_info {
86 static struct cvg *get_mod_cov(PyObject *py_cov, const char *module_name);
87 static void cvg_add(struct cvg *dst, const struct cvg *src);
88 static struct cvg *cvg_new(void);
89 static gboolean find_missed_line(struct cvg *cvg, const char *linespec);
91 static void logmsg(const char *prefix, FILE *out, const char *format, va_list args)
94 fprintf(out, "%s", prefix);
95 vfprintf(out, format, args);
99 static void DBG(const char *format, ...)
105 va_start(args, format);
106 logmsg("DBG: runtc: ", stdout, format, args);
110 static void ERR(const char *format, ...)
114 va_start(args, format);
115 logmsg("Error: ", stderr, format, args);
119 static int sr_log(void *cb_data, int loglevel, const char *format, va_list args)
123 if (loglevel == SR_LOG_ERR || loglevel == SR_LOG_WARN)
124 logmsg("Error: sr: ", stderr, format, args);
126 logmsg("DBG: sr: ", stdout, format, args);
131 static int srd_log(void *cb_data, int loglevel, const char *format, va_list args)
135 if (loglevel == SRD_LOG_ERR || loglevel == SRD_LOG_WARN)
136 logmsg("Error: srd: ", stderr, format, args);
138 logmsg("DBG: srd: ", stdout, format, args);
143 static void usage(const char *msg)
146 fprintf(stderr, "%s\n", msg);
148 printf("Usage: runtc [-dPpoiOfcS]\n");
149 printf(" -d (enables debug output)\n");
150 printf(" -P <protocol decoder>\n");
151 printf(" -p <channelname=channelnum> (optional)\n");
152 printf(" -o <channeloption=value> (optional)\n");
153 printf(" -N <channelname=initial-pin-value> (optional)\n");
154 printf(" -i <input file>\n");
155 printf(" -O <output-pd:output-type[:output-class]>\n");
156 printf(" -f <output file> (optional)\n");
157 printf(" -c <coverage report> (optional)\n");
158 printf(" -S (enables statistics)\n");
164 * This is a neutered version of libsigrokdecode's py_str_as_str(). It
165 * does no error checking, but then the only strings it processes are
166 * generated by Python's repr(), so are known good.
168 static char *py_str_as_str(const PyObject *py_str)
173 py_encstr = PyUnicode_AsEncodedString((PyObject *)py_str, "utf-8", NULL);
174 str = PyBytes_AS_STRING(py_encstr);
175 outstr = g_strdup(str);
176 Py_DecRef(py_encstr);
182 * The following routines are callbacks for libsigrokdecode. They receive
183 * output from protocol decoders, optionally dropping data to only forward
184 * a selected decoder's or class' information. Output is written to either
185 * a specified file or stdout, an external process will compare captured
186 * output against expectations.
188 * Note that runtc(1) output emits the decoder "class" name instead of the
189 * instance name. So that generated output remains compatible with existing
190 * .output files which hold expected output of test cases. Without this
191 * approach, developers had to "anticipate" instance names from test.conf
192 * setups (and knowledge about internal implementation details of the srd
193 * library), and adjust .output files to reflect those names. Or specify
194 * instance names in each and every test.conf description (-o inst_id=ID).
196 * It's assumed that runtc(1) is used to check stacked decoders, but not
197 * multiple stacks in parallel and no stacks with multiple instances of
198 * decoders of the same type. When such configurations become desirable,
199 * runtc(1) needs to emit the instance name, and test configurations and
200 * output expectations need adjustment.
203 static void srd_cb_py(struct srd_proto_data *pdata, void *cb_data)
206 PyObject *pydata, *pyrepr;
210 DBG("Python output from %s", pdata->pdo->di->inst_id);
212 pydata = pdata->data;
213 DBG("ptr %p", pydata);
215 if (strcmp(pdata->pdo->di->inst_id, op->pd_id))
216 /* This is not the PD selected for output. */
219 if (!(pyrepr = PyObject_Repr(pydata))) {
220 ERR("Invalid Python object.");
223 s = py_str_as_str(pyrepr);
226 /* Output format for testing is '<ss>-<es> <decoder-id>: <repr>\n'. */
227 out = g_string_sized_new(128);
228 g_string_printf(out, "%" PRIu64 "-%" PRIu64 " %s: %s\n",
229 pdata->start_sample, pdata->end_sample,
230 pdata->pdo->di->decoder->id, s);
232 if (write(op->outfd, out->str, out->len) == -1)
233 ERR("SRD_OUTPUT_PYTHON callback write failure!");
234 DBG("wrote '%s'", out->str);
235 g_string_free(out, TRUE);
239 static void srd_cb_bin(struct srd_proto_data *pdata, void *cb_data)
241 struct srd_proto_data_binary *pdb;
246 DBG("Binary output from %s", pdata->pdo->di->inst_id);
250 if (strcmp(pdata->pdo->di->inst_id, op->pd_id))
251 /* This is not the PD selected for output. */
254 if (op->class_idx != -1 && op->class_idx != pdb->bin_class)
256 * This output takes a specific binary class,
257 * but not the one that just came in.
261 out = g_string_sized_new(128);
262 g_string_printf(out, "%" PRIu64 "-%" PRIu64 " %s:",
263 pdata->start_sample, pdata->end_sample,
264 pdata->pdo->di->decoder->id);
265 for (i = 0; i < pdb->size; i++) {
266 g_string_append_printf(out, " %.2x", pdb->data[i]);
268 g_string_append(out, "\n");
269 if (write(op->outfd, out->str, out->len) == -1)
270 ERR("SRD_OUTPUT_BINARY callback write failure!");
274 static void srd_cb_ann(struct srd_proto_data *pdata, void *cb_data)
276 struct srd_decoder_inst *di;
277 struct srd_decoder *dec;
278 struct srd_proto_data_annotation *pda;
285 * Only inspect received annotations when they originate from
286 * the selected protocol decoder, and an optionally specified
287 * annotation class matches the received data.
293 DBG("Annotation output from %s", di->inst_id);
294 if (strcmp(di->inst_id, op->pd_id))
295 /* This is not the PD selected for output. */
298 if (op->class_idx != -1 && op->class_idx != pda->ann_class)
300 * This output takes a specific annotation class,
301 * but not the one that just came in.
306 * Print the annotation information in textual representation
307 * to the specified output file. Prefix the annotation strings
308 * with the start and end sample number, the decoder name, and
309 * the annotation name.
311 dec_ann = g_slist_nth_data(dec->annotations, pda->ann_class);
312 line = g_string_sized_new(256);
313 g_string_printf(line, "%" PRIu64 "-%" PRIu64 " %s: %s:",
314 pdata->start_sample, pdata->end_sample,
315 dec->id, dec_ann[0]);
316 for (i = 0; pda->ann_text[i]; i++)
317 g_string_append_printf(line, " \"%s\"", pda->ann_text[i]);
318 g_string_append(line, "\n");
319 if (write(op->outfd, line->str, line->len) == -1)
320 ERR("SRD_OUTPUT_ANN callback write failure!");
321 g_string_free(line, TRUE);
325 static void sr_cb(const struct sr_dev_inst *sdi,
326 const struct sr_datafeed_packet *packet, void *cb_data)
328 static int samplecnt = 0;
329 static gboolean start_sent;
331 const struct sr_datafeed_logic *logic;
332 struct srd_session *sess;
333 const struct sr_datafeed_meta *meta;
334 struct sr_config *src;
340 struct sr_dev_driver *driver;
344 driver = sr_dev_inst_driver_get(sdi);
346 switch (packet->type) {
348 DBG("Received SR_DF_META");
349 meta = packet->payload;
350 for (l = meta->config; l; l = l->next) {
353 case SR_CONF_SAMPLERATE:
354 samplerate = g_variant_get_uint64(src->data);
355 ret = srd_session_metadata_set(sess,
357 g_variant_new_uint64(samplerate));
359 ERR("Setting samplerate failed (meta)");
368 DBG("Received SR_DF_HEADER");
369 if (sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE,
371 DBG("Getting samplerate failed (SR_DF_HEADER)");
374 samplerate = g_variant_get_uint64(gvar);
375 g_variant_unref(gvar);
376 ret = srd_session_metadata_set(sess, SRD_CONF_SAMPLERATE,
377 g_variant_new_uint64(samplerate));
379 ERR("Setting samplerate failed (header)");
382 DBG("Received SR_DF_LOGIC");
384 if (srd_session_start(sess) != SRD_OK) {
385 ERR("Session start failed");
390 logic = packet->payload;
391 num_samples = logic->length / logic->unitsize;
392 DBG("Received SR_DF_LOGIC (%"PRIu64" bytes, unitsize = %d).",
393 logic->length, logic->unitsize);
394 srd_session_send(sess, samplecnt, samplecnt + num_samples,
395 logic->data, logic->length, logic->unitsize);
396 samplecnt += num_samples;
399 DBG("Received SR_DF_END");
400 #if defined HAVE_SRD_SESSION_SEND_EOF && HAVE_SRD_SESSION_SEND_EOF
401 (void)srd_session_send_eof(sess);
408 static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
410 struct srd_session *sess;
411 struct srd_decoder *dec;
412 struct srd_decoder_inst *di, *prev_di;
413 srd_pd_output_callback cb;
415 struct channel *channel;
416 struct option *option;
418 GHashTable *channels, *opts;
419 GSList *pdl, *l, *l2, *devices;
422 char **decoder_class;
423 struct sr_session *sr_sess;
426 GArray *initial_pins;
427 struct initial_pin_info *initial_pin;
430 if ((op->outfd = open(op->outfile, O_CREAT|O_WRONLY, 0600)) == -1) {
431 ERR("Unable to open %s for writing: %s", op->outfile,
437 if (sr_session_load(ctx, infile, &sr_sess) != SR_OK){
438 ERR("sr_session_load() failed");
442 sr_session_dev_list(sr_sess, &devices);
444 if (srd_session_new(&sess) != SRD_OK) {
445 ERR("srd_session_new() failed");
448 sr_session_datafeed_callback_add(sr_sess, sr_cb, sess);
453 case SRD_OUTPUT_BINARY:
456 case SRD_OUTPUT_PYTHON:
460 ERR("Invalid op->type");
463 srd_pd_output_callback_add(sess, op->type, cb, op);
467 for (pdl = pdlist; pdl; pdl = pdl->next) {
469 if (srd_decoder_load(pd->name) != SRD_OK) {
470 ERR("srd_decoder_load() failed");
474 /* Instantiate decoder and pass in options. */
475 opts = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
476 (GDestroyNotify)g_variant_unref);
477 for (l = pd->options; l; l = l->next) {
481 s = g_variant_get_string(option->value, NULL);
482 for (i = 0; i < (int)strlen(s); i++) {
488 /* Integer option value */
489 g_hash_table_insert(opts, option->key,
490 g_variant_new_int64(strtoull(s, NULL, 10)));
492 /* String option value */
493 g_hash_table_insert(opts, option->key, option->value);
496 if (!(di = srd_inst_new(sess, pd->name, opts))) {
497 ERR("srd_inst_new() failed");
500 g_hash_table_destroy(opts);
503 * Get (a reference to) the decoder instance's ID if we
504 * are about to receive PD output from it. We need to
505 * filter output that carries the decoder instance's name.
507 if (strcmp(pd->name, op->pd) == 0) {
508 op->pd_id = di->inst_id;
509 DBG("Decoder of type \"%s\" has instance ID \"%s\".",
515 channels = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
516 (GDestroyNotify)g_variant_unref);
518 for (l = pd->channels; l; l = l->next) {
520 if (channel->channel > max_channel)
521 max_channel = channel->channel;
522 gvar = g_variant_new_int32(channel->channel);
523 g_variant_ref_sink(gvar);
524 g_hash_table_insert(channels, channel->name, gvar);
527 if (srd_inst_channel_set_all(di, channels) != SRD_OK) {
528 ERR("srd_inst_channel_set_all() failed");
531 g_hash_table_destroy(channels);
534 /* Set initial pins. */
535 if (pd->initial_pins) {
536 initial_pins = g_array_sized_new(FALSE, TRUE, sizeof(uint8_t),
537 di->dec_num_channels);
538 g_array_set_size(initial_pins, di->dec_num_channels);
539 memset(initial_pins->data, SRD_INITIAL_PIN_SAME_AS_SAMPLE0,
540 di->dec_num_channels);
542 for (l = pd->channels, idx = 0; l; l = l->next, idx++) {
544 for (l2 = pd->initial_pins; l2; l2 = l2->next) {
545 initial_pin = l2->data;
546 if (!strcmp(initial_pin->name, channel->name))
547 initial_pins->data[idx] = initial_pin->value;
551 if (srd_inst_initial_pins_set_all(di, initial_pins) != SRD_OK) {
552 ERR("srd_inst_initial_pins_set_all() failed");
555 g_array_free(initial_pins, TRUE);
559 * If this is not the first decoder in the list, stack it
560 * on top of the previous one.
563 if (srd_inst_stack(sess, prev_di, di) != SRD_OK) {
564 ERR("Failed to stack decoder instances.");
571 * Bail out if we haven't created an instance of the selected
572 * decoder type of which we shall grab output data from.
575 ERR("No / invalid decoder");
579 /* Resolve selected decoder's class index, so we can match. */
580 dec = srd_decoder_get_by_id(pd->name);
582 if (op->type == SRD_OUTPUT_ANN)
583 l = dec->annotations;
584 else if (op->type == SRD_OUTPUT_BINARY)
587 /* Only annotations and binary can have a class. */
588 ERR("Invalid decoder class");
593 decoder_class = l->data;
594 if (!strcmp(decoder_class[0], op->class_)) {
601 if (op->class_idx == -1) {
602 ERR("Output class '%s' not found in decoder %s.",
603 op->class_, pd->name);
606 DBG("Class %s index is %d", op->class_, op->class_idx);
609 sr_session_start(sr_sess);
610 sr_session_run(sr_sess);
611 sr_session_stop(sr_sess);
613 srd_session_destroy(sess);
621 static PyObject *start_coverage(GSList *pdlist)
623 PyObject *py_mod, *py_pdlist, *py_pd, *py_func, *py_args, *py_kwargs, *py_cov;
627 DBG("Starting coverage.");
629 if (!(py_mod = PyImport_ImportModule("coverage")))
632 if (!(py_pdlist = PyList_New(0)))
634 for (l = pdlist; l; l = l->next) {
636 py_pd = PyUnicode_FromFormat("*/%s/*.py", pd->name);
637 if (PyList_Append(py_pdlist, py_pd) < 0)
641 if (!(py_func = PyObject_GetAttrString(py_mod, "coverage")))
643 if (!(py_args = PyTuple_New(0)))
645 if (!(py_kwargs = Py_BuildValue("{sO}", "include", py_pdlist)))
647 if (!(py_cov = PyObject_Call(py_func, py_args, py_kwargs)))
649 if (!(PyObject_CallMethod(py_cov, "start", NULL)))
651 Py_DecRef(py_pdlist);
653 Py_DecRef(py_kwargs);
659 static struct cvg *get_mod_cov(PyObject *py_cov, const char *module_name)
661 PyObject *py_mod, *py_pathlist, *py_path, *py_func, *py_pd;
662 PyObject *py_result, *py_missed, *py_item;
666 int num_lines, num_missed, linenum, i, j;
667 char *path, *linespec;
669 if (!(py_mod = PyImport_ImportModule(module_name)))
673 py_pathlist = PyObject_GetAttrString(py_mod, "__path__");
674 for (i = 0; i < PyList_Size(py_pathlist); i++) {
675 py_path = PyList_GetItem(py_pathlist, i);
676 PyUnicode_FSConverter(PyList_GetItem(py_pathlist, i), &py_path);
677 path = PyBytes_AS_STRING(py_path);
678 if (!(d = opendir(path))) {
679 ERR("Invalid module path '%s'", path);
682 while ((de = readdir(d))) {
683 if (strncmp(de->d_name + strlen(de->d_name) - 3, ".py", 3))
686 if (!(py_func = PyObject_GetAttrString(py_cov, "analysis2")))
688 if (!(py_pd = PyUnicode_FromFormat("%s/%s", path, de->d_name)))
690 if (!(py_result = PyObject_CallFunction(py_func, "O", py_pd)))
697 if (PyTuple_Size(py_result) != 5) {
698 ERR("Invalid result from coverage of '%s/%s'", path, de->d_name);
701 num_lines = PyList_Size(PyTuple_GetItem(py_result, 1));
702 py_missed = PyTuple_GetItem(py_result, 3);
703 num_missed = PyList_Size(py_missed);
704 cvg_mod->num_lines += num_lines;
705 cvg_mod->num_missed += num_missed;
706 for (j = 0; j < num_missed; j++) {
707 py_item = PyList_GetItem(py_missed, j);
708 linenum = PyLong_AsLong(py_item);
709 linespec = g_strdup_printf("%s/%s:%d", module_name,
710 de->d_name, linenum);
711 cvg_mod->missed_lines = g_slist_append(cvg_mod->missed_lines, linespec);
713 DBG("Coverage for %s/%s: %d lines, %d missed.",
714 module_name, de->d_name, num_lines, num_missed);
715 Py_DecRef(py_result);
718 if (cvg_mod->num_lines)
719 cvg_mod->coverage = 100 - ((float)cvg_mod->num_missed / (float)cvg_mod->num_lines * 100);
727 static struct cvg *cvg_new(void)
731 cvg = calloc(1, sizeof(struct cvg));
736 static gboolean find_missed_line(struct cvg *cvg, const char *linespec)
740 for (l = cvg->missed_lines; l; l = l->next)
741 if (!strcmp(l->data, linespec))
747 static void cvg_add(struct cvg *dst, const struct cvg *src)
752 dst->num_lines += src->num_lines;
753 dst->num_missed += src->num_missed;
754 for (l = src->missed_lines; l; l = l->next) {
756 if (!find_missed_line(dst, linespec))
757 dst->missed_lines = g_slist_append(dst->missed_lines, linespec);
762 static int report_coverage(PyObject *py_cov, GSList *pdlist)
764 PyObject *py_func, *py_mod, *py_args, *py_kwargs, *py_outfile, *py_pct;
767 struct cvg *cvg_mod, *cvg_all;
768 float total_coverage;
769 int lines, missed, cnt;
771 DBG("Making coverage report.");
773 /* Get coverage for each module in the stack. */
776 for (cnt = 0, l = pdlist; l; l = l->next, cnt++) {
778 if (!(cvg_mod = get_mod_cov(py_cov, pd->name)))
780 printf("coverage: scope=%s coverage=%.0f%% lines=%d missed=%d "
781 "missed_lines=", pd->name, cvg_mod->coverage,
782 cvg_mod->num_lines, cvg_mod->num_missed);
783 for (ml = cvg_mod->missed_lines; ml; ml = ml->next) {
784 if (ml != cvg_mod->missed_lines)
786 printf("%s", (char *)ml->data);
789 lines += cvg_mod->num_lines;
790 missed += cvg_mod->num_missed;
791 cvg_add(cvg_all, cvg_mod);
792 DBG("Coverage for module %s: %d lines, %d missed", pd->name,
793 cvg_mod->num_lines, cvg_mod->num_missed);
797 total_coverage = 100 - ((float)missed / (float)lines * 100);
799 /* Machine-readable stats on stdout. */
800 printf("coverage: scope=all coverage=%.0f%% lines=%d missed=%d\n",
801 total_coverage, cvg_all->num_lines, cvg_all->num_missed);
803 /* Write text report to file. */
804 /* io.open(coverage_report, "w") */
805 if (!(py_mod = PyImport_ImportModule("io")))
807 if (!(py_func = PyObject_GetAttrString(py_mod, "open")))
809 if (!(py_args = PyTuple_New(0)))
811 if (!(py_kwargs = Py_BuildValue("{ssss}", "file", coverage_report,
814 if (!(py_outfile = PyObject_Call(py_func, py_args, py_kwargs)))
816 Py_DecRef(py_kwargs);
819 /* py_cov.report(file=py_outfile) */
820 if (!(py_func = PyObject_GetAttrString(py_cov, "report")))
822 if (!(py_kwargs = Py_BuildValue("{sO}", "file", py_outfile)))
824 if (!(py_pct = PyObject_Call(py_func, py_args, py_kwargs)))
827 Py_DecRef(py_kwargs);
830 /* py_outfile.close() */
831 if (!(py_func = PyObject_GetAttrString(py_outfile, "close")))
833 if (!PyObject_Call(py_func, py_args, NULL))
835 Py_DecRef(py_outfile);
843 int main(int argc, char **argv)
848 struct channel *channel;
849 struct option *option;
852 char *opt_infile, **kv, **opstr;
853 struct initial_pin_info *initial_pin;
855 op = malloc(sizeof(struct output));
867 while ((c = getopt(argc, argv, "dP:p:o:N:i:O:f:c:S")) != -1) {
873 pd = g_malloc(sizeof(struct pd));
874 pd->name = g_strdup(optarg);
875 pd->channels = pd->options = pd->initial_pins = NULL;
876 pdlist = g_slist_append(pdlist, pd);
881 if (g_slist_length(pdlist) == 0) {
882 /* No previous -P. */
883 ERR("Syntax error at '%s'", optarg);
886 kv = g_strsplit(optarg, "=", 0);
887 if (!kv[0] || (!kv[1] || kv[2])) {
889 ERR("Syntax error at '%s'", optarg);
894 channel = malloc(sizeof(struct channel));
895 channel->name = g_strdup(kv[0]);
896 channel->channel = strtoul(kv[1], NULL, 10);
897 /* Apply to last PD. */
898 pd->channels = g_slist_append(pd->channels, channel);
899 } else if (c == 'o') {
900 option = malloc(sizeof(struct option));
901 option->key = g_strdup(kv[0]);
902 option->value = g_variant_new_string(kv[1]);
903 g_variant_ref_sink(option->value);
904 /* Apply to last PD. */
905 pd->options = g_slist_append(pd->options, option);
907 initial_pin = malloc(sizeof(struct initial_pin_info));
908 initial_pin->name = g_strdup(kv[0]);
909 initial_pin->value = strtoul(kv[1], NULL, 10);
910 /* Apply to last PD. */
911 pd->initial_pins = g_slist_append(pd->initial_pins, initial_pin);
918 opstr = g_strsplit(optarg, ":", 0);
919 if (!opstr[0] || !opstr[1]) {
920 /* Need at least abc:def. */
921 ERR("Syntax error at '%s'", optarg);
925 op->pd = g_strdup(opstr[0]);
926 if (!strcmp(opstr[1], "annotation"))
927 op->type = SRD_OUTPUT_ANN;
928 else if (!strcmp(opstr[1], "binary"))
929 op->type = SRD_OUTPUT_BINARY;
930 else if (!strcmp(opstr[1], "python"))
931 op->type = SRD_OUTPUT_PYTHON;
932 else if (!strcmp(opstr[1], "exception"))
933 /* Doesn't matter, we just need it to bomb out. */
934 op->type = SRD_OUTPUT_PYTHON;
936 ERR("Unknown output type '%s'", opstr[1]);
941 op->class_ = g_strdup(opstr[2]);
945 op->outfile = g_strdup(optarg);
949 coverage_report = optarg;
960 if (g_slist_length(pdlist) == 0)
964 if (!op->pd || op->type == -1)
967 sr_log_callback_set(sr_log, NULL);
968 if (sr_init(&ctx) != SR_OK)
971 srd_log_callback_set(srd_log, NULL);
972 if (srd_init(DECODERS_DIR) != SRD_OK)
975 if (coverage_report) {
976 if (!(coverage = start_coverage(pdlist))) {
977 DBG("Failed to start coverage.");
978 if (PyErr_Occurred()) {
986 if (!run_testcase(opt_infile, pdlist, op))
990 DBG("Stopping coverage.");
992 if (!(PyObject_CallMethod(coverage, "stop", NULL)))
993 ERR("Failed to stop coverage.");
994 else if (!(report_coverage(coverage, pdlist)))
995 ERR("Failed to make coverage report.");
997 DBG("Coverage report in %s", coverage_report);
999 if (PyErr_Occurred()) {
1003 Py_DecRef(coverage);