Skip to content

Commit 62957ec

Browse files
Gregory Shuecarlescufi
authored andcommitted
lib: add custom_lib
Enhance the example-application repository with a configurable, trivial library example and associated test cases. . This implementation appears to make no assumptions. . This implementation was verified by running the following commands in an example-application workspace and verifying all tests passed. 1. `west build -b native_posix -p always example-application/tests/lib/custom_lib/` 2. `./build/zephyr/zephyr.exe` 3. `west build -b native_posix -p always example-application/tests/lib/custom_lib/ -- -DCONFIG_CUSTOM_LIB_GET_VALUE_DEFAULT=6` 4. `./build/zephyr/zephyr.exe` 5. `zephyr/scripts/twister -T example-application/tests/ \ -p qemu_cortex_m0` 6. `cd zephyr/doc && make clean && make` built cleanly. . Note that `twister` does not follow the `zephyr/module.yml:tests` setting to discover tests in modules, so the testcase-root must be explicitly provided. Fixes #35177 Signed-off-by: Gregory Shue <[email protected]>
1 parent 5a66095 commit 62957ec

File tree

12 files changed

+136
-4
lines changed

12 files changed

+136
-4
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ jobs:
2727
run: |
2828
west build -b custom_plank app
2929
30+
- name: Twister Unit Tests
31+
working-directory: example-application
32+
run: |
33+
../zephyr/scripts/twister -p qemu_cortex_m0 --testcase-root ./tests/
34+
3035
- name: Archive firmware
3136
uses: actions/upload-artifact@v2
3237
with:

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
# This CMake file is picked by the Zephyr build system because it is defined
55
# as the module CMake entry point (see zephyr/module.yml).
66

7+
zephyr_include_directories(include)
8+
79
add_subdirectory(drivers)
810
add_subdirectory(lib)

include/custom_lib/custom_lib.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2021, Legrand North America, LLC.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef EXAMPLE_APPLICATION_INCLUDE_CUSTOM_LIB_CUSTOM_LIB_H_
8+
#define EXAMPLE_APPLICATION_INCLUDE_CUSTOM_LIB_CUSTOM_LIB_H_
9+
10+
/**
11+
* @brief Return parameter if non-zero, or Kconfig-controlled default
12+
*
13+
* Function returns the provided value if non-zero, or a Kconfig-controlled
14+
* default value if the parameter is zero. This trivial function is
15+
* provided in order to have a library interface example that is trivial
16+
* to test.
17+
*
18+
* @param return_value_if_nonzero Value to return if non-zero
19+
* @returns return_value_if_nonzero when the parameter is non-zero
20+
* @returns CONFIG_CUSTOM_LIB_GET_VALUE_DEFAULT if parameter is zero
21+
*/
22+
int custom_lib_get_value(int return_value_if_nonzero);
23+
24+
#endif /* EXAMPLE_APPLICATION_INCLUDE_CUSTOM_LIB_CUSTOM_LIB_H_ */

lib/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
# The visibility and compilation of libraries may be controlled
4-
# with a Kconfig setting as follows:
5-
#
6-
# add_subdirectory_ifdef(CONFIG_CUSTOM_LIB custom_lib)
3+
add_subdirectory_ifdef(CONFIG_CUSTOM_LIB custom_lib)

lib/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
menu "Libraries"
55

6+
rsource "custom_lib/Kconfig"
7+
68
endmenu

lib/custom_lib/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2021, Legrand North America, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_library()
5+
zephyr_library_sources(custom_lib.c)

lib/custom_lib/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2021, Legrand North America, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config CUSTOM_LIB
5+
bool "custom_lib Support"
6+
help
7+
This option enables the custom_lib library
8+
9+
config CUSTOM_LIB_GET_VALUE_DEFAULT
10+
int "custom_lib_get_value() default return value"
11+
depends on CUSTOM_LIB
12+
default 0
13+
help
14+
This option primarily exists as an example of a library Kconfig
15+
setting.
16+
17+
This option specifies the value for custom_lib_get_value()
18+
to return when the input parameter is zero. (Otherwise
19+
the function returns the input parameter value.)

lib/custom_lib/custom_lib.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2021, Legrand North America, LLC.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <custom_lib/custom_lib.h>
8+
9+
int custom_lib_get_value(int return_value_if_nonzero)
10+
{
11+
return (return_value_if_nonzero != 0) ? return_value_if_nonzero
12+
: CONFIG_CUSTOM_LIB_GET_VALUE_DEFAULT;
13+
}

tests/lib/custom_lib/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2021, Legrand North America, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.13.1)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(custom_lib)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})

tests/lib/custom_lib/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_CUSTOM_LIB=y

0 commit comments

Comments
 (0)