Skip to content

kernel-doc: make it parse new functions and structs

Mauro Carvalho Chehab intel-wired-lan linux-doc linux-hardening lkml netdev 4 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest41 patches 0 repliesNew
  2. v330 patches 25 repliesSuperseded
  3. v225 patches 30 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v114 patches0 repliesSuperseded

Changes in v4 from the cover letter

- minor cleanups at the description on the first 30 patches;
- picked paches from this series:

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/41docs: kdoc_re: add support for groups()tools/lib/python/kdoc/kdoc_re.py+7 -00 replies
2/41docs: kdoc_re: don't go past the end of a linetools/lib/python/kdoc/kdoc_re.py+1 -10 replies
3/41docs: kdoc_parser: move var transformers to the beginningtools/lib/python/kdoc/kdoc_parser.py+13 -100 replies
4/41docs: kdoc_parser: don't mangle with function definestools/lib/python/kdoc/kdoc_parser.py+7 -50 replies
5/41docs: kdoc_parser: add functions support for NestedMatchtools/lib/python/kdoc/kdoc_parser.py+25 -130 replies
6/41docs: kdoc_parser: use NestedMatch to handle __attribute__ on functionstools/lib/python/kdoc/kdoc_parser.py+1 -10 replies
7/41docs: kdoc_parser: fix variable regexes to work with size_ttools/lib/python/kdoc/kdoc_parser.py+2 -20 replies
8/41docs: kdoc_parser: fix the default_value logic for variablestools/lib/python/kdoc/kdoc_parser.py+2 -20 replies
9/41docs: kdoc_parser: add some debug for variable parsingtools/lib/python/kdoc/kdoc_parser.py+11 -00 replies
10/41docs: kdoc_parser: don't exclude defaults from prototypetools/lib/python/kdoc/kdoc_parser.py+0 -10 replies
11/41docs: kdoc_parser: fix parser to support multi-word typestools/lib/python/kdoc/kdoc_parser.py+2 -20 replies
12/41docs: kdoc_parser: ignore context analysis and lock attributestools/lib/python/kdoc/kdoc_parser.py+15 -00 replies
13/41docs: kdoc_parser: add support for LIST_HEADtools/lib/python/kdoc/kdoc_parser.py+1 -00 replies
14/41docs: kdoc_parser: handle struct member macro VIRTIO_DECLARE_FEATURES(name)tools/lib/python/kdoc/kdoc_parser.py+1 -00 replies
15/41docs: kdoc_re: properly handle strings and escape chars on ittools/lib/python/kdoc/kdoc_re.py+18 -00 replies
16/41docs: kdoc_re: better show KernRe() at documentationtools/lib/python/kdoc/kdoc_re.py+22 -10 replies
17/41docs: kdoc_re: don't recompile NestedMatch regex every timetools/lib/python/kdoc/kdoc_re.py+22 -130 replies
18/41docs: kdoc_re: Change NestedMath args replacement to \0tools/lib/python/kdoc/kdoc_parser.py tools/lib/python/kdoc/kdoc_re.py+6 -50 replies
19/41docs: kdoc_re: make NestedMatch use KernRetools/lib/python/kdoc/kdoc_parser.py tools/lib/python/kdoc/kdoc_re.py+32 -450 replies
20/41docs: kdoc_re: add support on NestedMatch for argument replacementtools/lib/python/kdoc/kdoc_re.py+59 -250 replies
21/41docs: kdoc_parser: better handle struct_group macrostools/lib/python/kdoc/kdoc_parser.py+5 -50 replies
22/41docs: kdoc_re: fix a parse bug on struct page_pool_paramstools/lib/python/kdoc/kdoc_re.py+8 -00 replies
23/41docs: kdoc_re: add a helper class to declare C function matchestools/lib/python/kdoc/kdoc_re.py+11 -00 replies
24/41docs: kdoc_parser: use the new CFunction classtools/lib/python/kdoc/kdoc_parser.py+19 -190 replies
25/41docs: kdoc_parser: minimize differences with struct_group_taggedtools/lib/python/kdoc/kdoc_parser.py+1 -10 replies
26/41docs: kdoc_parser: move transform lists to a separate fileDocumentation/tools/kdoc_parser.rst tools/lib/python/kdoc/kdoc_files.py tools/lib/python/kdoc/kdoc_parser.py +1 more+133 -1420 replies
27/41docs: kdoc_re: don't remove the trailing ";" with NestedMatchtools/lib/python/kdoc/kdoc_re.py+0 -40 replies
28/41docs: kdoc_re: prevent adding whitespaces on sub replacementstools/lib/python/kdoc/kdoc_re.py+7 -10 replies
29/41docs: xforms_lists.py: use CFuntion to handle all function macrostools/lib/python/kdoc/xforms_lists.py+31 -400 replies
30/41docs: kdoc_files: allows the caller to use a different xforms classtools/lib/python/kdoc/kdoc_files.py+7 -20 replies
31/41docs: kdoc_re: Fix NestedMatch.sub() which causes PDF builds to breaktools/lib/python/kdoc/kdoc_re.py+20 -110 replies
32/41docs: sphinx-build-wrapper: allow -v override -qtools/docs/sphinx-build-wrapper+11 -30 replies
33/41tools: sphinx-build-wrapper: improve its help messagetools/docs/sphinx-build-wrapper+25 -30 replies
34/41docs: kdoc_files: document KernelFiles() ABItools/lib/python/kdoc/kdoc_files.py+43 -10 replies
35/41docs: kdoc_output: add optional args to ManOutput classtools/lib/python/kdoc/kdoc_output.py+19 -80 replies
36/41docs: sphinx-build-wrapper: better handle troff .TH markupstools/docs/sphinx-build-wrapper+4 -40 replies
37/41docs: kdoc_output: use a more standard order for .TH on man pagestools/docs/sphinx-build-wrapper tools/lib/python/kdoc/kdoc_output.py+3 -30 replies
38/41docs: kdoc_output: describe the class init parameterstools/lib/python/kdoc/kdoc_output.py+28 -10 replies
39/41docs: kdoc_output: pick a better default for modulenametools/docs/kernel-doc tools/lib/python/kdoc/kdoc_output.py+25 -170 replies
40/41docs: python: add helpers to run unit testsDocumentation/tools/python.rst Documentation/tools/unittest.rst tools/lib/python/unittest_helper.py+374 -00 replies
41/41tools: unittests: add tests for kernel-doc NestedMatch and KernRetools/unittests/kdoc_xforms.py+654 -00 replies

