From d151314b4d84d6b2c209437c20d392d28110a022 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 31 Jan 2011 23:45:36 +0100 Subject: [PATCH] Import coccinelle test 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(+) 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 0000000000..dbe1f98bcc --- /dev/null +++ b/qa/coccinelle/direct-packet.cocci @@ -0,0 +1,15 @@ +@directpacket@ +identifier p; +typedef Packet; +position p1; +@@ + +Packet p@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 0000000000..61c00dcefe --- /dev/null +++ b/qa/coccinelle/pktnotset-packet.cocci @@ -0,0 +1,25 @@ +@zeroed@ +typedef Packet; +typedef uint8_t; +Packet *p; +position p1; +@@ + +memset(p@p1, 0, ...); + +@isset@ +Packet *p; +position zeroed.p1; +@@ + +memset(p@p1, 0, ...); +... when != p +p->pkt + +@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 0000000000..165ec92535 --- /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