Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-fixes-5.15-rc3' of git://git.kernel.org/pu…
Browse files Browse the repository at this point in the history
…b/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
  • Loading branch information
torvalds committed Sep 25, 2021
2 parents a5e0ace + f5013d4 commit 90316e6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
3 changes: 3 additions & 0 deletions tools/testing/selftests/kvm/include/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ struct vm_mem_backing_src_alias {
uint32_t flag;
};

#define MIN_RUN_DELAY_NS 200000UL

bool thp_configured(void);
size_t get_trans_hugepagesz(void);
size_t get_def_hugetlb_pagesz(void);
const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i);
size_t get_backing_src_pagesz(uint32_t i);
void backing_src_help(void);
enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
long get_run_delay(void);

/*
* Whether or not the given source type is shared memory (as opposed to
Expand Down
22 changes: 21 additions & 1 deletion tools/testing/selftests/kvm/lib/test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <linux/mman.h>
#include "linux/kernel.h"

Expand Down Expand Up @@ -129,13 +130,16 @@ size_t get_trans_hugepagesz(void)
{
size_t size;
FILE *f;
int ret;

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

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

fscanf(f, "%ld", &size);
ret = fscanf(f, "%ld", &size);
ret = fscanf(f, "%ld", &size);
TEST_ASSERT(ret < 1, "Error reading transparent_hugepage/hpage_pmd_size");
fclose(f);

return size;
Expand Down Expand Up @@ -300,3 +304,19 @@ enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name)
TEST_FAIL("Unknown backing src type: %s", type_name);
return -1;
}

long get_run_delay(void)
{
char path[64];
long val[2];
FILE *fp;

sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
fp = fopen(path, "r");
/* Return MIN_RUN_DELAY_NS upon failure just to be safe */
if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) < 2)
val[1] = MIN_RUN_DELAY_NS;
fclose(fp);

return val[1];
}
16 changes: 0 additions & 16 deletions tools/testing/selftests/kvm/steal_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <sched.h>
#include <pthread.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <asm/kvm.h>
#include <asm/kvm_para.h>

Expand All @@ -20,7 +19,6 @@

#define NR_VCPUS 4
#define ST_GPA_BASE (1 << 30)
#define MIN_RUN_DELAY_NS 200000UL

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

#endif

static long get_run_delay(void)
{
char path[64];
long val[2];
FILE *fp;

sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
fp = fopen(path, "r");
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
fclose(fp);

return val[1];
}

static void *do_steal_time(void *arg)
{
struct timespec ts, stop;
Expand Down
3 changes: 2 additions & 1 deletion tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ int get_warnings_count(void)
FILE *f;

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

return warnings;
Expand Down
15 changes: 0 additions & 15 deletions tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <stdint.h>
#include <time.h>
#include <sched.h>
#include <sys/syscall.h>

#define VCPU_ID 5

Expand Down Expand Up @@ -98,20 +97,6 @@ static void guest_code(void)
GUEST_DONE();
}

static long get_run_delay(void)
{
char path[64];
long val[2];
FILE *fp;

sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
fp = fopen(path, "r");
fscanf(fp, "%ld %ld ", &val[0], &val[1]);
fclose(fp);

return val[1];
}

static int cmp_timespec(struct timespec *a, struct timespec *b)
{
if (a->tv_sec > b->tv_sec)
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ARCH ?= $(SUBARCH)
# When local build is done, headers are installed in the default
# INSTALL_HDR_PATH usr/include.
.PHONY: khdr
.NOTPARALLEL:
khdr:
ifndef KSFT_KHDR_INSTALL_DONE
ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
Expand Down

0 comments on commit 90316e6

Please sign in to comment.