diff mbox series

[v7,kunit-next,3/4] kunit: subtests should be indented 4 spaces according to TAP

Message ID 1584110682-3837-4-git-send-email-alan.maguire@oracle.com (mailing list archive)
State Changes Requested
Headers show
Series kunit: add debugfs representation to show results | expand

Commit Message

Alan Maguire March 13, 2020, 2:44 p.m. UTC
Introduce KUNIT_INDENT macro which corresponds to 4-space indentation,
and use it to modify indentation from tab to 4 spaces.

Suggested-by: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Reviewed-by: Frank Rowand <frank.rowand@sony.com>
---
 include/kunit/test.h                |  7 +++-
 lib/kunit/assert.c                  | 79 +++++++++++++++++++------------------
 lib/kunit/test.c                    |  6 +--
 tools/testing/kunit/kunit_parser.py | 10 ++---
 4 files changed, 54 insertions(+), 48 deletions(-)

Comments

Brendan Higgins March 14, 2020, midnight UTC | #1
On Fri, Mar 13, 2020 at 7:45 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> Introduce KUNIT_INDENT macro which corresponds to 4-space indentation,
> and use it to modify indentation from tab to 4 spaces.
>
> Suggested-by: Frank Rowand <frowand.list@gmail.com>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> Reviewed-by: Frank Rowand <frank.rowand@sony.com>

Reviewed-by: Brendan Higgins <brendanhiggins@google.com>

