Skip to content

Commit

Permalink
lib: move utilities into own folder
Browse files Browse the repository at this point in the history
Move various utilities out of lib into own folder for better assignement
and management in the maintainer file. lib/os has become another dumping
ground for everything and it the Kconfig and contents in that folder
became difficult to manage, configure and test.

Signed-off-by: Anas Nashif <[email protected]>
  • Loading branch information
nashif authored and carlescufi committed Dec 22, 2023
1 parent e710c9c commit 0b999c0
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 78 deletions.
19 changes: 17 additions & 2 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ JSON Web Token:
files:
- subsys/jwt/
- include/zephyr/data/
- lib/os/json.c
- lib/utils/json.c
- tests/subsys/jwt/
- tests/lib/json/
labels:
Expand Down Expand Up @@ -2125,8 +2125,15 @@ Kernel:

Utilities:
status: maintained
maintainers:
- andyross
- nashif
collaborators:
- dcpleung
- peter-mitsis
files:
- lib/crc/
- lib/utils/
- tests/unit/timeutil/
- tests/unit/time_units/
- tests/unit/rbtree/
Expand All @@ -2136,7 +2143,6 @@ Utilities:
- tests/unit/math_extras/
- tests/unit/list/
- tests/unit/intmath/
- tests/misc/print_format/
- tests/unit/pot/
- tests/lib/time/
- tests/lib/onoff/
Expand All @@ -2147,6 +2153,10 @@ Utilities:
- tests/lib/linear_range/
labels:
- "area: Utilities"
tests:
- utilities
- libraries.ring_buffer
- libraries.linear_range

Base OS:
status: maintained
Expand All @@ -2159,6 +2169,9 @@ Base OS:
files:
- include/zephyr/sys/
- lib/os/
- tests/misc/print_format/
- tests/lib/p4workq/
- tests/lib/fdtable/
files-exclude:
- include/zephyr/sys/cbprintf*
- tests/unit/cbprintf/
Expand All @@ -2171,6 +2184,8 @@ Base OS:
- lib/os/mpsc_pbuf.c
labels:
- "area: Base OS"
tests:
- printk

Heap Management:
status: maintained
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_subdirectory(hash)
add_subdirectory(heap)
add_subdirectory(mem_blocks)
add_subdirectory(os)
add_subdirectory(utils)
add_subdirectory_ifdef(CONFIG_SMF smf)
add_subdirectory_ifdef(CONFIG_OPENAMP open-amp)
add_subdirectory_ifdef(CONFIG_ACPI acpi)
2 changes: 2 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ source "lib/smf/Kconfig"
source "lib/acpi/Kconfig"

source "lib/runtime/Kconfig"

source "lib/utils/Kconfig"
endmenu
17 changes: 0 additions & 17 deletions lib/os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@ zephyr_syscall_header(
${ZEPHYR_BASE}/include/zephyr/sys/mutex.h
)

zephyr_sources_ifdef(CONFIG_BASE64 base64.c)

zephyr_sources(
cbprintf_packaged.c
dec.c
hex.c
printk.c
rb.c
sem.c
thread_entry.c
timeutil.c
bitarray.c
)

zephyr_sources_ifdef(CONFIG_FDTABLE fdtable.c)
zephyr_sources_ifdef(CONFIG_ONOFF onoff.c)
zephyr_sources_ifdef(CONFIG_NOTIFY notify.c)

zephyr_sources_ifdef(CONFIG_CBPRINTF_COMPLETE cbprintf_complete.c)
zephyr_sources_ifdef(CONFIG_CBPRINTF_NANO cbprintf_nano.c)
Expand All @@ -29,10 +20,6 @@ if(NOT CONFIG_PICOLIBC)
zephyr_sources(cbprintf.c)
endif()

zephyr_sources_ifdef(CONFIG_JSON_LIBRARY json.c)

zephyr_sources_ifdef(CONFIG_RING_BUFFER ring_buffer.c)

if (CONFIG_ASSERT OR CONFIG_ASSERT_VERBOSE)
zephyr_sources(assert.c)
endif()
Expand All @@ -47,10 +34,6 @@ zephyr_sources_ifdef(CONFIG_SCHED_DEADLINE p4wq.c)

zephyr_sources_ifdef(CONFIG_REBOOT reboot.c)

zephyr_sources_ifdef(CONFIG_UTF8 utf8.c)

zephyr_sources_ifdef(CONFIG_WINSTREAM winstream.c)

zephyr_sources_ifdef(CONFIG_POWEROFF poweroff.c)

