linux/lib/kunit/attributes.c

// SPDX-License-Identifier: GPL-2.0
/*
 * KUnit API to save and access test attributes
 *
 * Copyright (C) 2023, Google LLC.
 * Author: Rae Moar <[email protected]>
 */

#include <kunit/test.h>
#include <kunit/attributes.h>

/* Options for printing attributes:
 * PRINT_ALWAYS - attribute is printed for every test case and suite if set
 * PRINT_SUITE - attribute is printed for every suite if set but not for test cases
 * PRINT_NEVER - attribute is never printed
 */
enum print_ops {};

/**
 * struct kunit_attr - represents a test attribute and holds flexible
 * helper functions to interact with attribute.
 *
 * @name: name of test attribute, eg. speed
 * @get_attr: function to return attribute value given a test
 * @to_string: function to return string representation of given
 * attribute value
 * @filter: function to indicate whether a given attribute value passes a
 * filter
 * @attr_default: default attribute value used during filtering
 * @print: value of enum print_ops to indicate when to print attribute
 */
struct kunit_attr {};

/* String Lists for enum Attributes */

static const char * const speed_str_list[] =;

/* To String Methods */

static const char *attr_enum_to_string(void *attr, const char * const str_list[], bool *to_free)
{}

static const char *attr_bool_to_string(void *attr, bool *to_free)
{}

static const char *attr_speed_to_string(void *attr, bool *to_free)
{}

static const char *attr_string_to_string(void *attr, bool *to_free)
{}

/* Filter Methods */

static const char op_list[] =;

/*
 * Returns whether the inputted integer value matches the filter given
 * by the operation string and inputted integer.
 */
static int int_filter(long val, const char *op, int input, int *err)
{}

/*
 * Returns whether the inputted enum value "attr" matches the filter given
 * by the input string. Note: the str_list includes the corresponding string
 * list to the enum values.
 */
static int attr_enum_filter(void *attr, const char *input, int *err,
		const char * const str_list[], int max)
{}

static int attr_speed_filter(void *attr, const char *input, int *err)
{}

/*
 * Returns whether the inputted string value (attr) matches the filter given
 * by the input string.
 */
static int attr_string_filter(void *attr, const char *input, int *err)
{}

static int attr_bool_filter(void *attr, const char *input, int *err)
{}

/* Get Attribute Methods */

static void *attr_speed_get(void *test_or_suite, bool is_test)
{}

static void *attr_module_get(void *test_or_suite, bool is_test)
{}

static void *attr_is_init_get(void *test_or_suite, bool is_test)
{}

/* List of all Test Attributes */

static struct kunit_attr kunit_attr_list[] =;

/* Helper Functions to Access Attributes */

const char *kunit_attr_filter_name(struct kunit_attr_filter filter)
{}

void kunit_print_attr(void *test_or_suite, bool is_test, unsigned int test_level)
{}

/* Helper Functions to Filter Attributes */

int kunit_get_filter_count(char *input)
{}

struct kunit_attr_filter kunit_next_attr_filter(char **filters, int *err)
{}

struct kunit_suite *kunit_filter_attr_tests(const struct kunit_suite *const suite,
		struct kunit_attr_filter filter, char *action, int *err)
{}