summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/pdtest19
-rw-r--r--tests/runtc.c44
2 files changed, 57 insertions, 6 deletions
diff --git a/tests/pdtest b/tests/pdtest
index 608cd8a..2a90f2c 100755
--- a/tests/pdtest
+++ b/tests/pdtest
@@ -6,6 +6,8 @@ from getopt import getopt
from tempfile import mkstemp
from subprocess import Popen, PIPE
from difflib import Differ
+from hashlib import md5
+from shutil import copy
DEBUG = 0
VERBOSE = False
@@ -203,7 +205,7 @@ def get_tests(testnames):
return tests
-def diff_files(f1, f2):
+def diff_textfiles(f1, f2):
t1 = open(f1).readlines()
t2 = open(f2).readlines()
diff = []
@@ -215,6 +217,19 @@ def diff_files(f1, f2):
return diff
+def compare_binfiles(f1, f2):
+ h1 = md5()
+ h1.update(open(f1, 'rb').read())
+ h2 = md5()
+ h2.update(open(f2, 'rb').read())
+ if h1.digest() == h2.digest():
+ result = None
+ else:
+ result = ["Binary output does not match."]
+
+ return result
+
+
def run_tests(tests, fix=False):
errors = 0
results = []
@@ -265,6 +280,8 @@ def run_tests(tests, fix=False):
diff = diff_error = None
if op['type'] == 'annotation':
diff = diff_textfiles(match, outfile)
+ elif op['type'] == 'binary':
+ diff = compare_binfiles(match, outfile)
else:
diff = ["Unsupported output type '%s'." % op['type']]
except Exception as e:
diff --git a/tests/runtc.c b/tests/runtc.c
index f0649f9..e6266b0 100644
--- a/tests/runtc.c
+++ b/tests/runtc.c
@@ -136,6 +136,34 @@ void usage(char *msg)
}
+static void srd_cb_bin(struct srd_proto_data *pdata, void *cb_data)
+{
+ struct srd_proto_data_binary *pdb;
+ struct output *op;
+
+ op = cb_data;
+ if (op->type != SRD_OUTPUT_BINARY)
+ return;
+
+ DBG("Binary output from %s", pdata->pdo->di->inst_id);
+ pdb = pdata->data;
+
+ if (strcmp(pdata->pdo->di->inst_id, op->pd))
+ /* This is not the PD selected for output. */
+ return;
+
+ if (op->class_idx != -1 && op->class_idx != pdb->bin_class)
+ /*
+ * This output takes a specific binary class,
+ * but not the one that just came in.
+ */
+ return;
+
+ if (write(op->outfd, pdb->data, pdb->size) == -1)
+ ERR("Oops!");
+
+}
+
static void srd_cb_ann(struct srd_proto_data *pdata, void *cb_data)
{
struct srd_decoder *dec;
@@ -145,18 +173,22 @@ static void srd_cb_ann(struct srd_proto_data *pdata, void *cb_data)
int i;
char **dec_ann;
- DBG("Annotation from %s", pdata->pdo->di->inst_id);
op = cb_data;
+ if (op->type != SRD_OUTPUT_ANN)
+ return;
+
+ DBG("Annotation output from %s", pdata->pdo->di->inst_id);
pda = pdata->data;
dec = pdata->pdo->di->decoder;
-
if (strcmp(pdata->pdo->di->inst_id, op->pd))
/* This is not the PD selected for output. */
return;
if (op->class_idx != -1 && op->class_idx != pda->ann_format)
- /* This output takes a specific annotation class,
- * but not the one that just came in. */
+ /*
+ * This output takes a specific annotation class,
+ * but not the one that just came in.
+ */
return;
dec_ann = g_slist_nth_data(dec->annotations, pda->ann_format);
@@ -282,6 +314,7 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op)
return FALSE;
sr_session_datafeed_callback_add(sr_cb, sess);
srd_pd_output_callback_add(sess, SRD_OUTPUT_ANN, srd_cb_ann, op);
+ srd_pd_output_callback_add(sess, SRD_OUTPUT_BINARY, srd_cb_bin, op);
prev_di = NULL;
pd = NULL;
@@ -352,7 +385,8 @@ static int run_testcase(char *infile, GSList *pdlist, struct output *op)
ERR("Output class '%s' not found in decoder %s.",
op->class, pd->name);
return FALSE;
- }
+ } else
+ DBG("Class %s index is %d", op->class, op->class_idx);
}
sr_session_start();