Reviews trailers per patch

27 of 41 patches have a Reviewed-by or Acked-by.

PatchRandy DunlapAleksandr LoktionovMauro Carvalho Chehab
1/41A-b T-b R-b
2/41A-b T-b R-b
3/41A-b T-b R-b
4/41A-b T-b R-b
5/41A-b T-b R-b
6/41A-b T-b R-b
7/41A-b T-b R-b
8/41A-b T-b R-b
9/41A-b T-b R-b
10/41A-b T-b R-b
11/41A-b T-b R-b
12/41R-b R-b
13/41A-b T-b R-b
14/41R-b
15/41R-b
16/41R-b
17/41R-b
18/41R-b
19/41R-b
20/41R-b
21/41R-b
22/41R-b
23/41R-b
24/41R-b
25/41R-b
26/41R-b
27/41R-b
28/41
29/41
30/41
31/41
32/41
33/41
34/41
35/41
36/41
37/41
38/41
39/41
40/41
41/41

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v4 thread

Cover letter [PATCH v4 00/41] kernel-doc: make it parse new functions and structs

Hi Jon,

Rebased the changes on the top of docs-mw, and merged the /4 patch series with fixes from me that ws pending and contained a conflicting patch with this series.

Oh well, it means that this one increased its size again...

The initial goal were to address some new warnings at linux next due to some new macro annotations.

As the previous version, this one contains a new CFunction class, with is just an alias for "NestedMatch", meant to make easier to maintain transforms, which are now on a separate file:

tools/lib/python/kdoc/xforms_lists.py

With that, transform lists now use CFunction for macros with a function prototype, using KernRe only the remaining macros and part of the declarations we want to strip (like extern).

