blob: 2a75211008323a833af62bfc315e13a6ad099a1d [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>
10
11/*
12 * struct unit_test_state - Entire state of test system
13 *
14 * @fail_count: Number of tests that failed
15 * @start: Store the starting mallinfo when doing leak test
16 * @priv: A pointer to some other info some suites want to track
Simon Glass6fb2f572017-05-18 20:09:17 -060017 * @of_root: Record of the livetree root node (used for setting up tests)
Simon Glass400175b2020-01-27 08:49:56 -070018 * @expect_str: Temporary string used to hold expected string value
19 * @actual_str: Temporary string used to hold actual string value
Joe Hershbergere721b882015-05-20 14:27:27 -050020 */
21struct unit_test_state {
22 int fail_count;
23 struct mallinfo start;
24 void *priv;
Simon Glass6fb2f572017-05-18 20:09:17 -060025 struct device_node *of_root;
Simon Glass400175b2020-01-27 08:49:56 -070026 char expect_str[256];
27 char actual_str[256];
Joe Hershbergere721b882015-05-20 14:27:27 -050028};
29
30/**
31 * struct unit_test - Information about a unit test
32 *
33 * @name: Name of test
34 * @func: Function to call to perform test
35 * @flags: Flags indicated pre-conditions for test
36 */
37struct unit_test {
Simon Glass801587b2017-05-18 20:09:15 -060038 const char *file;
Joe Hershbergere721b882015-05-20 14:27:27 -050039 const char *name;
40 int (*func)(struct unit_test_state *state);
41 int flags;
42};
43
44/* Declare a new unit test */
45#define UNIT_TEST(_name, _flags, _suite) \
46 ll_entry_declare(struct unit_test, _name, _suite) = { \
Simon Glass801587b2017-05-18 20:09:15 -060047 .file = __FILE__, \
Joe Hershbergere721b882015-05-20 14:27:27 -050048 .name = #_name, \
49 .flags = _flags, \
50 .func = _name, \
51 }
52
Simon Glassdc12ebb2019-12-29 21:19:25 -070053/* Sizes for devres tests */
54enum {
55 TEST_DEVRES_SIZE = 100,
56 TEST_DEVRES_COUNT = 10,
57 TEST_DEVRES_TOTAL = TEST_DEVRES_SIZE * TEST_DEVRES_COUNT,
58
Simon Glass42a0ce52019-12-29 21:19:28 -070059 /* A few different sizes */
Simon Glassdc12ebb2019-12-29 21:19:25 -070060 TEST_DEVRES_SIZE2 = 15,
Simon Glass42a0ce52019-12-29 21:19:28 -070061 TEST_DEVRES_SIZE3 = 37,
Simon Glassdc12ebb2019-12-29 21:19:25 -070062};
Joe Hershbergere721b882015-05-20 14:27:27 -050063
64#endif /* __TEST_TEST_H */