[Spice-devel,v3,44/51] test: Add check on output strings

Submitted by Frediano Ziglio on July 21, 2015, 4:46 p.m.

Details

Message ID 1437497181-26929-45-git-send-email-fziglio@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 21, 2015, 4:46 p.m.
Make sure the generated dissector contains all strings from
the protocol file.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 codegen/Makefile.am   |  2 +-
 codegen/check_strings | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100755 codegen/check_strings

Patch hide | download patch | download mbox

diff --git a/codegen/Makefile.am b/codegen/Makefile.am
index e169d88..000a41b 100644
--- a/codegen/Makefile.am
+++ b/codegen/Makefile.am
@@ -45,7 +45,7 @@  dissector.h: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
 packet-spice.h: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
 	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-wireshark-dissector $< $@ >/dev/null
 
-TESTS = check_dissector
+TESTS = check_dissector check_strings
 check_PROGRAMS = dissector_test compile_check
 
 dissector_test_SOURCES = dissector_test.c test.c test.h
diff --git a/codegen/check_strings b/codegen/check_strings
new file mode 100755
index 0000000..0dd08ef
--- /dev/null
+++ b/codegen/check_strings
@@ -0,0 +1,33 @@ 
+#!/usr/bin/perl
+
+# This scripts check that all strings in the protocol
+# file are found in the output dissector
+use strict;
+
+my $proto = '../spice.proto';
+my $out = 'dissector.c';
+
+open(IN, '<', $out) or die "Error opening output file $out";
+my @all = <IN>;
+close(IN);
+@all = map { $_ =~ s/" G_GINT64_MODIFIER "//g; $_ } @all;
+my $all = join('', @all);
+
+sub check($) {
+	my $what = shift;
+	open(IN, '<', $proto) or die "Error opening protocol file $proto";
+	while (<IN>) {
+		if (m/\@$what\(("[^"]+")/) {
+			if (index($all, $1) < 0) {
+				print "$1 not found!\n";
+			}
+		}
+	}
+	close(IN);
+}
+
+check('ws');
+check('ws_desc');
+check('ws_txt');
+check('ws_txt_n');
+