From 9212ff7e592d4cee3f7ac1472319ce4abb158967 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Fri, 5 Jul 2013 12:33:17 +0200 Subject: [PATCH] coccinelle: dynamic testing through make check This patch modify build system to have make to create the struct-flags.cocci file by running struct-flags.py. This way 'make check' is running the test defined from source code. --- qa/coccinelle/Makefile.am | 18 +++++++- qa/coccinelle/struct-flags.cocci | 69 ++++++++++++++++++++++++++++ qa/coccinelle/tcp-struct-flags.cocci | 38 --------------- 3 files changed, 85 insertions(+), 40 deletions(-) create mode 100644 qa/coccinelle/struct-flags.cocci delete mode 100644 qa/coccinelle/tcp-struct-flags.cocci diff --git a/qa/coccinelle/Makefile.am b/qa/coccinelle/Makefile.am index b5af7dffaa..71dfabf47e 100644 --- a/qa/coccinelle/Makefile.am +++ b/qa/coccinelle/Makefile.am @@ -1,7 +1,21 @@ -EXTRA_DIST= access-pkt-packet.cocci banned-functions.cocci direct-packet.cocci \ - pktnotset-packet.cocci run_check.sh +EXTRA_DIST= access-pkt-packet.cocci \ + action-pkt.cocci \ + banned-functions.cocci \ + direct-packet.cocci \ + malloc-error-check.cocci \ + pktnotset-packet.cocci \ + size_t.cocci \ + struct-flags.cocci \ + sz3.cocci \ + run_check.sh struct-flags.py + +struct-flags.cocci: + $(srcdir)/struct-flags.py > $(top_builddir)/qa/coccinelle/struct-flags.cocci if HAVE_COCCINELLE check: $(top_srcdir)/qa/coccinelle/run_check.sh endif + +distclean-local: + -rm $(top_builddir)/qa/coccinelle/struct-flags.cocci diff --git a/qa/coccinelle/struct-flags.cocci b/qa/coccinelle/struct-flags.cocci new file mode 100644 index 0000000000..d7204aada4 --- /dev/null +++ b/qa/coccinelle/struct-flags.cocci @@ -0,0 +1,69 @@ +@flags@ +TcpSegment *struct0; +identifier struct_flags0 =~ "^(?!SEGMENTTCP_FLAG).+"; +TcpStream *struct1; +identifier struct_flags1 =~ "^(?!STREAMTCP_STREAM_FLAG_).+"; +TcpSession *struct2; +identifier struct_flags2 =~ "^(?!STREAMTCP_FLAG).+"; +Packet *struct3; +identifier struct_flags3 =~ "^(?!FLOW_PKT_).+"; +SignatureHeader *struct4; +identifier struct_flags4 =~ "^(?!SIG_FLAG).+"; +Signature *struct5; +identifier struct_flags5 =~ "^(?!SIG_FLAG).+"; +Signature *struct6; +identifier struct_flags6 =~ "^(?!SIG_FLAG_INIT_).+"; +position p1; +@@ + +( +struct0->flags@p1 |= struct_flags0 +| +struct0->flags@p1 & struct_flags0 +| +struct0->flags@p1 &= ~struct_flags0 +| +struct1->flags@p1 |= struct_flags1 +| +struct1->flags@p1 & struct_flags1 +| +struct1->flags@p1 &= ~struct_flags1 +| +struct2->flags@p1 |= struct_flags2 +| +struct2->flags@p1 & struct_flags2 +| +struct2->flags@p1 &= ~struct_flags2 +| +struct3->flowflags@p1 |= struct_flags3 +| +struct3->flowflags@p1 & struct_flags3 +| +struct3->flowflags@p1 &= ~struct_flags3 +| +struct4->flags@p1 |= struct_flags4 +| +struct4->flags@p1 & struct_flags4 +| +struct4->flags@p1 &= ~struct_flags4 +| +struct5->flags@p1 |= struct_flags5 +| +struct5->flags@p1 & struct_flags5 +| +struct5->flags@p1 &= ~struct_flags5 +| +struct6->init_flags@p1 |= struct_flags6 +| +struct6->init_flags@p1 & struct_flags6 +| +struct6->init_flags@p1 &= ~struct_flags6 +) + +@script:python@ +p1 << flags.p1; +@@ + +print "Invalid usage of flags field at %s:%s, flags value is incorrect (wrong family)." % (p1[0].file, p1[0].line) +import sys +sys.exit(1) diff --git a/qa/coccinelle/tcp-struct-flags.cocci b/qa/coccinelle/tcp-struct-flags.cocci deleted file mode 100644 index 5c8b34df29..0000000000 --- a/qa/coccinelle/tcp-struct-flags.cocci +++ /dev/null @@ -1,38 +0,0 @@ -@flags@ -TcpSession *ssn; -identifier ssn_flags =~ "^(?!STREAMTCP_FLAG).+"; -TcpStream *stream; -identifier stream_flags =~ "^(?!STREAMTCP_STREAM_FLAG).+"; -TcpSegment *segment; -identifier segment_flags =~ "^(?!SEGMENTTCP_FLAG)_.+"; -position p1; -@@ - -( -ssn->flags@p1 |= ssn_flags -| -ssn->flags@p1 & ssn_flags -| -ssn->flags@p1 &= ~ssn_flags -| -stream->flags@p1 |= stream_flags -| -stream->flags@p1 & stream_flags -| -stream->flags@p1 &= ~stream_flags -| -segment->flags@p1 |= segment_flags -| -segment->flags@p1 &= ~segment_flags -| -segment->flags@p1 & segment_flags -) - - -@script:python@ -p1 << flags.p1; -@@ - -print "Invalid usage of flags field at %s:%s, flags value is incorrect (wrong family)." % (p1[0].file, p1[0].line) -import sys -sys.exit(1)