So, for instance, the entire transform list for structs is now:

    #: Transforms for structs and unions
    struct_xforms = [
        (CFunction("__attribute__"), ' '),
        (CFunction('__aligned'), ' '),
        (CFunction('__counted_by'), ' '),
        (CFunction('__counted_by_(le|be)'), ' '),
        (CFunction('__guarded_by'), ' '),
        (CFunction('__pt_guarded_by'), ' '),

        (KernRe(r'\s*__packed\s*', re.S), ' '),
        (KernRe(r'\s*CRYPTO_MINALIGN_ATTR', re.S), ' '),
        (KernRe(r'\s*__private', re.S), ' '),
        (KernRe(r'\s*__rcu', re.S), ' '),
        (KernRe(r'\s*____cacheline_aligned_in_smp', re.S), ' '),
        (KernRe(r'\s*____cacheline_aligned', re.S), ' '),

        (CFunction('__cacheline_group_(begin|end)'), ''),

        (CFunction('struct_group'), r'\2'),
        (CFunction('struct_group_attr'), r'\3'),
        (CFunction('struct_group_tagged'), r'struct \1 \2; \3'),
        (CFunction('__struct_group'), r'\4'),

        (CFunction('__ETHTOOL_DECLARE_LINK_MODE_MASK'), r'DECLARE_BITMAP(\1, __ETHTOOL_LINK_MODE_MASK_NBITS)'),
        (CFunction('DECLARE_PHY_INTERFACE_MASK',), r'DECLARE_BITMAP(\1, PHY_INTERFACE_MODE_MAX)'),
        (CFunction('DECLARE_BITMAP'), r'unsigned long \1[BITS_TO_LONGS(\2)]'),

        (CFunction('DECLARE_HASHTABLE'), r'unsigned long \1[1 << ((\2) - 1)]'),
        (CFunction('DECLARE_KFIFO'), r'\2 *\1'),
        (CFunction('DECLARE_KFIFO_PTR'), r'\2 *\1'),
        (CFunction('(?:__)?DECLARE_FLEX_ARRAY'), r'\1 \2[]'),
        (CFunction('DEFINE_DMA_UNMAP_ADDR'), r'dma_addr_t \1'),
        (CFunction('DEFINE_DMA_UNMAP_LEN'), r'__u32 \1'),
        (CFunction('VIRTIO_DECLARE_FEATURES'), r'union { u64 \1; u64 \1_array[VIRTIO_FEATURES_U64S]; }'),
    ]

As KernRe, CFunction and NestedMatch have a ".sub" method, a single transforms table can have them all.

Due to the complexity of NestedMatch, I opted to write unit tests to verify that the logic there is correct.

On this version, the module was almost entirely re-written by hand, and the test suite has now 3 groups:

- TestDifferentReplacements: basic tests using several tests to try checkin border cases with NestedMatch.sub. They all use a single macro name;
- TestMultipleMacros: test different macros and conditions, also trying to get border cases;
- TestRealUsecases: as the name says, on this one I picked real test cases. I used an example given by Randy on some of them and placed a testset to try covering struct_group macros, which are quite complex.

Using it is as easy as running:

	$ tools/unittests/kdoc_xforms.py

And, if something goes wrong, -v will show the problem in unified diff[1]:

    $ tools/unittests/kdoc_xforms.py -k test_functions_with_acquires_and_releases -v

test_functions_with_acquires_and_releases (kdoc_xforms.TestRealUsecases.test_functions_with_acquires_and_releases) Test guarded_by on vars from lib/stackdepot.c. ... FAIL

======================================================================
FAIL: test_functions_with_acquires_and_releases (kdoc_xforms.TestRealUsecases.test_functions_with_acquires_and_releases)
Test guarded_by on vars from lib/stackdepot.c.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/new_devel/docs/tools/unittests/kdoc_xforms.py", line 649, in test_functions_with_acquires_and_releases
self.assertLogicallyEqual(result, expected)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/new_devel/docs/tools/unittests/kdoc_xforms.py", line 56, in assertLogicallyEqual
self.assertEqual(a, b)
~~~~~~~~~~~~~~~~^^^^^^
AssertionError: 'bool[477 chars]\n\n acpi_cpu_flags acpi_os_acquire_lock(acpi_[90 chars]sed)' != 'bool[477 chars]\n\n /* THIS IS UNEXPECTED. TEST WILL FAIL HER[140 chars]sed)'
bool prepare_report_consumer(unsigned long *flags,
const struct access_info *ai,
struct other_info *other_info);

int tcp_sigpool_start(unsigned int id, struct tcp_sigpool *c);

bool undo_report_consumer(unsigned long *flags, const struct access_info *ai,
struct other_info *other_info);

void debugfs_enter_cancellation(struct file *file, struct debugfs_cancellation *c);

void debugfs_leave_cancellation(struct file *file, struct debugfs_cancellation *c);

+ /* THIS IS UNEXPECTED. TEST WILL FAIL HERE */
+
acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp);

void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags not_used)

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (failures=1)

