From: Bagas Sanjaya <bagasdotme@gmail.com>
To: Sadiya Kazi <sadiyakazi@google.com>
Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <davidgow@google.com>, Jonathan Corbet <corbet@lwn.net>,
Khalid Masum <khalid.masum.92@gmail.com>
Subject: Re: [PATCH v2] Documentation: kunit: rewrite writing first test instructions
Date: Fri, 7 Oct 2022 10:03:52 +0700 [thread overview]
Message-ID: <95439cec-5357-0953-8f55-e3486f763345@gmail.com> (raw)
In-Reply-To: <CAO2JNKUqkt3p1OcRt9tSa9T=sv8RG+F3LydZfTdVBc0WewhHVg@mail.gmail.com>
On 10/6/22 16:41, Sadiya Kazi wrote:
> Consider updating this section as below:
> In this section, you will learn how to write a program to test the addition
> of two numbers using KUnit. To do so, you must write the addition driver
> code followed by the test case.
>
> 1.To write the addition driver code, follow the steps given below:
>
>> a.Navigate to the Kernel repository.
>
> b.Create a file ``drivers/misc/example.h``.
> c.In the ``example.h`` file, add the following code to declare the
> function ``misc_example_add()``:
>
>>
>> -1. Create a file ``drivers/misc/example.h``, which includes:
>> +1. Write the feature that will be tested. First, write the declaration
>> + for ``misc_example_add()`` in ``drivers/misc/example.h``:
>>
>> -.. code-block:: c
>> + .. code-block:: c
>>
>> int misc_example_add(int left, int right);
>>
>> -2. Create a file ``drivers/misc/example.c``, which includes:
>> + Then implement the function in ``drivers/misc/example.c``:
>
>
> d. To implement the function, create a file ``drivers/misc/example.c` and
> add the following code to it:
>
>
>>
>> -.. code-block:: c
>> + .. code-block:: c
>>
>> #include <linux/errno.h>
>>
>> @@ -152,24 +154,25 @@ In your kernel repository, let's add some code that
>> we can test.
>> return left + right;
>> }
>>
>> -3. Add the following lines to ``drivers/misc/Kconfig``:
>> +2. Add Kconfig menu entry for the feature to ``drivers/misc/Kconfig``:
>>
>
> e. Update ``drivers/misc/Kconfig`` with the following code to add the
> driver configuration:
>
>
>>
>> -.. code-block:: kconfig
>> + .. code-block:: kconfig
>>
>> config MISC_EXAMPLE
>> bool "My example"
>>
>> -4. Add the following lines to ``drivers/misc/Makefile``:
>> +3. Add the kbuild goal that will build the feature to
>> + ``drivers/misc/Makefile``:
>>
> f.To build the feature, update ``drivers/misc/Makefile`` with the following
> code:
>
>
>>
>> -.. code-block:: make
>> + .. code-block:: make
>>
>> obj-$(CONFIG_MISC_EXAMPLE) += example.o
>>
>> Now we are ready to write the test cases.
>>
> 2. To write the test cases, follow the steps given below:
>
>>
>> -1. Add the below test case in ``drivers/misc/example_test.c``:
>> +1. Write the test in ``drivers/misc/example_test.c``:
>>
> a. Write the test in ``drivers/misc/example_test.c``:
>
>>
>> -.. code-block:: c
>> + .. code-block:: c
>>
>> #include <kunit/test.h>
>> #include "example.h"
>> @@ -202,31 +205,32 @@ Now we are ready to write the test cases.
>> };
>> kunit_test_suite(misc_example_test_suite);
>>
>> -2. Add the following lines to ``drivers/misc/Kconfig``:
>> +2. Add following Kconfig entry for the test to ``drivers/misc/Kconfig``:
>>
> b. Add the following test configuration to ``drivers/misc/Kconfig``:
>
>>
>> -.. code-block:: kconfig
>> + .. code-block:: kconfig
>>
>> config MISC_EXAMPLE_TEST
>> tristate "Test for my example" if !KUNIT_ALL_TESTS
>> depends on MISC_EXAMPLE && KUNIT=y
>> default KUNIT_ALL_TESTS
>>
>> -3. Add the following lines to ``drivers/misc/Makefile``:
>> +3. Add kbuild goal of the test to ``drivers/misc/Makefile``:
>>
> c. Update ``drivers/misc/Makefile`` with the following code:
>
>>
>> -.. code-block:: make
>> + .. code-block:: make
>>
>> obj-$(CONFIG_MISC_EXAMPLE_TEST) += example_test.o
>>
>> -4. Add following configuration fragments to ``.kunit/.kunitconfig``:
>> +4. Add following configuration fragments for the test to
>> + ``.kunit/.kunitconfig``:
>>
> d. Add the following test configuration to ``.kunit/.kunitconfig``:
>
>>
>> -.. code-block:: none
>> + .. code-block:: none
>>
>> CONFIG_MISC_EXAMPLE=y
>> CONFIG_MISC_EXAMPLE_TEST=y
>>
>> 5. Run the test:
>>
> e. Run the test using the following command:
>
>>
>> -.. code-block:: bash
>> + .. code-block:: bash
>>
>> ./tools/testing/kunit/kunit.py run
>>
I think the documentation assumes the knowledge of writing kernel
code (C language and build infrastructure). This means that the
instructions should be written for brevity.
--
An old man doll... just what I always wanted! - Clara
prev parent reply other threads:[~2022-10-07 3:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 13:25 [PATCH v2] Documentation: kunit: rewrite writing first test instructions Bagas Sanjaya
2022-09-30 6:42 ` David Gow
2022-09-30 9:51 ` Bagas Sanjaya
2022-09-30 10:32 ` David Gow
2022-10-01 3:07 ` Bagas Sanjaya
2022-10-01 6:51 ` David Gow
[not found] ` <CAO2JNKUqkt3p1OcRt9tSa9T=sv8RG+F3LydZfTdVBc0WewhHVg@mail.gmail.com>
2022-10-07 3:03 ` Bagas Sanjaya [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95439cec-5357-0953-8f55-e3486f763345@gmail.com \
--to=bagasdotme@gmail.com \
--cc=brendan.higgins@linux.dev \
--cc=corbet@lwn.net \
--cc=davidgow@google.com \
--cc=khalid.masum.92@gmail.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=sadiyakazi@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).