Thanks!
Shuah March 25, 2020, 8:05 p.m. UTC | #2
On 3/13/20 8:44 AM, Alan Maguire wrote:
> Introduce KUNIT_INDENT macro which corresponds to 4-space indentation,
> and use it to modify indentation from tab to 4 spaces.
> 
> Suggested-by: Frank Rowand <frowand.list@gmail.com>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> Reviewed-by: Frank Rowand <frank.rowand@sony.com>
> ---
>   include/kunit/test.h                |  7 +++-
>   lib/kunit/assert.c                  | 79 +++++++++++++++++++------------------
>   lib/kunit/test.c                    |  6 +--
>   tools/testing/kunit/kunit_parser.py | 10 ++---
>   4 files changed, 54 insertions(+), 48 deletions(-)
> 
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index f7b2ed4c..d49cdb4 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -84,6 +84,10 @@ struct kunit_resource {
>   /* Size of log associated with test. */
>   #define KUNIT_LOG_SIZE	512
>   
> +/* TAP specifies subtest indentation of 4 spaces. */
> +#define KUNIT_INDENT	"    "
> +#define KUNIT_INDENT2	KUNIT_INDENT KUNIT_INDENT

Sorry for a late comment on this.

What's the reason to do it this way? Why wouldn't you define
it as 8 spaces long string?

Also can you please make sure to run checkpatch --strict on the
patches you send?

thanks,
-- Shuah
Alan Maguire March 25, 2020, 10:03 p.m. UTC | #3
On Wed, 25 Mar 2020, shuah wrote:

> On 3/13/20 8:44 AM, Alan Maguire wrote:
> > Introduce KUNIT_INDENT macro which corresponds to 4-space indentation,
> > and use it to modify indentation from tab to 4 spaces.
> > 
> > Suggested-by: Frank Rowand <frowand.list@gmail.com>
> > Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> > Reviewed-by: Frank Rowand <frank.rowand@sony.com>
> > ---
> >   include/kunit/test.h                |  7 +++-
> >   lib/kunit/assert.c                  | 79
> >   +++++++++++++++++++------------------
> >   lib/kunit/test.c                    |  6 +--
> >   tools/testing/kunit/kunit_parser.py | 10 ++---
> >   4 files changed, 54 insertions(+), 48 deletions(-)
> > 
> > diff --git a/include/kunit/test.h b/include/kunit/test.h
> > index f7b2ed4c..d49cdb4 100644
> > --- a/include/kunit/test.h
> > +++ b/include/kunit/test.h
> > @@ -84,6 +84,10 @@ struct kunit_resource {
> >   /* Size of log associated with test. */
> >   #define KUNIT_LOG_SIZE	512
> >   
> > +/* TAP specifies subtest indentation of 4 spaces. */
> > +#define KUNIT_INDENT	"    "
> > +#define KUNIT_INDENT2	KUNIT_INDENT KUNIT_INDENT
> 
> Sorry for a late comment on this.
> 
> What's the reason to do it this way? Why wouldn't you define
> it as 8 spaces long string?
>

I could have I suppose; I thought it makes it a bit easier
to read as above (though it did generate a checkpatch
warning; I thought readability was more important in this   
case, but I can alter if needed).
 
> Also can you please make sure to run checkpatch --strict on the
> patches you send?
>

Sure! There were also some other line-too-long warnings
generated as a result of this patch, but when I fixed those
checkpatch complained about splitting strings across multiple
lines.  The only way out was to reduce the amount of information
in the log messages, which I didn't want to do.  In future I can
note checkpatch warnings that I couldn't find a way to fix in the
commit message if that would help?

Thanks for taking a look!

Alan
 
> thanks,
> -- Shuah
> 
>
Shuah March 25, 2020, 10:11 p.m. UTC | #4
On 3/25/20 4:03 PM, Alan Maguire wrote:
> On Wed, 25 Mar 2020, shuah wrote:
> 
>> On 3/13/20 8:44 AM, Alan Maguire wrote:
>>> Introduce KUNIT_INDENT macro which corresponds to 4-space indentation,
>>> and use it to modify indentation from tab to 4 spaces.
>>>
>>> Suggested-by: Frank Rowand <frowand.list@gmail.com>
>>> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
>>> Reviewed-by: Frank Rowand <frank.rowand@sony.com>
>>> ---
>>>    include/kunit/test.h                |  7 +++-
>>>    lib/kunit/assert.c                  | 79
>>>    +++++++++++++++++++------------------
>>>    lib/kunit/test.c                    |  6 +--
>>>    tools/testing/kunit/kunit_parser.py | 10 ++---
>>>    4 files changed, 54 insertions(+), 48 deletions(-)
>>>
>>> diff --git a/include/kunit/test.h b/include/kunit/test.h
>>> index f7b2ed4c..d49cdb4 100644
>>> --- a/include/kunit/test.h
>>> +++ b/include/kunit/test.h
>>> @@ -84,6 +84,10 @@ struct kunit_resource {
>>>    /* Size of log associated with test. */
>>>    #define KUNIT_LOG_SIZE	512
>>>    
>>> +/* TAP specifies subtest indentation of 4 spaces. */
>>> +#define KUNIT_INDENT	"    "
>>> +#define KUNIT_INDENT2	KUNIT_INDENT KUNIT_INDENT
>>
>> Sorry for a late comment on this.
>>
>> What's the reason to do it this way? Why wouldn't you define
>> it as 8 spaces long string?
>>
> 
> I could have I suppose; I thought it makes it a bit easier
> to read as above (though it did generate a checkpatch
> warning; I thought readability was more important in this
> case, but I can alter if needed).
>   
Please do. Couple of things. KUNIT_INDENT2 doesn't really
tell me much. Same with KUNIT_INDENT

Please make the names more descriptive. Something along the
lines of

KUNIT_INDENT_4SPACE
KUNIT_INDENT_8SPACE

>> Also can you please make sure to run checkpatch --strict on the
>> patches you send?
>>
> 
> Sure! There were also some other line-too-long warnings
> generated as a result of this patch, but when I fixed those
> checkpatch complained about splitting strings across multiple
> lines.  The only way out was to reduce the amount of information
> in the log messages, which I didn't want to do.  In future I can
> note checkpatch warnings that I couldn't find a way to fix in the
> commit message if that would help?
> 

I understand. This is an error though. I am willing to ignore line-too
long warnings for the most part. I don't like to see errors in general.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/include/kunit/test.h b/include/kunit/test.h
index f7b2ed4c..d49cdb4 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -84,6 +84,10 @@  struct kunit_resource {
 /* Size of log associated with test. */
 #define KUNIT_LOG_SIZE	512
 
+/* TAP specifies subtest indentation of 4 spaces. */
+#define KUNIT_INDENT	"    "
+#define KUNIT_INDENT2	KUNIT_INDENT KUNIT_INDENT
+
 /**
  * struct kunit_case - represents an individual test case.
  *
@@ -395,7 +399,8 @@  static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
 	} while (0)
 
 #define kunit_printk(lvl, test, fmt, ...)				\
-	kunit_log(lvl, test, "\t# %s: " fmt, (test)->name, ##__VA_ARGS__)
+	kunit_log(lvl, test, KUNIT_INDENT "# %s: " fmt, (test)->name,	\
+		  ##__VA_ARGS__)
 
 /**
  * kunit_info() - Prints an INFO level message associated with @test.
diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c
index b24bebc..17b0214 100644
--- a/lib/kunit/assert.c
+++ b/lib/kunit/assert.c
@@ -6,6 +6,7 @@ 
  * Author: Brendan Higgins <brendanhiggins@google.com>
  */
 #include <kunit/assert.h>
+#include <kunit/test.h>
 
 #include "string-stream.h"
 
@@ -53,12 +54,12 @@  void kunit_unary_assert_format(const struct kunit_assert *assert,
 	kunit_base_assert_format(assert, stream);
 	if (unary_assert->expected_true)
 		string_stream_add(stream,
-				 "\tExpected %s to be true, but is false\n",
-				 unary_assert->condition);
+				  KUNIT_INDENT "Expected %s to be true, but is false\n",
+				  unary_assert->condition);
 	else
 		string_stream_add(stream,
-				 "\tExpected %s to be false, but is true\n",
-				 unary_assert->condition);
+				  KUNIT_INDENT "Expected %s to be false, but is true\n",
+				  unary_assert->condition);
 	kunit_assert_print_msg(assert, stream);
 }
 EXPORT_SYMBOL_GPL(kunit_unary_assert_format);
@@ -72,13 +73,13 @@  void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
 	kunit_base_assert_format(assert, stream);
 	if (!ptr_assert->value) {
 		string_stream_add(stream,
-				 "\tExpected %s is not null, but is\n",
-				 ptr_assert->text);
+				  KUNIT_INDENT "Expected %s is not null, but is\n",
+				  ptr_assert->text);
 	} else if (IS_ERR(ptr_assert->value)) {
 		string_stream_add(stream,
-				 "\tExpected %s is not error, but is: %ld\n",
-				 ptr_assert->text,
-				 PTR_ERR(ptr_assert->value));
+				  KUNIT_INDENT "Expected %s is not error, but is: %ld\n",
+				  ptr_assert->text,
+				  PTR_ERR(ptr_assert->value));
 	}
 	kunit_assert_print_msg(assert, stream);
 }
