Skip to content

Commit 9e9671c

Browse files
committed
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
2 parents e21a712 + fbb01c5 commit 9e9671c

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef __KSELFTEST_H
1111
#define __KSELFTEST_H
1212

13+
#include <errno.h>
1314
#include <stdlib.h>
1415
#include <unistd.h>
1516
#include <stdarg.h>
@@ -81,58 +82,68 @@ static inline void ksft_print_cnts(void)
8182

8283
static inline void ksft_print_msg(const char *msg, ...)
8384
{
85+
int saved_errno = errno;
8486
va_list args;
8587

8688
va_start(args, msg);
8789
printf("# ");
90+
errno = saved_errno;
8891
vprintf(msg, args);
8992
va_end(args);
9093
}
9194

9295
static inline void ksft_test_result_pass(const char *msg, ...)
9396
{
97+
int saved_errno = errno;
9498
va_list args;
9599

96100
ksft_cnt.ksft_pass++;
97101

98102
va_start(args, msg);
99103
printf("ok %d ", ksft_test_num());
104+
errno = saved_errno;
100105
vprintf(msg, args);
101106
va_end(args);
102107
}
103108

104109
static inline void ksft_test_result_fail(const char *msg, ...)
105110
{
111+
int saved_errno = errno;
106112
va_list args;
107113

108114
ksft_cnt.ksft_fail++;
109115

110116
va_start(args, msg);
111117
printf("not ok %d ", ksft_test_num());
118+
errno = saved_errno;
112119
vprintf(msg, args);
113120
va_end(args);
114121
}
115122

116123
static inline void ksft_test_result_skip(const char *msg, ...)
117124
{
125+
int saved_errno = errno;
118126
va_list args;
119127

120128
ksft_cnt.ksft_xskip++;
121129

122130
va_start(args, msg);
123131
printf("not ok %d # SKIP ", ksft_test_num());
132+
errno = saved_errno;
124133
vprintf(msg, args);
125134
va_end(args);
126135
}
127136

128137
static inline void ksft_test_result_error(const char *msg, ...)
129138
{
139+
int saved_errno = errno;
130140
va_list args;
131141

132142
ksft_cnt.ksft_error++;
133143

134144
va_start(args, msg);
135145
printf("not ok %d # error ", ksft_test_num());
146+
errno = saved_errno;
136147
vprintf(msg, args);
137148
va_end(args);
138149
}
@@ -152,10 +163,12 @@ static inline int ksft_exit_fail(void)
152163

153164
static inline int ksft_exit_fail_msg(const char *msg, ...)
154165
{
166+
int saved_errno = errno;
155167
va_list args;
156168

157169
va_start(args, msg);
158170
printf("Bail out! ");
171+
errno = saved_errno;
159172
vprintf(msg, args);
160173
va_end(args);
161174

@@ -178,10 +191,12 @@ static inline int ksft_exit_xpass(void)
178191
static inline int ksft_exit_skip(const char *msg, ...)
179192
{
180193
if (msg) {
194+
int saved_errno = errno;
181195
va_list args;
182196

183197
va_start(args, msg);
184198
printf("not ok %d # SKIP ", 1 + ksft_test_num());
199+
errno = saved_errno;
185200
vprintf(msg, args);
186201
va_end(args);
187202
} else {

tools/testing/selftests/livepatch/functions.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,27 @@ function die() {
2929
exit 1
3030
}
3131

32-
# set_dynamic_debug() - setup kernel dynamic debug
33-
# TODO - push and pop this config?
32+
function push_dynamic_debug() {
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.
3446
function set_dynamic_debug() {
35-
cat << EOF > /sys/kernel/debug/dynamic_debug/control
36-
file kernel/livepatch/* +p
37-
func klp_try_switch_task -p
38-
EOF
47+
push_dynamic_debug
48+
trap pop_dynamic_debug EXIT INT TERM HUP
49+
cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
50+
file kernel/livepatch/* +p
51+
func klp_try_switch_task -p
52+
EOF
3953
}
4054

4155
# loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,

0 commit comments

Comments
 (0)