Add tests for the new board uclass. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Mario Six <mario.six@gdsys.cc>lime2-spi
parent
6238ae4d60
commit
e6fd018108
@ -0,0 +1,107 @@ |
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* (C) Copyright 2018 |
||||||
|
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <common.h> |
||||||
|
#include <dm.h> |
||||||
|
#include <board.h> |
||||||
|
|
||||||
|
#include "sandbox.h" |
||||||
|
|
||||||
|
struct board_sandbox_priv { |
||||||
|
bool called_detect; |
||||||
|
int test_i1; |
||||||
|
int test_i2; |
||||||
|
}; |
||||||
|
|
||||||
|
char vacation_spots[][64] = {"R'lyeh", "Dreamlands", "Plateau of Leng", |
||||||
|
"Carcosa", "Yuggoth", "The Nameless City"}; |
||||||
|
|
||||||
|
int board_sandbox_detect(struct udevice *dev) |
||||||
|
{ |
||||||
|
struct board_sandbox_priv *priv = dev_get_priv(dev); |
||||||
|
|
||||||
|
priv->called_detect = true; |
||||||
|
priv->test_i2 = 100; |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int board_sandbox_get_bool(struct udevice *dev, int id, bool *val) |
||||||
|
{ |
||||||
|
struct board_sandbox_priv *priv = dev_get_priv(dev); |
||||||
|
|
||||||
|
switch (id) { |
||||||
|
case BOOL_CALLED_DETECT: |
||||||
|
/* Checks if the dectect method has been called */ |
||||||
|
*val = priv->called_detect; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
return -ENOENT; |
||||||
|
} |
||||||
|
|
||||||
|
int board_sandbox_get_int(struct udevice *dev, int id, int *val) |
||||||
|
{ |
||||||
|
struct board_sandbox_priv *priv = dev_get_priv(dev); |
||||||
|
|
||||||
|
switch (id) { |
||||||
|
case INT_TEST1: |
||||||
|
*val = priv->test_i1; |
||||||
|
/* Increments with every call */ |
||||||
|
priv->test_i1++; |
||||||
|
return 0; |
||||||
|
case INT_TEST2: |
||||||
|
*val = priv->test_i2; |
||||||
|
/* Decrements with every call */ |
||||||
|
priv->test_i2--; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
return -ENOENT; |
||||||
|
} |
||||||
|
|
||||||
|
int board_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val) |
||||||
|
{ |
||||||
|
struct board_sandbox_priv *priv = dev_get_priv(dev); |
||||||
|
int i1 = priv->test_i1; |
||||||
|
int i2 = priv->test_i2; |
||||||
|
int index = (i1 * i2) % ARRAY_SIZE(vacation_spots); |
||||||
|
|
||||||
|
switch (id) { |
||||||
|
case STR_VACATIONSPOT: |
||||||
|
/* Picks a vacation spot depending on i1 and i2 */ |
||||||
|
snprintf(val, size, vacation_spots[index]); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
return -ENOENT; |
||||||
|
} |
||||||
|
|
||||||
|
static const struct udevice_id board_sandbox_ids[] = { |
||||||
|
{ .compatible = "sandbox,board_sandbox" }, |
||||||
|
{ /* sentinel */ } |
||||||
|
}; |
||||||
|
|
||||||
|
static const struct board_ops board_sandbox_ops = { |
||||||
|
.detect = board_sandbox_detect, |
||||||
|
.get_bool = board_sandbox_get_bool, |
||||||
|
.get_int = board_sandbox_get_int, |
||||||
|
.get_str = board_sandbox_get_str, |
||||||
|
}; |
||||||
|
|
||||||
|
int board_sandbox_probe(struct udevice *dev) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
U_BOOT_DRIVER(board_sandbox) = { |
||||||
|
.name = "board_sandbox", |
||||||
|
.id = UCLASS_BOARD, |
||||||
|
.of_match = board_sandbox_ids, |
||||||
|
.ops = &board_sandbox_ops, |
||||||
|
.priv_auto_alloc_size = sizeof(struct board_sandbox_priv), |
||||||
|
.probe = board_sandbox_probe, |
||||||
|
}; |
@ -0,0 +1,12 @@ |
|||||||
|
/* SPDX-License-Identifier: GPL-2.0+ */ |
||||||
|
/*
|
||||||
|
* (C) Copyright 2018 |
||||||
|
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
||||||
|
*/ |
||||||
|
|
||||||
|
enum { |
||||||
|
BOOL_CALLED_DETECT, |
||||||
|
INT_TEST1, |
||||||
|
INT_TEST2, |
||||||
|
STR_VACATIONSPOT, |
||||||
|
}; |
@ -0,0 +1,57 @@ |
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* (C) Copyright 2018 |
||||||
|
* Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <common.h> |
||||||
|
#include <dm.h> |
||||||
|
#include <dm/test.h> |
||||||
|
#include <board.h> |
||||||
|
#include <test/ut.h> |
||||||
|
|
||||||
|
#include "../../drivers/board/sandbox.h" |
||||||
|
|
||||||
|
static int dm_test_board(struct unit_test_state *uts) |
||||||
|
{ |
||||||
|
struct udevice *board; |
||||||
|
bool called_detect; |
||||||
|
char str[64]; |
||||||
|
int i; |
||||||
|
|
||||||
|
board_get(&board); |
||||||
|
ut_assert(board); |
||||||
|
|
||||||
|
board_get_bool(board, BOOL_CALLED_DETECT, &called_detect); |
||||||
|
ut_assert(!called_detect); |
||||||
|
|
||||||
|
board_detect(board); |
||||||
|
|
||||||
|
board_get_bool(board, BOOL_CALLED_DETECT, &called_detect); |
||||||
|
ut_assert(called_detect); |
||||||
|
|
||||||
|
board_get_str(board, STR_VACATIONSPOT, sizeof(str), str); |
||||||
|
ut_assertok(strcmp(str, "R'lyeh")); |
||||||
|
|
||||||
|
board_get_int(board, INT_TEST1, &i); |
||||||
|
ut_asserteq(0, i); |
||||||
|
|
||||||
|
board_get_int(board, INT_TEST2, &i); |
||||||
|
ut_asserteq(100, i); |
||||||
|
|
||||||
|
board_get_str(board, STR_VACATIONSPOT, sizeof(str), str); |
||||||
|
ut_assertok(strcmp(str, "Carcosa")); |
||||||
|
|
||||||
|
board_get_int(board, INT_TEST1, &i); |
||||||
|
ut_asserteq(1, i); |
||||||
|
|
||||||
|
board_get_int(board, INT_TEST2, &i); |
||||||
|
ut_asserteq(99, i); |
||||||
|
|
||||||
|
board_get_str(board, STR_VACATIONSPOT, sizeof(str), str); |
||||||
|
ut_assertok(strcmp(str, "Yuggoth")); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
DM_TEST(dm_test_board, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Loading…
Reference in new issue