]> sigrok.org Git - libsigrokdecode.git/blobdiff - tests/runtc.c
ir_nec: Drop some unneeded options.
[libsigrokdecode.git] / tests / runtc.c
index 902ca8e1dd4aff2b1295cbe822dc620c00d9f632..b75e4142c67d079b19035be1b806d2d7501d4041 100644 (file)
@@ -36,7 +36,6 @@
 #endif
 #include "../config.h"
 
-
 int debug = FALSE;
 int statistics = FALSE;
 
@@ -66,7 +65,7 @@ struct output {
 };
 
 
-void logmsg(char *prefix, FILE *out, const char *format, va_list args)
+static void logmsg(char *prefix, FILE *out, const char *format, va_list args)
 {
        if (prefix)
                fprintf(out, "%s", prefix);
@@ -74,7 +73,7 @@ void logmsg(char *prefix, FILE *out, const char *format, va_list args)
        fprintf(out, "\n");
 }
 
-void DBG(const char *format, ...)
+static void DBG(const char *format, ...)
 {
        va_list args;
 
@@ -85,7 +84,7 @@ void DBG(const char *format, ...)
        va_end(args);
 }
 
-void ERR(const char *format, ...)
+static void ERR(const char *format, ...)
 {
        va_list args;
 
@@ -94,7 +93,7 @@ void ERR(const char *format, ...)
        va_end(args);
 }
 
-int sr_log(void *cb_data, int loglevel, const char *format, va_list args)
+static int sr_log(void *cb_data, int loglevel, const char *format, va_list args)
 {
        (void)cb_data;
 
@@ -106,7 +105,7 @@ int sr_log(void *cb_data, int loglevel, const char *format, va_list args)
        return SRD_OK;
 }
 
-int srd_log(void *cb_data, int loglevel, const char *format, va_list args)
+static int srd_log(void *cb_data, int loglevel, const char *format, va_list args)
 {
        (void)cb_data;
 
@@ -118,7 +117,7 @@ int srd_log(void *cb_data, int loglevel, const char *format, va_list args)
        return SRD_OK;
 }
 
-void usage(char *msg)
+static void usage(char *msg)
 {
        if (msg)
                fprintf(stderr, "%s\n", msg);
@@ -138,7 +137,7 @@ void usage(char *msg)
 /* This is a neutered version of libsigrokdecode's py_str_as_str(). It
  * does no error checking, but then the only strings it processes are
  * generated by Python's repr(), so are known good. */
-char *py_str_as_str(const PyObject *py_str)
+static char *py_str_as_str(const PyObject *py_str)
 {
        PyObject *py_encstr;
        char *str, *outstr;
@@ -191,6 +190,8 @@ static void srd_cb_bin(struct srd_proto_data *pdata, void *cb_data)
 {
        struct srd_proto_data_binary *pdb;
        struct output *op;
+       GString *out;
+       unsigned int i;
 
        DBG("Binary output from %s", pdata->pdo->di->inst_id);
        op = cb_data;
@@ -207,7 +208,15 @@ static void srd_cb_bin(struct srd_proto_data *pdata, void *cb_data)
                 */
                return;
 
-       if (write(op->outfd, pdb->data, pdb->size) == -1)
+       out = g_string_sized_new(128);
+       g_string_printf(out, "%"PRIu64"-%"PRIu64" %s:",
+                       pdata->start_sample, pdata->end_sample,
+                       pdata->pdo->di->inst_id);
+       for (i = 0; i < pdb->size; i++) {
+               g_string_append_printf(out, " %.2x", pdb->data[i]);
+       }
+       g_string_append(out, "\n");
+       if (write(op->outfd, out->str, out->len) == -1)
                ERR("SRD_OUTPUT_BINARY callback write failure!");
 
 }
@@ -297,39 +306,6 @@ static void sr_cb(const struct sr_dev_inst *sdi,
 
 }
 
-int get_stats(int stats[2])
-{
-       FILE *f;
-       size_t len;
-       int tmp;
-       char *buf;
-
-       stats[0] = stats[1] = -1;
-       if (!(f = fopen("/proc/self/status", "r")))
-               return FALSE;
-       len = 128;
-       buf = malloc(len);
-       while (getline(&buf, &len, f) != -1) {
-               if (strcasestr(buf, "vmpeak:")) {
-                       stats[0] = strtoul(buf + 10, NULL, 10);
-               } else if (strcasestr(buf, "vmsize:")) {
-                       tmp = strtoul(buf + 10, NULL, 10);
-                       if (tmp > stats[0])
-                               stats[0] = tmp;
-               } else if (strcasestr(buf, "vmhwm:")) {
-                       stats[1] = strtoul(buf + 6, NULL, 10);
-               } else if (strcasestr(buf, "vmrss:")) {
-                       tmp = strtoul(buf + 10, NULL, 10);
-                       if (tmp > stats[0])
-                               stats[0] = tmp;
-               }
-       }
-       free(buf);
-       fclose(f);
-
-       return TRUE;
-}
-
 static int run_testcase(char *infile, GSList *pdlist, struct output *op)
 {
        struct srd_session *sess;
@@ -343,6 +319,7 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op)
        GHashTable *probes, *opts;
        GSList *pdl, *l;
        int idx;
+       int max_probe;
        char **decoder_class;
 
        if (op->outfile) {
@@ -396,13 +373,17 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op)
                if (pd->probes) {
                        probes = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                                        (GDestroyNotify)g_variant_unref);
+                       max_probe = 0;
                        for (l = pd->probes; l; l = l->next) {
                                probe = l->data;
+                               if (probe->probe > max_probe)
+                                       max_probe = probe->probe;
                                gvar = g_variant_new_int32(probe->probe);
                                g_variant_ref_sink(gvar);
                                g_hash_table_insert(probes, probe->name, gvar);
                        }
-                       if (srd_inst_probe_set_all(di, probes) != SRD_OK)
+                       if (srd_inst_probe_set_all(di, probes,
+                                       (max_probe + 8) / 8) != SRD_OK)
                                return FALSE;
                        g_hash_table_destroy(probes);
                }
@@ -429,7 +410,7 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op)
                        /* Only annotations and binary can have a class. */
                        return FALSE;
                idx = 0;
-               while(l) {
+               while (l) {
                        decoder_class = l->data;
                        if (!strcmp(decoder_class[0], op->class)) {
                                op->class_idx = idx;
@@ -479,7 +460,7 @@ int main(int argc, char **argv)
        pdlist = NULL;
        opt_infile = NULL;
        pd = NULL;
-       while((c = getopt(argc, argv, "dP:p:o:i:O:f:S")) != -1) {
+       while ((c = getopt(argc, argv, "dP:p:o:i:O:f:S")) != -1) {
                switch(c) {
                case 'd':
                        debug = TRUE;
@@ -582,5 +563,3 @@ int main(int argc, char **argv)
 
        return ret;
 }
-
-