Skip to content

Commit 5976137

Browse files
committed
doc: Convert tst_kvercmp.h to RST
Link: https://lore.kernel.org/ltp/[email protected]/ Co-developed-by: Cyril Hrubis <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
1 parent 69e0ff4 commit 5976137

File tree

2 files changed

+78
-11
lines changed

2 files changed

+78
-11
lines changed

doc/developers/api_c_tests.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.. SPDX-License-Identifier: GPL-2.0-or-later
2-
.. Copyright (c) Linux Test Project, 2024
2+
.. Copyright (c) Linux Test Project, 2024-2025
33
44
.. Include headers in this file with:
55
.. .. kernel-doc:: ../../include/tst_test.h
@@ -41,6 +41,7 @@ Guarded buffers
4141
Kernel
4242
------
4343
.. kernel-doc:: ../../include/tst_kernel.h
44+
.. kernel-doc:: ../../include/tst_kvercmp.h
4445

4546
NUMA
4647
----

include/tst_kvercmp.h

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,110 @@
11
/* SPDX-License-Identifier: GPL-2.0-or-later
22
* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
33
* Copyright (c) 2009-2016 Cyril Hrubis [email protected]
4+
* Copyright (c) Linux Test Project, 2020-2025
45
*/
56

67
#ifndef TST_KVERCMP_H__
78
#define TST_KVERCMP_H__
89

9-
/*
10+
/**
11+
* tst_kvcmp() - Compare given kernel version with kernel in string.
12+
*
13+
* @cur_kver: Kernel version string (struct utsname.release).
14+
* @r1: Major kernel version.
15+
* @r2: Minor kernel version.
16+
* @r3: Kernel patch level.
17+
*
18+
* Everything after first three version numbers till the end of the string is
19+
* ignored.
20+
*
1021
* The same as tst_kvercmp() but running kernel version is passed as parameter
1122
* instead of utilizing uname().
23+
*
24+
* Return: Negative if older, 0 if the same and positive if newer.
1225
*/
1326
int tst_kvcmp(const char *cur_kver, int r1, int r2, int r3);
1427

15-
/*
16-
* Parsers string into three integer version.
28+
/**
29+
* tst_parse_kver() - Parses a version string into three integers.
30+
*
31+
* @str_kver: Kernel version string (struct utsname.release).
32+
* @v1: Major kernel version.
33+
* @v2: Minor kernel version.
34+
* @v3: Kernel patch level.
35+
*
36+
* Everything after first three version numbers till the end of the string is
37+
* ignored.
38+
*
39+
* Return: 0 on success, 1 on error.
1740
*/
1841
int tst_parse_kver(const char *str_kver, int *v1, int *v2, int *v3);
1942

20-
/*
21-
* Returns distribution name parsed from kernel version string or NULL.
43+
/**
44+
* tst_kvcmp_distname() - Get the distribution name from kernel version string.
45+
*
46+
* @cur_kver: Kernel version string (struct utsname.release).
47+
*
48+
* Return: The distribution name parsed from kernel version string or NULL.
2249
*/
2350
const char *tst_kvcmp_distname(const char *cur_kver);
2451

25-
/*
26-
* Compares versions up to five version numbers long.
52+
/**
53+
* tst_kvexcmp() - Compares versions up to five version numbers long.
54+
* @tst_exv: The tested kernel version string (struct utsname.release).
55+
* @cur_kver: The current version in string (struct utsname.release).
56+
*
57+
* The return value is similar to the :man3:`strcmp` function, i.e. zero means
58+
* equal, negative value means that the kernel is older than the expected value
59+
* and positive means that it's newer.
60+
*
61+
* Return: negative if older, 0 if the same and positive if newer.
2762
*/
2863
int tst_kvexcmp(const char *tst_exv, const char *cur_kver);
2964

30-
/*
31-
* Compare given kernel version with currently running kernel.
65+
/**
66+
* tst_kvercmp() - Compare a kernel version against currently running kernel.
67+
*
68+
* @r1: Major kernel version.
69+
* @r2: Minor kernel version.
70+
* @r3: Kernel patch level.
71+
*
72+
* Parse the output from :man2:`uname` and compare it to the passed values.
73+
* This is shortcut for calling tst_kvcmp() with ``uname -r`` as str_kver.
3274
*
33-
* Returns negative if older, 0 if the same and positive if newer.
75+
* Return: Negative if older, 0 if the same and positive if newer.
3476
*/
3577
int tst_kvercmp(int r1, int r2, int r3);
3678

79+
/**
80+
* struct tst_kern_exv - describe vendor kernel.
81+
*
82+
* @dist_name: A distribution name, e.g. "SLES", "RHEL9", "UBUNTU".
83+
* @extra_ver: A vendor kernel version to check, e.g. "5.14.0-441".
84+
*/
3785
struct tst_kern_exv {
3886
char *dist_name;
3987
char *extra_ver;
4088
};
4189

90+
/**
91+
* tst_kvercmp2() - Compare given *distro* kernel version with the currently running kernel.
92+
*
93+
* @r1: Major kernel version.
94+
* @r2: Minor kernel version.
95+
* @r3: Kernel patch level.
96+
* @vers: A {} terminated array of :ref:`struct tst_kern_exv`.
97+
*
98+
* Attempts to look up a distro specific kernel version from the struct
99+
* tst_kern_exv table first and if no match is found falls back to the version
100+
* passed in r1, r2, r3 (see tst_kvercmp()).
101+
*
102+
* The distribution name is detected either from the kernel release string e.g.
103+
* el9 is mapped to RHEL9 or as a capitalized value of the ``ID=`` variable from
104+
* ``/etc/os-release``.
105+
*
106+
* Return: Negative if older, 0 if the same and positive if newer.
107+
*/
42108
int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers);
43109

44110
#endif /* TST_KVERCMP_H__ */

0 commit comments

Comments
 (0)