Zephyr Project API 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

 DECLARE_FAKE_VALUE_FUNC (int, fake_eeprom_read, const struct device *, off_t, void *, size_t)
 @fake_of{eeprom_driver_api::read}
 DECLARE_FAKE_VALUE_FUNC (int, fake_eeprom_write, const struct device *, off_t, const void *, size_t)
 @fake_of{eeprom_driver_api::write}
 DECLARE_FAKE_VALUE_FUNC (size_t, fake_eeprom_size, const struct device *)
 @fake_of{eeprom_driver_api::size}

Detailed Description

Fake EEPROM driver.

@driver_fake{eeprom_interface,CONFIG_EEPROM_FAKE,zephyr\,fake-eeprom}

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:317
#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:525
void * data
Address of the device instance private data.
Definition device.h:535

Function Documentation

◆ DECLARE_FAKE_VALUE_FUNC() [1/3]

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

#include <eeprom_fake.h>

@fake_of{eeprom_driver_api::read}

◆ DECLARE_FAKE_VALUE_FUNC() [2/3]

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

◆ DECLARE_FAKE_VALUE_FUNC() [3/3]

DECLARE_FAKE_VALUE_FUNC ( size_t ,
fake_eeprom_size ,
const struct device *  )

#include <eeprom_fake.h>

@fake_of{eeprom_driver_api::size}