diff mbox series

Documentation: kunit: rewrite writing first test instructions

Message ID 20220929125458.52979-1-bagasdotme@gmail.com (mailing list archive)
State New
Delegated to: Brendan Higgins
Headers show
Series Documentation: kunit: rewrite writing first test instructions | expand

Commit Message

Bagas Sanjaya Sept. 29, 2022, 12:54 p.m. UTC
The wordings of step-by-step instructions on writing the first Kunit test
are instructing readers to write codes without knowing what these are about.
Rewrite these instructions to include the purpose of written code.

While at it, align the code blocks of these contents.

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 This patch is based on Khalid's full path to .kunitconfig patch [1].

 [1]: https://lore.kernel.org/linux-doc/20220929085332.4155-1-khalid.masum.92@gmail.com/

 Documentation/dev-tools/kunit/start.rst | 40 ++++++++++++++-----------
 1 file changed, 22 insertions(+), 18 deletions(-)

Comments

Bagas Sanjaya Sept. 29, 2022, 1 p.m. UTC | #1
On 9/29/22 19:54, Bagas Sanjaya wrote:
>  Writing Your First Test
>  =======================
> -In your kernel repository, let's add some code that we can test.
> +In your kernel repository, let's add some code that we can test. For this
> +purpose, we are going to add simple addition driver.
>  
> -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``:
>  
> -.. 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``:
> +3. Add Kconfig menu entry for the feature to ``drivers/misc/Kconfig``:
>  

The numbering looks jumped. Please ignore this patch as I'll resend shortly.
diff mbox series

Patch

diff --git a/Documentation/dev-tools/kunit/start.rst b/Documentation/dev-tools/kunit/start.rst
index 7999874dc4ddb3..9628360947507b 100644
--- a/Documentation/dev-tools/kunit/start.rst
+++ b/Documentation/dev-tools/kunit/start.rst
@@ -131,17 +131,19 @@  are built-in. Otherwise the module will need to be loaded.
 
 Writing Your First Test
 =======================
-In your kernel repository, let's add some code that we can test.
+In your kernel repository, let's add some code that we can test. For this
+purpose, we are going to add simple addition driver.
 
-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``:
 
-.. 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``:
+3. Add Kconfig menu entry for the feature to ``drivers/misc/Kconfig``:
 
-.. code-block:: kconfig
+   .. code-block:: kconfig
 
 	config MISC_EXAMPLE
 		bool "My example"
 
-4. Add the following lines to ``drivers/misc/Makefile``:
+4. Add the kbuild goal that will build the feature to
+   ``drivers/misc/Makefile``:
 
-.. code-block:: make
+   .. code-block:: make
 
 	obj-$(CONFIG_MISC_EXAMPLE) += example.o
 
 Now we are ready to write the test cases.
 
-1. Add the below test case in ``drivers/misc/example_test.c``:
+1. 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``:
 
-.. 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``:
 
-.. 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``:
 
-.. code-block:: none
+   .. code-block:: none
 
 	CONFIG_MISC_EXAMPLE=y
 	CONFIG_MISC_EXAMPLE_TEST=y
 
 5. Run the test:
 
-.. code-block:: bash
+   .. code-block:: bash
 
 	./tools/testing/kunit/kunit.py run