zephyr/tests/kernel
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
..
cache tests: cache: Add cache test 2022-12-01 13:40:56 -05:00
common util: Replace all POSIX arch busy_waits with Z_SPIN_DELAY 2023-03-04 22:14:04 +01:00
condvar/condvar_api yamllint: fix all yamllint truthy errors 2023-01-04 01:16:45 +09:00
context tests/kernel: Cast time difference to int32_t before abs call 2023-04-05 10:38:34 +02:00
device init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
early_sleep init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
events yamllint: fix all yamllint truthy errors 2023-01-04 01:16:45 +09:00
fatal tests: kernel: fatal: report testcase results 2023-04-05 10:27:28 +02:00
fifo tests: kernel: fifo_timeout: Do not print status messages during tests 2022-12-05 13:38:16 +01:00
fpu_sharing tests: kernel: fpu_sharing: generic: add xtensa testing 2023-04-08 12:34:25 +02:00
gen_isr_table tests: gen_isr_table: remove exta TC_START call 2023-04-05 10:27:28 +02:00
interrupt tests: interrupt: Fix armclang compiler warning 2023-04-11 09:35:42 +02:00
lifo tests: kernel: cleanup test meta-data 2022-11-04 22:13:54 -04:00
mbox tests: kernel: cleanup test meta-data 2022-11-04 22:13:54 -04:00
mem_heap boards: mps2_an521: clean up memory map 2023-02-19 20:55:47 -05:00
mem_protect tests: mem_protect: Add support for configurable granularity of PMP 2023-04-06 11:50:43 +02:00
mem_slab tests/samples: use integration_plaforms in more tests/samples 2022-11-29 16:03:23 +01:00
mp tests: kernel: cleanup test meta-data 2022-11-04 22:13:54 -04:00
msgq tests: kernel: cleanup test meta-data 2022-11-04 22:13:54 -04:00
mutex tests: sys_mutex: do not use TC_START for debugging 2023-04-05 10:27:28 +02:00
obj_tracking tests: kernel: Add events to object tracking 2023-02-02 20:21:12 +09:00
pending tests: move to using CONFIG_MP_MAX_NUM_CPUS 2022-10-20 22:04:10 +09:00
pipe tests: kernel: print FAILED when wrong faults caught 2023-02-21 18:06:44 -05:00
poll tests: use ignore_fault field instead of tags 2022-11-25 06:38:05 -05:00
profiling/profiling_api tests: mark testcases with pm where CONFIG_PM=y is forced 2023-04-04 13:34:45 +02:00
queue tests: use ignore_fault field instead of tags 2022-11-25 06:38:05 -05:00
sched util: Replace all POSIX arch busy_waits with Z_SPIN_DELAY 2023-03-04 22:14:04 +01:00
semaphore tests: use ignore_fault field instead of tags 2022-11-25 06:38:05 -05:00
sleep util: Replace all POSIX arch busy_waits with Z_SPIN_DELAY 2023-03-04 22:14:04 +01:00
smp tests/kernel/smp: Limit 'stress' tests based on factor 2023-03-30 09:44:00 -04:00
smp_boot_delay tests: remove intel adsp cavs platforms from filters 2023-04-06 18:51:56 +02:00
spinlock tests: spin lock timeout test spin time 2022-12-14 13:44:36 -06:00
stack/stack tests: use ignore_fault field instead of tags 2022-11-25 06:38:05 -05:00
threads init: remove the need for a dummy device pointer in SYS_INIT functions 2023-04-12 14:28:07 +00:00
tickless/tickless_concept tests: mark testcases with pm where CONFIG_PM=y is forced 2023-04-04 13:34:45 +02:00
timer tests: kernel: timer: remove extra TC_START 2023-04-05 10:27:28 +02:00
usage/thread_runtime_stats renode: Add Renode overlays for selected tests 2023-01-25 14:02:29 -08:00
workq util: Replace all POSIX arch busy_waits with Z_SPIN_DELAY 2023-03-04 22:14:04 +01:00
xip tests: kernel: cleanup test meta-data 2022-11-04 22:13:54 -04:00