zephyr_library_include_directories(
Expand Down
54 changes: 0 additions & 54 deletions lib/os/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,6 @@ config FDTABLE
for any I/O object implementing POSIX I/O semantics (i.e. read/write +
aux operations).

config JSON_LIBRARY
bool "Build JSON library"
help
Build a minimal JSON parsing/encoding library. Used by sample
applications such as the NATS client.

config RING_BUFFER
bool "Ring buffers"
help
Enable usage of ring buffers. This is similar to kernel FIFOs but ring
buffers manage their own buffer memory and can store arbitrary data.
For optimal performance, use buffer sizes that are a power of 2.

config NOTIFY
bool "Asynchronous Notifications"
help
Use this API to support async transactions.

config BASE64
bool "Base64 encoding and decoding"
help
Enable base64 encoding and decoding functionality

config PRINTK_SYNC
bool "Serialize printk() calls"
default y if SMP && MP_MAX_NUM_CPUS > 1 && !(EFI_CONSOLE && LOG)
Expand All @@ -50,14 +27,6 @@ config MPSC_PBUF
storing variable length packets in a circular way and operate directly
on the buffer memory.

config ONOFF
bool "On-Off Manager"
select NOTIFY
help
An on-off manager supports an arbitrary number of clients of a
service which has a binary state. Example applications are power
rails, clocks, and binary device power management.

config SPSC_PBUF
bool "Single producer, single consumer packet buffer"
help
Expand Down Expand Up @@ -119,23 +88,6 @@ config SPSC_PBUF_UTILIZATION

endif # SPSC_PBUF

config WINSTREAM
bool "Lockless shared memory window byte stream"
help
Winstream is a byte stream IPC for use in shared memory
"windows", generally for transmit to non-Zephyr contexts that
can't share Zephyr APIs or data structures.

if WINSTREAM
config WINSTREAM_STDLIB_MEMCOPY
bool "Use standard memcpy() in winstream"
help
The sys_winstream utility is sometimes used in early boot
environments before the standard library is usable. By
default it uses a simple internal bytewise memcpy(). Set
this to use the one from the standard library.
endif

if MPSC_PBUF
config MPSC_CLEAR_ALLOCATED
bool "Clear allocated packet"
Expand All @@ -161,12 +113,6 @@ config POWEROFF
help
Enable support for system power off.

config UTF8
bool "UTF-8 string operation supported"
help
Enable the utf8 API. The API implements functions to specifically
handle UTF-8 encoded strings.

rsource "Kconfig.cbprintf"

endmenu
27 changes: 27 additions & 0 deletions lib/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_sources_ifdef(CONFIG_BASE64 base64.c)

zephyr_sources(
dec.c
hex.c
rb.c
timeutil.c
bitarray.c
)

zephyr_sources_ifdef(CONFIG_ONOFF onoff.c)
zephyr_sources_ifdef(CONFIG_NOTIFY notify.c)

zephyr_sources_ifdef(CONFIG_JSON_LIBRARY json.c)

zephyr_sources_ifdef(CONFIG_RING_BUFFER ring_buffer.c)

zephyr_sources_ifdef(CONFIG_UTF8 utf8.c)

zephyr_sources_ifdef(CONFIG_WINSTREAM winstream.c)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/${ARCH}/include
)
60 changes: 60 additions & 0 deletions lib/utils/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) 2016 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

menu "Utility Library"

config JSON_LIBRARY
bool "Build JSON library"
help
Build a minimal JSON parsing/encoding library. Used by sample
applications such as the NATS client.

config RING_BUFFER
bool "Ring buffers"
help
Enable usage of ring buffers. This is similar to kernel FIFOs but ring
buffers manage their own buffer memory and can store arbitrary data.
For optimal performance, use buffer sizes that are a power of 2.

config NOTIFY
bool "Asynchronous Notifications"
help
Use this API to support async transactions.

config BASE64
bool "Base64 encoding and decoding"
help
Enable base64 encoding and decoding functionality

config ONOFF
bool "On-Off Manager"
select NOTIFY
help
An on-off manager supports an arbitrary number of clients of a
service which has a binary state. Example applications are power
rails, clocks, and binary device power management.

config WINSTREAM
bool "Lockless shared memory window byte stream"
help
Winstream is a byte stream IPC for use in shared memory
"windows", generally for transmit to non-Zephyr contexts that
can't share Zephyr APIs or data structures.

if WINSTREAM
config WINSTREAM_STDLIB_MEMCOPY
bool "Use standard memcpy() in winstream"
help
The sys_winstream utility is sometimes used in early boot
environments before the standard library is usable. By
default it uses a simple internal bytewise memcpy(). Set
this to use the one from the standard library.
endif

config UTF8
bool "UTF-8 string operation supported"
help
Enable the utf8 API. The API implements functions to specifically
handle UTF-8 encoded strings.

endmenu
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/unit/base64/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <zephyr/sys/base64.h>
#include <zephyr/ztest.h>

#include "../../../lib/os/base64.c"
#include "../../../lib/utils/base64.c"

static const unsigned char base64_test_dec[64] = {
0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/rbtree/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <zephyr/ztest.h>
#include <zephyr/sys/rb.h>

#include "../../../lib/os/rb.c"
#include "../../../lib/utils/rb.c"

#define _CHECK(n) \
zassert_true(!!(n), "Tree check failed: [ " #n " ] @%d", __LINE__)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/timeutil/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <zephyr/ztest.h>
#include "timeutil_test.h"
#include "../../../lib/os/timeutil.c"
#include "../../../lib/utils/timeutil.c"

void timeutil_check(const struct timeutil_test_data *tp,
size_t count)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ cmake_minimum_required(VERSION 3.20.0)

project(util)
find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
target_sources(testbinary PRIVATE main.c maincxx.cxx ${ZEPHYR_BASE}/lib/os/dec.c)
target_sources(testbinary PRIVATE main.c maincxx.cxx ${ZEPHYR_BASE}/lib/utils/dec.c)
2 changes: 1 addition & 1 deletion tests/unit/winstream/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/* This, uh, seems to be the standard way to unit test library code.
* Or so I gather from tests/unit/rbtree ...
*/
#include "../../../lib/os/winstream.c"
#include "../../../lib/utils/winstream.c"

#define BUFLEN 64

Expand Down

0 comments on commit 0b999c0

Please sign in to comment.