Today, when we want to check if a pointer is NULL and not ERR we have
two options:
KUNIT_EXPECT_TRUE(test, ptr == NULL);
or
KUNIT_EXPECT_PTR_NE(test, ptr, (struct mystruct *)NULL);
Create a new set of macros that take care of NULL checks.
Reviewed-by: Daniel Latypov <dlatypov(a)google.com>
Signed-off-by: Ricardo Ribalda <ribalda(a)chromium.org>
---
include/kunit/test.h | 88 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 00b9ff7783ab..340169723669 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -1218,6 +1218,50 @@ do { \
fmt, \
##__VA_ARGS__)
+/**
+ * KUNIT_EXPECT_NULL() - Expects that @ptr is null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an expectation that the value that @ptr evaluates to is null. This is
+ * semantically equivalent to KUNIT_EXPECT_PTR_EQ(@test, ptr, NULL).
+ * See KUNIT_EXPECT_TRUE() for more information.
+ */
+#define KUNIT_EXPECT_NULL(test, ptr) \
+ KUNIT_EXPECT_PTR_EQ_MSG(test, \
+ ptr, \
+ NULL, \
+ NULL)
+
+#define KUNIT_EXPECT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ ptr, ==, NULL, \
+ fmt, \
+ ##__VA_ARGS__)
+
+/**
+ * KUNIT_EXPECT_NOT_NULL() - Expects that @ptr is not null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an expectation that the value that @ptr evaluates to is not null. This
+ * is semantically equivalent to KUNIT_EXPECT_PTR_NE(@test, ptr, NULL).
+ * See KUNIT_EXPECT_TRUE() for more information.
+ */
+#define KUNIT_EXPECT_NOT_NULL(test, ptr) \
+ KUNIT_EXPECT_PTR_NE_MSG(test, \
+ ptr, \
+ NULL, \
+ NULL)
+
+#define KUNIT_EXPECT_NOT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ ptr, !=, NULL, \
+ fmt, \
+ ##__VA_ARGS__)
+
/**
* KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
* @test: The test context object.
@@ -1485,6 +1529,50 @@ do { \
fmt, \
##__VA_ARGS__)
+/**
+ * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an assertion that the values that @ptr evaluates to is null. This is
+ * the same as KUNIT_EXPECT_NULL(), except it causes an assertion
+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_NULL(test, ptr) \
+ KUNIT_ASSERT_PTR_EQ_MSG(test, \
+ ptr, \
+ NULL, \
+ NULL)
+
+#define KUNIT_ASSERT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ ptr, ==, NULL, \
+ fmt, \
+ ##__VA_ARGS__)
+
+/**
+ * KUNIT_ASSERT_NOT_NULL() - Asserts that pointers @ptr is not null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an assertion that the values that @ptr evaluates to is not null. This
+ * is the same as KUNIT_EXPECT_NOT_NULL(), except it causes an assertion
+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_NOT_NULL(test, ptr) \
+ KUNIT_ASSERT_PTR_NE_MSG(test, \
+ ptr, \
+ NULL, \
+ NULL)
+
+#define KUNIT_ASSERT_NOT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ ptr, !=, NULL, \
+ fmt, \
+ ##__VA_ARGS__)
+
/**
* KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
* @test: The test context object.
--
2.35.0.263.gb82422642f-goog
If only futex selftest is compiled, uapi header files are copied to the
selftests/futex/functional directory. This copy isn't needed. Set the
DEFAULT_INSTALL_HDR_PATH variable to 1 to use the default header install
path only. This removes extra copy of header file.
Signed-off-by: Muhammad Usama Anjum <usama.anjum(a)collabora.com>
---
tools/testing/selftests/futex/functional/Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/testing/selftests/futex/functional/Makefile
index 5cc38de9d8ea..9a8c3700d773 100644
--- a/tools/testing/selftests/futex/functional/Makefile
+++ b/tools/testing/selftests/futex/functional/Makefile
@@ -24,6 +24,7 @@ TEST_PROGS := run.sh
top_srcdir = ../../../../..
KSFT_KHDR_INSTALL := 1
+DEFAULT_INSTALL_HDR_PATH := 1
include ../../lib.mk
$(TEST_GEN_FILES): $(HEADERS)
--
2.30.2
Today, when we want to check if a pointer is NULL and not ERR we have
two options:
EXPECT_TRUE(test, ptr == NULL);
or
EXPECT_PTR_NE(test, ptr, (struct mystruct *)NULL);
Create a new set of macros that take care of NULL checks.
Signed-off-by: Ricardo Ribalda <ribalda(a)chromium.org>
---
include/kunit/test.h | 88 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 00b9ff7783ab..5970d3a0e4af 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -1218,6 +1218,50 @@ do { \
fmt, \
##__VA_ARGS__)
+/**
+ * KUNIT_EXPECT_NULL() - Expects that @ptr is null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an expectation that the value that @ptr evaluates to is null. This is
+ * semantically equivalent to KUNIT_EXPECT_PTR_EQ(@test, NULL, ptr).
+ * See KUNIT_EXPECT_TRUE() for more information.
+ */
+#define KUNIT_EXPECT_NULL(test, ptr) \
+ KUNIT_EXPECT_PTR_EQ_MSG(test, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ NULL)
+
+#define KUNIT_EXPECT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ (typeof(ptr))NULL, ==, ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+
+/**
+ * KUNIT_EXPECT_NOT_NULL() - Expects that @ptr is not null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an expectation that the value that @ptr evaluates to is not null. This
+ * is semantically equivalent to KUNIT_EXPECT_PTR_NE(@test, NULL, ptr).
+ * See KUNIT_EXPECT_TRUE() for more information.
+ */
+#define KUNIT_EXPECT_NOT_NULL(test, ptr) \
+ KUNIT_EXPECT_PTR_NE_MSG(test, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ NULL)
+
+#define KUNIT_EXPECT_NOT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ (typeof(ptr))NULL, !=, ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+
/**
* KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
* @test: The test context object.
@@ -1485,6 +1529,50 @@ do { \
fmt, \
##__VA_ARGS__)
+/**
+ * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an assertion that the values that @ptr evaluates to is null. This is
+ * the same as KUNIT_EXPECT_NULL(), except it causes an assertion
+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_NULL(test, ptr) \
+ KUNIT_ASSERT_PTR_EQ_MSG(test, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ NULL)
+
+#define KUNIT_ASSERT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ (typeof(ptr))NULL, ==, ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+
+/**
+ * KUNIT_ASSERT_NOT_NULL() - Asserts that pointers @ptr is not null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an assertion that the values that @ptr evaluates to is not null. This
+ * is the same as KUNIT_EXPECT_NOT_NULL(), except it causes an assertion
+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_NOT_NULL(test, ptr) \
+ KUNIT_ASSERT_PTR_NE_MSG(test, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ NULL)
+
+#define KUNIT_ASSERT_NOT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ (typeof(ptr))NULL, !=, ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+
/**
* KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
* @test: The test context object.
--
2.35.0.263.gb82422642f-goog
Today, when we want to check if a pointer is NULL and not ERR we have
two options:
EXPECT_TRUE(test, ptr == NULL);
or
EXPECT_PTR_NE(test, ptr, (struct mystruct *)NULL);
Create a new set of macros that take care of NULL checks.
Signed-off-by: Ricardo Ribalda <ribalda(a)chromium.org>
---
include/kunit/test.h | 91 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
diff --git a/include/kunit/test.h b/include/kunit/test.h
index b26400731c02..a84bf065e64b 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -1395,6 +1395,51 @@ do { \
##__VA_ARGS__)
/**
+ * KUNIT_EXPECT_NULL() - Expects that @ptr is null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an expectation that the value that @ptr evaluates to is null. This is
+ * semantically equivalent to KUNIT_EXPECT_PTR_EQ(@test, NULL, ptr).
+ * See KUNIT_EXPECT_TRUE() for more information.
+ */
+#define KUNIT_EXPECT_NULL(test, ptr) \
+ KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ (typeof(ptr))NULL, \
+ ptr)
+
+#define KUNIT_EXPECT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+/**
+ * KUNIT_EXPECT_NOT_NULL() - Expects that @ptr is not null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an expectation that the value that @ptr evaluates to is not null. This
+ * is semantically equivalent to KUNIT_EXPECT_PTR_NE(@test, NULL, ptr).
+ * See KUNIT_EXPECT_TRUE() for more information.
+ */
+#define KUNIT_EXPECT_NOT_NULL(test, ptr) \
+ KUNIT_BINARY_PTR_NE_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ (typeof(ptr))NULL, \
+ ptr)
+
+#define KUNIT_EXPECT_NOT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
+ KUNIT_EXPECTATION, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+
+ /**
* KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
* @test: The test context object.
* @left: an arbitrary expression that evaluates to a primitive C type.
@@ -1678,6 +1723,52 @@ do { \
fmt, \
##__VA_ARGS__)
+/**
+ * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an assertion that the values that @ptr evaluates to is null. This is
+ * the same as KUNIT_EXPECT_NULL(), except it causes an assertion
+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_NULL(test, ptr) \
+ KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ (typeof(ptr))NULL, \
+ ptr)
+
+#define KUNIT_ASSERT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+
+/**
+ * KUNIT_ASSERT_NOT_NULL() - Asserts that pointers @ptr is not null.
+ * @test: The test context object.
+ * @ptr: an arbitrary pointer.
+ *
+ * Sets an assertion that the values that @ptr evaluates to is not null. This
+ * is the same as KUNIT_EXPECT_NOT_NULL(), except it causes an assertion
+ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
+ */
+#define KUNIT_ASSERT_NOT_NULL(test, ptr) \
+ KUNIT_BINARY_PTR_NE_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ (typeof(ptr))NULL, \
+ ptr)
+
+#define KUNIT_ASSERT_NOT_NULL_MSG(test, ptr, fmt, ...) \
+ KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
+ KUNIT_ASSERTION, \
+ (typeof(ptr))NULL, \
+ ptr, \
+ fmt, \
+ ##__VA_ARGS__)
+
/**
* KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
* @test: The test context object.
--
2.35.0.263.gb82422642f-goog
A few tests that require running CPUID do so with a private
implementation of a wrapper for CPUID. This duplication of
the CPUID wrapper should be avoided but having one is also
unnecessary because of the existence of a macro that can
be used instead.
This series replaces private CPUID wrappers with calls
to the __cpuid_count() macro from cpuid.h as made available
by gcc and clang/llvm.
Cc: Dave Hansen <dave.hansen(a)linux.intel.com>
Cc: Ram Pai <linuxram(a)us.ibm.com>
Cc: Sandipan Das <sandipan(a)linux.ibm.com>
Cc: Florian Weimer <fweimer(a)redhat.com>
Cc: "Desnes A. Nunes do Rosario" <desnesn(a)linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo(a)kernel.org>
Cc: Thiago Jung Bauermann <bauerman(a)linux.ibm.com>
Cc: Michael Ellerman <mpe(a)ellerman.id.au>
Cc: Michal Suchanek <msuchanek(a)suse.de>
Cc: linux-mm(a)kvack.org
Cc: Chang S. Bae <chang.seok.bae(a)intel.com>
Cc: Borislav Petkov <bp(a)suse.de>
Cc: Thomas Gleixner <tglx(a)linutronix.de>
Cc: Ingo Molnar <mingo(a)redhat.com>
Cc: "H. Peter Anvin" <hpa(a)zytor.com>
Cc: x86(a)kernel.org
Cc: Andy Lutomirski <luto(a)kernel.org>
Reinette Chatre (3):
selftests/vm/pkeys: Use existing __cpuid_count() macro
selftests/x86/amx: Use existing __cpuid_count() macro
selftests/x86/corrupt_xstate_header: Use existing __cpuid_count()
macro
tools/testing/selftests/vm/pkey-x86.h | 22 +++---------------
tools/testing/selftests/x86/amx.c | 23 +++++--------------
.../selftests/x86/corrupt_xstate_header.c | 17 ++------------
3 files changed, 11 insertions(+), 51 deletions(-)
--
2.25.1
From: Frank Rowand <frank.rowand(a)sony.com>
Clarify some confusing phrasing.
Signed-off-by: Frank Rowand <frank.rowand(a)sony.com>
---
One item that may result in bikeshedding is that I added the spec
version to the title line.
Documentation/dev-tools/ktap.rst | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/Documentation/dev-tools/ktap.rst b/Documentation/dev-tools/ktap.rst
index 878530cb9c27..3b7a26816930 100644
--- a/Documentation/dev-tools/ktap.rst
+++ b/Documentation/dev-tools/ktap.rst
@@ -1,8 +1,8 @@
.. SPDX-License-Identifier: GPL-2.0
-========================================
-The Kernel Test Anything Protocol (KTAP)
-========================================
+===================================================
+The Kernel Test Anything Protocol (KTAP), version 1
+===================================================
TAP, or the Test Anything Protocol is a format for specifying test results used
by a number of projects. It's website and specification are found at this `link
@@ -186,7 +186,7 @@ starting with another KTAP version line and test plan, and end with the overall
result. If one of the subtests fail, for example, the parent test should also
fail.
-Additionally, all result lines in a subtest should be indented. One level of
+Additionally, all lines in a subtest should be indented. One level of
indentation is two spaces: " ". The indentation should begin at the version
line and should end before the parent test's result line.
@@ -225,8 +225,8 @@ Major differences between TAP and KTAP
--------------------------------------
Note the major differences between the TAP and KTAP specification:
-- yaml and json are not recommended in diagnostic messages
-- TODO directive not recognized
+- yaml and json are not recommended in KTAP diagnostic messages
+- TODO directive not recognized in KTAP
- KTAP allows for an arbitrary number of tests to be nested
The TAP14 specification does permit nested tests, but instead of using another
--
Frank Rowand <frank.rowand(a)sony.com>
Hello Dave Hansen,
The patch 5f23f6d082a9: "x86/pkeys: Add self-tests" from Jul 29,
2016, leads to the following Smatch static checker warning:
tools/testing/selftests/vm/protection_keys.c:647 record_pkey_malloc()
warn: address of 'pkey_malloc_records[i]' is probably non-NULL
tools/testing/selftests/vm/protection_keys.c
638 long nr_pkey_malloc_records;
639 void record_pkey_malloc(void *ptr, long size, int prot)
640 {
641 long i;
642 struct pkey_malloc_record *rec = NULL;
643
644 for (i = 0; i < nr_pkey_malloc_records; i++) {
645 rec = &pkey_malloc_records[i];
646 /* find a free record */
--> 647 if (rec)
648 break;
649 }
650 if (!rec) {
This code is supposed re-allocate memory. If we run out, then allocate
2x the memory. But it only works for the first allocation where
"pkey_malloc_records" is NULL.
For the following allocations it will just select &pkey_malloc_records[0]
and re-use that again.
651 /* every record is full */
652 size_t old_nr_records = nr_pkey_malloc_records;
653 size_t new_nr_records = (nr_pkey_malloc_records * 2 + 1);
654 size_t new_size = new_nr_records * sizeof(struct pkey_malloc_record);
655 dprintf2("new_nr_records: %zd\n", new_nr_records);
656 dprintf2("new_size: %zd\n", new_size);
657 pkey_malloc_records = realloc(pkey_malloc_records, new_size);
658 pkey_assert(pkey_malloc_records != NULL);
659 rec = &pkey_malloc_records[nr_pkey_malloc_records];
660 /*
661 * realloc() does not initialize memory, so zero it from
662 * the first new record all the way to the end.
663 */
664 for (i = 0; i < new_nr_records - old_nr_records; i++)
665 memset(rec + i, 0, sizeof(*rec));
666 }
667 dprintf3("filling malloc record[%d/%p]: {%p, %ld}\n",
668 (int)(rec - pkey_malloc_records), rec, ptr, size);
669 rec->ptr = ptr;
670 rec->size = size;
671 rec->prot = prot;
672 pkey_last_malloc_record = rec;
673 nr_pkey_malloc_records++;
674 }
regards,
dan carpenter