This series is posted in context of the discussion at:
https://lore.kernel.org/lkml/Ywa9T+jKUpaHLu%2Fl@google.com/
Changes in v3:
* Original series is split into two and this v3 version contains the
improvements to selftest and VM setup.
* Planning to upload the second series to execute hypercall
instruction according to cpu type separately.
* Addressed comments from David and Sean.
link to v2:
https://lore.kernel.org/all/20220915000448.1674802-1-vannapurve@google.com/
Changes in v2:
* Addressed comments from Andrew and David
* Common function with constructor attribute used to setup initial state
* Changes are split in more logical granules as per feedback
Major changes:
1) Move common startup logic to a single function in kvm_util.c
2) Introduce following APIs:
kvm_selftest_arch_init: to perform arch specific common startup.
kvm_arch_vm_post_create: to update the guest memory state to convey
common information to guests.
3) For x86, capture cpu type at startup and pass on the cpu type to
guest after guest elf is loaded.
Vishal Annapurve (4):
KVM: selftests: move common startup logic to kvm_util.c
KVM: selftests: Add arch specific initialization
KVM: selftests: Add arch specific post vm creation hook
KVM: selftests: x86: Precompute the cpu type
.../selftests/kvm/aarch64/arch_timer.c | 3 ---
.../selftests/kvm/aarch64/hypercalls.c | 2 --
.../testing/selftests/kvm/aarch64/vgic_irq.c | 3 ---
.../selftests/kvm/include/kvm_util_base.h | 9 ++++++++
.../selftests/kvm/lib/aarch64/processor.c | 18 ++++++++--------
tools/testing/selftests/kvm/lib/kvm_util.c | 21 ++++++++++++++++---
.../selftests/kvm/lib/x86_64/processor.c | 16 ++++++++++++--
.../testing/selftests/kvm/memslot_perf_test.c | 3 ---
tools/testing/selftests/kvm/rseq_test.c | 3 ---
tools/testing/selftests/kvm/s390x/memop.c | 2 --
tools/testing/selftests/kvm/s390x/resets.c | 2 --
.../selftests/kvm/s390x/sync_regs_test.c | 3 ---
.../selftests/kvm/set_memory_region_test.c | 3 ---
.../kvm/x86_64/cr4_cpuid_sync_test.c | 3 ---
.../kvm/x86_64/emulator_error_test.c | 3 ---
.../selftests/kvm/x86_64/hyperv_cpuid.c | 3 ---
.../selftests/kvm/x86_64/platform_info_test.c | 3 ---
.../kvm/x86_64/pmu_event_filter_test.c | 3 ---
.../selftests/kvm/x86_64/set_sregs_test.c | 3 ---
.../kvm/x86_64/svm_nested_soft_inject_test.c | 3 ---
.../selftests/kvm/x86_64/sync_regs_test.c | 3 ---
.../selftests/kvm/x86_64/userspace_io_test.c | 3 ---
.../kvm/x86_64/userspace_msr_exit_test.c | 3 ---
23 files changed, 50 insertions(+), 68 deletions(-)
--
2.38.0.rc1.362.ged0d419d3c-goog
usage.rst had most of the content of the tips.rst page copied over.
But it's missing https://www.kernel.org/doc/html/v6.0/dev-tools/kunit/tips.html#customizing-…
Copy it over so we can retire tips.rst w/o losing content.
And in that process, it also gained a duplicate section about how
KUNIT_ASSERT_*() exit the test case early. Remove that.
Signed-off-by: Daniel Latypov <dlatypov(a)google.com>
---
Documentation/dev-tools/kunit/usage.rst | 49 ++++++++++++++++---------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
index 2737863ef365..b0a6c3bc0eeb 100644
--- a/Documentation/dev-tools/kunit/usage.rst
+++ b/Documentation/dev-tools/kunit/usage.rst
@@ -118,6 +118,37 @@ expectation could crash the test case. `ASSERT_NOT_ERR_OR_NULL(...)` allows us
to bail out of the test case if the appropriate conditions are not satisfied to
complete the test.
+Customizing error messages
+--------------------------
+
+Each of the ``KUNIT_EXPECT`` and ``KUNIT_ASSERT`` macros have a ``_MSG``
+variant. These take a format string and arguments to provide additional
+context to the automatically generated error messages.
+
+.. code-block:: c
+
+ char some_str[41];
+ generate_sha1_hex_string(some_str);
+
+ /* Before. Not easy to tell why the test failed. */
+ KUNIT_EXPECT_EQ(test, strlen(some_str), 40);
+
+ /* After. Now we see the offending string. */
+ KUNIT_EXPECT_EQ_MSG(test, strlen(some_str), 40, "some_str='%s'", some_str);
+
+Alternatively, one can take full control over the error message by using
+``KUNIT_FAIL()``, e.g.
+
+.. code-block:: c
+
+ /* Before */
+ KUNIT_EXPECT_EQ(test, some_setup_function(), 0);
+
+ /* After: full control over the failure message. */
+ if (some_setup_function())
+ KUNIT_FAIL(test, "Failed to setup thing for testing");
+
+
Test Suites
~~~~~~~~~~~
@@ -546,24 +577,6 @@ By reusing the same ``cases`` array from above, we can write the test as a
{}
};
-Exiting Early on Failed Expectations
-------------------------------------
-
-We can use ``KUNIT_EXPECT_EQ`` to mark the test as failed and continue
-execution. In some cases, it is unsafe to continue. We can use the
-``KUNIT_ASSERT`` variant to exit on failure.
-
-.. code-block:: c
-
- void example_test_user_alloc_function(struct kunit *test)
- {
- void *object = alloc_some_object_for_me();
-
- /* Make sure we got a valid pointer back. */
- KUNIT_ASSERT_NOT_ERR_OR_NULL(test, object);
- do_something_with_object(object);
- }
-
Allocating Memory
-----------------
base-commit: 6fe1ad4a156095859721fef85073df3ed43081d4
--
2.38.1.431.g37b22c650d-goog