mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
Merge tag 'linux-kselftest-5.6-rc1-kunit' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest kunit updates from Shuah Khan: "This kunit update consists of: - Support for building kunit as a module from Alan Maguire - AppArmor KUnit tests for policy unpack from Mike Salvatore" * tag 'linux-kselftest-5.6-rc1-kunit' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: building kunit as a module breaks allmodconfig kunit: update documentation to describe module-based build kunit: allow kunit to be loaded as a module kunit: remove timeout dependence on sysctl_hung_task_timeout_seconds kunit: allow kunit tests to be loaded as a module kunit: hide unexported try-catch interface in try-catch-impl.h kunit: move string-stream.h to lib/kunit apparmor: add AppArmor KUnit tests for policy unpack
This commit is contained in:
@@ -29,7 +29,8 @@ Yes, well, mostly.
|
||||
|
||||
For the most part, the KUnit core framework (what you use to write the tests)
|
||||
can compile to any architecture; it compiles like just another part of the
|
||||
kernel and runs when the kernel boots. However, there is some infrastructure,
|
||||
kernel and runs when the kernel boots, or when built as a module, when the
|
||||
module is loaded. However, there is some infrastructure,
|
||||
like the KUnit Wrapper (``tools/testing/kunit/kunit.py``) that does not support
|
||||
other architectures.
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ to a standalone program that can be run like any other program directly inside
|
||||
of a host operating system; to be clear, it does not require any virtualization
|
||||
support; it is just a regular program.
|
||||
|
||||
Alternatively, kunit and kunit tests can be built as modules and tests will
|
||||
run when the test module is loaded.
|
||||
|
||||
KUnit is fast. Excluding build time, from invocation to completion KUnit can run
|
||||
several dozen tests in only 10 to 20 seconds; this might not sound like a big
|
||||
deal to some people, but having such fast and easy to run tests fundamentally
|
||||
|
||||
@@ -539,6 +539,22 @@ Interspersed in the kernel logs you might see the following:
|
||||
|
||||
Congratulations, you just ran a KUnit test on the x86 architecture!
|
||||
|
||||
In a similar manner, kunit and kunit tests can also be built as modules,
|
||||
so if you wanted to run tests in this way you might add the following config
|
||||
options to your ``.config``:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
CONFIG_KUNIT=m
|
||||
CONFIG_KUNIT_EXAMPLE_TEST=m
|
||||
|
||||
Once the kernel is built and installed, a simple
|
||||
|
||||
.. code-block:: bash
|
||||
modprobe example-test
|
||||
|
||||
...will run the tests.
|
||||
|
||||
Writing new tests for other architectures
|
||||
-----------------------------------------
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ config DEBUG_TEST_DRIVER_REMOVE
|
||||
|
||||
config PM_QOS_KUNIT_TEST
|
||||
bool "KUnit Test for PM QoS features"
|
||||
depends on KUNIT
|
||||
depends on KUNIT=y
|
||||
|
||||
config HMEM_REPORTING
|
||||
bool
|
||||
|
||||
@@ -114,4 +114,4 @@ static struct kunit_suite pm_qos_test_module = {
|
||||
.name = "qos-kunit-test",
|
||||
.test_cases = pm_qos_test_cases,
|
||||
};
|
||||
kunit_test_suite(pm_qos_test_module);
|
||||
kunit_test_suites(&pm_qos_test_module);
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ config EXT4_DEBUG
|
||||
echo 1 > /sys/module/ext4/parameters/mballoc_debug
|
||||
|
||||
config EXT4_KUNIT_TESTS
|
||||
bool "KUnit tests for ext4"
|
||||
tristate "KUnit tests for ext4"
|
||||
select EXT4_FS
|
||||
depends on KUNIT
|
||||
help
|
||||
|
||||
+2
-1
@@ -13,5 +13,6 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
|
||||
|
||||
ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
|
||||
ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o
|
||||
ext4-$(CONFIG_EXT4_KUNIT_TESTS) += inode-test.o
|
||||
ext4-inode-test-objs += inode-test.o
|
||||
obj-$(CONFIG_EXT4_KUNIT_TESTS) += ext4-inode-test.o
|
||||
ext4-$(CONFIG_FS_VERITY) += verity.o
|
||||
|
||||
@@ -269,4 +269,6 @@ static struct kunit_suite ext4_inode_test_suite = {
|
||||
.test_cases = ext4_inode_test_cases,
|
||||
};
|
||||
|
||||
kunit_test_suite(ext4_inode_test_suite);
|
||||
kunit_test_suites(&ext4_inode_test_suite);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#ifndef _KUNIT_ASSERT_H
|
||||
#define _KUNIT_ASSERT_H
|
||||
|
||||
#include <kunit/string-stream.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
struct kunit;
|
||||
struct string_stream;
|
||||
|
||||
/**
|
||||
* enum kunit_assert_type - Type of expectation/assertion.
|
||||
|
||||
+27
-10
@@ -12,6 +12,7 @@
|
||||
#include <kunit/assert.h>
|
||||
#include <kunit/try-catch.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
@@ -197,31 +198,47 @@ void kunit_init_test(struct kunit *test, const char *name);
|
||||
int kunit_run_tests(struct kunit_suite *suite);
|
||||
|
||||
/**
|
||||
* kunit_test_suite() - used to register a &struct kunit_suite with KUnit.
|
||||
* kunit_test_suites() - used to register one or more &struct kunit_suite
|
||||
* with KUnit.
|
||||
*
|
||||
* @suite: a statically allocated &struct kunit_suite.
|
||||
* @suites: a statically allocated list of &struct kunit_suite.
|
||||
*
|
||||
* Registers @suite with the test framework. See &struct kunit_suite for
|
||||
* Registers @suites with the test framework. See &struct kunit_suite for
|
||||
* more information.
|
||||
*
|
||||
* NOTE: Currently KUnit tests are all run as late_initcalls; this means
|
||||
* When builtin, KUnit tests are all run as late_initcalls; this means
|
||||
* that they cannot test anything where tests must run at a different init
|
||||
* phase. One significant restriction resulting from this is that KUnit
|
||||
* cannot reliably test anything that is initialize in the late_init phase;
|
||||
* another is that KUnit is useless to test things that need to be run in
|
||||
* an earlier init phase.
|
||||
*
|
||||
* An alternative is to build the tests as a module. Because modules
|
||||
* do not support multiple late_initcall()s, we need to initialize an
|
||||
* array of suites for a module.
|
||||
*
|
||||
* TODO(brendanhiggins@google.com): Don't run all KUnit tests as
|
||||
* late_initcalls. I have some future work planned to dispatch all KUnit
|
||||
* tests from the same place, and at the very least to do so after
|
||||
* everything else is definitely initialized.
|
||||
*/
|
||||
#define kunit_test_suite(suite) \
|
||||
static int kunit_suite_init##suite(void) \
|
||||
{ \
|
||||
return kunit_run_tests(&suite); \
|
||||
} \
|
||||
late_initcall(kunit_suite_init##suite)
|
||||
#define kunit_test_suites(...) \
|
||||
static struct kunit_suite *suites[] = { __VA_ARGS__, NULL}; \
|
||||
static int kunit_test_suites_init(void) \
|
||||
{ \
|
||||
unsigned int i; \
|
||||
for (i = 0; suites[i] != NULL; i++) \
|
||||
kunit_run_tests(suites[i]); \
|
||||
return 0; \
|
||||
} \
|
||||
late_initcall(kunit_test_suites_init); \
|
||||
static void __exit kunit_test_suites_exit(void) \
|
||||
{ \
|
||||
return; \
|
||||
} \
|
||||
module_exit(kunit_test_suites_exit)
|
||||
|
||||
#define kunit_test_suite(suite) kunit_test_suites(&suite)
|
||||
|
||||
/*
|
||||
* Like kunit_alloc_resource() below, but returns the struct kunit_resource
|
||||
|
||||
@@ -53,11 +53,6 @@ struct kunit_try_catch {
|
||||
void *context;
|
||||
};
|
||||
|
||||
void kunit_try_catch_init(struct kunit_try_catch *try_catch,
|
||||
struct kunit *test,
|
||||
kunit_try_catch_func_t try,
|
||||
kunit_try_catch_func_t catch);
|
||||
|
||||
void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context);
|
||||
|
||||
void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch);
|
||||
@@ -67,9 +62,4 @@ static inline int kunit_try_catch_get_result(struct kunit_try_catch *try_catch)
|
||||
return try_catch->try_result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Exposed for testing only.
|
||||
*/
|
||||
void kunit_generic_try_catch_init(struct kunit_try_catch *try_catch);
|
||||
|
||||
#endif /* _KUNIT_TRY_CATCH_H */
|
||||
|
||||
@@ -389,4 +389,6 @@ static struct kunit_suite sysctl_test_suite = {
|
||||
.test_cases = sysctl_test_cases,
|
||||
};
|
||||
|
||||
kunit_test_suite(sysctl_test_suite);
|
||||
kunit_test_suites(&sysctl_test_suite);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
+2
-2
@@ -2025,7 +2025,7 @@ config TEST_SYSCTL
|
||||
If unsure, say N.
|
||||
|
||||
config SYSCTL_KUNIT_TEST
|
||||
bool "KUnit test for sysctl"
|
||||
tristate "KUnit test for sysctl"
|
||||
depends on KUNIT
|
||||
help
|
||||
This builds the proc sysctl unit test, which runs on boot.
|
||||
@@ -2036,7 +2036,7 @@ config SYSCTL_KUNIT_TEST
|
||||
If unsure, say N.
|
||||
|
||||
config LIST_KUNIT_TEST
|
||||
bool "KUnit Test for Kernel Linked-list structures"
|
||||
tristate "KUnit Test for Kernel Linked-list structures"
|
||||
depends on KUNIT
|
||||
help
|
||||
This builds the linked list KUnit test suite.
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@
|
||||
#
|
||||
|
||||
menuconfig KUNIT
|
||||
bool "KUnit - Enable support for unit tests"
|
||||
tristate "KUnit - Enable support for unit tests"
|
||||
help
|
||||
Enables support for kernel unit tests (KUnit), a lightweight unit
|
||||
testing and mocking framework for the Linux kernel. These tests are
|
||||
@@ -15,7 +15,7 @@ menuconfig KUNIT
|
||||
if KUNIT
|
||||
|
||||
config KUNIT_TEST
|
||||
bool "KUnit test for KUnit"
|
||||
tristate "KUnit test for KUnit"
|
||||
help
|
||||
Enables the unit tests for the KUnit test framework. These tests test
|
||||
the KUnit test framework itself; the tests are both written using
|
||||
@@ -24,7 +24,7 @@ config KUNIT_TEST
|
||||
expected.
|
||||
|
||||
config KUNIT_EXAMPLE_TEST
|
||||
bool "Example test for KUnit"
|
||||
tristate "Example test for KUnit"
|
||||
help
|
||||
Enables an example unit test that illustrates some of the basic
|
||||
features of KUnit. This test only exists to help new users understand
|
||||
|
||||
+10
-4
@@ -1,9 +1,15 @@
|
||||
obj-$(CONFIG_KUNIT) += test.o \
|
||||
obj-$(CONFIG_KUNIT) += kunit.o
|
||||
|
||||
kunit-objs += test.o \
|
||||
string-stream.o \
|
||||
assert.o \
|
||||
try-catch.o
|
||||
|
||||
obj-$(CONFIG_KUNIT_TEST) += test-test.o \
|
||||
string-stream-test.o
|
||||
obj-$(CONFIG_KUNIT_TEST) += kunit-test.o
|
||||
|
||||
obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += example-test.o
|
||||
# string-stream-test compiles built-in only.
|
||||
ifeq ($(CONFIG_KUNIT_TEST),y)
|
||||
obj-$(CONFIG_KUNIT_TEST) += string-stream-test.o
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-test.o
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
#include <kunit/assert.h>
|
||||
|
||||
#include "string-stream.h"
|
||||
|
||||
void kunit_base_assert_format(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
{
|
||||
@@ -24,6 +26,7 @@ void kunit_base_assert_format(const struct kunit_assert *assert,
|
||||
string_stream_add(stream, "%s FAILED at %s:%d\n",
|
||||
expect_or_assert, assert->file, assert->line);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_base_assert_format);
|
||||
|
||||
void kunit_assert_print_msg(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
@@ -31,6 +34,7 @@ void kunit_assert_print_msg(const struct kunit_assert *assert,
|
||||
if (assert->message.fmt)
|
||||
string_stream_add(stream, "\n%pV", &assert->message);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_assert_print_msg);
|
||||
|
||||
void kunit_fail_assert_format(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
@@ -38,6 +42,7 @@ void kunit_fail_assert_format(const struct kunit_assert *assert,
|
||||
kunit_base_assert_format(assert, stream);
|
||||
string_stream_add(stream, "%pV", &assert->message);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_fail_assert_format);
|
||||
|
||||
void kunit_unary_assert_format(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
@@ -56,6 +61,7 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,
|
||||
unary_assert->condition);
|
||||
kunit_assert_print_msg(assert, stream);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_unary_assert_format);
|
||||
|
||||
void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
@@ -76,6 +82,7 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
|
||||
}
|
||||
kunit_assert_print_msg(assert, stream);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_ptr_not_err_assert_format);
|
||||
|
||||
void kunit_binary_assert_format(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
@@ -97,6 +104,7 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
|
||||
binary_assert->right_value);
|
||||
kunit_assert_print_msg(assert, stream);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_binary_assert_format);
|
||||
|
||||
void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
@@ -118,6 +126,7 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
|
||||
binary_assert->right_value);
|
||||
kunit_assert_print_msg(assert, stream);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_binary_ptr_assert_format);
|
||||
|
||||
void kunit_binary_str_assert_format(const struct kunit_assert *assert,
|
||||
struct string_stream *stream)
|
||||
@@ -139,3 +148,4 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
|
||||
binary_assert->right_value);
|
||||
kunit_assert_print_msg(assert, stream);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(kunit_binary_str_assert_format);
|
||||
|
||||
@@ -85,4 +85,6 @@ static struct kunit_suite example_test_suite = {
|
||||
* This registers the above test suite telling KUnit that this is a suite of
|
||||
* tests that need to be run.
|
||||
*/
|
||||
kunit_test_suite(example_test_suite);
|
||||
kunit_test_suites(&example_test_suite);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
#include <kunit/test.h>
|
||||
|
||||
#include "try-catch-impl.h"
|
||||
|
||||
struct kunit_try_catch_test_context {
|
||||
struct kunit_try_catch *try_catch;
|
||||
bool function_called;
|
||||
@@ -100,7 +102,6 @@ static struct kunit_suite kunit_try_catch_test_suite = {
|
||||
.init = kunit_try_catch_test_init,
|
||||
.test_cases = kunit_try_catch_test_cases,
|
||||
};
|
||||
kunit_test_suite(kunit_try_catch_test_suite);
|
||||
|
||||
/*
|
||||
* Context for testing test managed resources
|
||||
@@ -328,4 +329,6 @@ static struct kunit_suite kunit_resource_test_suite = {
|
||||
.exit = kunit_resource_test_exit,
|
||||
.test_cases = kunit_resource_test_cases,
|
||||
};
|
||||
kunit_test_suite(kunit_resource_test_suite);
|
||||
kunit_test_suites(&kunit_try_catch_test_suite, &kunit_resource_test_suite);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
@@ -6,10 +6,11 @@
|
||||
* Author: Brendan Higgins <brendanhiggins@google.com>
|
||||
*/
|
||||
|
||||
#include <kunit/string-stream.h>
|
||||
#include <kunit/test.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "string-stream.h"
|
||||
|
||||
static void string_stream_test_empty_on_creation(struct kunit *test)
|
||||
{
|
||||
struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL);
|
||||
@@ -49,4 +50,4 @@ static struct kunit_suite string_stream_test_suite = {
|
||||
.name = "string-stream-test",
|
||||
.test_cases = string_stream_test_cases
|
||||
};
|
||||
kunit_test_suite(string_stream_test_suite);
|
||||
kunit_test_suites(&string_stream_test_suite);
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
* Author: Brendan Higgins <brendanhiggins@google.com>
|
||||
*/
|
||||
|
||||
#include <kunit/string-stream.h>
|
||||
#include <kunit/test.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "string-stream.h"
|
||||
|
||||
struct string_stream_fragment_alloc_context {
|
||||
struct kunit *test;
|
||||
int len;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user