Zephyr API Documentation  3.2.99
A Scalable Open Source RTOS

Test cases to verify device objects. More...

Data Structures

struct  init_record
 

Functions

 ZTEST (device, test_dummy_device)
 Test device object binding. More...
 
 ZTEST_USER (device, test_dynamic_name)
 Test device binding for existing device. More...
 
 ZTEST_USER (device, test_bogus_dynamic_name)
 Test device binding for non-existing device. More...
 
 ZTEST_USER (device, test_null_dynamic_name)
 Test device binding for passing null name. More...
 
static __pinned_func int add_init_record (bool pre_kernel)
 
static __pinned_func int pre1_fn (const struct device *dev)
 
static __pinned_func int pre2_fn (const struct device *dev)
 
static int post_fn (const struct device *dev)
 
static int app_fn (const struct device *dev)
 
 SYS_INIT (pre1_fn, PRE_KERNEL_1, 0)
 
 SYS_INIT (pre2_fn, PRE_KERNEL_2, 0)
 
 SYS_INIT (post_fn, POST_KERNEL, 0)
 
 SYS_INIT (app_fn, APPLICATION, 0)
 
static int null_driver_init (const struct device *dev)
 
 SYS_INIT (null_driver_init, POST_KERNEL, 0)
 
 ZTEST (device, test_pre_kernel_detection)
 Test detection of initialization before kernel services available. More...
 
 ZTEST (device, test_device_list)
 Test system device list query API. More...
 
static int init_fn (const struct device *dev)
 
 SYS_INIT (init_fn, APPLICATION, 0)
 
 SYS_INIT_NAMED (init1, init_fn, APPLICATION, 1)
 
 SYS_INIT_NAMED (init2, init_fn, APPLICATION, 2)
 
 SYS_INIT_NAMED (init3, init_fn, APPLICATION, 2)
 
 ZTEST (device, test_sys_init_multiple)
 
 ZTEST (device, test_device_init_level)
 Test initialization level for device driver instances. More...
 
 ZTEST (device, test_device_init_priority)
 Test initialization priorities for device driver instances. More...
 
 ZTEST (device, test_abstraction_driver_common)
 Test abstraction of device drivers with common functionalities. More...
 
 ZTEST (device, test_mmio_single)
 Test DEVICE_MMIO_* macros. More...
 
 ZTEST (device, test_mmio_multiple)
 Test DEVICE_MMIO_NAMED_* macros. More...
 
 ZTEST (device, test_mmio_toplevel)
 Test DEVICE_MMIO_TOPLEVEL_* macros. More...
 
 ZTEST (device, test_mmio_multireg)
 Test DEVICE_MMIO_NAMED_* macros. More...
 

Variables

static __pinned_bss struct init_record init_records [4]
 
static __pinned_data struct init_recordrp = init_records
 
static int sys_init_counter
 
int init_level_sequence [4]
 
int init_priority_sequence [4]
 
unsigned int seq_level_cnt
 
unsigned int seq_priority_cnt
 

Detailed Description

Test cases to verify device objects.

Verify zephyr device driver apis with different device types

Function Documentation

◆ add_init_record()

static __pinned_func int add_init_record ( bool  pre_kernel)
static

◆ app_fn()

static int app_fn ( const struct device dev)
static

◆ init_fn()

static int init_fn ( const struct device dev)
static

◆ null_driver_init()

static int null_driver_init ( const struct device dev)
static

◆ post_fn()

static int post_fn ( const struct device dev)
static

◆ pre1_fn()

static __pinned_func int pre1_fn ( const struct device dev)
static

◆ pre2_fn()

static __pinned_func int pre2_fn ( const struct device dev)
static

◆ SYS_INIT() [1/6]

SYS_INIT ( app_fn  ,
APPLICATION  ,
 
)

◆ SYS_INIT() [2/6]

SYS_INIT ( init_fn  ,
APPLICATION  ,
 
)

◆ SYS_INIT() [3/6]

SYS_INIT ( null_driver_init  ,
POST_KERNEL  ,
 
)

◆ SYS_INIT() [4/6]

SYS_INIT ( post_fn  ,
POST_KERNEL  ,
 
)

◆ SYS_INIT() [5/6]

SYS_INIT ( pre1_fn  ,
PRE_KERNEL_1  ,
 
)

◆ SYS_INIT() [6/6]

SYS_INIT ( pre2_fn  ,
PRE_KERNEL_2  ,
 
)

◆ SYS_INIT_NAMED() [1/3]

SYS_INIT_NAMED ( init1  ,
init_fn  ,
APPLICATION  ,
 
)

◆ SYS_INIT_NAMED() [2/3]

SYS_INIT_NAMED ( init2  ,
init_fn  ,
APPLICATION  ,
 
)

◆ SYS_INIT_NAMED() [3/3]

SYS_INIT_NAMED ( init3  ,
init_fn  ,
APPLICATION  ,
 
)

◆ ZTEST() [1/11]

