From patchwork Thu Oct 17 18:07:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 11196795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC52813B1 for ; Thu, 17 Oct 2019 18:09:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 82B2E21D7C for ; Thu, 17 Oct 2019 18:09:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="bBWA1ouR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395536AbfJQSJI (ORCPT ); Thu, 17 Oct 2019 14:09:08 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34960 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395417AbfJQSJH (ORCPT ); Thu, 17 Oct 2019 14:09:07 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI4Bwo161294; Thu, 17 Oct 2019 18:07:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=7JKg8okzpJWNJf5zujaC24NrMGYE1iKIoSUN+NfOr9k=; b=bBWA1ouRm0Zv+mrXzl8hiJ8pQAQIU6s68VzExj8x532Qw0VTasA9G9zHFtW8sUJU+bpR /birDGwj5EW7n2Km8Tp+Hu4b3dLohncIfR3KyiSi4gXZv9EqZUZZx/akxR7ieUQ01xMB Lw/cFP7Bkq7dY6PfxLHR2Y5rJOQgrUrlGPSkqvFk8oag0waGeOn1ZNyNBQG8NQQGIike xwF/hz+U1X5jpwFnNhXJDxZbaN2ajENk5uka/S4l40g0LOXjeku7u79xUqZw1876VTpX HdfxnMPLerQKsWK+aPbV2YoCbRn0Ts0F8FjkSg8lA8ZKrOQ7vqhlsqpSSntOuynMD7uY Rg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2vk68v0518-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:07:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI3NG5165386; Thu, 17 Oct 2019 18:07:41 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2vpcm3bve7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:07:41 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9HI7epS029041; Thu, 17 Oct 2019 18:07:40 GMT Received: from dhcp-10-175-161-223.vpn.oracle.com (/10.175.161.223) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Oct 2019 18:07:39 +0000 From: Alan Maguire To: brendanhiggins@google.com, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, yamada.masahiro@socionext.com, catalin.marinas@arm.com, joe.lawrence@redhat.com, penguin-kernel@i-love.sakura.ne.jp, schowdary@nvidia.com, urezki@gmail.com, andriy.shevchenko@linux.intel.com, corbet@lwn.net, linux-doc@vger.kernel.org, Alan Maguire , Knut Omang Subject: [PATCH v3 linux-kselftest-test 1/6] kunit: move string-stream.h to lib/kunit/string-stream-impl.h Date: Thu, 17 Oct 2019 19:07:14 +0100 Message-Id: <1571335639-21675-2-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> References: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170163 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170163 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org string stream interfaces are not intended for external use; move them from include/kunit to lib/kunit/string-stream-impl.h accordingly. Signed-off-by: Alan Maguire Signed-off-by: Knut Omang --- include/kunit/assert.h | 3 ++- include/kunit/string-stream.h | 51 ------------------------------------------ lib/kunit/assert.c | 1 + lib/kunit/string-stream-impl.h | 51 ++++++++++++++++++++++++++++++++++++++++++ lib/kunit/string-stream-test.c | 2 +- lib/kunit/string-stream.c | 3 ++- lib/kunit/test.c | 1 + 7 files changed, 58 insertions(+), 54 deletions(-) delete mode 100644 include/kunit/string-stream.h create mode 100644 lib/kunit/string-stream-impl.h diff --git a/include/kunit/assert.h b/include/kunit/assert.h index db6a0fc..ad889b5 100644 --- a/include/kunit/assert.h +++ b/include/kunit/assert.h @@ -9,10 +9,11 @@ #ifndef _KUNIT_ASSERT_H #define _KUNIT_ASSERT_H -#include #include +#include struct kunit; +struct string_stream; /** * enum kunit_assert_type - Type of expectation/assertion. diff --git a/include/kunit/string-stream.h b/include/kunit/string-stream.h deleted file mode 100644 index fe98a00..0000000 --- a/include/kunit/string-stream.h +++ /dev/null @@ -1,51 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * C++ stream style string builder used in KUnit for building messages. - * - * Copyright (C) 2019, Google LLC. - * Author: Brendan Higgins - */ - -#ifndef _KUNIT_STRING_STREAM_H -#define _KUNIT_STRING_STREAM_H - -#include -#include -#include - -struct string_stream_fragment { - struct kunit *test; - struct list_head node; - char *fragment; -}; - -struct string_stream { - size_t length; - struct list_head fragments; - /* length and fragments are protected by this lock */ - spinlock_t lock; - struct kunit *test; - gfp_t gfp; -}; - -struct kunit; - -struct string_stream *alloc_string_stream(struct kunit *test, gfp_t gfp); - -int __printf(2, 3) string_stream_add(struct string_stream *stream, - const char *fmt, ...); - -int string_stream_vadd(struct string_stream *stream, - const char *fmt, - va_list args); - -char *string_stream_get_string(struct string_stream *stream); - -int string_stream_append(struct string_stream *stream, - struct string_stream *other); - -bool string_stream_is_empty(struct string_stream *stream); - -int string_stream_destroy(struct string_stream *stream); - -#endif /* _KUNIT_STRING_STREAM_H */ diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c index 86013d4..d8ae94e 100644 --- a/lib/kunit/assert.c +++ b/lib/kunit/assert.c @@ -6,6 +6,7 @@ * Author: Brendan Higgins */ #include +#include "string-stream-impl.h" void kunit_base_assert_format(const struct kunit_assert *assert, struct string_stream *stream) diff --git a/lib/kunit/string-stream-impl.h b/lib/kunit/string-stream-impl.h new file mode 100644 index 0000000..0fe4100 --- /dev/null +++ b/lib/kunit/string-stream-impl.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * C++ stream style string builder used in KUnit for building messages. + * + * Copyright (C) 2019, Google LLC. + * Author: Brendan Higgins + */ + +#ifndef _KUNIT_STRING_STREAM_IMPL_H +#define _KUNIT_STRING_STREAM_IMPL_H + +#include +#include +#include + +struct string_stream_fragment { + struct kunit *test; + struct list_head node; + char *fragment; +}; + +struct string_stream { + size_t length; + struct list_head fragments; + /* length and fragments are protected by this lock */ + spinlock_t lock; + struct kunit *test; + gfp_t gfp; +}; + +struct kunit; + +struct string_stream *alloc_string_stream(struct kunit *test, gfp_t gfp); + +int __printf(2, 3) string_stream_add(struct string_stream *stream, + const char *fmt, ...); + +int string_stream_vadd(struct string_stream *stream, + const char *fmt, + va_list args); + +char *string_stream_get_string(struct string_stream *stream); + +int string_stream_append(struct string_stream *stream, + struct string_stream *other); + +bool string_stream_is_empty(struct string_stream *stream); + +int string_stream_destroy(struct string_stream *stream); + +#endif /* _KUNIT_STRING_STREAM_IMPL_H */ diff --git a/lib/kunit/string-stream-test.c b/lib/kunit/string-stream-test.c index 76cc05e..25b2cf3 100644 --- a/lib/kunit/string-stream-test.c +++ b/lib/kunit/string-stream-test.c @@ -6,9 +6,9 @@ * Author: Brendan Higgins */ -#include #include #include +#include "string-stream-impl.h" static void string_stream_test_empty_on_creation(struct kunit *test) { diff --git a/lib/kunit/string-stream.c b/lib/kunit/string-stream.c index e6d17aa..a1e005d 100644 --- a/lib/kunit/string-stream.c +++ b/lib/kunit/string-stream.c @@ -6,11 +6,12 @@ * Author: Brendan Higgins */ -#include #include #include #include +#include "string-stream-impl.h" + struct string_stream_fragment_alloc_context { struct kunit *test; int len; diff --git a/lib/kunit/test.c b/lib/kunit/test.c index c83c0fa..017d4fb 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -10,6 +10,7 @@ #include #include #include +#include "string-stream-impl.h" static void kunit_set_failure(struct kunit *test) { From patchwork Thu Oct 17 18:07:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 11196797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 579011575 for ; Thu, 17 Oct 2019 18:09:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 36FAE21925 for ; Thu, 17 Oct 2019 18:09:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="q1nmY7kg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437997AbfJQSJ0 (ORCPT ); Thu, 17 Oct 2019 14:09:26 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:58382 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395417AbfJQSJZ (ORCPT ); Thu, 17 Oct 2019 14:09:25 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI4A6o143655; Thu, 17 Oct 2019 18:08:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=R7ga5CIYQVpUkfRKUAEufFb82t96tNzBlSD59pwtVOo=; b=q1nmY7kgncqSrJdGS/gSa00vifHZBQhk0fZ8oUVWKM+kfp8EvWeKVNqFNQ9lu+i0RJpu QxcmB7rieEhAC0kpMBuDvRnJjRvKF0BxcamuIrwluSP+/Xdh0uCjqtP2xYHg0uwGh3iy 450envKAK+HrXueDLwtkoY1FzjnDXYkzw0k4JLOsyY86DAP0ewjPGB+GkolMMq903DEZ 2I2NHisWyV/wlbHvn9HNv3iGZWW80Kmb3KWPX2N5AZAZ/OYRrPQgw3liteNGx7+MjfWE lWUMaQ3JejjYhfJpZtNkKF/xmhNB/D4dyFarfIH+cfPpsn3BC9VFmvQOkY46ixBzZxiQ kQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2vk6sr051p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:03 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI80kh178282; Thu, 17 Oct 2019 18:08:02 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2vpcm3bvpx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:02 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x9HI7mWV021886; Thu, 17 Oct 2019 18:07:48 GMT Received: from dhcp-10-175-161-223.vpn.oracle.com (/10.175.161.223) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Oct 2019 18:07:44 +0000 From: Alan Maguire To: brendanhiggins@google.com, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, yamada.masahiro@socionext.com, catalin.marinas@arm.com, joe.lawrence@redhat.com, penguin-kernel@i-love.sakura.ne.jp, schowdary@nvidia.com, urezki@gmail.com, andriy.shevchenko@linux.intel.com, corbet@lwn.net, linux-doc@vger.kernel.org, Alan Maguire Subject: [PATCH v3 linux-kselftest-test 2/6] kunit: hide unexported try-catch interface in try-catch-impl.h Date: Thu, 17 Oct 2019 19:07:15 +0100 Message-Id: <1571335639-21675-3-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> References: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170164 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170163 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org also remove unused kunit_generic_try_catch Signed-off-by: Alan Maguire Reviewed-by: Brendan Higgins --- include/kunit/try-catch.h | 10 ---------- lib/kunit/test-test.c | 1 + lib/kunit/test.c | 1 + lib/kunit/try-catch-impl.h | 23 +++++++++++++++++++++++ lib/kunit/try-catch.c | 1 + 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 lib/kunit/try-catch-impl.h diff --git a/include/kunit/try-catch.h b/include/kunit/try-catch.h index 404f336..c507dd4 100644 --- a/include/kunit/try-catch.h +++ b/include/kunit/try-catch.h @@ -53,11 +53,6 @@ struct kunit_try_catch { void *context; }; -void kunit_try_catch_init(struct kunit_try_catch *try_catch, - struct kunit *test, - kunit_try_catch_func_t try, - kunit_try_catch_func_t catch); - void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context); void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch); @@ -67,9 +62,4 @@ static inline int kunit_try_catch_get_result(struct kunit_try_catch *try_catch) return try_catch->try_result; } -/* - * Exposed for testing only. - */ -void kunit_generic_try_catch_init(struct kunit_try_catch *try_catch); - #endif /* _KUNIT_TRY_CATCH_H */ diff --git a/lib/kunit/test-test.c b/lib/kunit/test-test.c index 5ebe059..c4162a9 100644 --- a/lib/kunit/test-test.c +++ b/lib/kunit/test-test.c @@ -6,6 +6,7 @@ * Author: Brendan Higgins */ #include +#include "try-catch-impl.h" struct kunit_try_catch_test_context { struct kunit_try_catch *try_catch; diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 017d4fb..49ac5fe 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -11,6 +11,7 @@ #include #include #include "string-stream-impl.h" +#include "try-catch-impl.h" static void kunit_set_failure(struct kunit *test) { diff --git a/lib/kunit/try-catch-impl.h b/lib/kunit/try-catch-impl.h new file mode 100644 index 0000000..aa11e46 --- /dev/null +++ b/lib/kunit/try-catch-impl.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * An API to allow a function, that may fail, to be executed, and recover in a + * controlled manner. + * + * Copyright (C) 2019, Google LLC. + * Author: Brendan Higgins + */ + +#ifndef _KUNIT_TRY_CATCH_IMPL_H +#define _KUNIT_TRY_CATCH_IMPL_H + +#include +#include + +struct kunit; + +void kunit_try_catch_init(struct kunit_try_catch *try_catch, + struct kunit *test, + kunit_try_catch_func_t try, + kunit_try_catch_func_t catch); + +#endif /* _KUNIT_TRY_CATCH_IMPL_H */ diff --git a/lib/kunit/try-catch.c b/lib/kunit/try-catch.c index 55686839..0c4c90c 100644 --- a/lib/kunit/try-catch.c +++ b/lib/kunit/try-catch.c @@ -13,6 +13,7 @@ #include #include #include +#include "try-catch-impl.h" void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch) { From patchwork Thu Oct 17 18:07:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 11196791 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E82BD13B1 for ; Thu, 17 Oct 2019 18:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE96721925 for ; Thu, 17 Oct 2019 18:08:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ChcLJCkV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395430AbfJQSIQ (ORCPT ); Thu, 17 Oct 2019 14:08:16 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:33952 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395417AbfJQSIQ (ORCPT ); Thu, 17 Oct 2019 14:08:16 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI4cTL161556; Thu, 17 Oct 2019 18:07:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=uSEqo1vwzdjctc96LUNCD5ybeWnPpZ9dSMDULQK9zAI=; b=ChcLJCkVNG6Ap9oj9/s302DKsvV+w8wUg/0Wq7hNc+kLy4O48SwF3b0eFkzqHquudFjH AQvaAGi1+KWhR0FBqRK5C67kByMYd0jsTfdWXpHm/UIhpDuuqnwrem2vAODL/k3TPuJB bu2X65hLP0+Z3AjbOHO1Je/X/ii0p4a65pt3BMpmAJzGAUFhbLm5y8Ty6XgN+Knn9nQR Uf3vMuU3pO4y+xl4dIEmxrYJ5t58M7wgfxBO0a4dF5Mn+7F9+VDv3r86tHrze2j6wXRQ VsyJtRAnwjvTuogtpiMDN8kHbNiKh1Y94DQiSEQBvAMcspVZO/tiXYSVM8Jr37GrPcW1 Hw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2vk68v052g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:07:59 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI7uSV041991; Thu, 17 Oct 2019 18:07:59 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2vpf14dv69-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:07:58 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x9HI7rFx021918; Thu, 17 Oct 2019 18:07:53 GMT Received: from dhcp-10-175-161-223.vpn.oracle.com (/10.175.161.223) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Oct 2019 18:07:53 +0000 From: Alan Maguire To: brendanhiggins@google.com, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, yamada.masahiro@socionext.com, catalin.marinas@arm.com, joe.lawrence@redhat.com, penguin-kernel@i-love.sakura.ne.jp, schowdary@nvidia.com, urezki@gmail.com, andriy.shevchenko@linux.intel.com, corbet@lwn.net, linux-doc@vger.kernel.org, Alan Maguire , Knut Omang Subject: [PATCH v3 linux-kselftest-test 3/6] kunit: add kunit_find_symbol() function for symbol lookup Date: Thu, 17 Oct 2019 19:07:16 +0100 Message-Id: <1571335639-21675-4-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> References: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=11 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=774 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170164 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=11 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=851 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170163 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org In preparation for module support for kunit and kunit tests, we need a way of retrieving non-exported symbols from the core kernel and modules. kunit_find_symbol() supports this. Signed-off-by: Alan Maguire Signed-off-by: Knut Omang --- include/kunit/test.h | 8 ++++++++ lib/kunit/test-test.c | 19 +++++++++++++++++++ lib/kunit/test.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/include/kunit/test.h b/include/kunit/test.h index dba4830..c645d18 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -339,6 +339,14 @@ static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp) void kunit_cleanup(struct kunit *test); +/** + * kunit_find_symbol() - lookup un-exported symbol in kernel or modules. + * @sym: symbol name. + * + * Returns symbol or ERR_PTR value on error. + */ +void *kunit_find_symbol(const char *sym); + #define kunit_printk(lvl, test, fmt, ...) \ printk(lvl "\t# %s: " fmt, (test)->name, ##__VA_ARGS__) diff --git a/lib/kunit/test-test.c b/lib/kunit/test-test.c index c4162a9..7f09dd0 100644 --- a/lib/kunit/test-test.c +++ b/lib/kunit/test-test.c @@ -330,3 +330,22 @@ static void kunit_resource_test_exit(struct kunit *test) .test_cases = kunit_resource_test_cases, }; kunit_test_suite(kunit_resource_test_suite); + +/* + * Find non-exported kernel symbol; we use the modules list as a safe + * choice that should always be present. + */ +static void kunit_find_symbol_kernel(struct kunit *test) +{ + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, kunit_find_symbol("modules")); +} + +static struct kunit_case kunit_find_symbol_test_cases[] = { + KUNIT_CASE(kunit_find_symbol_kernel), +}; + +static struct kunit_suite kunit_find_symbol_test_suite = { + .name = "kunit-find-symbol", + .test_cases = kunit_find_symbol_test_cases, +}; +kunit_test_suite(kunit_find_symbol_test_suite); diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 49ac5fe..a2b1b46 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include "string-stream-impl.h" @@ -478,3 +479,38 @@ void kunit_cleanup(struct kunit *test) kunit_resource_free(test, resource); } } + +/* + * Support for looking up kernel/module internal symbols to enable testing. + */ +void *kunit_find_symbol(const char *sym) +{ + unsigned long (*modlookup)(const char *name); + unsigned long addr = 0; + + if (!sym || strlen(sym) > KSYM_NAME_LEN) + return ERR_PTR(-EINVAL); + + /* + * Try for kernel-internal symbol first; fall back to modules + * if that fails. + */ + addr = kallsyms_lookup_name(sym); + if (addr) + return (void *)addr; + modlookup = (void *)kallsyms_lookup_name("module_kallsyms_lookup_name"); + if (modlookup) + addr = modlookup(sym); + if (addr) + return (void *)addr; + +#ifndef CONFIG_KALLSYMS_ALL + WARN_ONCE(true, + "CONFIG_KALLSYMS_ALL is not set, so unexported symbols like '%s' are not available\n", + sym); + return ERR_PTR(-ENOTSUPP); +#else + WARN_ONCE(true, "symbol '%s' is not available\n", sym); +#endif + return ERR_PTR(-ENOENT); +} From patchwork Thu Oct 17 18:07:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 11196793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60ADF1575 for ; Thu, 17 Oct 2019 18:09:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1946421925 for ; Thu, 17 Oct 2019 18:09:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="SXgXLBGt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395496AbfJQSJF (ORCPT ); Thu, 17 Oct 2019 14:09:05 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34880 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395417AbfJQSJF (ORCPT ); Thu, 17 Oct 2019 14:09:05 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI4BiS161325; Thu, 17 Oct 2019 18:08:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=eGFxGT0sCmiQABEVnhIzmqtfbnf0SEuMq3D6lWk+X5U=; b=SXgXLBGtrGr3axSLO9guucDBqQFg0JWaQapefLk9uNl2GV9p50SXizjAmP1dgkul6OVd 0FMcVhtMJEmv/9ski0L9HM3uYfxrHzTcnidarFc+r8J7Uf/5XMjF+L6TkC1e8WaBSsA0 VY446GXoofV0B6W65sOLcIG2rjsvyTKOMQswxpNcgfbjqyb4VH12J+m6eXnINh08Xs+I WwieghEHNRArc8wVM43p7Z4tK/u+P+WqkEl8Lv3pLxPHIeRAqM0334ZGbqdLjqvuPl5B x7HgDwLPlWKx8ZhGe+mmOjomlHfBkeWG9u3BtvnjpQDTrF6iqlvCt3HjO7Bi671+uonq 8A== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2vk68v055b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:28 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI8JMj176263; Thu, 17 Oct 2019 18:08:27 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2vpvtm1nsy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:27 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9HI7wnU029198; Thu, 17 Oct 2019 18:07:58 GMT Received: from dhcp-10-175-161-223.vpn.oracle.com (/10.175.161.223) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Oct 2019 18:07:58 +0000 From: Alan Maguire To: brendanhiggins@google.com, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, yamada.masahiro@socionext.com, catalin.marinas@arm.com, joe.lawrence@redhat.com, penguin-kernel@i-love.sakura.ne.jp, schowdary@nvidia.com, urezki@gmail.com, andriy.shevchenko@linux.intel.com, corbet@lwn.net, linux-doc@vger.kernel.org, Alan Maguire , Knut Omang Subject: [PATCH v3 linux-kselftest-test 4/6] kunit: allow kunit tests to be loaded as a module Date: Thu, 17 Oct 2019 19:07:17 +0100 Message-Id: <1571335639-21675-5-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> References: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=11 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=739 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170164 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=11 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=823 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170163 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org as tests are added to kunit, it will become less feasible to execute all built tests together. By supporting modular tests we provide a simple way to do selective execution on a running system; specifying CONFIG_KUNIT=y CONFIG_KUNIT_EXAMPLE_TEST=m ...means we can simply "insmod example-test.ko" to run the tests. To achieve this we need to o export the required symbols in kunit o for non-exported symbols, we need to utilize kunit_find_symbol; the simplest way is for the test suite init to call KUNIT_INIT_[FN|VAR]_SYMBOL() for each non-exported symbol. o support a new way of declaring test suites. Because a module cannot do multiple late_initcall()s, we provide a kunit_test_suites() macro to declare multiple suites within the same module at once. When compiled as a module, use of KUNIT_INIT_[FN|VAR]_symbol() will retrieve the symbol address via kunit_find_symbol() and assign a local variable with the same symbol name appropriately. When compiled builtin, these definitions are used to verify that the types we specify match the type of the symbol we are looking for. Compiler errors will be generated if not. One wrinkle here is that we cannot use the same names for local function pointer definitions; the reason for this is we have likely #included a definition for the function in question already, so an attempt to redefine it as a function pointer variable fails. As a result the KUNIT_INIT_FN_SYMBOL() macro requires a name for a local symbol we have defined as a function pointer (with a signature matching the desired function). Signed-off-by: Alan Maguire Signed-off-by: Knut Omang --- include/kunit/test.h | 115 +++++++++++++++++++++++++++++++++++++---- kernel/sysctl-test.c | 4 +- lib/Kconfig.debug | 2 +- lib/kunit/Kconfig | 4 +- lib/kunit/assert.c | 8 +++ lib/kunit/example-test.c | 4 +- lib/kunit/string-stream-test.c | 44 ++++++++++++---- lib/kunit/test-test.c | 32 ++++++++---- lib/kunit/test.c | 9 ++++ lib/kunit/try-catch.c | 2 + 10 files changed, 187 insertions(+), 37 deletions(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index c645d18..9a3835a 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -78,6 +79,86 @@ struct kunit_resource { struct list_head node; }; +/** + * KUNIT_VAR_SYMBOL - A helper for defining non-exported variable symbols + * + * @name: name of the symbol. + * @type: type of symbol. + * + * In the module case, we define the pointer to the symbol type where + * we will store the symbol address; KUNIT_INIT_VAR_SYMBOL() will assign + * the symbol name to the dereferenced kunit_. Note that + * in the builtin case we still define kunit_; the reason + * for this is it allows us to verify that the type value is correct + * in the builtin case and has not fallen out-of-sync with its original + * definition. + */ +#ifdef MODULE +#define KUNIT_VAR_SYMBOL(symbol, type) \ + type * kunit_##symbol; \ + type symbol +#else +#define KUNIT_VAR_SYMBOL(symbol, type) \ + type * kunit_##symbol +#endif + +/** + * KUNIT_INIT_VAR_SYMBOL - A helper for initializing non-exported variable + * symbols + * @test: optional pointer to test context + * @name: name of symbol + * + * In the module case, initialization consists of using kunit_find_symbol() + * to find the address of the symbol, and if found, we set the variable + * to the dereferenced address value. As mentioned above, in the builtin + * case we simply assing kunit_ to & ; this will + * generate a compilation warning if the type we specified in KUNIT_VAR_SYMBOL + * and the type of the symbol itself do not match. + */ +#ifdef MODULE +#define KUNIT_INIT_VAR_SYMBOL(test, symbol) \ + do { \ + if (!(kunit_##symbol)) { \ + kunit_##symbol = kunit_find_symbol(#symbol); \ + if (!IS_ERR((kunit_##symbol))) \ + symbol = *(kunit_##symbol); \ + } \ + if (test) \ + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, \ + kunit_##symbol); \ + } while (0) +#else +#define KUNIT_INIT_VAR_SYMBOL(test, symbol) \ + kunit_##symbol = &(symbol) +#endif + +/** + * KUNIT_INIT_FN_SYMBOL - A helper for initializing non-exported function + * symbols + * @test: optional pointer to test context + * @symbol: name of symbol + * @name: local name of function used to store function pointer to symbol + * + * In the module case, initialization consists of using kunit_find_symbol() + * to find the address of the symbol, and if found, we set function pointer + * name to the function address value. In the non-module case, we simply + * assign name to symbol; this will generate a compilation error if the + * type we specified for function pointer @name does not match the symbol + * function type. + */ +#ifdef MODULE +#define KUNIT_INIT_FN_SYMBOL(test, symbol, name) \ + do { \ + if (!name) \ + name = kunit_find_symbol(#symbol); \ + if (test) \ + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, name); \ + } while (0) +#else +#define KUNIT_INIT_FN_SYMBOL(test, symbol, name) \ + name = symbol +#endif + struct kunit; /** @@ -197,31 +278,45 @@ struct kunit { int kunit_run_tests(struct kunit_suite *suite); /** - * kunit_test_suite() - used to register a &struct kunit_suite with KUnit. + * kunit_test_suites() - used to register one or more &struct kunit_suite + * with KUnit. * - * @suite: a statically allocated &struct kunit_suite. + * @suites: a statically allocated list of &struct kunit_suite. * - * Registers @suite with the test framework. See &struct kunit_suite for + * Registers @suites with the test framework. See &struct kunit_suite for * more information. * - * NOTE: Currently KUnit tests are all run as late_initcalls; this means + * When builtin, KUnit tests are all run as late_initcalls; this means * that they cannot test anything where tests must run at a different init * phase. One significant restriction resulting from this is that KUnit * cannot reliably test anything that is initialize in the late_init phase; * another is that KUnit is useless to test things that need to be run in * an earlier init phase. * + * An alternative is to build the tests as a module. Because modules + * do not support multiple late_initcall()s, we need to initialize an + * array of suites for a module. + * * TODO(brendanhiggins@google.com): Don't run all KUnit tests as * late_initcalls. I have some future work planned to dispatch all KUnit * tests from the same place, and at the very least to do so after * everything else is definitely initialized. */ -#define kunit_test_suite(suite) \ - static int kunit_suite_init##suite(void) \ - { \ - return kunit_run_tests(&suite); \ - } \ - late_initcall(kunit_suite_init##suite) +#define kunit_test_suites(...) \ + static struct kunit_suite *suites[] = { __VA_ARGS__, NULL}; \ + static int kunit_test_suites_init(void) \ + { \ + unsigned int i; \ + for (i = 0; suites[i] != NULL; i++) \ + kunit_run_tests(suites[i]); \ + return 0; \ + } \ + late_initcall(kunit_test_suites_init); \ + static void __exit kunit_test_suites_exit(void) \ + { \ + return; \ + } \ + module_exit(kunit_test_suites_exit) /* * Like kunit_alloc_resource() below, but returns the struct kunit_resource diff --git a/kernel/sysctl-test.c b/kernel/sysctl-test.c index 2a63241..98d3e4e 100644 --- a/kernel/sysctl-test.c +++ b/kernel/sysctl-test.c @@ -389,4 +389,6 @@ static void sysctl_test_api_dointvec_write_single_greater_int_max( .test_cases = sysctl_test_cases, }; -kunit_test_suite(sysctl_test_suite); +kunit_test_suites(&sysctl_test_suite); + +MODULE_LICENSE("GPL"); diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index a3017a5..cdf14ce 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1951,7 +1951,7 @@ config TEST_SYSCTL If unsure, say N. config SYSCTL_KUNIT_TEST - bool "KUnit test for sysctl" + tristate "KUnit test for sysctl" depends on KUNIT help This builds the proc sysctl unit test, which runs on boot. diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index af37016..9ebd5e6 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -15,7 +15,7 @@ menuconfig KUNIT if KUNIT config KUNIT_TEST - bool "KUnit test for KUnit" + tristate "KUnit test for KUnit" help Enables the unit tests for the KUnit test framework. These tests test the KUnit test framework itself; the tests are both written using @@ -24,7 +24,7 @@ config KUNIT_TEST expected. config KUNIT_EXAMPLE_TEST - bool "Example test for KUnit" + tristate "Example test for KUnit" help Enables an example unit test that illustrates some of the basic features of KUnit. This test only exists to help new users understand diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c index d8ae94e..2d57302 100644 --- a/lib/kunit/assert.c +++ b/lib/kunit/assert.c @@ -25,6 +25,7 @@ void kunit_base_assert_format(const struct kunit_assert *assert, string_stream_add(stream, "%s FAILED at %s:%d\n", expect_or_assert, assert->file, assert->line); } +EXPORT_SYMBOL_GPL(kunit_base_assert_format); void kunit_assert_print_msg(const struct kunit_assert *assert, struct string_stream *stream) @@ -32,6 +33,7 @@ void kunit_assert_print_msg(const struct kunit_assert *assert, if (assert->message.fmt) string_stream_add(stream, "\n%pV", &assert->message); } +EXPORT_SYMBOL_GPL(kunit_assert_print_msg); void kunit_fail_assert_format(const struct kunit_assert *assert, struct string_stream *stream) @@ -39,6 +41,7 @@ void kunit_fail_assert_format(const struct kunit_assert *assert, kunit_base_assert_format(assert, stream); string_stream_add(stream, "%pV", &assert->message); } +EXPORT_SYMBOL_GPL(kunit_fail_assert_format); void kunit_unary_assert_format(const struct kunit_assert *assert, struct string_stream *stream) @@ -57,6 +60,7 @@ void kunit_unary_assert_format(const struct kunit_assert *assert, unary_assert->condition); kunit_assert_print_msg(assert, stream); } +EXPORT_SYMBOL_GPL(kunit_unary_assert_format); void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, struct string_stream *stream) @@ -77,6 +81,7 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, } kunit_assert_print_msg(assert, stream); } +EXPORT_SYMBOL_GPL(kunit_ptr_not_err_assert_format); void kunit_binary_assert_format(const struct kunit_assert *assert, struct string_stream *stream) @@ -98,6 +103,7 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, binary_assert->right_value); kunit_assert_print_msg(assert, stream); } +EXPORT_SYMBOL_GPL(kunit_binary_assert_format); void kunit_binary_ptr_assert_format(const struct kunit_assert *assert, struct string_stream *stream) @@ -119,6 +125,7 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert, binary_assert->right_value); kunit_assert_print_msg(assert, stream); } +EXPORT_SYMBOL_GPL(kunit_binary_ptr_assert_format); void kunit_binary_str_assert_format(const struct kunit_assert *assert, struct string_stream *stream) @@ -140,3 +147,4 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert, binary_assert->right_value); kunit_assert_print_msg(assert, stream); } +EXPORT_SYMBOL_GPL(kunit_binary_str_assert_format); diff --git a/lib/kunit/example-test.c b/lib/kunit/example-test.c index f64a829..ff930e0 100644 --- a/lib/kunit/example-test.c +++ b/lib/kunit/example-test.c @@ -85,4 +85,6 @@ static int example_test_init(struct kunit *test) * This registers the above test suite telling KUnit that this is a suite of * tests that need to be run. */ -kunit_test_suite(example_test_suite); +kunit_test_suites(&example_test_suite); + +MODULE_LICENSE("GPL"); diff --git a/lib/kunit/string-stream-test.c b/lib/kunit/string-stream-test.c index 25b2cf3..7d6055a 100644 --- a/lib/kunit/string-stream-test.c +++ b/lib/kunit/string-stream-test.c @@ -10,34 +10,53 @@ #include #include "string-stream-impl.h" +/* Non-exported string stream functions which we will use in testing. */ +struct string_stream * (*_alloc_string_stream)(struct kunit *test, gfp_t gfp); +int __printf(2, 3) (*_string_stream_add)(struct string_stream *stream, + const char *fmt, ...); +char * (*_string_stream_get_string)(struct string_stream *stream); +bool (*_string_stream_is_empty)(struct string_stream *stream); + static void string_stream_test_empty_on_creation(struct kunit *test) { - struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); + struct string_stream *stream = _alloc_string_stream(test, GFP_KERNEL); - KUNIT_EXPECT_TRUE(test, string_stream_is_empty(stream)); + KUNIT_EXPECT_TRUE(test, _string_stream_is_empty(stream)); } static void string_stream_test_not_empty_after_add(struct kunit *test) { - struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); + struct string_stream *stream = _alloc_string_stream(test, GFP_KERNEL); - string_stream_add(stream, "Foo"); + _string_stream_add(stream, "Foo"); - KUNIT_EXPECT_FALSE(test, string_stream_is_empty(stream)); + KUNIT_EXPECT_FALSE(test, _string_stream_is_empty(stream)); } static void string_stream_test_get_string(struct kunit *test) { - struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL); + struct string_stream *stream = _alloc_string_stream(test, GFP_KERNEL); char *output; - string_stream_add(stream, "Foo"); - string_stream_add(stream, " %s", "bar"); + _string_stream_add(stream, "Foo"); + _string_stream_add(stream, " %s", "bar"); - output = string_stream_get_string(stream); + output = _string_stream_get_string(stream); KUNIT_ASSERT_STREQ(test, output, "Foo bar"); } +static int string_stream_test_init(struct kunit *test) +{ + KUNIT_INIT_FN_SYMBOL(test, alloc_string_stream, _alloc_string_stream); + KUNIT_INIT_FN_SYMBOL(test, string_stream_add, _string_stream_add); + KUNIT_INIT_FN_SYMBOL(test, string_stream_get_string, + _string_stream_get_string); + KUNIT_INIT_FN_SYMBOL(test, string_stream_is_empty, + _string_stream_is_empty); + + return 0; +} + static struct kunit_case string_stream_test_cases[] = { KUNIT_CASE(string_stream_test_empty_on_creation), KUNIT_CASE(string_stream_test_not_empty_after_add), @@ -47,6 +66,9 @@ static void string_stream_test_get_string(struct kunit *test) static struct kunit_suite string_stream_test_suite = { .name = "string-stream-test", - .test_cases = string_stream_test_cases + .test_cases = string_stream_test_cases, + .init = string_stream_test_init }; -kunit_test_suite(string_stream_test_suite); +kunit_test_suites(&string_stream_test_suite); + +MODULE_LICENSE("GPL"); diff --git a/lib/kunit/test-test.c b/lib/kunit/test-test.c index 7f09dd0..b4c1216 100644 --- a/lib/kunit/test-test.c +++ b/lib/kunit/test-test.c @@ -8,6 +8,11 @@ #include #include "try-catch-impl.h" +void (*_kunit_try_catch_init)(struct kunit_try_catch *try_catch, + struct kunit *test, + kunit_try_catch_func_t try, + kunit_try_catch_func_t catch); + struct kunit_try_catch_test_context { struct kunit_try_catch *try_catch; bool function_called; @@ -33,10 +38,10 @@ static void kunit_test_try_catch_successful_try_no_catch(struct kunit *test) struct kunit_try_catch_test_context *ctx = test->priv; struct kunit_try_catch *try_catch = ctx->try_catch; - kunit_try_catch_init(try_catch, - test, - kunit_test_successful_try, - kunit_test_no_catch); + _kunit_try_catch_init(try_catch, + test, + kunit_test_successful_try, + kunit_test_no_catch); kunit_try_catch_run(try_catch, test); KUNIT_EXPECT_TRUE(test, ctx->function_called); @@ -65,10 +70,10 @@ static void kunit_test_try_catch_unsuccessful_try_does_catch(struct kunit *test) struct kunit_try_catch_test_context *ctx = test->priv; struct kunit_try_catch *try_catch = ctx->try_catch; - kunit_try_catch_init(try_catch, - test, - kunit_test_unsuccessful_try, - kunit_test_catch); + _kunit_try_catch_init(try_catch, + test, + kunit_test_unsuccessful_try, + kunit_test_catch); kunit_try_catch_run(try_catch, test); KUNIT_EXPECT_TRUE(test, ctx->function_called); @@ -78,6 +83,8 @@ static int kunit_try_catch_test_init(struct kunit *test) { struct kunit_try_catch_test_context *ctx; + KUNIT_INIT_FN_SYMBOL(test, kunit_try_catch_init, _kunit_try_catch_init); + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); test->priv = ctx; @@ -101,7 +108,6 @@ static int kunit_try_catch_test_init(struct kunit *test) .init = kunit_try_catch_test_init, .test_cases = kunit_try_catch_test_cases, }; -kunit_test_suite(kunit_try_catch_test_suite); /* * Context for testing test managed resources @@ -329,7 +335,6 @@ static void kunit_resource_test_exit(struct kunit *test) .exit = kunit_resource_test_exit, .test_cases = kunit_resource_test_cases, }; -kunit_test_suite(kunit_resource_test_suite); /* * Find non-exported kernel symbol; we use the modules list as a safe @@ -348,4 +353,9 @@ static void kunit_find_symbol_kernel(struct kunit *test) .name = "kunit-find-symbol", .test_cases = kunit_find_symbol_test_cases, }; -kunit_test_suite(kunit_find_symbol_test_suite); + +kunit_test_suites(&kunit_resource_test_suite, + &kunit_try_catch_test_suite, + &kunit_find_symbol_test_suite); + +MODULE_LICENSE("GPL"); diff --git a/lib/kunit/test.c b/lib/kunit/test.c index a2b1b46..e8b2443 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -174,6 +174,7 @@ void kunit_do_assertion(struct kunit *test, if (assert->type == KUNIT_ASSERTION) kunit_abort(test); } +EXPORT_SYMBOL_GPL(kunit_do_assertion); void kunit_init_test(struct kunit *test, const char *name) { @@ -182,6 +183,7 @@ void kunit_init_test(struct kunit *test, const char *name) test->name = name; test->success = true; } +EXPORT_SYMBOL_GPL(kunit_init_test); /* * Initializes and runs test case. Does not clean up or do post validations. @@ -320,6 +322,7 @@ int kunit_run_tests(struct kunit_suite *suite) return 0; } +EXPORT_SYMBOL_GPL(kunit_run_tests); struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test, kunit_resource_init_t init, @@ -345,6 +348,7 @@ struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test, return res; } +EXPORT_SYMBOL_GPL(kunit_alloc_and_get_resource); static void kunit_resource_free(struct kunit *test, struct kunit_resource *res) { @@ -403,6 +407,7 @@ int kunit_resource_destroy(struct kunit *test, kunit_resource_free(test, resource); return 0; } +EXPORT_SYMBOL_GPL(kunit_resource_destroy); struct kunit_kmalloc_params { size_t size; @@ -438,6 +443,7 @@ void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp) gfp, ¶ms); } +EXPORT_SYMBOL_GPL(kunit_kmalloc); void kunit_kfree(struct kunit *test, const void *ptr) { @@ -450,6 +456,7 @@ void kunit_kfree(struct kunit *test, const void *ptr) WARN_ON(rc); } +EXPORT_SYMBOL_GPL(kunit_kfree); void kunit_cleanup(struct kunit *test) { @@ -479,6 +486,7 @@ void kunit_cleanup(struct kunit *test) kunit_resource_free(test, resource); } } +EXPORT_SYMBOL_GPL(kunit_cleanup); /* * Support for looking up kernel/module internal symbols to enable testing. @@ -514,3 +522,4 @@ void *kunit_find_symbol(const char *sym) #endif return ERR_PTR(-ENOENT); } +EXPORT_SYMBOL(kunit_find_symbol); diff --git a/lib/kunit/try-catch.c b/lib/kunit/try-catch.c index 0c4c90c..1c1e9af 100644 --- a/lib/kunit/try-catch.c +++ b/lib/kunit/try-catch.c @@ -20,6 +20,7 @@ void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch) try_catch->try_result = -EFAULT; complete_and_exit(try_catch->try_completion, -EFAULT); } +EXPORT_SYMBOL_GPL(kunit_try_catch_throw); static int kunit_generic_run_threadfn_adapter(void *data) { @@ -107,6 +108,7 @@ void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context) try_catch->catch(try_catch->context); } +EXPORT_SYMBOL_GPL(kunit_try_catch_run); void kunit_try_catch_init(struct kunit_try_catch *try_catch, struct kunit *test, From patchwork Thu Oct 17 18:07:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 11196799 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD1651575 for ; Thu, 17 Oct 2019 18:09:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B223A21848 for ; Thu, 17 Oct 2019 18:09:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="KdagHJpy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438238AbfJQSJf (ORCPT ); Thu, 17 Oct 2019 14:09:35 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:46502 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395292AbfJQSJf (ORCPT ); Thu, 17 Oct 2019 14:09:35 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI4AdW147084; Thu, 17 Oct 2019 18:08:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=/8CLOJ2pMliNyB2yJzLsx8/lcr53M3C2bB3rrY57eoo=; b=KdagHJpyvyhx599KlPuq2xRqro59GE4MfcxdBTnht334R9kXUT5zxMYRgmOL0qesnvKD dhXJNY/CANLBPVmiQ7YDIVNbHc6/UZLVE9Px0aAOjeATT9F5tvJP1k7L0zmFWy3/Azkt AvMzwmny8NSsOo1OjfjbXzAD5gO63R8HQnKgGXlI4c7ApugHPoUtgh4lEktq2sqxo9bX COsXB1dNk2gCDjpv4wX+IXz4dAxehnUBQ2hCnCO1TWKTrp0IV9kSxZBudYkhBRXWoXq9 sd6WsVPGmlOVZs0KpcpqBcWKjbqGJRAigDqSfIBYIkgFFvFpdWIBIW8m111dJHV6oyyI aA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vk7frqxxy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:25 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI8KKA176273; Thu, 17 Oct 2019 18:08:25 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2vpvtm1nwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:24 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x9HI83Nq020236; Thu, 17 Oct 2019 18:08:03 GMT Received: from dhcp-10-175-161-223.vpn.oracle.com (/10.175.161.223) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Oct 2019 18:08:02 +0000 From: Alan Maguire To: brendanhiggins@google.com, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, yamada.masahiro@socionext.com, catalin.marinas@arm.com, joe.lawrence@redhat.com, penguin-kernel@i-love.sakura.ne.jp, schowdary@nvidia.com, urezki@gmail.com, andriy.shevchenko@linux.intel.com, corbet@lwn.net, linux-doc@vger.kernel.org, Alan Maguire , Knut Omang Subject: [PATCH v3 linux-kselftest-test 5/6] kunit: allow kunit to be loaded as a module Date: Thu, 17 Oct 2019 19:07:18 +0100 Message-Id: <1571335639-21675-6-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> References: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170164 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170163 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Making kunit itself buildable as a module allows for "always-on" kunit configuration; specifying CONFIG_KUNIT=m means the module is built but only used when loaded. Kunit test modules will load kunit.ko as an implicit dependency, so simply running "modprobe my-kunit-tests" will load the tests along with the kunit module and run them. Signed-off-by: Alan Maguire Signed-off-by: Knut Omang --- lib/kunit/Kconfig | 2 +- lib/kunit/Makefile | 4 +++- lib/kunit/test.c | 2 ++ lib/kunit/try-catch.c | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 9ebd5e6..065aa16 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -3,7 +3,7 @@ # menuconfig KUNIT - bool "KUnit - Enable support for unit tests" + tristate "KUnit - Enable support for unit tests" help Enables support for kernel unit tests (KUnit), a lightweight unit testing and mocking framework for the Linux kernel. These tests are diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 769d940..8e2635a 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -1,4 +1,6 @@ -obj-$(CONFIG_KUNIT) += test.o \ +obj-$(CONFIG_KUNIT) += kunit.o + +kunit-objs += test.o \ string-stream.o \ assert.o \ try-catch.o diff --git a/lib/kunit/test.c b/lib/kunit/test.c index e8b2443..c0ace36 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -523,3 +523,5 @@ void *kunit_find_symbol(const char *sym) return ERR_PTR(-ENOENT); } EXPORT_SYMBOL(kunit_find_symbol); + +MODULE_LICENSE("GPL"); diff --git a/lib/kunit/try-catch.c b/lib/kunit/try-catch.c index 1c1e9af..72fc8ed 100644 --- a/lib/kunit/try-catch.c +++ b/lib/kunit/try-catch.c @@ -31,6 +31,8 @@ static int kunit_generic_run_threadfn_adapter(void *data) complete_and_exit(try_catch->try_completion, 0); } +KUNIT_VAR_SYMBOL(sysctl_hung_task_timeout_secs, unsigned long); + static unsigned long kunit_test_timeout(void) { unsigned long timeout_msecs; @@ -52,6 +54,7 @@ static unsigned long kunit_test_timeout(void) * For more background on this topic, see: * https://mike-bland.com/2011/11/01/small-medium-large.html */ + KUNIT_INIT_VAR_SYMBOL(NULL, sysctl_hung_task_timeout_secs); if (sysctl_hung_task_timeout_secs) { /* * If sysctl_hung_task is active, just set the timeout to some From patchwork Thu Oct 17 18:07:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Maguire X-Patchwork-Id: 11196801 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D5E41575 for ; Thu, 17 Oct 2019 18:10:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 21F2D21A49 for ; Thu, 17 Oct 2019 18:10:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="MjIjelz0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438404AbfJQSKE (ORCPT ); Thu, 17 Oct 2019 14:10:04 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59060 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395229AbfJQSKE (ORCPT ); Thu, 17 Oct 2019 14:10:04 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI4CX1143735; Thu, 17 Oct 2019 18:08:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=kEBzW5bFpEsigVBsTTXhd4LHdOdlS9x/rndpgUook+0=; b=MjIjelz03VYaTipphXkkEr9dkSmMvKgpYphPlw/98jzS/HYNVoGM9ggw4G6nhCDIpSzi +j97qyK5Sv0SCE+PbxQy1i6xaTVfinS9QeC5teshewLcMfUk3yzBc5u5HdXI5HhSEueE p+4n5uCGMjeqqyhc5ypoAh0+Y7yqDKHnaWnhQ9S/wWv/pLTbenD9u4lIotLl6o8uJQMr 3f+lxY0Ns9oZwtRNKfaCw8OYMkknRSXy6DA92rBo1NzzIsbBdgRAYPk4Y9SKrp8maV9+ uZH0h2416FN6habSgPQjm8yz+RjQbvktkuAnWM4fC9o22OopVfXp+Qy4kzAmOtGdpwR6 1g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2vk6sr054t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:36 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9HI8KdO176309; Thu, 17 Oct 2019 18:08:35 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2vpvtm1p06-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Oct 2019 18:08:35 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9HI88ep029269; Thu, 17 Oct 2019 18:08:08 GMT Received: from dhcp-10-175-161-223.vpn.oracle.com (/10.175.161.223) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Oct 2019 18:08:08 +0000 From: Alan Maguire To: brendanhiggins@google.com, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, keescook@chromium.org, yzaikin@google.com, akpm@linux-foundation.org, yamada.masahiro@socionext.com, catalin.marinas@arm.com, joe.lawrence@redhat.com, penguin-kernel@i-love.sakura.ne.jp, schowdary@nvidia.com, urezki@gmail.com, andriy.shevchenko@linux.intel.com, corbet@lwn.net, linux-doc@vger.kernel.org, Alan Maguire , Knut Omang Subject: [PATCH v3 linux-kselftest-test 6/6] kunit: update documentation to describe module-based build Date: Thu, 17 Oct 2019 19:07:19 +0100 Message-Id: <1571335639-21675-7-git-send-email-alan.maguire@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> References: <1571335639-21675-1-git-send-email-alan.maguire@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=4 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170164 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9413 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910170163 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Documentation should describe how to build kunit and tests as modules. Signed-off-by: Alan Maguire Signed-off-by: Knut Omang --- Documentation/dev-tools/kunit/faq.rst | 3 ++- Documentation/dev-tools/kunit/index.rst | 3 +++ Documentation/dev-tools/kunit/usage.rst | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Documentation/dev-tools/kunit/faq.rst b/Documentation/dev-tools/kunit/faq.rst index bf20951..ea55b24 100644 --- a/Documentation/dev-tools/kunit/faq.rst +++ b/Documentation/dev-tools/kunit/faq.rst @@ -29,7 +29,8 @@ Yes, well, mostly. For the most part, the KUnit core framework (what you use to write the tests) can compile to any architecture; it compiles like just another part of the -kernel and runs when the kernel boots. However, there is some infrastructure, +kernel and runs when the kernel boots, or when built as a module, when the +module is loaded. However, there is some infrastructure, like the KUnit Wrapper (``tools/testing/kunit/kunit.py``) that does not support other architectures. diff --git a/Documentation/dev-tools/kunit/index.rst b/Documentation/dev-tools/kunit/index.rst index 26ffb46..7ddc385 100644 --- a/Documentation/dev-tools/kunit/index.rst +++ b/Documentation/dev-tools/kunit/index.rst @@ -48,6 +48,9 @@ to a standalone program that can be run like any other program directly inside of a host operating system; to be clear, it does not require any virtualization support; it is just a regular program. +Alternatively, kunit and kunit tests can be built as modules and tests will +run when the test module is loaded. + KUnit is fast. Excluding build time, from invocation to completion KUnit can run several dozen tests in only 10 to 20 seconds; this might not sound like a big deal to some people, but having such fast and easy to run tests fundamentally diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst index c6e6963..82f9213 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -539,6 +539,22 @@ Interspersed in the kernel logs you might see the following: Congratulations, you just ran a KUnit test on the x86 architecture! +In a similar manner, kunit and kunit tests can also be built as modules, +so if you wanted to run tests in this way you might add the following config +options to your ``.config``: + +.. code-block:: none + + CONFIG_KUNIT=m + CONFIG_KUNIT_EXAMPLE_TEST=m + +Once the kernel is built and installed, a simple + +.. code-block:: bash + modprobe example-test + +...will run the tests. + Writing new tests for other architectures -----------------------------------------