diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-08-05 14:43:16 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-08-05 14:43:16 -0400 |
commit | 9e9671cea72e0652a8a0d03b7c96a8a798470c43 (patch) | |
tree | e64b3879e9d36bfd417efbb5b3c800a0d1ad9082 /tools | |
parent | e21a712a9685488f5ce80495b37b9fdbe96c230d (diff) | |
parent | fbb01c52471c8fb4ec2422c0ab26c134bd90bbff (diff) |
Merge tag 'linux-kselftest-5.3-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest fixes from Shuah Khan:
"A fix to the Kselftest framework to save and restore errno and a fix
to livepatch to push and pop dynamic debug config"
* tag 'linux-kselftest-5.3-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
selftests/livepatch: push and pop dynamic debug config
kselftest: save-and-restore errno to allow for %m formatting
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/kselftest.h | 15 | ||||
-rw-r--r-- | tools/testing/selftests/livepatch/functions.sh | 26 |
2 files changed, 35 insertions, 6 deletions
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index ec15c4f6af55..0ac49d91a260 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h | |||
@@ -10,6 +10,7 @@ | |||
10 | #ifndef __KSELFTEST_H | 10 | #ifndef __KSELFTEST_H |
11 | #define __KSELFTEST_H | 11 | #define __KSELFTEST_H |
12 | 12 | ||
13 | #include <errno.h> | ||
13 | #include <stdlib.h> | 14 | #include <stdlib.h> |
14 | #include <unistd.h> | 15 | #include <unistd.h> |
15 | #include <stdarg.h> | 16 | #include <stdarg.h> |
@@ -81,58 +82,68 @@ static inline void ksft_print_cnts(void) | |||
81 | 82 | ||
82 | static inline void ksft_print_msg(const char *msg, ...) | 83 | static inline void ksft_print_msg(const char *msg, ...) |
83 | { | 84 | { |
85 | int saved_errno = errno; | ||
84 | va_list args; | 86 | va_list args; |
85 | 87 | ||
86 | va_start(args, msg); | 88 | va_start(args, msg); |
87 | printf("# "); | 89 | printf("# "); |
90 | errno = saved_errno; | ||
88 | vprintf(msg, args); | 91 | vprintf(msg, args); |
89 | va_end(args); | 92 | va_end(args); |
90 | } | 93 | } |
91 | 94 | ||
92 | static inline void ksft_test_result_pass(const char *msg, ...) | 95 | static inline void ksft_test_result_pass(const char *msg, ...) |
93 | { | 96 | { |
97 | int saved_errno = errno; | ||
94 | va_list args; | 98 | va_list args; |
95 | 99 | ||
96 | ksft_cnt.ksft_pass++; | 100 | ksft_cnt.ksft_pass++; |
97 | 101 | ||
98 | va_start(args, msg); | 102 | va_start(args, msg); |
99 | printf("ok %d ", ksft_test_num()); | 103 | printf("ok %d ", ksft_test_num()); |
104 | errno = saved_errno; | ||
100 | vprintf(msg, args); | 105 | vprintf(msg, args); |
101 | va_end(args); | 106 | va_end(args); |
102 | } | 107 | } |
103 | 108 | ||
104 | static inline void ksft_test_result_fail(const char *msg, ...) | 109 | static inline void ksft_test_result_fail(const char *msg, ...) |
105 | { | 110 | { |
111 | int saved_errno = errno; | ||
106 | va_list args; | 112 | va_list args; |
107 | 113 | ||
108 | ksft_cnt.ksft_fail++; | 114 | ksft_cnt.ksft_fail++; |
109 | 115 | ||
110 | va_start(args, msg); | 116 | va_start(args, msg); |
111 | printf("not ok %d ", ksft_test_num()); | 117 | printf("not ok %d ", ksft_test_num()); |
118 | errno = saved_errno; | ||
112 | vprintf(msg, args); | 119 | vprintf(msg, args); |
113 | va_end(args); | 120 | va_end(args); |
114 | } | 121 | } |
115 | 122 | ||
116 | static inline void ksft_test_result_skip(const char *msg, ...) | 123 | static inline void ksft_test_result_skip(const char *msg, ...) |
117 | { | 124 | { |
125 | int saved_errno = errno; | ||
118 | va_list args; | 126 | va_list args; |
119 | 127 | ||
120 | ksft_cnt.ksft_xskip++; | 128 | ksft_cnt.ksft_xskip++; |
121 | 129 | ||
122 | va_start(args, msg); | 130 | va_start(args, msg); |
123 | printf("not ok %d # SKIP ", ksft_test_num()); | 131 | printf("not ok %d # SKIP ", ksft_test_num()); |
132 | errno = saved_errno; | ||
124 | vprintf(msg, args); | 133 | vprintf(msg, args); |
125 | va_end(args); | 134 | va_end(args); |
126 | } | 135 | } |
127 | 136 | ||
128 | static inline void ksft_test_result_error(const char *msg, ...) | 137 | static inline void ksft_test_result_error(const char *msg, ...) |
129 | { | 138 | { |
139 | int saved_errno = errno; | ||
130 | va_list args; | 140 | va_list args; |
131 | 141 | ||
132 | ksft_cnt.ksft_error++; | 142 | ksft_cnt.ksft_error++; |
133 | 143 | ||
134 | va_start(args, msg); | 144 | va_start(args, msg); |
135 | printf("not ok %d # error ", ksft_test_num()); | 145 | printf("not ok %d # error ", ksft_test_num()); |
146 | errno = saved_errno; | ||
136 | vprintf(msg, args); | 147 | vprintf(msg, args); |
137 | va_end(args); | 148 | va_end(args); |
138 | } | 149 | } |
@@ -152,10 +163,12 @@ static inline int ksft_exit_fail(void) | |||
152 | 163 | ||
153 | static inline int ksft_exit_fail_msg(const char *msg, ...) | 164 | static inline int ksft_exit_fail_msg(const char *msg, ...) |
154 | { | 165 | { |
166 | int saved_errno = errno; | ||
155 | va_list args; | 167 | va_list args; |
156 | 168 | ||
157 | va_start(args, msg); | 169 | va_start(args, msg); |
158 | printf("Bail out! "); | 170 | printf("Bail out! "); |
171 | errno = saved_errno; | ||
159 | vprintf(msg, args); | 172 | vprintf(msg, args); |
160 | va_end(args); | 173 | va_end(args); |
161 | 174 | ||
@@ -178,10 +191,12 @@ static inline int ksft_exit_xpass(void) | |||
178 | static inline int ksft_exit_skip(const char *msg, ...) | 191 | static inline int ksft_exit_skip(const char *msg, ...) |
179 | { | 192 | { |
180 | if (msg) { | 193 | if (msg) { |
194 | int saved_errno = errno; | ||
181 | va_list args; | 195 | va_list args; |
182 | 196 | ||
183 | va_start(args, msg); | 197 | va_start(args, msg); |
184 | printf("not ok %d # SKIP ", 1 + ksft_test_num()); | 198 | printf("not ok %d # SKIP ", 1 + ksft_test_num()); |
199 | errno = saved_errno; | ||
185 | vprintf(msg, args); | 200 | vprintf(msg, args); |
186 | va_end(args); | 201 | va_end(args); |
187 | } else { | 202 | } else { |
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh index edcfeace4655..79b0affd21fb 100644 --- a/tools/testing/selftests/livepatch/functions.sh +++ b/tools/testing/selftests/livepatch/functions.sh | |||
@@ -29,13 +29,27 @@ function die() { | |||
29 | exit 1 | 29 | exit 1 |
30 | } | 30 | } |
31 | 31 | ||
32 | # set_dynamic_debug() - setup kernel dynamic debug | 32 | function push_dynamic_debug() { |
33 | # TODO - push and pop this config? | 33 | DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \ |
34 | awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}') | ||
35 | } | ||
36 | |||
37 | function pop_dynamic_debug() { | ||
38 | if [[ -n "$DYNAMIC_DEBUG" ]]; then | ||
39 | echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control | ||
40 | fi | ||
41 | } | ||
42 | |||
43 | # set_dynamic_debug() - save the current dynamic debug config and tweak | ||
44 | # it for the self-tests. Set a script exit trap | ||
45 | # that restores the original config. | ||
34 | function set_dynamic_debug() { | 46 | function set_dynamic_debug() { |
35 | cat << EOF > /sys/kernel/debug/dynamic_debug/control | 47 | push_dynamic_debug |
36 | file kernel/livepatch/* +p | 48 | trap pop_dynamic_debug EXIT INT TERM HUP |
37 | func klp_try_switch_task -p | 49 | cat <<-EOF > /sys/kernel/debug/dynamic_debug/control |
38 | EOF | 50 | file kernel/livepatch/* +p |
51 | func klp_try_switch_task -p | ||
52 | EOF | ||
39 | } | 53 | } |
40 | 54 | ||
41 | # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES, | 55 | # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES, |