blob: ff92c39006b6de67773843a491eb32319d532fbc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Joe Hershbergere721b882015-05-20 14:27:27 -05002/*
3 * Copyright (c) 2013 Google, Inc.
Joe Hershbergere721b882015-05-20 14:27:27 -05004 */
5
6#ifndef __TEST_TEST_H
7#define __TEST_TEST_H
8
9#include <malloc.h>
Simon Glasse180c2b2020-07-28 19:41:12 -060010#include <linux/bitops.h>
Joe Hershbergere721b882015-05-20 14:27:27 -050011
12/*
13 * struct unit_test_state - Entire state of test system
14 *
15 * @fail_count: Number of tests that failed
16 * @start: Store the starting mallinfo when doing leak test
17 * @priv: A pointer to some other info some suites want to track
Simon Glass6fb2f572017-05-18 20:09:17 -060018 * @of_root: Record of the livetree root node (used for setting up tests)
Simon Glass400175b2020-01-27 08:49:56 -070019 * @expect_str: Temporary string used to hold expected string value
20 * @actual_str: Temporary string used to hold actual string value
Joe Hershbergere721b882015-05-20 14:27:27 -050021 */
22struct unit_test_state {
23 int fail_count;
24 struct mallinfo start;
25 void *priv;
Simon Glass6fb2f572017-05-18 20:09:17 -060026 struct device_node *of_root;
Simon Glass400175b2020-01-27 08:49:56 -070027 char expect_str[256];
28 char actual_str[256];
Joe Hershbergere721b882015-05-20 14:27:27 -050029};
30
Simon Glasse180c2b2020-07-28 19:41:12 -060031/* Test flags for each test */
32enum {
33 UT_TESTF_SCAN_PDATA = BIT(0), /* test needs platform data */
34 UT_TESTF_PROBE_TEST = BIT(1), /* probe test uclass */
35 UT_TESTF_SCAN_FDT = BIT(2), /* scan device tree */
36 UT_TESTF_FLAT_TREE = BIT(3), /* test needs flat DT */
37 UT_TESTF_LIVE_TREE = BIT(4), /* needs live device tree */
38};
39
Joe Hershbergere721b882015-05-20 14:27:27 -050040/**
41 * struct unit_test - Information about a unit test
42 *
43 * @name: Name of test
44 * @func: Function to call to perform test
45 * @flags: Flags indicated pre-conditions for test
46 */
47struct unit_test {
Simon Glass801587b2017-05-18 20:09:15 -060048 const char *file;
Joe Hershbergere721b882015-05-20 14:27:27 -050049 const char *name;
50 int (*func)(struct unit_test_state *state);
51 int flags;
52};
53
Heinrich Schuchardtd0ba0262020-05-06 18:26:07 +020054/**
55 * UNIT_TEST() - create linker generated list entry for unit a unit test
56 *
57 * The macro UNIT_TEST() is used to create a linker generated list entry. These
58 * list entries are enumerate tests that can be execute using the ut command.
59 * The list entries are used both by the implementation of the ut command as
60 * well as in a related Python test.
61 *
62 * For Python testing the subtests are collected in Python function
63 * generate_ut_subtest() by applying a regular expression to the lines of file
64 * u-boot.sym. The list entries have to follow strict naming conventions to be
65 * matched by the expression.
66 *
67 * Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in test suite
68 * foo that can be executed via command 'ut foo bar' and is implemented in
69 * function foo_test_bar().
70 *
71 * @_name: concatenation of name of the test suite, "_test_", and the name
72 * of the test
73 * @_flags: an integer field that can be evaluated by the test suite
74 * implementation
75 * @_suite: name of the test suite concatenated with "_test"
76 */
Joe Hershbergere721b882015-05-20 14:27:27 -050077#define UNIT_TEST(_name, _flags, _suite) \
78 ll_entry_declare(struct unit_test, _name, _suite) = { \
Simon Glass801587b2017-05-18 20:09:15 -060079 .file = __FILE__, \
Joe Hershbergere721b882015-05-20 14:27:27 -050080 .name = #_name, \
81 .flags = _flags, \
82 .func = _name, \
83 }
84
Simon Glassdc12ebb2019-12-29 21:19:25 -070085/* Sizes for devres tests */
86enum {
87 TEST_DEVRES_SIZE = 100,
88 TEST_DEVRES_COUNT = 10,
89 TEST_DEVRES_TOTAL = TEST_DEVRES_SIZE * TEST_DEVRES_COUNT,
90
Simon Glass42a0ce52019-12-29 21:19:28 -070091 /* A few different sizes */
Simon Glassdc12ebb2019-12-29 21:19:25 -070092 TEST_DEVRES_SIZE2 = 15,
Simon Glass42a0ce52019-12-29 21:19:28 -070093 TEST_DEVRES_SIZE3 = 37,
Simon Glassdc12ebb2019-12-29 21:19:25 -070094};
Joe Hershbergere721b882015-05-20 14:27:27 -050095
96#endif /* __TEST_TEST_H */