Revert "tests: devicetree: test supported devices API"

This reverts commit 4c32e21fc7 with some
manual conflict resolution.

It's not clear that the supported devices are being properly computed,
so let's revert this for v2.7.0 until we've had more time to think
it through.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-09-24 12:22:39 -07:00 committed by Christopher Friedt
commit e643464b20

View file

@ -74,15 +74,15 @@ static bool check_handle(device_handle_t hdl,
return false;
}
struct visitor_context {
struct requires_context {
uint8_t ndevs;
const struct device *rdevs[2];
};
static int device_visitor(const struct device *dev,
void *context)
static int requires_visitor(const struct device *dev,
void *context)
{
struct visitor_context *ctx = context;
struct requires_context *ctx = context;
const struct device **rdp = ctx->rdevs;
while (rdp < (ctx->rdevs + ctx->ndevs)) {
@ -102,14 +102,14 @@ static void test_requires(void)
size_t nhdls = 0;
const device_handle_t *hdls;
const struct device *dev;
struct visitor_context ctx = { 0 };
struct requires_context ctx = { 0 };
/* TEST_GPIO: no req */
dev = device_get_binding(DT_LABEL(TEST_GPIO));
zassert_equal(dev, DEVICE_DT_GET(TEST_GPIO), NULL);
hdls = device_required_handles_get(dev, &nhdls);
zassert_equal(nhdls, 0, NULL);
zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx),
zassert_equal(0, device_required_foreach(dev, requires_visitor, &ctx),
NULL);
/* TEST_I2C: no req */
@ -117,7 +117,7 @@ static void test_requires(void)
zassert_equal(dev, DEVICE_DT_GET(TEST_I2C), NULL);
hdls = device_required_handles_get(dev, &nhdls);
zassert_equal(nhdls, 0, NULL);
zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx),
zassert_equal(0, device_required_foreach(dev, requires_visitor, &ctx),
NULL);
/* TEST_DEVA: TEST_I2C GPIO */
@ -129,23 +129,23 @@ static void test_requires(void)
zassert_true(check_handle(DEV_HDL(TEST_GPIO), hdls, nhdls), NULL);
/* Visit fails if not enough space */
ctx = (struct visitor_context){
ctx = (struct requires_context){
.ndevs = 1,
};
zassert_equal(-ENOSPC, device_required_foreach(dev, device_visitor, &ctx),
zassert_equal(-ENOSPC, device_required_foreach(dev, requires_visitor, &ctx),
NULL);
/* Visit succeeds if enough space. */
ctx = (struct visitor_context){
ctx = (struct requires_context){
.ndevs = 2,
};
zassert_equal(2, device_required_foreach(dev, device_visitor, &ctx),
zassert_equal(2, device_required_foreach(dev, requires_visitor, &ctx),
NULL);
zassert_true((ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_I2C)))
|| (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_I2C))),
|| (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_I2C))),
NULL);
zassert_true((ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_GPIO)))
|| (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_GPIO))),
|| (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_GPIO))),
NULL);
/* TEST_GPIOX: TEST_I2C */
@ -154,10 +154,10 @@ static void test_requires(void)
hdls = device_required_handles_get(dev, &nhdls);
zassert_equal(nhdls, 1, NULL);
zassert_true(check_handle(DEV_HDL(TEST_I2C), hdls, nhdls), NULL);
ctx = (struct visitor_context){
ctx = (struct requires_context){
.ndevs = 3,
};
zassert_equal(1, device_required_foreach(dev, device_visitor, &ctx),
zassert_equal(1, device_required_foreach(dev, requires_visitor, &ctx),
NULL);
zassert_true(ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_I2C)),
NULL);
@ -171,45 +171,6 @@ static void test_requires(void)
zassert_true(check_handle(DEV_HDL(TEST_GPIOX), hdls, nhdls), NULL);
}
static void test_supports(void)
{
size_t nhdls = 0;
const device_handle_t *hdls;
const struct device *dev;
struct visitor_context ctx = { 0 };
/* TEST_DEVB: None */
dev = DEVICE_DT_GET(TEST_DEVB);
hdls = device_supported_handles_get(dev, &nhdls);
zassert_equal(nhdls, 0, NULL);
/* TEST_GPIO: TEST_DEVA */
dev = DEVICE_DT_GET(TEST_GPIO);
hdls = device_supported_handles_get(dev, &nhdls);
zassert_equal(nhdls, 1, NULL);
zassert_true(check_handle(DEV_HDL(TEST_DEVA), hdls, nhdls), NULL);
/* Visit fails if not enough space */
ctx = (struct visitor_context){
.ndevs = 0,
};
zassert_equal(-ENOSPC, device_supported_foreach(dev, device_visitor, &ctx), NULL);
/* Visit succeeds if enough space. */
ctx = (struct visitor_context){
.ndevs = 1,
};
zassert_equal(1, device_supported_foreach(dev, device_visitor, &ctx), NULL);
zassert_true(ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_DEVA)), NULL);
/* TEST_I2C: TEST_DEVA TEST_GPIOX TEST_DEVB */
dev = DEVICE_DT_GET(TEST_I2C);
hdls = device_supported_handles_get(dev, &nhdls);
zassert_equal(nhdls, 3, NULL);
zassert_true(check_handle(DEV_HDL(TEST_DEVA), hdls, nhdls), NULL);
zassert_true(check_handle(DEV_HDL(TEST_GPIOX), hdls, nhdls), NULL);
zassert_true(check_handle(DEV_HDL(TEST_DEVB), hdls, nhdls), NULL);
}
static void test_get_or_null(void)
{
@ -232,7 +193,6 @@ void test_main(void)
ztest_test_suite(devicetree_driver,
ztest_unit_test(test_init_order),
ztest_unit_test(test_requires),
ztest_unit_test(test_supports),
ztest_unit_test(test_get_or_null)
);
ztest_run_test_suite(devicetree_driver);