[Oisf-devel] [PATCH 2/7] Import coccinelle test
Eric Leblond
eric at regit.org
Mon Jan 31 22:45:36 UTC 2011
This is a import of two coccinelle patches that detect problem
on Packet handling. They are run on all commited C files in src
by the script run_check.sh.
---
qa/coccinelle/direct-packet.cocci | 15 +++++++++++++++
qa/coccinelle/pktnotset-packet.cocci | 25 +++++++++++++++++++++++++
qa/coccinelle/run_check.sh | 10 ++++++++++
3 files changed, 50 insertions(+), 0 deletions(-)
create mode 100644 qa/coccinelle/direct-packet.cocci
create mode 100644 qa/coccinelle/pktnotset-packet.cocci
create mode 100755 qa/coccinelle/run_check.sh
diff --git a/qa/coccinelle/direct-packet.cocci b/qa/coccinelle/direct-packet.cocci
new file mode 100644
index 0000000..f914644
--- /dev/null
+++ b/qa/coccinelle/direct-packet.cocci
@@ -0,0 +1,15 @@
+ at directpacket@
+identifier p;
+typedef Packet;
+position p1;
+@@
+
+Packet p at p1;
+
+@ script:python @
+p1 << directpacket.p1;
+@@
+
+print "Invalid Packet definition, explicit allocation must be used at %s:%s" % (p1[0].file, p1[0].line)
+import sys
+sys.exit(1)
diff --git a/qa/coccinelle/pktnotset-packet.cocci b/qa/coccinelle/pktnotset-packet.cocci
new file mode 100644
index 0000000..61c00dc
--- /dev/null
+++ b/qa/coccinelle/pktnotset-packet.cocci
@@ -0,0 +1,25 @@
+ at zeroed@
+typedef Packet;
+typedef uint8_t;
+Packet *p;
+position p1;
+@@
+
+memset(p at p1, 0, ...);
+
+ at isset@
+Packet *p;
+position zeroed.p1;
+@@
+
+memset(p at p1, 0, ...);
+... when != p
+p->pkt
+
+ at script:python depends on !isset@
+p1 << zeroed.p1;
+@@
+
+print "Packet zeroed at %s:%s but pkt field is not set afterward." % (p1[0].file, p1[0].line)
+import sys
+sys.exit(1)
diff --git a/qa/coccinelle/run_check.sh b/qa/coccinelle/run_check.sh
new file mode 100755
index 0000000..165ec92
--- /dev/null
+++ b/qa/coccinelle/run_check.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+for SMPL in *.cocci; do
+ echo "Testing cocci file: $SMPL"
+ for FILE in $(git ls-tree -r --name-only --full-tree HEAD src/ | grep -E '*.c$') ; do
+ spatch -sp_file $SMPL ../../$FILE 2>/dev/null || exit 1;
+ done
+done
+
+exit 0
--
1.7.1
More information about the Oisf-devel
mailing list