linux/lib/kunit/test.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Base unit test (KUnit) API.
 *
 * Copyright (C) 2019, Google LLC.
 * Author: Brendan Higgins <[email protected]>
 */

#include <kunit/resource.h>
#include <kunit/test.h>
#include <kunit/test-bug.h>
#include <kunit/attributes.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/mutex.h>
#include <linux/panic.h>
#include <linux/sched/debug.h>
#include <linux/sched.h>
#include <linux/mm.h>

#include "debugfs.h"
#include "device-impl.h"
#include "hooks-impl.h"
#include "string-stream.h"
#include "try-catch-impl.h"

static DEFINE_MUTEX(kunit_run_lock);

/*
 * Hook to fail the current test and print an error message to the log.
 */
void __printf(3, 4) __kunit_fail_current_test_impl(const char *file, int line, const char *fmt, ...)
{}

/*
 * Enable KUnit tests to run.
 */
#ifdef CONFIG_KUNIT_DEFAULT_ENABLED
static bool enable_param =;
#else
static bool enable_param;
#endif
module_param_named(enable, enable_param, bool, 0);
MODULE_PARM_DESC();

/*
 * KUnit statistic mode:
 * 0 - disabled
 * 1 - only when there is more than one subtest
 * 2 - enabled
 */
static int kunit_stats_enabled =;
module_param_named(stats_enabled, kunit_stats_enabled, int, 0644);
MODULE_PARM_DESC();

struct kunit_result_stats {};

static bool kunit_should_print_stats(struct kunit_result_stats stats)
{}

static void kunit_print_test_stats(struct kunit *test,
				   struct kunit_result_stats stats)
{}

/* Append formatted message to log. */
void kunit_log_append(struct string_stream *log, const char *fmt, ...)
{}
EXPORT_SYMBOL_GPL();

size_t kunit_suite_num_test_cases(struct kunit_suite *suite)
{}
EXPORT_SYMBOL_GPL();

/* Currently supported test levels */
enum {};

static void kunit_print_suite_start(struct kunit_suite *suite)
{}

static void kunit_print_ok_not_ok(struct kunit *test,
				  unsigned int test_level,
				  enum kunit_status status,
				  size_t test_number,
				  const char *description,
				  const char *directive)
{}

enum kunit_status kunit_suite_has_succeeded(struct kunit_suite *suite)
{}
EXPORT_SYMBOL_GPL();

static size_t kunit_suite_counter =;

static void kunit_print_suite_end(struct kunit_suite *suite)
{}

unsigned int kunit_test_case_num(struct kunit_suite *suite,
				 struct kunit_case *test_case)
{}
EXPORT_SYMBOL_GPL();

static void kunit_print_string_stream(struct kunit *test,
				      struct string_stream *stream)
{}

static void kunit_fail(struct kunit *test, const struct kunit_loc *loc,
		       enum kunit_assert_type type, const struct kunit_assert *assert,
		       assert_format_t assert_format, const struct va_format *message)
{}

void __noreturn __kunit_abort(struct kunit *test)
{}
EXPORT_SYMBOL_GPL();

void __kunit_do_failed_assertion(struct kunit *test,
			       const struct kunit_loc *loc,
			       enum kunit_assert_type type,
			       const struct kunit_assert *assert,
			       assert_format_t assert_format,
			       const char *fmt, ...)
{}
EXPORT_SYMBOL_GPL();

void kunit_init_test(struct kunit *test, const char *name, struct string_stream *log)
{}
EXPORT_SYMBOL_GPL();

/* Only warn when a test takes more than twice the threshold */
#define KUNIT_SPEED_WARNING_MULTIPLIER

/* Slow tests are defined as taking more than 1s */
#define KUNIT_SPEED_SLOW_THRESHOLD_S

#define KUNIT_SPEED_SLOW_WARNING_THRESHOLD_S

#define s_to_timespec64(s)

static void kunit_run_case_check_speed(struct kunit *test,
				       struct kunit_case *test_case,
				       struct timespec64 duration)
{}

/*
 * Initializes and runs test case. Does not clean up or do post validations.
 */
static void kunit_run_case_internal(struct kunit *test,
				    struct kunit_suite *suite,
				    struct kunit_case *test_case)
{}

static void kunit_case_internal_cleanup(struct kunit *test)
{}

/*
 * Performs post validations and cleanup after a test case was run.
 * XXX: Should ONLY BE CALLED AFTER kunit_run_case_internal!
 */
static void kunit_run_case_cleanup(struct kunit *test,
				   struct kunit_suite *suite)
{}

struct kunit_try_catch_context {};

static void kunit_try_run_case(void *data)
{}

static void kunit_try_run_case_cleanup(void *data)
{}

static void kunit_catch_run_case_cleanup(void *data)
{}


static void kunit_catch_run_case(void *data)
{}

/*
 * Performs all logic to run a test case. It also catches most errors that
 * occur in a test case and reports them as failures.
 */
static void kunit_run_case_catch_errors(struct kunit_suite *suite,
					struct kunit_case *test_case,
					struct kunit *test)
{}

static void kunit_print_suite_stats(struct kunit_suite *suite,
				    struct kunit_result_stats suite_stats,
				    struct kunit_result_stats param_stats)
{}

static void kunit_update_stats(struct kunit_result_stats *stats,
			       enum kunit_status status)
{}

static void kunit_accumulate_stats(struct kunit_result_stats *total,
				   struct kunit_result_stats add)
{}

int kunit_run_tests(struct kunit_suite *suite)
{}
EXPORT_SYMBOL_GPL();

static void kunit_init_suite(struct kunit_suite *suite)
{}

bool kunit_enabled(void)
{}

int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites)
{}
EXPORT_SYMBOL_GPL();

static void kunit_exit_suite(struct kunit_suite *suite)
{}

void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
{}
EXPORT_SYMBOL_GPL();

#ifdef CONFIG_MODULES
static void kunit_module_init(struct module *mod)
{}

static void kunit_module_exit(struct module *mod)
{}

static int kunit_module_notify(struct notifier_block *nb, unsigned long val,
			       void *data)
{}

static struct notifier_block kunit_mod_nb =;
#endif

KUNIT_DEFINE_ACTION_WRAPPER()

void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp)
{}
EXPORT_SYMBOL_GPL();

void kunit_kfree(struct kunit *test, const void *ptr)
{}
EXPORT_SYMBOL_GPL();

void kunit_cleanup(struct kunit *test)
{}
EXPORT_SYMBOL_GPL();

static int __init kunit_init(void)
{}
late_initcall(kunit_init);

static void __exit kunit_exit(void)
{}
module_exit(kunit_exit);

MODULE_DESCRIPTION();
MODULE_LICENSE();