ZTEST ( device  ,
test_abstraction_driver_common   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test abstraction of device drivers with common functionalities.

Abstraction of device drivers with common functionalities shall be provided as an intermediate interface between applications and device drivers, where such interface is implemented by individual device drivers. We verify this by following step:

  1. Define a subsystem api for drivers.
  2. Define and create two driver instances.
  3. Two drivers call the same subsystem API, and we verify that each driver instance will call their own implementations.

◆ ZTEST() [2/11]

ZTEST ( device  ,
test_device_init_level   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test initialization level for device driver instances.

After the defined device instances have initialized, we check the sequence number that each driver stored during initialization. If the sequence of initial level stored is corresponding with our expectation, it means assigning the level for driver instance works.

◆ ZTEST() [3/11]

ZTEST ( device  ,
test_device_init_priority   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test initialization priorities for device driver instances.

details After the defined device instances have initialized, we check the sequence number that each driver stored during initialization. If the sequence of initial priority stored is corresponding with our expectation, it means assigning the priority for driver instance works.

◆ ZTEST() [4/11]

ZTEST ( device  ,
test_device_list   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test system device list query API.

It queries the list of devices in the system, used to suspend or resume the devices in PM applications.

See also
z_device_get_all_static()

◆ ZTEST() [5/11]

ZTEST ( device  ,
test_dummy_device   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test device object binding.

Validates device binding for an existing and a non-existing device object. It creates a dummy_driver device object with basic init and configuration information and validates its binding.

Validates three kinds situations of driver object:

  1. A non-existing device object.
  2. An existing device object with basic init and configuration information.
  3. A failed init device object.
See also
device_get_binding(), DEVICE_DEFINE()

◆ ZTEST() [6/11]

ZTEST ( device  ,
test_mmio_multiple   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/mmio.c>

Test DEVICE_MMIO_NAMED_* macros.

We show that we can make mapping calls and that the address returned by DEVICE_MMIO_NAMED_GET() is not NULL, indicating that the kernel mapped stuff somewhere.

We show that this works for a device instance that has two named regions, 'corge' and 'grault' that respectively come from DTS instances 1 and 2.

We also perform some checks depending on configuration:

  • If MMIO addresses are maintained in RAM, check that the ROM struct was populated correctly.
  • If MMIO addresses are maintained in ROM, check that the DTS info, the ROM region, and the result of DEVICE_MMIO_NAMED_GET() all point to the same address. We show that no extra memory is used in dev_data.

◆ ZTEST() [7/11]

ZTEST ( device  ,
test_mmio_multireg   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/mmio_multireg.c>

Test DEVICE_MMIO_NAMED_* macros.

This is the same as the test_mmio_multiple test but in this test the memory regions are created by the named DT property 'reg'.

See also
test_mmio_multiple

◆ ZTEST() [8/11]

ZTEST ( device  ,
test_mmio_single   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/mmio.c>

Test DEVICE_MMIO_* macros.

We show that we can make mapping calls and that the address returned by DEVICE_MMIO_GET() is not NULL, indicating that the kernel mapped stuff somewhere.

We also perform some checks depending on configuration:

  • If MMIO addresses are maintained in RAM, check that the ROM struct was populated correctly.
  • If MMIO addresses are maintained in ROM, check that the DTS info, the ROM region, and the result of DEVICE_MMIO_GET() all point to the same address. We show that no extra memory is used in dev_data.

◆ ZTEST() [9/11]

ZTEST ( device  ,
test_mmio_toplevel   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/mmio.c>

Test DEVICE_MMIO_TOPLEVEL_* macros.

We show that we can make mapping calls and that the address returned by DEVICE_MMIO_TOPLEVEL_GET() is not NULL, indicating that the kernel mapped stuff somewhere.

We do this for two different MMIO toplevel instances; one declared statically and one not.

We also perform some checks depending on configuration:

  • If MMIO addresses are maintained in RAM, check that the ROM struct was populated correctly.
  • If MMIO addresses are maintained in ROM, check that the DTS info, the ROM region, and the result of DEVICE_MMIO_TOPLEVEL_GET() all point to the same address

◆ ZTEST() [10/11]

ZTEST ( device  ,
test_pre_kernel_detection   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test detection of initialization before kernel services available.

Confirms check is correct.

See also
k_is_pre_kernel()

◆ ZTEST() [11/11]

ZTEST ( device  ,
test_sys_init_multiple   
)

◆ ZTEST_USER() [1/3]

ZTEST_USER ( device  ,
test_bogus_dynamic_name   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test device binding for non-existing device.

Validates binding of a random device driver(non-defined driver) named "ANOTHER_BOGUS_NAME".

See also
device_get_binding(), DEVICE_DEFINE()

◆ ZTEST_USER() [2/3]

ZTEST_USER ( device  ,
test_dynamic_name   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test device binding for existing device.

Validates device binding for an existing device object.

See also
device_get_binding(), DEVICE_DEFINE()

◆ ZTEST_USER() [3/3]

ZTEST_USER ( device  ,
test_null_dynamic_name   
)

#include </home/runner/work/zephyr/zephyr/tests/kernel/device/src/main.c>

Test device binding for passing null name.

Validates device binding for device object when given dynamic name is null.

See also
device_get_binding(), DEVICE_DEFINE()

Variable Documentation

◆ init_level_sequence

int init_level_sequence[4]
extern

◆ init_priority_sequence

int init_priority_sequence[4]
extern

◆ init_records

__pinned_bss struct init_record init_records[4]
static

◆ rp

◆ seq_level_cnt

◆ seq_priority_cnt

◆ sys_init_counter