diff mbox

Teach sparse about the __COUNTER__ predefined macro

Message ID 20150124112705.GA47109@macpro.local (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Luc Van Oostenryck Jan. 24, 2015, 11:27 a.m. UTC
On Fri, Jan 23, 2015 at 05:29:58PM -0800, Josh Triplett wrote:
> On Sat, Jan 24, 2015 at 12:59:35AM +0100, Luc Van Oostenryck wrote:
> > Subject: [PATCH] Teach sparse about the __COUNTER__ predefined macro.
> > 
> > This macro expands to sequential integral values starting from 0,
> > and this for each top-level source file.
> > 
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> 
> counter3.c seems like a bit of an abuse of the test suite framework, but
> I don't have a better suggestion.
> 
> Reviewed-by: Josh Triplett <josh@joshtriplett.org>

Yes, I know ...

Would the following change to the test-suite (introducing tags to separate input sections)
and the corresponding test be more OK ?


Luc

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Josh Triplett Jan. 24, 2015, 8:19 p.m. UTC | #1
On Sat, Jan 24, 2015 at 12:27:06PM +0100, Luc Van Oostenryck wrote:
> On Fri, Jan 23, 2015 at 05:29:58PM -0800, Josh Triplett wrote:
> > On Sat, Jan 24, 2015 at 12:59:35AM +0100, Luc Van Oostenryck wrote:
> > > Subject: [PATCH] Teach sparse about the __COUNTER__ predefined macro.
> > > 
> > > This macro expands to sequential integral values starting from 0,
> > > and this for each top-level source file.
> > > 
> > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> > 
> > counter3.c seems like a bit of an abuse of the test suite framework, but
> > I don't have a better suggestion.
> > 
> > Reviewed-by: Josh Triplett <josh@joshtriplett.org>
> 
> Yes, I know ...
> 
> Would the following change to the test-suite (introducing tags to separate input sections)
> and the corresponding test be more OK ?

Interesting idea!  That would also allow consolidating tests that
require include files into a single test file, if it's possible to
#include "$file1"; for instance, pragma-once.c could avoid recursing if
the test fails.

I'll leave it to others to decide if this seems like a direction the
test suite should expand to cover, or if for this single case counter3.c
should just include other tests as your previous patch did.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Luc Van Oostenryck Jan. 24, 2015, 8:39 p.m. UTC | #2
On Sat, Jan 24, 2015 at 12:19:50PM -0800, Josh Triplett wrote:
> On Sat, Jan 24, 2015 at 12:27:06PM +0100, Luc Van Oostenryck wrote:
> > On Fri, Jan 23, 2015 at 05:29:58PM -0800, Josh Triplett wrote:
> > > On Sat, Jan 24, 2015 at 12:59:35AM +0100, Luc Van Oostenryck wrote:
> > > > Subject: [PATCH] Teach sparse about the __COUNTER__ predefined macro.
> > > > 
> > > > This macro expands to sequential integral values starting from 0,
> > > > and this for each top-level source file.
> > > > 
> > > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> > > 
> > > counter3.c seems like a bit of an abuse of the test suite framework, but
> > > I don't have a better suggestion.
> > > 
> > > Reviewed-by: Josh Triplett <josh@joshtriplett.org>
> > 
> > Yes, I know ...
> > 
> > Would the following change to the test-suite (introducing tags to separate input sections)
> > and the corresponding test be more OK ?
> 
> Interesting idea!  That would also allow consolidating tests that
> require include files into a single test file, if it's possible to
> #include "$file1"; for instance, pragma-once.c could avoid recursing if
> the test fails.
> 
> I'll leave it to others to decide if this seems like a direction the
> test suite should expand to cover, or if for this single case counter3.c
> should just include other tests as your previous patch did.
> 
> - Josh Triplett
> --

Yes, it's fairly easy to add. In fact ... yesterday I had a version that
did that but I removed it because I found it a bit hackish and it was
not needed.


Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/validation/test-suite b/validation/test-suite
index df5a7c60..97d4dd40 100755
--- a/validation/test-suite
+++ b/validation/test-suite
@@ -102,6 +102,15 @@  do_test()
 	fi
 	test_name=$last_result
 
+	# grab the input sections
+	input_nr=1
+	while grep -q "input-file-$input_nr-start" "$file"; do
+		sed -n "/input-file-$input_nr-start/,/input-file-$input_nr-end/p" "$file" \
+			| grep -v input-file > "$file".input$input_nr
+		eval "file$input_nr=$file.input$input_nr"
+		input_nr=$(($input_nr + 1))
+	done
+
 	# does the test provide a specific command ?
 	cmd=`eval echo $default_path/$default_cmd`
 	get_value "check-command" $file
diff --git a/Documentation/test-suite b/Documentation/test-suite
index 6c4f24f6..34b38696 100644
--- a/Documentation/test-suite
+++ b/Documentation/test-suite
@@ -32,6 +32,10 @@  check-output-start / check-output-end (optional)
 check-known-to-fail (optional)
 	Mark the test as being known to fail.
 
+input-file-1-start / input-file-1-end, / input-file-2-start / ... (optional)
+	The input files of check-command lies between those tags.
+	It's only needed when the test needs several distincts input files.
+
 
 	Using test-suite
 	~~~~~~~~~~~~~~~~
@@ -58,6 +62,9 @@  name:
 cmd:
 	check-command value. If no cmd is provided, it defaults to
 	"sparse $file".
+	If the "input-file-1-start/..." tags are used those files are to be
+	referenced with "$file1", ... and the command need to be something like:
+	"sparse $file1 $file2"
 
 The output of the test-suite format command can be redirected into the
 test case to create a test-suite formated file.
diff --git a/validation/preprocessor/counter3.c b/validation/preprocessor/counter3.c
index e69de29b..76635e82 100644
--- a/validation/preprocessor/counter3.c
+++ b/validation/preprocessor/counter3.c
@@ -0,0 +1,20 @@ 
+/* input-file-1-start */
+__COUNTER__
+__COUNTER__
+/* input-file-1-end */
+
+/* input-file-2-start */
+__COUNTER__
+/* input-file-2-end */
+
+/*
+ * check-name: __COUNTER__ #3
+ * check-command: sparse -E $file1 $file2
+ *
+ * check-output-start
+
+0
+1
+0
+ * check-output-end
+ */