Commit 856385e0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux_kselftest-next-6.13-rc1' of...

Merge tag 'linux_kselftest-next-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest update from Shuah Khan:
 "timer test:
   - remove duplicate defines
   - fixes to improve error reporting

  rtc test:
   - check rtc alarm status in alarm test

  resctrl test:
   - add array overrun checks during iMC config parsing code and when
     reading strings
   - fixes and reorganizing code"

* tag 'linux_kselftest-next-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (23 commits)
  selftests/resctrl: Replace magic constants used as array size
  selftests/resctrl: Keep results from first test run
  selftests/resctrl: Do not compare performance counters and resctrl at low bandwidth
  selftests/resctrl: Use cache size to determine "fill_buf" buffer size
  selftests/resctrl: Ensure measurements skip initialization of default benchmark
  selftests/resctrl: Make benchmark parameter passing robust
  selftests/resctrl: Remove unused measurement code
  selftests/resctrl: Only support measured read operation
  selftests/resctrl: Remove "once" parameter required to be false
  selftests/resctrl: Make wraparound handling obvious
  selftests/resctrl: Protect against array overflow when reading strings
  selftests/resctrl: Protect against array overrun during iMC config parsing
  selftests/resctrl: Fix memory overflow due to unhandled wraparound
  selftests/resctrl: Print accurate buffer size as part of MBM results
  selftests/resctrl: Make functions only used in same file static
  selftests: Add a test mangling with uc_sigmask
  selftests: Rename sigaltstack to generic signal
  selftest: rtc: Add to check rtc alarm status for alarm related test
  selftests:timers: remove local CLOCKID defines
  selftests: timers: Remove unneeded semicolon
  ...
parents f89a687a a44c26d7
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -31,6 +31,15 @@ kselftest runs as a userspace process. Tests that can be written/run in
userspace may wish to use the `Test Harness`_.  Tests that need to be
run in kernel space may wish to use a `Test Module`_.

Documentation on the tests
==========================

For documentation on the kselftests themselves, see:

.. toctree::

   testing-devices

Running the selftests (hotplug tests are run in limited mode)
=============================================================

+47 −0
Original line number Diff line number Diff line
.. SPDX-License-Identifier: GPL-2.0
.. Copyright (c) 2024 Collabora Ltd

=============================
Device testing with kselftest
=============================


There are a few different kselftests available for testing devices generically,
with some overlap in coverage and different requirements. This document aims to
give an overview of each one.

Note: Paths in this document are relative to the kselftest folder
(``tools/testing/selftests``).

Device oriented kselftests:

* Devicetree (``dt``)

  * **Coverage**: Probe status for devices described in Devicetree
  * **Requirements**: None

* Error logs (``devices/error_logs``)

  * **Coverage**: Error (or more critical) log messages presence coming from any
    device
  * **Requirements**: None

* Discoverable bus (``devices/probe``)

  * **Coverage**: Presence and probe status of USB or PCI devices that have been
    described in the reference file
  * **Requirements**: Manually describe the devices that should be tested in a
    YAML reference file (see ``devices/probe/boards/google,spherion.yaml`` for
    an example)

* Exist (``devices/exist``)

  * **Coverage**: Presence of all devices
  * **Requirements**: Generate the reference (see ``devices/exist/README.rst``
    for details) on a known-good kernel

Therefore, the suggestion is to enable the error log and devicetree tests on all
(DT-based) platforms, since they don't have any requirements. Then to greatly
improve coverage, generate the reference for each platform and enable the exist
test. The discoverable bus test can be used to verify the probe status of
specific USB or PCI devices, but is probably not worth it for most cases.
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ TARGETS += rust
TARGETS += sched_ext
TARGETS += seccomp
TARGETS += sgx
TARGETS += sigaltstack
TARGETS += signal
TARGETS += size
TARGETS += sparc64
TARGETS += splice
+14 −23
Original line number Diff line number Diff line
@@ -99,14 +99,13 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of
		}

		/* Field 3 is llc occ resc value */
		if (runs > 0)
		sum_llc_occu_resc += strtoul(token_array[3], NULL, 0);
		runs++;
	}
	fclose(fp);

	return show_results_info(sum_llc_occu_resc, no_of_bits, span,
				 MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, true);
				 MAX_DIFF, MAX_DIFF_PERCENT, runs, true);
}

