blob: 76c0d6f9da46d866a243dae411af6129d374ed3a [file] [log] [blame]
Tomáš Pecka5123e002020-06-05 15:29:21 +02001project(velia LANGUAGES CXX)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +02002cmake_minimum_required(VERSION 3.19)
3cmake_policy(SET CMP0109 NEW)
Tomáš Pecka5123e002020-06-05 15:29:21 +02004
5# Build options
Václav Kubernátb332d982021-04-16 01:40:11 +02006set(CMAKE_CXX_STANDARD 20)
Tomáš Pecka5123e002020-06-05 15:29:21 +02007set(CMAKE_CXX_STANDARD_REQUIRED ON)
8
9set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
Václav Kubernátd4b8a692021-04-16 01:21:44 +020010set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough ${CMAKE_CXX_FLAGS}")
Tomáš Pecka5123e002020-06-05 15:29:21 +020011if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
12 set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
13endif()
14
Tomáš Pecka5d4cf2a2020-07-13 13:19:41 +020015if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
16 set(STD_FILESYSTEM_LIBRARY c++fs)
17elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
18 set(STD_FILESYSTEM_LIBRARY stdc++fs)
19endif()
20
21
Tomáš Pecka5123e002020-06-05 15:29:21 +020022add_custom_target(velia-version-cmake-ide
23 cmake/ProjectGitVersion.cmake
24 cmake/ProjectGitVersionRunner.cmake
25 )
26include(cmake/ProjectGitVersion.cmake)
27prepare_git_version(VELIA_VERSION "0.0")
28
29find_package(Doxygen)
30option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
31
Václav Kubernátde0e4e62021-02-08 17:46:14 +010032find_package(Boost REQUIRED)
Tomáš Peckaa193c032020-06-22 17:33:31 +020033find_package(docopt REQUIRED)
Tomáš Pecka5123e002020-06-05 15:29:21 +020034find_package(spdlog REQUIRED)
Tomáš Pecka0a2e8902020-06-09 21:11:20 +020035find_package(sdbus-c++ REQUIRED)
Tomáš Peckaa4336812020-07-24 15:32:58 +020036find_package(PkgConfig)
Václav Kubernátbabbab92021-01-27 09:25:05 +010037find_package(fmt)
Tomáš Peckaa4336812020-07-24 15:32:58 +020038
39pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET libsystemd)
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020040if(${SYSTEMD_VERSION} VERSION_EQUAL 245)
41 message(FATAL_ERROR "Systemd 245 has a bug affecting DBus method calls using sdbus-c++. Please see https://github.com/Kistler-Group/sdbus-cpp/issues/106.")
42endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +020043
Jan Kundrát5681a502021-10-01 01:38:22 +020044pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.148 IMPORTED_TARGET sysrepo)
45pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.248 IMPORTED_TARGET libyang)
Tomáš Pecka2d578c82021-02-23 19:01:35 +010046pkg_check_modules(LIBNL REQUIRED IMPORTED_TARGET libnl-route-3.0)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010047
Tomáš Pecka7acf3922021-08-10 11:16:57 +020048find_path(SD_LLDP_H systemd/sd-lldp.h PATHS ${SYSTEMD_INCLUDEDIR} NO_DEFAULT_PATH)
49if(NOT SD_LLDP_H)
50 message(FATAL_ERROR "Cannot find required header <systemd/sd-lldp.h>, use https://github.com/systemd/systemd/pull/16744")
51endif()
52
Tomáš Peckac927d662020-07-13 11:16:16 +020053include(GNUInstallDirs)
54
Tomáš Pecka261c8862020-11-05 11:23:08 +010055include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
56
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010057set(YANG_SRCS
Tomáš Pecka9a02c3f2021-01-21 15:27:22 +010058 yang/czechlight-system@2021-01-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010059 yang/iana-hardware@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010060 yang/ietf-hardware@2018-03-13.yang
Tomáš Peckaf98ce032021-01-14 13:35:00 +010061 yang/iana-crypt-hash@2014-08-06.yang
62 yang/ietf-inet-types@2013-07-15.yang
63 yang/ietf-netconf-acm@2018-02-14.yang
64 yang/ietf-system@2014-08-06.yang
65 yang/ietf-yang-types@2013-07-15.yang
Tomáš Pecka435ca2a2021-01-27 10:53:48 +010066 yang/ietf-ethertypes@2019-03-04.yang
67 yang/ietf-interfaces@2018-02-20.yang
68 yang/ietf-packet-fields@2019-03-04.yang
Václav Kubernát637fe802021-01-22 02:43:18 +010069 yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernát457d1ad2021-01-22 02:43:18 +010070 yang/czechlight-firewall@2021-01-25.yang
Tomáš Peckadac27d42021-02-22 13:20:05 +010071 yang/czechlight-network@2021-02-22.yang
72 yang/iana-if-type@2017-01-19.yang
73 yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +020074 yang/ietf-routing@2018-03-13.yang
75 yang/ietf-ipv4-unicast-routing@2018-03-13.yang
76 yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Pecka7acf3922021-08-10 11:16:57 +020077 yang/czechlight-lldp@2020-11-04.yang
78 yang/iana-afn-safi@2013-07-04.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010079 )
80
Tomáš Pecka5123e002020-06-05 15:29:21 +020081# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010082# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020083add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020084 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010085 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010086 src/utils/exec.cpp
87 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010088 src/utils/io.cpp
89 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020090 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010091 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010092 src/utils/libyang.cpp
93 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +010094 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +010095 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010096 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020097 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010098 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +010099 src/utils/sysrepo.cpp
100 src/utils/sysrepo.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100101 src/utils/time.cpp
102 src/utils/time.h
Tomáš Peckad0337072021-01-25 19:57:00 +0100103 src/utils/waitUntilSignalled.cpp
104 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +0200105 )
Václav Kubernát6018f082021-02-11 01:32:18 +0100106target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +0200107
Tomáš Pecka261c8862020-11-05 11:23:08 +0100108# - health
109add_library(velia-health STATIC
110 src/health/inputs/AbstractInput.cpp
111 src/health/inputs/DbusSemaphoreInput.cpp
112 src/health/inputs/DbusSystemdInput.cpp
113 src/health/manager/AbstractManager.cpp
114 src/health/manager/StateManager.cpp
115 src/health/outputs/LedSysfsDriver.cpp
116 src/health/outputs/callables.cpp
117 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200118 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100119target_link_libraries(velia-health
120 PUBLIC
121 velia-utils
122 Boost::boost
123 SDBusCpp::sdbus-c++
124 ${STD_FILESYSTEM_LIBRARY}
125 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200126
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100127# - ietf-hardware
128add_library(velia-ietf-hardware STATIC
129 src/ietf-hardware/sysfs/EMMC.cpp
130 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100131 src/ietf-hardware/sysfs/HWMon.cpp
132 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100133 src/ietf-hardware/IETFHardware.cpp
134 src/ietf-hardware/IETFHardware.h
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100135 src/ietf-hardware/FspYhPsu.cpp
136 src/ietf-hardware/FspYhPsu.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100137 )
138target_link_libraries(velia-ietf-hardware
139 PUBLIC
140 velia-utils
141 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100142 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100143 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100144
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100145add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100146 src/ietf-hardware/sysrepo/Sysrepo.cpp
147 src/ietf-hardware/sysrepo/Sysrepo.h
148 )
149target_link_libraries(velia-ietf-hardware-sysrepo
150 PUBLIC
151 velia-utils
152 PkgConfig::SYSREPO
153 PkgConfig::LIBYANG
154 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200155
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100156set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
157set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
158
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100159if(NOT NFT_EXECUTABLE)
160 find_program(NFT_EXECUTABLE nft)
161endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100162if(NOT SSH_KEYGEN_EXECUTABLE)
163 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
164endif()
165if(NOT CHPASSWD_EXECUTABLE)
166 find_program(CHPASSWD_EXECUTABLE chpasswd)
167endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100168if(NOT SYSTEMCTL_EXECUTABLE)
169 find_program(SYSTEMCTL_EXECUTABLE systemctl)
170endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100171if(NOT NETWORKCTL_EXECUTABLE)
172 find_program(NETWORKCTL_EXECUTABLE networkctl)
173endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100174if(NOT HOSTNAMECTL_EXECUTABLE)
175 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
176endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100177
178set(VELIA_AUTHORIZED_KEYS_FORMAT "{HOME}/.ssh/authorized_keys" CACHE STRING "pattern for determining path to users' SSH authorized_keys file. Must at least one of '{USER}' or '{HOME}' which will get replaced by the name of the user and the home directory of the user respectively.")
179if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
180 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
181endif()
182
183if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
184 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
185endif()
186
187set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
188if(NOT VELIA_REAL_ETC_PASSWD)
189 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
190endif()
191
192set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
193if(NOT VELIA_REAL_ETC_SHADOW)
194 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
195endif()
196
197set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
198if(NOT VELIA_BACKUP_ETC_SHADOW)
199 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
200endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100201
Václav Kubernát566c9402021-02-10 08:33:54 +0100202set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
203if(NOT VELIA_BACKUP_ETC_HOSTNAME )
204 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
205endif()
206
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100207configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
208include_directories(${CMAKE_CURRENT_BINARY_DIR})
209
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100210# - ietf-system
211add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100212 src/system/RAUC.cpp
213 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100214 src/system/Firmware.cpp
215 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100216 src/system/IETFSystem.cpp
217 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100218 src/system/Authentication.cpp
219 src/system/Authentication.h
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100220 src/system/Rtnetlink.cpp
221 src/system/Rtnetlink.h
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100222 src/system/IETFInterfaces.cpp
223 src/system/IETFInterfaces.h
Tomáš Pecka39bbb512021-05-23 22:07:22 +0200224 src/system/IETFInterfacesConfig.cpp
225 src/system/IETFInterfacesConfig.h
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200226 src/system/LED.cpp
227 src/system/LED.h
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200228 src/system/LLDP.cpp
229 src/system/LLDP.h
230 src/system/LLDPCallback.cpp
231 src/system/LLDPCallback.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100232 )
233target_link_libraries(velia-system
234 PUBLIC
235 velia-utils
236 PkgConfig::SYSREPO
237 PkgConfig::LIBYANG
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100238 PkgConfig::LIBNL
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100239 SDBusCpp::sdbus-c++
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100240 )
241
Václav Kubernátd386aba2021-01-19 10:03:28 +0100242# - firewall
243add_library(velia-firewall STATIC
244 src/firewall/Firewall.cpp
245 )
246target_link_libraries(velia-firewall
247 PUBLIC
248 velia-utils
249 PkgConfig::SYSREPO
250 PRIVATE
251 PkgConfig::LIBYANG
252 )
253
254
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100255# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100256add_executable(veliad-health
257 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100258 src/health/Factory.cpp
259 src/health/Factory.h
260 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100261target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100262 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100263 velia-health
Tomáš Peckad03044f2020-11-12 14:33:10 +0100264 docopt
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100265 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100266add_dependencies(veliad-health target-VELIA_VERSION)
267target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100268
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100269add_executable(veliad-system
270 src/main-system.cpp
271 )
272target_link_libraries(veliad-system
273 PUBLIC
274 velia-system
275 docopt
276 )
277add_dependencies(veliad-system target-VELIA_VERSION)
278target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
279
Václav Kubernátd386aba2021-01-19 10:03:28 +0100280add_executable(veliad-firewall
281 src/main-firewall.cpp
282 )
283target_link_libraries(veliad-firewall
284 PUBLIC
285 velia-firewall
286 velia-utils
Václav Kubernátd386aba2021-01-19 10:03:28 +0100287 docopt
288 )
289add_dependencies(veliad-firewall target-VELIA_VERSION)
290target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
291
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100292add_executable(veliad-hardware
293 src/main-hardware.cpp
294 src/ietf-hardware/Factory.cpp
295 src/ietf-hardware/Factory.h
296 )
297target_link_libraries(veliad-hardware
298 PUBLIC
299 velia-ietf-hardware
300 velia-ietf-hardware-sysrepo
301 docopt
302 )
303add_dependencies(veliad-hardware target-VELIA_VERSION)
304target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
305
Tomáš Pecka5123e002020-06-05 15:29:21 +0200306# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200307include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200308if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200309 find_package(trompeloeil 33 REQUIRED)
310 find_package(doctest 2.3.1 REQUIRED)
311
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200312 option(TEST_NETWORK_WITH_SUDO "Include ietf-routing and ietf-interfaces tests that require root privileges" "OFF")
313
Tomáš Peckaefd88432020-06-17 15:31:39 +0200314 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
315
Tomáš Pecka5123e002020-06-05 15:29:21 +0200316 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100317 tests/doctest_integration.cpp
318 tests/trompeloeil_doctest.h
319 tests/wait-a-bit-longer.cpp
320 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200321 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100322 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200323 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
324
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100325 add_library(SysrepoTesting STATIC
326 tests/mock/sysrepo/events.cpp
327 tests/mock/sysrepo/events.h
328 )
329 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
330
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200331 add_library(DbusTesting STATIC
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200332 tests/dbus-helpers/dbus_network1_server.cpp
333 tests/dbus-helpers/dbus_network1_server.h
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100334 tests/dbus-helpers/dbus_rauc_server.cpp
335 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka79344c82021-09-16 18:25:59 +0200336 tests/dbus-helpers/dbus_resolve1_server.cpp
337 tests/dbus-helpers/dbus_resolve1_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200338 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100339 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200340 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100341 tests/dbus-helpers/dbus_systemd_server.h
342 )
343 target_link_libraries(DbusTesting
344 PUBLIC
345 velia-utils
346 SDBusCpp::sdbus-c++
347 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200348
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100349 add_library(FsTestUtils STATIC
350 tests/fs-helpers/FileInjector.cpp
351 tests/fs-helpers/FileInjector.h
352 tests/fs-helpers/utils.cpp
353 tests/fs-helpers/utils.h
354 )
355 target_link_libraries(FsTestUtils
356 PUBLIC
357 ${STD_FILESYSTEM_LIBRARY}
358 )
359
Tomáš Pecka5123e002020-06-05 15:29:21 +0200360 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100361 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
362 target_link_libraries(test-${name} DoctestIntegration ${ARGN})
363 target_include_directories(test-${name}
364 PUBLIC
365 ${CMAKE_CURRENT_SOURCE_DIR}
366 PRIVATE
367 ${CMAKE_BINARY_DIR}
368 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200369
370 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100371 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200372 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200373 endfunction()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200374
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100375 find_program(SYSREPOCTL sysrepoctl)
376 find_program(SYSREPOCFG sysrepocfg)
377
378 set(sysrepo_previous_fixture_name UNDEFINED)
379 function(sysrepo_fixture_env name)
380 set(test_name_init sysrepo:prep:${name})
381 set(test_name_cleanup sysrepo:clean:${name})
382 set(fixture_name sysrepo:env:${name})
383
384 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${ARGN})
385 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name} RESOURCE_LOCK sysrepo)
386 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${ARGN})
387 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name} RESOURCE_LOCK sysrepo)
388
389 if (sysrepo_previous_fixture_name)
390 set_tests_properties(${test_name_init} PROPERTIES DEPENDS sysrepo:clean:${sysrepo_previous_fixture_name})
391 endif ()
392
393 set(sysrepo_previous_fixture_name ${name} PARENT_SCOPE)
394 endfunction()
395
Tomáš Pecka261c8862020-11-05 11:23:08 +0100396 velia_test(health_state-manager velia-health)
397 velia_test(health_input-semaphore velia-health DbusTesting)
398 velia_test(health_input-systemd velia-health DbusTesting)
399 velia_test(health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100400
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100401 velia_test(system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100402 set_tests_properties(
403 test-system_rauc
404 PROPERTIES RESOURCE_LOCK dbus-rauc
405 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100406
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200407 velia_test(system_lldp velia-system DbusTesting)
408
409 sysrepo_fixture_env(sysrepo-czechlight-lldp YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-lldp@2020-11-04.yang)
410 velia_test(sysrepo_system-lldp velia-system DbusTesting)
411 target_link_libraries(test-sysrepo_system-lldp)
412 set_tests_properties(
413 test-sysrepo_system-lldp
414 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-lldp
415 RESOURCE_LOCK sysrepo
416 )
417
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100418 velia_test(hardware_emmc velia-ietf-hardware FsTestUtils)
419 velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100420
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100421 sysrepo_fixture_env(sysrepo-ietf-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-system@2014-08-06.yang)
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100422 velia_test(sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100423 set_tests_properties(
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100424 test-sysrepo_system-ietfsystem
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100425 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-system
426 RESOURCE_LOCK sysrepo
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100427)
428
429 sysrepo_fixture_env(sysrepo-czechlight-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-system@2021-01-13.yang)
Tomáš Pecka594a6762021-01-29 11:06:08 +0100430 velia_test(sysrepo_system-firmware velia-system DbusTesting)
431 target_link_libraries(test-sysrepo_system-firmware SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100432 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100433 test-sysrepo_system-firmware
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100434 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
435 RESOURCE_LOCK "sysrepo;dbus-rauc"
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100436 )
437
Václav Kubernátbabbab92021-01-27 09:25:05 +0100438 velia_test(sysrepo_authentication velia-system FsTestUtils)
439
440 set_tests_properties(
441 test-sysrepo_authentication
442 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
443 RESOURCE_LOCK sysrepo
444 )
445
Tomáš Pecka5be83e42021-04-21 17:26:40 +0200446 velia_test(sysrepo_system-leds velia-system FsTestUtils)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200447 set_tests_properties(
448 test-sysrepo_system-leds
449 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
450 RESOURCE_LOCK sysrepo
451 )
452
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100453 sysrepo_fixture_env(sysrepo-czechlight-network
454 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
455 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
456 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +0200457 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
458 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
459 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100460 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200461
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100462 velia_test(sysrepo_system-ietfinterfaces velia-system)
463 set_tests_properties(
464 test-sysrepo_system-ietfinterfaces
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200465 PROPERTIES FIXTURES_REQUIRED "sysrepo:env:sysrepo-czechlight-network"
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100466 RESOURCE_LOCK sysrepo
467 )
468
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200469 if(TEST_NETWORK_WITH_SUDO)
470 find_program(SUDO_EXECUTABLE sudo REQUIRED)
471 find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
472 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
473
474 add_test(NAME network-czechlight0-prepare COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
475 add_test(NAME network-czechlight0-cleanup COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
476 set_tests_properties(network-czechlight0-prepare PROPERTIES FIXTURES_SETUP network-czechlight0)
477 set_tests_properties(network-czechlight0-cleanup PROPERTIES FIXTURES_CLEANUP network-czechlight0)
478
479 velia_test(sysrepo_system-ietfinterfaces-sudo velia-system)
480 set_tests_properties(
481 test-sysrepo_system-ietfinterfaces-sudo
482 PROPERTIES FIXTURES_REQUIRED "sysrepo:env:sysrepo-czechlight-network;network-czechlight0"
483 RESOURCE_LOCK sysrepo
484 )
485 endif()
486
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100487 sysrepo_fixture_env(sysrepo-ietf-hardware YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-hardware@2018-03-13.yang YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-hardware@2018-03-13.yang FEATURE hardware-sensor)
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100488 velia_test(hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100489 set_tests_properties(
490 test-hardware_ietf-hardware
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100491 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-hardware
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100492 RESOURCE_LOCK sysrepo
493 )
494
495 velia_test(sysrepo_two-daemons velia-ietf-hardware-sysrepo)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100496 # ctest dance for sysrepo_two-daemons: compile daemon, create a fixture for test, add the test into the fixture
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100497 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
498 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
499
500 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
501 add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop)
502 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
503 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100504
505 set_tests_properties(
506 test-sysrepo_two-daemons
507 PROPERTIES
508 FIXTURES_REQUIRED "sysrepo:two-daemons;sysrepo:env:sysrepo-ietf-hardware"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100509 RESOURCE_LOCK sysrepo
510 )
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100511 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
512 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware)
513 set_tests_properties(sysrepo:clean:sysrepo-ietf-hardware PROPERTIES DEPENDS sysrepo_test_merge-stop)
514
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100515
516 find_program(YANGLINT_PATH yanglint)
517 if (NOT YANGLINT_PATH)
518 message(FATAL_ERROR "Cannot find libyang's yanglint")
519 endif()
520 foreach(yang_file ${YANG_SRCS})
521 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
522 endforeach()
Václav Kubernátd386aba2021-01-19 10:03:28 +0100523
524 sysrepo_fixture_env(sysrepo-firewall
525 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
526 # imported) but I still need to install it myself to enable the features.
527 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
528 FEATURE eth
529 FEATURE match-on-eth
530 FEATURE match-on-ipv4
531 FEATURE ipv4
532 FEATURE match-on-ipv6
533 FEATURE ipv6
534 FEATURE mixed-eth-ipv4-ipv6
535 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
536 )
537
538 velia_test(sysrepo-firewall velia-firewall)
539 set_tests_properties(
540 test-sysrepo-firewall
541 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-firewall
542 RESOURCE_LOCK sysrepo
543 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100544endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200545
Tomáš Pecka5123e002020-06-05 15:29:21 +0200546if(WITH_DOCS)
547 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
548 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
549 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
550 add_custom_target(doc
551 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
552 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
553 COMMENT "Generating API documentation with Doxygen"
554 VERBATIM
555 SOURCES ${doxyfile_in}
556 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200557endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100558
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100559set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
560install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckaeb317722021-04-13 21:33:20 +0200561install(FILES ${CMAKE_SOURCE_DIR}/yang/ietf-ipv6-router-advertisements@2018-03-13.yang DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100562install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100563install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100564install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100565install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)