[1] This error was caused when I applied this patch:

    --- a/tools/unittests/kdoc_xforms.py
    +++ b/tools/unittests/kdoc_xforms.py
    @@ -637,6 +637,8 @@ class TestRealUsecases(TestCaseDiff):
                 void debugfs_leave_cancellation(struct file *file,
                                                 struct debugfs_cancellation *c);
 
    +            /* THIS IS UNEXPECTED. TEST WILL FAIL HERE */
    +
                 acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp);
 
                 void acpi_os_release_lock(acpi_spinlock lockp,

---
v4:
- minor cleanups at the description on the first 30 patches;
- picked paches from this series:

    https://lore.kernel.org/linux-doc/[email protected]/

- added patches to make easier for kernel-doc to be used on other projects (QEMU currently uses it)
- did some extra fixes at NestedMatch for some corner cases;
- added patches to improve man pages output;
- unittests were revamped.

v3:
- improved the unittest helper to allow adding in the future a runner to create a test suite directly;
- added unittest to tools/python library documentation;
- improved comments at the new modules;
- did several cleanups at the new logic;
- added a fix for NestedMatch not remove ";" at the end, mimicing the behavior of KernRe;
- moved transforms to a separate module;
- replaced all regexes to parse macros with the new CFunction alias for NestedMatch.

v2:
- added 10 new patches adding support at NestedMatch to properly group and replace arguments with \1, \2, ...

Mauro Carvalho Chehab (39):
docs: kdoc_re: add support for groups()
docs: kdoc_re: don't go past the end of a line
docs: kdoc_parser: move var transformers to the beginning
docs: kdoc_parser: don't mangle with function defines
docs: kdoc_parser: add functions support for NestedMatch
docs: kdoc_parser: use NestedMatch to handle __attribute__ on
functions
docs: kdoc_parser: fix variable regexes to work with size_t
docs: kdoc_parser: fix the default_value logic for variables
docs: kdoc_parser: add some debug for variable parsing
docs: kdoc_parser: don't exclude defaults from prototype
docs: kdoc_parser: fix parser to support multi-word types
docs: kdoc_parser: add support for LIST_HEAD
docs: kdoc_re: properly handle strings and escape chars on it
docs: kdoc_re: better show KernRe() at documentation
docs: kdoc_re: don't recompile NestedMatch regex every time
docs: kdoc_re: Change NestedMath args replacement to \0
docs: kdoc_re: make NestedMatch use KernRe
docs: kdoc_re: add support on NestedMatch for argument replacement
docs: kdoc_parser: better handle struct_group macros
docs: kdoc_re: fix a parse bug on struct page_pool_params
docs: kdoc_re: add a helper class to declare C function matches
docs: kdoc_parser: use the new CFunction class
docs: kdoc_parser: minimize differences with struct_group_tagged
docs: kdoc_parser: move transform lists to a separate file
docs: kdoc_re: don't remove the trailing ";" with NestedMatch
docs: kdoc_re: prevent adding whitespaces on sub replacements
docs: xforms_lists.py: use CFuntion to handle all function macros
docs: kdoc_files: allows the caller to use a different xforms class
docs: kdoc_re: Fix NestedMatch.sub() which causes PDF builds to break
docs: sphinx-build-wrapper: allow -v override -q
tools: sphinx-build-wrapper: improve its help message
docs: kdoc_files: document KernelFiles() ABI
docs: kdoc_output: add optional args to ManOutput class
docs: sphinx-build-wrapper: better handle troff .TH markups
docs: kdoc_output: use a more standard order for .TH on man pages
docs: kdoc_output: describe the class init parameters
docs: kdoc_output: pick a better default for modulename
docs: python: add helpers to run unit tests
tools: unittests: add tests for kernel-doc NestedMatch and KernRe

Randy Dunlap (2):
docs: kdoc_parser: ignore context analysis and lock attributes
docs: kdoc_parser: handle struct member macro
VIRTIO_DECLARE_FEATURES(name)

 Documentation/tools/kdoc_parser.rst   |   8 +
 Documentation/tools/python.rst        |   2 +
 Documentation/tools/unittest.rst      |  24 +
 tools/docs/kernel-doc                 |   1 -
 tools/docs/sphinx-build-wrapper       |  50 +-
 tools/lib/python/kdoc/kdoc_files.py   |  54 ++-
 tools/lib/python/kdoc/kdoc_output.py  |  73 ++-
 tools/lib/python/kdoc/kdoc_parser.py  | 182 ++-----
 tools/lib/python/kdoc/kdoc_re.py      | 242 +++++++---
 tools/lib/python/kdoc/xforms_lists.py | 108 +++++
 tools/lib/python/unittest_helper.py   | 348 ++++++++++++++
 tools/unittests/kdoc_xforms.py        | 654 ++++++++++++++++++++++++++
 12 files changed, 1515 insertions(+), 231 deletions(-)
 create mode 100644 Documentation/tools/unittest.rst
 create mode 100644 tools/lib/python/kdoc/xforms_lists.py
 create mode 100755 tools/lib/python/unittest_helper.py
 create mode 100755 tools/unittests/kdoc_xforms.py
Signature · 1 line
2.52.0