@@ -92,16 +93,16 @@  void kunit_binary_assert_format(const struct kunit_assert *assert,
 
 	kunit_base_assert_format(assert, stream);
 	string_stream_add(stream,
-			 "\tExpected %s %s %s, but\n",
-			 binary_assert->left_text,
-			 binary_assert->operation,
-			 binary_assert->right_text);
-	string_stream_add(stream, "\t\t%s == %lld\n",
-			 binary_assert->left_text,
-			 binary_assert->left_value);
-	string_stream_add(stream, "\t\t%s == %lld",
-			 binary_assert->right_text,
-			 binary_assert->right_value);
+			  KUNIT_INDENT "Expected %s %s %s, but\n",
+			  binary_assert->left_text,
+			  binary_assert->operation,
+			  binary_assert->right_text);
+	string_stream_add(stream, KUNIT_INDENT2 "%s == %lld\n",
+			  binary_assert->left_text,
+			  binary_assert->left_value);
+	string_stream_add(stream, KUNIT_INDENT "%s == %lld",
+			  binary_assert->right_text,
+			  binary_assert->right_value);
 	kunit_assert_print_msg(assert, stream);
 }
 EXPORT_SYMBOL_GPL(kunit_binary_assert_format);
@@ -114,16 +115,16 @@  void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
 
 	kunit_base_assert_format(assert, stream);
 	string_stream_add(stream,
-			 "\tExpected %s %s %s, but\n",
-			 binary_assert->left_text,
-			 binary_assert->operation,
-			 binary_assert->right_text);
-	string_stream_add(stream, "\t\t%s == %pK\n",
-			 binary_assert->left_text,
-			 binary_assert->left_value);
-	string_stream_add(stream, "\t\t%s == %pK",
-			 binary_assert->right_text,
-			 binary_assert->right_value);
+			  KUNIT_INDENT "Expected %s %s %s, but\n",
+			  binary_assert->left_text,
+			  binary_assert->operation,
+			  binary_assert->right_text);
+	string_stream_add(stream, KUNIT_INDENT2 "%s == %pK\n",
+			  binary_assert->left_text,
+			  binary_assert->left_value);
+	string_stream_add(stream, KUNIT_INDENT2 "%s == %pK",
+			  binary_assert->right_text,
+			  binary_assert->right_value);
 	kunit_assert_print_msg(assert, stream);
 }
 EXPORT_SYMBOL_GPL(kunit_binary_ptr_assert_format);