static void cmt_test_cleanup(void)
@@ -116,15 +115,13 @@ static void cmt_test_cleanup(void)

static int cmt_run_test(const struct resctrl_test *test, const struct user_params *uparams)
{
	const char * const *cmd = uparams->benchmark_cmd;
	const char *new_cmd[BENCHMARK_ARGS];
	struct fill_buf_param fill_buf = {};
	unsigned long cache_total_size = 0;
	int n = uparams->bits ? : 5;
	unsigned long long_mask;
	char *span_str = NULL;
	int count_of_bits;
	size_t span;
	int ret, i;
	int ret;

	ret = get_full_cbm("L3", &long_mask);
	if (ret)
@@ -155,32 +152,26 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param

	span = cache_portion_size(cache_total_size, param.mask, long_mask);

	if (strcmp(cmd[0], "fill_buf") == 0) {
		/* Duplicate the command to be able to replace span in it */
		for (i = 0; uparams->benchmark_cmd[i]; i++)
			new_cmd[i] = uparams->benchmark_cmd[i];
		new_cmd[i] = NULL;

		ret = asprintf(&span_str, "%zu", span);
		if (ret < 0)
			return -1;
		new_cmd[1] = span_str;
		cmd = new_cmd;
	if (uparams->fill_buf) {
		fill_buf.buf_size = span;
		fill_buf.memflush = uparams->fill_buf->memflush;
		param.fill_buf = &fill_buf;
	} else if (!uparams->benchmark_cmd[0]) {
		fill_buf.buf_size = span;
		fill_buf.memflush = true;
		param.fill_buf = &fill_buf;
	}

	remove(RESULT_FILE_NAME);

	ret = resctrl_val(test, uparams, cmd, &param);
	ret = resctrl_val(test, uparams, &param);
	if (ret)
		goto out;
		return ret;

	ret = check_results(&param, span, n);
	if (ret && (get_vendor() == ARCH_INTEL))
		ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");

out:
	free(span_str);

	return ret;
}

+10 −35
Original line number Diff line number Diff line
@@ -88,18 +88,6 @@ static int fill_one_span_read(unsigned char *buf, size_t buf_size)
	return sum;
}

static void fill_one_span_write(unsigned char *buf, size_t buf_size)
{
	unsigned char *end_ptr = buf + buf_size;
	unsigned char *p;

	p = buf;
	while (p < end_ptr) {
		*p = '1';
		p += (CL_SIZE / 2);
	}
}

void fill_cache_read(unsigned char *buf, size_t buf_size, bool once)
{
	int ret = 0;
@@ -114,20 +102,11 @@ void fill_cache_read(unsigned char *buf, size_t buf_size, bool once)
	*value_sink = ret;
}

static void fill_cache_write(unsigned char *buf, size_t buf_size, bool once)
{
	while (1) {
		fill_one_span_write(buf, buf_size);
		if (once)
			break;
	}
}

unsigned char *alloc_buffer(size_t buf_size, int memflush)
unsigned char *alloc_buffer(size_t buf_size, bool memflush)
{
	void *buf = NULL;
	uint64_t *p64;
	size_t s64;
	ssize_t s64;
	int ret;

	ret = posix_memalign(&buf, PAGE_SIZE, buf_size);
@@ -151,19 +130,15 @@ unsigned char *alloc_buffer(size_t buf_size, int memflush)
	return buf;
}

int run_fill_buf(size_t buf_size, int memflush, int op, bool once)
ssize_t get_fill_buf_size(int cpu_no, const char *cache_type)
{
	unsigned char *buf;

	buf = alloc_buffer(buf_size, memflush);
	if (!buf)
		return -1;
	unsigned long cache_total_size = 0;
	int ret;

	if (op == 0)
		fill_cache_read(buf, buf_size, once);
	else
		fill_cache_write(buf, buf_size, once);
	free(buf);
	ret = get_cache_size(cpu_no, cache_type, &cache_total_size);
	if (ret)
		return ret;

	return 0;
	return cache_total_size * 2 > MINIMUM_SPAN ?
			cache_total_size * 2 : MINIMUM_SPAN;
}
Loading