Skip to content

Commit 90316e6

Browse files
committed
Merge tag 'linux-kselftest-fixes-5.15-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest fixes from Shuah Khan: - fix to Kselftest common framework header install to run before other targets for it work correctly in parallel build case. - fixes to kvm test to not ignore fscanf() returns which could result in inconsistent test behavior and failures. * tag 'linux-kselftest-fixes-5.15-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests: kvm: fix get_run_delay() ignoring fscanf() return warn selftests: kvm: move get_run_delay() into lib/test_util selftests:kvm: fix get_trans_hugepagesz() ignoring fscanf() return warn selftests:kvm: fix get_warnings_count() ignoring fscanf() return warn selftests: be sure to make khdr before other targets
2 parents a5e0ace + f5013d4 commit 90316e6

File tree

6 files changed

+27
-33
lines changed

6 files changed

+27
-33
lines changed

tools/testing/selftests/kvm/include/test_util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ struct vm_mem_backing_src_alias {
9595
uint32_t flag;
9696
};
9797

98+
#define MIN_RUN_DELAY_NS 200000UL
99+
98100
bool thp_configured(void);
99101
size_t get_trans_hugepagesz(void);
100102
size_t get_def_hugetlb_pagesz(void);
101103
const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i);
102104
size_t get_backing_src_pagesz(uint32_t i);
103105
void backing_src_help(void);
104106
enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
107+
long get_run_delay(void);
105108

106109
/*
107110
* Whether or not the given source type is shared memory (as opposed to

tools/testing/selftests/kvm/lib/test_util.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdlib.h>
1212
#include <time.h>
1313
#include <sys/stat.h>
14+
#include <sys/syscall.h>
1415
#include <linux/mman.h>
1516
#include "linux/kernel.h"
1617

@@ -129,13 +130,16 @@ size_t get_trans_hugepagesz(void)
129130
{
130131
size_t size;
131132
FILE *f;
133+
int ret;
132134

133135
TEST_ASSERT(thp_configured(), "THP is not configured in host kernel");
134136

135137
f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
136138
TEST_ASSERT(f != NULL, "Error in opening transparent_hugepage/hpage_pmd_size");
137139

138-
fscanf(f, "%ld", &size);
140+
ret = fscanf(f, "%ld", &size);
141+
ret = fscanf(f, "%ld", &size);
142+
TEST_ASSERT(ret < 1, "Error reading transparent_hugepage/hpage_pmd_size");
139143
fclose(f);
140144

141145
return size;
@@ -300,3 +304,19 @@ enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name)
300304
TEST_FAIL("Unknown backing src type: %s", type_name);
301305
return -1;
302306
}
307+
308+
long get_run_delay(void)
309+
{
310+
char path[64];
311+
long val[2];
312+
FILE *fp;
313+
314+
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
315+
fp = fopen(path, "r");
316+
/* Return MIN_RUN_DELAY_NS upon failure just to be safe */
317+
if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) < 2)
318+
val[1] = MIN_RUN_DELAY_NS;
319+
fclose(fp);
320+
321+
return val[1];
322+
}

tools/testing/selftests/kvm/steal_time.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <sched.h>
1111
#include <pthread.h>
1212
#include <linux/kernel.h>
13-
#include <sys/syscall.h>
1413
#include <asm/kvm.h>
1514
#include <asm/kvm_para.h>
1615

@@ -20,7 +19,6 @@
2019

2120
#define NR_VCPUS 4
2221
#define ST_GPA_BASE (1 << 30)
23-
#define MIN_RUN_DELAY_NS 200000UL
2422

2523
static void *st_gva[NR_VCPUS];
2624
static uint64_t guest_stolen_time[NR_VCPUS];
@@ -217,20 +215,6 @@ static void steal_time_dump(struct kvm_vm *vm, uint32_t vcpuid)
217215

218216
#endif
219217

220-
static long get_run_delay(void)
221-
{
222-
char path[64];
223-
long val[2];
224-
FILE *fp;
225-
226-
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
227-
fp = fopen(path, "r");
228-
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
229-
fclose(fp);
230-
231-
return val[1];
232-
}
233-
234218
static void *do_steal_time(void *arg)
235219
{
236220
struct timespec ts, stop;

tools/testing/selftests/kvm/x86_64/mmio_warning_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ int get_warnings_count(void)
8282
FILE *f;
8383

8484
f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
85-
fscanf(f, "%d", &warnings);
85+
if (fscanf(f, "%d", &warnings) < 1)
86+
warnings = 0;
8687
fclose(f);
8788

8889
return warnings;

tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <stdint.h>
1515
#include <time.h>
1616
#include <sched.h>
17-
#include <sys/syscall.h>
1817

1918
#define VCPU_ID 5
2019

@@ -98,20 +97,6 @@ static void guest_code(void)
9897
GUEST_DONE();
9998
}
10099

101-
static long get_run_delay(void)
102-
{
103-
char path[64];
104-
long val[2];
105-
FILE *fp;
106-
107-
sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
108-
fp = fopen(path, "r");
109-
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
110-
fclose(fp);
111-
112-
return val[1];
113-
}
114-
115100
static int cmp_timespec(struct timespec *a, struct timespec *b)
116101
{
117102
if (a->tv_sec > b->tv_sec)

tools/testing/selftests/lib.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ARCH ?= $(SUBARCH)
4848
# When local build is done, headers are installed in the default
4949
# INSTALL_HDR_PATH usr/include.
5050
.PHONY: khdr
51+
.NOTPARALLEL:
5152
khdr:
5253
ifndef KSFT_KHDR_INSTALL_DONE
5354
ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))

0 commit comments

Comments
 (0)