@@ -136,16 +137,16 @@  void kunit_binary_str_assert_format(const struct kunit_assert *assert,
 
 	kunit_base_assert_format(assert, stream);
 	string_stream_add(stream,
-			 "\tExpected %s %s %s, but\n",
-			 binary_assert->left_text,
-			 binary_assert->operation,
-			 binary_assert->right_text);
-	string_stream_add(stream, "\t\t%s == %s\n",
-			 binary_assert->left_text,
-			 binary_assert->left_value);
-	string_stream_add(stream, "\t\t%s == %s",
-			 binary_assert->right_text,
-			 binary_assert->right_value);
+			  KUNIT_INDENT "Expected %s %s %s, but\n",
+			  binary_assert->left_text,
+			  binary_assert->operation,
+			  binary_assert->right_text);
+	string_stream_add(stream, KUNIT_INDENT2 "%s == %s\n",
+			  binary_assert->left_text,
+			  binary_assert->left_value);
+	string_stream_add(stream, KUNIT_INDENT2 "%s == %s",
+			  binary_assert->right_text,
+			  binary_assert->right_value);
 	kunit_assert_print_msg(assert, stream);
 }
 EXPORT_SYMBOL_GPL(kunit_binary_str_assert_format);
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index a3fa21f..e9609c2 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -69,8 +69,8 @@  size_t kunit_suite_num_test_cases(struct kunit_suite *suite)
 static void kunit_print_subtest_start(struct kunit_suite *suite)
 {
 	kunit_print_tap_version();
-	kunit_log(KERN_INFO, suite, "\t# Subtest: %s", suite->name);
-	kunit_log(KERN_INFO, suite, "\t1..%zd",
+	kunit_log(KERN_INFO, suite, KUNIT_INDENT "# Subtest: %s", suite->name);
+	kunit_log(KERN_INFO, suite, KUNIT_INDENT "1..%zd",
 		  kunit_suite_num_test_cases(suite));
 }
 
@@ -96,7 +96,7 @@  static void kunit_print_ok_not_ok(void *test_or_suite,
 			kunit_status_to_string(is_ok),
 			test_number, description);
 	else
-		kunit_log(KERN_INFO, test, "\t%s %zd - %s",
+		kunit_log(KERN_INFO, test, KUNIT_INDENT "%s %zd - %s",
 			  kunit_status_to_string(is_ok),
 			  test_number, description);
 }
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index 4ffbae0..14265a5 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -91,7 +91,7 @@  def print_log(log):
 	for m in log:
 		print_with_timestamp(m)
 
-TAP_ENTRIES = re.compile(r'^(TAP|\t?ok|\t?not ok|\t?[0-9]+\.\.[0-9]+|\t?#).*$')
+TAP_ENTRIES = re.compile(r'^(TAP|[\s]*ok|[\s]*not ok|[\s]*[0-9]+\.\.[0-9]+|[\s]*#).*$')
 
 def consume_non_diagnositic(lines: List[str]) -> None:
 	while lines and not TAP_ENTRIES.match(lines[0]):
@@ -104,7 +104,7 @@  def save_non_diagnositic(lines: List[str], test_case: TestCase) -> None:
 
 OkNotOkResult = namedtuple('OkNotOkResult', ['is_ok','description', 'text'])
 
-OK_NOT_OK_SUBTEST = re.compile(r'^\t(ok|not ok) [0-9]+ - (.*)$')
+OK_NOT_OK_SUBTEST = re.compile(r'^[\s]+(ok|not ok) [0-9]+ - (.*)$')
 
 OK_NOT_OK_MODULE = re.compile(r'^(ok|not ok) [0-9]+ - (.*)$')
 
@@ -133,7 +133,7 @@  def parse_ok_not_ok_test_case(lines: List[str],
 	else:
 		return False
 
-SUBTEST_DIAGNOSTIC = re.compile(r'^\t# .*?: (.*)$')
+SUBTEST_DIAGNOSTIC = re.compile(r'^[\s]+# .*?: (.*)$')
 DIAGNOSTIC_CRASH_MESSAGE = 'kunit test case crashed!'
 
 def parse_diagnostic(lines: List[str], test_case: TestCase) -> bool:
@@ -160,7 +160,7 @@  def parse_test_case(lines: List[str], expecting_test_case: bool) -> TestCase:
 	else:
 		return None
 
-SUBTEST_HEADER = re.compile(r'^\t# Subtest: (.*)$')
+SUBTEST_HEADER = re.compile(r'^[\s]+# Subtest: (.*)$')
 
 def parse_subtest_header(lines: List[str]) -> str:
 	consume_non_diagnositic(lines)
@@ -173,7 +173,7 @@  def parse_subtest_header(lines: List[str]) -> str:
 	else:
 		return None
 
-SUBTEST_PLAN = re.compile(r'\t[0-9]+\.\.([0-9]+)')
+SUBTEST_PLAN = re.compile(r'[\s]+[0-9]+\.\.([0-9]+)')
 
 def parse_subtest_plan(lines: List[str]) -> int:
 	consume_non_diagnositic(lines)