mirror of
https://github.com/torvalds/linux.git
synced 2024-11-29 23:51:37 +00:00
c475c77d5b
As tests are added to kunit, it will become less feasible to execute all built tests together. By supporting modular tests we provide a simple way to do selective execution on a running system; specifying CONFIG_KUNIT=y CONFIG_KUNIT_EXAMPLE_TEST=m ...means we can simply "insmod example-test.ko" to run the tests. To achieve this we need to do the following: o export the required symbols in kunit o string-stream tests utilize non-exported symbols so for now we skip building them when CONFIG_KUNIT_TEST=m. o drivers/base/power/qos-test.c contains a few unexported interface references, namely freq_qos_read_value() and freq_constraints_init(). Both of these could be potentially defined as static inline functions in include/linux/pm_qos.h, but for now we simply avoid supporting module build for that test suite. o support a new way of declaring test suites. Because a module cannot do multiple late_initcall()s, we provide a kunit_test_suites() macro to declare multiple suites within the same module at once. o some test module names would have been too general ("test-test" and "example-test" for kunit tests, "inode-test" for ext4 tests); rename these as appropriate ("kunit-test", "kunit-example-test" and "ext4-inode-test" respectively). Also define kunit_test_suite() via kunit_test_suites() as callers in other trees may need the old definition. Co-developed-by: Knut Omang <knut.omang@oracle.com> Signed-off-by: Knut Omang <knut.omang@oracle.com> Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Acked-by: Theodore Ts'o <tytso@mit.edu> # for ext4 bits Acked-by: David Gow <davidgow@google.com> # For list-test Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
54 lines
1.4 KiB
C
54 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* KUnit test for struct string_stream.
|
|
*
|
|
* Copyright (C) 2019, Google LLC.
|
|
* Author: Brendan Higgins <brendanhiggins@google.com>
|
|
*/
|
|
|
|
#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);
|
|
|
|
KUNIT_EXPECT_TRUE(test, string_stream_is_empty(stream));
|
|
}
|
|
|
|
static void string_stream_test_not_empty_after_add(struct kunit *test)
|
|
{
|
|
struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL);
|
|
|
|
string_stream_add(stream, "Foo");
|
|
|
|
KUNIT_EXPECT_FALSE(test, string_stream_is_empty(stream));
|
|
}
|
|
|
|
static void string_stream_test_get_string(struct kunit *test)
|
|
{
|
|
struct string_stream *stream = alloc_string_stream(test, GFP_KERNEL);
|
|
char *output;
|
|
|
|
string_stream_add(stream, "Foo");
|
|
string_stream_add(stream, " %s", "bar");
|
|
|
|
output = string_stream_get_string(stream);
|
|
KUNIT_ASSERT_STREQ(test, output, "Foo bar");
|
|
}
|
|
|
|
static struct kunit_case string_stream_test_cases[] = {
|
|
KUNIT_CASE(string_stream_test_empty_on_creation),
|
|
KUNIT_CASE(string_stream_test_not_empty_after_add),
|
|
KUNIT_CASE(string_stream_test_get_string),
|
|
{}
|
|
};
|
|
|
|
static struct kunit_suite string_stream_test_suite = {
|
|
.name = "string-stream-test",
|
|
.test_cases = string_stream_test_cases
|
|
};
|
|
kunit_test_suites(&string_stream_test_suite);
|