diff options
author | Przemyslaw Marczak <p.marczak@samsung.com> | 2015-05-13 13:38:33 +0200 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2015-05-14 19:58:34 -0600 |
commit | e8f339e0e8bb15ba6e4079d0a239ddc211a02935 (patch) | |
tree | 4fdd151e07a51987f7a629cd9abe18a38a28dec4 /test/dm/pmic.c | |
parent | 5d387d0df9816cdf05d7bce3b7379057068a7e58 (diff) | |
download | u-boot-imx-e8f339e0e8bb15ba6e4079d0a239ddc211a02935.zip u-boot-imx-e8f339e0e8bb15ba6e4079d0a239ddc211a02935.tar.gz u-boot-imx-e8f339e0e8bb15ba6e4079d0a239ddc211a02935.tar.bz2 |
test: dm: add sandbox PMIC framework tests
This change adds new file to sandbox driver model test environment.
The file is: test/dm/power.c, and it includes tests for PMIC framework,
which includes PMIC uclass and REGULATOR uclass.
All tests are based od Sandbox PMIC emulated device. Some test constants for
this device are defined in the header: include/power/sandbox_pmic.h
PMIC tests includes:
- pmic get - tests, that pmic_get() returns the requested device
- pmic I/O - tests I/O by writing and reading some values to PMIC's registers
and then compares, that the write/read values are equal.
The regulator tests includes:
- Regulator get by devname/platname
- Voltage set/get
- Current set/get
- Enable set/get
- Mode set/get
- Autoset
- List autoset
For the regulator 'get' test, the returned device pointers are compared,
and their names are also compared to the requested one.
Every other test, first sets the given attribute and next try to get it.
The test pass, when the set/get values are equal.
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested on sandbox:
Tested-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/dm/pmic.c')
-rw-r--r-- | test/dm/pmic.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/dm/pmic.c b/test/dm/pmic.c new file mode 100644 index 0000000..e9c904c --- /dev/null +++ b/test/dm/pmic.c @@ -0,0 +1,69 @@ +/* + * Tests for the driver model pmic API + * + * Copyright (c) 2015 Samsung Electronics + * Przemyslaw Marczak <p.marczak@samsung.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <errno.h> +#include <dm.h> +#include <fdtdec.h> +#include <malloc.h> +#include <dm/device-internal.h> +#include <dm/root.h> +#include <dm/ut.h> +#include <dm/util.h> +#include <dm/test.h> +#include <dm/uclass-internal.h> +#include <power/pmic.h> +#include <power/sandbox_pmic.h> + +DECLARE_GLOBAL_DATA_PTR; + +/* Test PMIC get method */ +static int dm_test_power_pmic_get(struct dm_test_state *dms) +{ + const char *name = "sandbox_pmic"; + struct udevice *dev; + + ut_assertok(pmic_get(name, &dev)); + ut_assertnonnull(dev); + + /* Check PMIC's name */ + ut_asserteq_str(name, dev->name); + + return 0; +} +DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT); + +/* Test PMIC I/O */ +static int dm_test_power_pmic_io(struct dm_test_state *dms) +{ + const char *name = "sandbox_pmic"; + uint8_t out_buffer, in_buffer; + struct udevice *dev; + int reg_count, i; + + ut_assertok(pmic_get(name, &dev)); + + reg_count = pmic_reg_count(dev); + ut_asserteq(reg_count, SANDBOX_PMIC_REG_COUNT); + + /* + * Test PMIC I/O - write and read a loop counter. + * usually we can't write to all PMIC's registers in the real hardware, + * but we can to the sandbox pmic. + */ + for (i = 0; i < reg_count; i++) { + out_buffer = i; + ut_assertok(pmic_write(dev, i, &out_buffer, 1)); + ut_assertok(pmic_read(dev, i, &in_buffer, 1)); + ut_asserteq(out_buffer, in_buffer); + } + + return 0; +} +DM_TEST(dm_test_power_pmic_io, DM_TESTF_SCAN_FDT); |