diff mbox series

[v2,2/3] kunit: Add support for suite initialization and cleanup

Message ID 20210729044125.7435-3-bvanassche@acm.org (mailing list archive)
State New
Delegated to: Brendan Higgins
Headers show
Series None | expand

Commit Message

Bart Van Assche July 29, 2021, 4:41 a.m. UTC
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Cc: David Gow <davidgow@google.com>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Cc: kunit-dev@googlegroups.com
Cc: linux-kselftest@vger.kernel.org
Cc: Bodo Stroesser <bostroesser@gmail.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Yanko Kaneti <yaneti@declera.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/kunit/test.h |  4 ++++
 lib/kunit/test.c     | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

Comments

Greg KH July 29, 2021, 5:55 a.m. UTC | #1
On Wed, Jul 28, 2021 at 09:41:24PM -0700, Bart Van Assche wrote:
> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
> Cc: David Gow <davidgow@google.com>
> Cc: Shuah Khan <skhan@linuxfoundation.org>
> Cc: kunit-dev@googlegroups.com
> Cc: linux-kselftest@vger.kernel.org
> Cc: Bodo Stroesser <bostroesser@gmail.com>
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Cc: Yanko Kaneti <yaneti@declera.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---

I know I do not take patches without any changelog text.  Maybe other
maintainers are more lax :(
Bart Van Assche July 29, 2021, 4:52 p.m. UTC | #2
On 7/28/21 10:55 PM, Greg KH wrote:
> On Wed, Jul 28, 2021 at 09:41:24PM -0700, Bart Van Assche wrote:
>> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
>> Cc: David Gow <davidgow@google.com>
>> Cc: Shuah Khan <skhan@linuxfoundation.org>
>> Cc: kunit-dev@googlegroups.com
>> Cc: linux-kselftest@vger.kernel.org
>> Cc: Bodo Stroesser <bostroesser@gmail.com>
>> Cc: Martin K. Petersen <martin.petersen@oracle.com>
>> Cc: Yanko Kaneti <yaneti@declera.com>
>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>> ---
> 
> I know I do not take patches without any changelog text.  Maybe other
> maintainers are more lax :(

Almost every patch from me has an elaborate changelog. For this patch I 
chose not to add a changelog since I think that the subject is 
self-explanatory?

Thanks,

Bart.
Shuah Khan July 29, 2021, 4:55 p.m. UTC | #3
On 7/29/21 10:52 AM, Bart Van Assche wrote:
> On 7/28/21 10:55 PM, Greg KH wrote:
>> On Wed, Jul 28, 2021 at 09:41:24PM -0700, Bart Van Assche wrote:
>>> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
>>> Cc: David Gow <davidgow@google.com>
>>> Cc: Shuah Khan <skhan@linuxfoundation.org>
>>> Cc: kunit-dev@googlegroups.com
>>> Cc: linux-kselftest@vger.kernel.org
>>> Cc: Bodo Stroesser <bostroesser@gmail.com>
>>> Cc: Martin K. Petersen <martin.petersen@oracle.com>
>>> Cc: Yanko Kaneti <yaneti@declera.com>
>>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>>> ---
>>
>> I know I do not take patches without any changelog text.  Maybe other
>> maintainers are more lax :(
> 
> Almost every patch from me has an elaborate changelog. For this patch I chose not to add a changelog since I think that the subject is self-explanatory?
> 

I don't take patches without change logs either. I can't say the subject
tells me what you are doing.

Please add a change log.

thanks,
-- Shuah
Bart Van Assche July 29, 2021, 5:16 p.m. UTC | #4
On 7/29/21 9:55 AM, Shuah Khan wrote:
> On 7/29/21 10:52 AM, Bart Van Assche wrote:
>> On 7/28/21 10:55 PM, Greg KH wrote:
>>> On Wed, Jul 28, 2021 at 09:41:24PM -0700, Bart Van Assche wrote:
>>>> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
>>>> Cc: David Gow <davidgow@google.com>
>>>> Cc: Shuah Khan <skhan@linuxfoundation.org>
>>>> Cc: kunit-dev@googlegroups.com
>>>> Cc: linux-kselftest@vger.kernel.org
>>>> Cc: Bodo Stroesser <bostroesser@gmail.com>
>>>> Cc: Martin K. Petersen <martin.petersen@oracle.com>
>>>> Cc: Yanko Kaneti <yaneti@declera.com>
>>>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>>>> ---
>>>
>>> I know I do not take patches without any changelog text.  Maybe other
>>> maintainers are more lax :(
>>
>> Almost every patch from me has an elaborate changelog. For this patch 
>> I chose not to add a changelog since I think that the subject is 
>> self-explanatory?
> 
> I don't take patches without change logs either. I can't say the subject
> tells me what you are doing.
> 
> Please add a change log.

I will add a changelog. But please note that this patch has been sent to 
Christoph as configfs maintainer.

Bart.
Shuah Khan July 29, 2021, 6:42 p.m. UTC | #5
On 7/29/21 11:16 AM, Bart Van Assche wrote:
> On 7/29/21 9:55 AM, Shuah Khan wrote:
>> On 7/29/21 10:52 AM, Bart Van Assche wrote:
>>> On 7/28/21 10:55 PM, Greg KH wrote:
>>>> On Wed, Jul 28, 2021 at 09:41:24PM -0700, Bart Van Assche wrote:
>>>>> Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
>>>>> Cc: David Gow <davidgow@google.com>
>>>>> Cc: Shuah Khan <skhan@linuxfoundation.org>
>>>>> Cc: kunit-dev@googlegroups.com
>>>>> Cc: linux-kselftest@vger.kernel.org
>>>>> Cc: Bodo Stroesser <bostroesser@gmail.com>
>>>>> Cc: Martin K. Petersen <martin.petersen@oracle.com>
>>>>> Cc: Yanko Kaneti <yaneti@declera.com>
>>>>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>>>>> ---
>>>>
>>>> I know I do not take patches without any changelog text.  Maybe other
>>>> maintainers are more lax :(
>>>
>>> Almost every patch from me has an elaborate changelog. For this patch I chose not to add a changelog since I think that the subject is self-explanatory?
>>
>> I don't take patches without change logs either. I can't say the subject
>> tells me what you are doing.
>>
>> Please add a change log.
> 
> I will add a changelog. But please note that this patch has been sent to Christoph as configfs maintainer.
> 

Sure. This is a kunit patch - hence Kunit maintainers can comment on it.
Besides the comment is about missing change log which is rather basic
kernel dev 101.

Please take a look at Documentation/process/submitting-patches.rst
for information on commit logs.

thanks,
-- Shuah
Bart Van Assche July 29, 2021, 7:22 p.m. UTC | #6
On 7/29/21 11:42 AM, Shuah Khan wrote:
> Please take a look at Documentation/process/submitting-patches.rst
> for information on commit logs.

As one can see below, I'm already familiar with the kernel development 
process:

$ git log --author="Bart Van Assche" | grep -c ^commit
1664

Bart.
Shuah Khan July 29, 2021, 8:42 p.m. UTC | #7
On 7/29/21 1:22 PM, Bart Van Assche wrote:
> On 7/29/21 11:42 AM, Shuah Khan wrote:
>> Please take a look at Documentation/process/submitting-patches.rst
>> for information on commit logs.
> 
> As one can see below, I'm already familiar with the kernel development process:
> 
> $ git log --author="Bart Van Assche" | grep -c ^commit
> 1664
> 

Terrific. I am glad you know the process.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 24b40e5c160b..a6eef96a409c 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -215,6 +215,8 @@  static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
  * struct kunit_suite - describes a related collection of &struct kunit_case
  *
  * @name:	the name of the test. Purely informational.
+ * @init_suite:	called once per test suite before the test cases.
+ * @exit_suite:	called once per test suite after all test cases.
  * @init:	called before every test case.
  * @exit:	called after every test case.
  * @test_cases:	a null terminated array of test cases.
@@ -229,6 +231,8 @@  static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
  */
 struct kunit_suite {
 	const char name[256];
+	int (*init_suite)(void);
+	void (*exit_suite)(void);
 	int (*init)(struct kunit *test);
 	void (*exit)(struct kunit *test);
 	struct kunit_case *test_cases;
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index d79ecb86ea57..c271692ced93 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -397,9 +397,19 @@  int kunit_run_tests(struct kunit_suite *suite)
 {
 	char param_desc[KUNIT_PARAM_DESC_SIZE];
 	struct kunit_case *test_case;
+	int res = 0;
 
 	kunit_print_subtest_start(suite);
 
+	if (suite->init_suite)
+		res = suite->init_suite();
+
+	if (res < 0) {
+		kunit_log(KERN_INFO, suite, KUNIT_SUBTEST_INDENT
+			  "# Suite initialization failed (%d)\n", res);
+		goto end;
+	}
+
 	kunit_suite_for_each_test_case(suite, test_case) {
 		struct kunit test = { .param_value = NULL, .param_index = 0 };
 		test_case->status = KUNIT_SKIPPED;
@@ -439,6 +449,10 @@  int kunit_run_tests(struct kunit_suite *suite)
 				      test.status_comment);
 	}
 
+	if (suite->exit_suite)
+		suite->exit_suite();
+
+end:
 	kunit_print_subtest_end(suite);
 
 	return 0;