blob: eb3581333b96a9e12ff73e344b081c10c2e135e0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassb2c1cac2014-02-26 15:59:21 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glassb2c1cac2014-02-26 15:59:21 -07004 */
5
6#include <common.h>
Joe Hershberger9dc1d712015-05-20 14:27:29 -05007#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -07008#include <console.h>
Simon Glassb2c1cac2014-02-26 15:59:21 -07009#include <dm.h>
10#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass0927a6f2014-10-04 11:29:50 -060012#include <malloc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glass2d7c4992015-11-08 23:47:44 -070014#include <asm/state.h>
Simon Glassb2c1cac2014-02-26 15:59:21 -070015#include <dm/root.h>
16#include <dm/uclass-internal.h>
Simon Glass75c4d412020-07-19 10:15:37 -060017#include <test/test.h>
18#include <test/test.h>
Joe Hershberger3a77be52015-05-20 14:27:27 -050019#include <test/ut.h>
Simon Glassb2c1cac2014-02-26 15:59:21 -070020
21DECLARE_GLOBAL_DATA_PTR;
22
Simon Glass1ef74ab2021-03-07 17:35:12 -070023/**
24 * dm_test_run() - Run driver model tests
25 *
26 * Run all the available driver model tests, or a selection
27 *
28 * @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just
29 * "fdt_pre_reloc"), or NULL to run all
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010030 * Return: 0 if all tests passed, 1 if not
Simon Glass1ef74ab2021-03-07 17:35:12 -070031 */
Simon Glass91a187b2022-08-01 07:58:45 -060032static int dm_test_run(const char *test_name, int runs_per_text)
Simon Glassb2c1cac2014-02-26 15:59:21 -070033{
Simon Glassb50211f2021-03-07 17:35:10 -070034 struct unit_test *tests = UNIT_TEST_SUITE_START(dm_test);
35 const int n_ents = UNIT_TEST_SUITE_COUNT(dm_test);
Simon Glass5ed319b2021-03-07 17:35:06 -070036 int ret;
Stephen Warrenfcebff52016-01-27 23:57:46 -070037
Simon Glass91a187b2022-08-01 07:58:45 -060038 ret = ut_run_list("driver model", "dm_test_", tests, n_ents, test_name,
39 runs_per_text);
Simon Glassb2c1cac2014-02-26 15:59:21 -070040
Simon Glass5ed319b2021-03-07 17:35:06 -070041 return ret ? CMD_RET_FAILURE : 0;
Simon Glassb2c1cac2014-02-26 15:59:21 -070042}
Joe Hershberger9dc1d712015-05-20 14:27:29 -050043
Simon Glassed38aef2020-05-10 11:40:03 -060044int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Joe Hershberger9dc1d712015-05-20 14:27:29 -050045{
46 const char *test_name = NULL;
Simon Glass91a187b2022-08-01 07:58:45 -060047 int runs_per_text = 1;
Joe Hershberger9dc1d712015-05-20 14:27:29 -050048
Simon Glass91a187b2022-08-01 07:58:45 -060049 if (argc > 1 && !strncmp("-r", argv[1], 2)) {
50 runs_per_text = dectoul(argv[1] + 2, NULL);
51 argv++;
52 argc++;
53 }
Joe Hershberger9dc1d712015-05-20 14:27:29 -050054 if (argc > 1)
55 test_name = argv[1];
56
Simon Glass91a187b2022-08-01 07:58:45 -060057 return dm_test_run(test_name, runs_per_text);
Joe Hershberger9dc1d712015-05-20 14:27:29 -050058}