diff options
author | Jonathan Corbet <corbet@lwn.net> | 2014-11-24 12:50:40 -0500 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2014-11-24 12:50:40 -0500 |
commit | 86d3e023e05d90b2b5f88dcbf2e334b5835131f8 (patch) | |
tree | 7695c67ca0ae65bbe04f7b6d7f244ab395f8dabc | |
parent | 690b0543a813b0ecfc51b0374c0ce6c8275435f0 (diff) | |
parent | 3c415707b37f1e4483c418c77f57692b89bcfd5e (diff) |
Merge branch 'docs-3.19' into docs-next
-rw-r--r-- | Documentation/CodingStyle | 43 | ||||
-rw-r--r-- | Documentation/kselftest.txt (renamed from tools/testing/selftests/README.txt) | 30 |
2 files changed, 62 insertions, 11 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 3171822c22a5..9f28b140dc89 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle | |||
@@ -845,6 +845,49 @@ next instruction in the assembly output: | |||
845 | : /* outputs */ : /* inputs */ : /* clobbers */); | 845 | : /* outputs */ : /* inputs */ : /* clobbers */); |
846 | 846 | ||
847 | 847 | ||
848 | Chapter 20: Conditional Compilation | ||
849 | |||
850 | Wherever possible, don't use preprocessor conditionals (#if, #ifdef) in .c | ||
851 | files; doing so makes code harder to read and logic harder to follow. Instead, | ||
852 | use such conditionals in a header file defining functions for use in those .c | ||
853 | files, providing no-op stub versions in the #else case, and then call those | ||
854 | functions unconditionally from .c files. The compiler will avoid generating | ||
855 | any code for the stub calls, producing identical results, but the logic will | ||
856 | remain easy to follow. | ||
857 | |||
858 | Prefer to compile out entire functions, rather than portions of functions or | ||
859 | portions of expressions. Rather than putting an ifdef in an expression, factor | ||
860 | out part or all of the expression into a separate helper function and apply the | ||
861 | conditional to that function. | ||
862 | |||
863 | If you have a function or variable which may potentially go unused in a | ||
864 | particular configuration, and the compiler would warn about its definition | ||
865 | going unused, mark the definition as __maybe_unused rather than wrapping it in | ||
866 | a preprocessor conditional. (However, if a function or variable *always* goes | ||
867 | unused, delete it.) | ||
868 | |||
869 | Within code, where possible, use the IS_ENABLED macro to convert a Kconfig | ||
870 | symbol into a C boolean expression, and use it in a normal C conditional: | ||
871 | |||
872 | if (IS_ENABLED(CONFIG_SOMETHING)) { | ||
873 | ... | ||
874 | } | ||
875 | |||
876 | The compiler will constant-fold the conditional away, and include or exclude | ||
877 | the block of code just as with an #ifdef, so this will not add any runtime | ||
878 | overhead. However, this approach still allows the C compiler to see the code | ||
879 | inside the block, and check it for correctness (syntax, types, symbol | ||
880 | references, etc). Thus, you still have to use an #ifdef if the code inside the | ||
881 | block references symbols that will not exist if the condition is not met. | ||
882 | |||
883 | At the end of any non-trivial #if or #ifdef block (more than a few lines), | ||
884 | place a comment after the #endif on the same line, noting the conditional | ||
885 | expression used. For instance: | ||
886 | |||
887 | #ifdef CONFIG_SOMETHING | ||
888 | ... | ||
889 | #endif /* CONFIG_SOMETHING */ | ||
890 | |||
848 | 891 | ||
849 | Appendix I: References | 892 | Appendix I: References |
850 | 893 | ||
diff --git a/tools/testing/selftests/README.txt b/Documentation/kselftest.txt index 2660d5ff9179..a87d840bacfe 100644 --- a/tools/testing/selftests/README.txt +++ b/Documentation/kselftest.txt | |||
@@ -15,37 +15,45 @@ Running the selftests (hotplug tests are run in limited mode) | |||
15 | ============================================================= | 15 | ============================================================= |
16 | 16 | ||
17 | To build the tests: | 17 | To build the tests: |
18 | |||
19 | $ make -C tools/testing/selftests | 18 | $ make -C tools/testing/selftests |
20 | 19 | ||
21 | 20 | ||
22 | To run the tests: | 21 | To run the tests: |
23 | |||
24 | $ make -C tools/testing/selftests run_tests | 22 | $ make -C tools/testing/selftests run_tests |
25 | 23 | ||
24 | To build and run the tests with a single command, use: | ||
25 | $ make kselftest | ||
26 | |||
26 | - note that some tests will require root privileges. | 27 | - note that some tests will require root privileges. |
27 | 28 | ||
28 | To run only tests targeted for a single subsystem: (including | ||
29 | hotplug targets in limited mode) | ||
30 | 29 | ||
31 | $ make -C tools/testing/selftests TARGETS=cpu-hotplug run_tests | 30 | Running a subset of selftests |
31 | ======================================== | ||
32 | You can use the "TARGETS" variable on the make command line to specify | ||
33 | single test to run, or a list of tests to run. | ||
34 | |||
35 | To run only tests targeted for a single subsystem: | ||
36 | $ make -C tools/testing/selftests TARGETS=ptrace run_tests | ||
37 | |||
38 | You can specify multiple tests to build and run: | ||
39 | $ make TARGETS="size timers" kselftest | ||
40 | |||
41 | See the top-level tools/testing/selftests/Makefile for the list of all | ||
42 | possible targets. | ||
32 | 43 | ||
33 | See the top-level tools/testing/selftests/Makefile for the list of all possible | ||
34 | targets. | ||
35 | 44 | ||
36 | Running the full range hotplug selftests | 45 | Running the full range hotplug selftests |
37 | ======================================== | 46 | ======================================== |
38 | 47 | ||
39 | To build the tests: | 48 | To build the hotplug tests: |
40 | |||
41 | $ make -C tools/testing/selftests hotplug | 49 | $ make -C tools/testing/selftests hotplug |
42 | 50 | ||
43 | To run the tests: | 51 | To run the hotplug tests: |
44 | |||
45 | $ make -C tools/testing/selftests run_hotplug | 52 | $ make -C tools/testing/selftests run_hotplug |
46 | 53 | ||
47 | - note that some tests will require root privileges. | 54 | - note that some tests will require root privileges. |
48 | 55 | ||
56 | |||
49 | Contributing new tests | 57 | Contributing new tests |
50 | ====================== | 58 | ====================== |
51 | 59 | ||