Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Fake EEPROM driver. More...

Files

file  eeprom_fake.h
 Fake EEPROM driver API functions.

Functions

int fake_eeprom_read (const struct device *, off_t, void *, size_t)
 Fake implementation of the eeprom_driver_api::read driver operation.
int fake_eeprom_write (const struct device *, off_t, const void *, size_t)
 Fake implementation of the eeprom_driver_api::write driver operation.
size_t fake_eeprom_size (const struct device *)
 Fake implementation of the eeprom_driver_api::size driver operation.

Detailed Description

Fake EEPROM driver.

This is a Fake Function Framework (FFF) implementation of the EEPROM API, provided for use in tests. It is enabled by CONFIG_EEPROM_FAKE and instantiated from zephyr,fake-eeprom devicetree nodes.

Each fake below is paired with an FFF control structure named after it with an additional _fake suffix, which tests use to set return values, install custom fakes, or inspect call counts and captured arguments. The control structures are not listed here; see Mocking via FFF.

Use return_val for fakes that only report status; a fake with output parameters must be driven with a custom_fake, as return_val leaves those parameters untouched.

When CONFIG_ZTEST is enabled, a ztest rule resets every fake before each test case.

fake_eeprom_read() and fake_eeprom_size() are given a default custom_fake honouring the size from devicetree and zero-filling reads, re-installed on every reset. Install your own custom_fake in the test case to change what they report.

const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(fake_eeprom));
const uint8_t data[] = {0x01, 0x02};
zassert_ok(eeprom_write(dev, 8, data, sizeof(data)));
zassert_equal(1, fake_eeprom_write_fake.call_count);
zassert_equal(dev, fake_eeprom_write_fake.arg0_val);
zassert_equal(8, fake_eeprom_write_fake.arg1_val);
zassert_equal(sizeof(data), fake_eeprom_write_fake.arg3_val);
#define DEVICE_DT_GET(node_id)
Get a device reference from a devicetree node identifier.
Definition device.h:323
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition devicetree.h:197
int eeprom_write(const struct device *dev, off_t offset, const void *data, size_t len)
Write data to EEPROM.
#define zassert_equal(a, b,...)
Assert that a equals b.
Definition ztest_assert.h:321
#define zassert_ok(cond,...)
Assert that cond is 0 (success).
Definition ztest_assert.h:289
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
void * data
Address of the device instance private data.
Definition device.h:553

Function Documentation

◆ fake_eeprom_read()

int fake_eeprom_read ( const struct device * ,
off_t ,
void * ,
size_t  )

#include <zephyr/drivers/eeprom/eeprom_fake.h>

Fake implementation of the eeprom_driver_api::read driver operation.

◆ fake_eeprom_size()

size_t fake_eeprom_size ( const struct device * )

#include <zephyr/drivers/eeprom/eeprom_fake.h>

Fake implementation of the eeprom_driver_api::size driver operation.

◆ fake_eeprom_write()

int fake_eeprom_write ( const struct device * ,
off_t ,
const void * ,
size_t  )

#include <zephyr/drivers/eeprom/eeprom_fake.h>

Fake implementation of the eeprom_driver_api::write driver operation.