zephyr/tests/kernel/device/src/bad_driver.c
Daniel Leung a404bb76ee tests/kernel/device: extends test for code coverage
device_get_binding() compares pointers first before doing strcmp().
However, enabling coverage forces -O0 to disable any compiler
optimizations. There would be multiple copies of the same string,
and the code pathing doing pointer comparsion would not be tested
at all. So add this flag to merge string constants such that
the pointer comparison would be exercised.

This also adds a bad driver which fails initialization. This is
to make sure that execution path is covered.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-05-01 10:38:03 -04:00

45 lines
734 B
C

/*
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#define BAD_DRIVER_NAME "bad_driver"
typedef int (*bad_api_configure_t)(struct device *dev,
u32_t dev_config);
struct bad_driver_api {
bad_api_configure_t configure;
};
static int bad_configure(struct device *dev, u32_t config)
{
return 0;
}
static const struct bad_driver_api funcs = {
.configure = bad_configure,
};
int bad_driver_init(struct device *dev)
{
return -EINVAL;
}
/**
* @cond INTERNAL_HIDDEN
*/
DEVICE_AND_API_INIT(bad_driver, BAD_DRIVER_NAME, &bad_driver_init,
NULL, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&funcs);
/**
* @endcond
*/