blob: 4b5b6ca6cceb3837260aeae9082c8c705da69abe [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áš Pecka070f60d2021-10-13 21:48:14 +020043#TODO: Check patch 20333 active
Tomáš Pecka5123e002020-06-05 15:29:21 +020044
Jan Kundrát5681a502021-10-01 01:38:22 +020045pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.148 IMPORTED_TARGET sysrepo)
46pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.248 IMPORTED_TARGET libyang)
Tomáš Pecka2d578c82021-02-23 19:01:35 +010047pkg_check_modules(LIBNL REQUIRED IMPORTED_TARGET libnl-route-3.0)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010048
Tomáš Peckac927d662020-07-13 11:16:16 +020049include(GNUInstallDirs)
50
Tomáš Pecka261c8862020-11-05 11:23:08 +010051include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
52
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010053set(YANG_SRCS
Tomáš Pecka9a02c3f2021-01-21 15:27:22 +010054 yang/czechlight-system@2021-01-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010055 yang/iana-hardware@2018-03-13.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010056 yang/ietf-hardware@2018-03-13.yang
Tomáš Peckaf98ce032021-01-14 13:35:00 +010057 yang/iana-crypt-hash@2014-08-06.yang
58 yang/ietf-inet-types@2013-07-15.yang
59 yang/ietf-netconf-acm@2018-02-14.yang
60 yang/ietf-system@2014-08-06.yang
61 yang/ietf-yang-types@2013-07-15.yang
Tomáš Pecka435ca2a2021-01-27 10:53:48 +010062 yang/ietf-ethertypes@2019-03-04.yang
63 yang/ietf-interfaces@2018-02-20.yang
64 yang/ietf-packet-fields@2019-03-04.yang
Václav Kubernát637fe802021-01-22 02:43:18 +010065 yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernát457d1ad2021-01-22 02:43:18 +010066 yang/czechlight-firewall@2021-01-25.yang
Tomáš Peckadac27d42021-02-22 13:20:05 +010067 yang/czechlight-network@2021-02-22.yang
68 yang/iana-if-type@2017-01-19.yang
69 yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +020070 yang/ietf-routing@2018-03-13.yang
71 yang/ietf-ipv4-unicast-routing@2018-03-13.yang
72 yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Pecka7acf3922021-08-10 11:16:57 +020073 yang/czechlight-lldp@2020-11-04.yang
74 yang/iana-afn-safi@2013-07-04.yang
Tomáš Pecka73a13cc2020-11-17 11:12:19 +010075 )
76
Tomáš Pecka5123e002020-06-05 15:29:21 +020077# Targets
Tomáš Pecka261c8862020-11-05 11:23:08 +010078# - utils
Tomáš Peckabd828862020-06-15 15:53:35 +020079add_library(velia-utils STATIC
Tomáš Peckaa193c032020-06-22 17:33:31 +020080 src/utils/exceptions.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010081 src/utils/exceptions.h
Václav Kubernát6d9357e2021-01-28 15:38:24 +010082 src/utils/exec.cpp
83 src/utils/exec.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +010084 src/utils/io.cpp
85 src/utils/io.h
Tomáš Peckaa4336812020-07-24 15:32:58 +020086 src/utils/journal.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010087 src/utils/journal.h
Václav Kubernátcbdc98a2021-01-28 13:24:37 +010088 src/utils/libyang.cpp
89 src/utils/libyang.h
Tomáš Pecka261c8862020-11-05 11:23:08 +010090 src/utils/log.h
Václav Kubernát6018f082021-02-11 01:32:18 +010091 src/utils/log.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010092 src/utils/log-fwd.h
Tomáš Pecka5123e002020-06-05 15:29:21 +020093 src/utils/log-init.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +010094 src/utils/log-init.h
Tomáš Peckaba2dc312021-01-23 22:29:11 +010095 src/utils/sysrepo.cpp
96 src/utils/sysrepo.h
Tomáš Pecka339bc672020-11-11 15:59:03 +010097 src/utils/time.cpp
98 src/utils/time.h
Tomáš Peckad0337072021-01-25 19:57:00 +010099 src/utils/waitUntilSignalled.cpp
100 src/utils/waitUntilSignalled.h
Tomáš Pecka5123e002020-06-05 15:29:21 +0200101 )
Václav Kubernát6018f082021-02-11 01:32:18 +0100102target_link_libraries(velia-utils PUBLIC spdlog::spdlog PRIVATE PkgConfig::SYSTEMD PkgConfig::SYSREPO fmt::fmt docopt)
Tomáš Peckaa4336812020-07-24 15:32:58 +0200103
Tomáš Pecka261c8862020-11-05 11:23:08 +0100104# - health
105add_library(velia-health STATIC
106 src/health/inputs/AbstractInput.cpp
107 src/health/inputs/DbusSemaphoreInput.cpp
108 src/health/inputs/DbusSystemdInput.cpp
109 src/health/manager/AbstractManager.cpp
110 src/health/manager/StateManager.cpp
111 src/health/outputs/LedSysfsDriver.cpp
112 src/health/outputs/callables.cpp
113 src/health/State.cpp
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200114 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100115target_link_libraries(velia-health
116 PUBLIC
117 velia-utils
118 Boost::boost
119 SDBusCpp::sdbus-c++
120 ${STD_FILESYSTEM_LIBRARY}
121 )
Tomáš Pecka74b885f2020-06-06 20:02:41 +0200122
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100123# - ietf-hardware
124add_library(velia-ietf-hardware STATIC
125 src/ietf-hardware/sysfs/EMMC.cpp
126 src/ietf-hardware/sysfs/EMMC.h
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100127 src/ietf-hardware/sysfs/HWMon.cpp
128 src/ietf-hardware/sysfs/HWMon.h
Tomáš Pecka339bc672020-11-11 15:59:03 +0100129 src/ietf-hardware/IETFHardware.cpp
130 src/ietf-hardware/IETFHardware.h
Václav Kubernát97e5ea12021-03-24 00:36:57 +0100131 src/ietf-hardware/FspYhPsu.cpp
132 src/ietf-hardware/FspYhPsu.h
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100133 )
134target_link_libraries(velia-ietf-hardware
135 PUBLIC
136 velia-utils
137 ${STD_FILESYSTEM_LIBRARY}
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100138 Boost::boost
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100139 )
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100140
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100141add_library(velia-ietf-hardware-sysrepo STATIC
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100142 src/ietf-hardware/sysrepo/Sysrepo.cpp
143 src/ietf-hardware/sysrepo/Sysrepo.h
144 )
145target_link_libraries(velia-ietf-hardware-sysrepo
146 PUBLIC
147 velia-utils
148 PkgConfig::SYSREPO
149 PkgConfig::LIBYANG
150 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200151
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100152set(NOBODY_UID 65534 CACHE STRING "UID which refers to 'nobody'. Used for dropping root privileges.")
153set(NOBODY_GID 65534 CACHE STRING "GID which refers to 'nobody'. Used for dropping root privileges.")
154
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100155if(NOT NFT_EXECUTABLE)
156 find_program(NFT_EXECUTABLE nft)
157endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100158if(NOT SSH_KEYGEN_EXECUTABLE)
159 find_program(SSH_KEYGEN_EXECUTABLE ssh-keygen)
160endif()
161if(NOT CHPASSWD_EXECUTABLE)
162 find_program(CHPASSWD_EXECUTABLE chpasswd)
163endif()
Tomáš Pecka879a6032021-02-03 17:21:48 +0100164if(NOT SYSTEMCTL_EXECUTABLE)
165 find_program(SYSTEMCTL_EXECUTABLE systemctl)
166endif()
Tomáš Pecka5c19e722021-02-15 20:41:29 +0100167if(NOT NETWORKCTL_EXECUTABLE)
168 find_program(NETWORKCTL_EXECUTABLE networkctl)
169endif()
Václav Kubernát566c9402021-02-10 08:33:54 +0100170if(NOT HOSTNAMECTL_EXECUTABLE)
171 find_program(HOSTNAMECTL_EXECUTABLE hostnamectl)
172endif()
Václav Kubernátbabbab92021-01-27 09:25:05 +0100173
174set(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.")
175if(NOT VELIA_AUTHORIZED_KEYS_FORMAT)
176 message(FATAL_ERROR "VELIA_AUTHORIZED_KEYS_FORMAT not set.")
177endif()
178
179if(NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{USER}" AND NOT VELIA_AUTHORIZED_KEYS_FORMAT MATCHES "{HOME}")
180 message(FATAL_ERROR "Wrong format string given for VELIA_AUTHORIZED_KEYS_FORMAT: at least one of {USER} or {HOME} expected.")
181endif()
182
183set(VELIA_REAL_ETC_PASSWD "/etc/passwd" CACHE STRING "Path to passwd file")
184if(NOT VELIA_REAL_ETC_PASSWD)
185 message(FATAL_ERROR "VELIA_REAL_ETC_PASSWD not set")
186endif()
187
188set(VELIA_REAL_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to shadow file")
189if(NOT VELIA_REAL_ETC_SHADOW)
190 message(FATAL_ERROR "VELIA_REAL_ETC_SHADOW not set")
191endif()
192
193set(VELIA_BACKUP_ETC_SHADOW "/etc/shadow" CACHE STRING "Path to where /etc/shadow gets copied to upon each change")
194if(NOT VELIA_BACKUP_ETC_SHADOW)
195 message(FATAL_ERROR "VELIA_BACKUP_ETC_SHADOW not set")
196endif()
Václav Kubernátde0e4e62021-02-08 17:46:14 +0100197
Václav Kubernát566c9402021-02-10 08:33:54 +0100198set(VELIA_BACKUP_ETC_HOSTNAME "/etc/hostname" CACHE STRING "Path to hostname file")
199if(NOT VELIA_BACKUP_ETC_HOSTNAME )
200 message(FATAL_ERROR "VELIA_BACKUP_ETC_HOSTNAME not set")
201endif()
202
Václav Kubernát6d9357e2021-01-28 15:38:24 +0100203configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/system/system_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/system_vars.h @ONLY)
204include_directories(${CMAKE_CURRENT_BINARY_DIR})
205
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100206# - ietf-system
207add_library(velia-system STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100208 src/system/RAUC.cpp
209 src/system/RAUC.h
Tomáš Pecka594a6762021-01-29 11:06:08 +0100210 src/system/Firmware.cpp
211 src/system/Firmware.h
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100212 src/system/IETFSystem.cpp
213 src/system/IETFSystem.h
Václav Kubernátbabbab92021-01-27 09:25:05 +0100214 src/system/Authentication.cpp
215 src/system/Authentication.h
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100216 src/system/Rtnetlink.cpp
217 src/system/Rtnetlink.h
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100218 src/system/IETFInterfaces.cpp
219 src/system/IETFInterfaces.h
Tomáš Pecka39bbb512021-05-23 22:07:22 +0200220 src/system/IETFInterfacesConfig.cpp
221 src/system/IETFInterfacesConfig.h
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200222 src/system/LED.cpp
223 src/system/LED.h
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200224 src/system/LLDP.cpp
225 src/system/LLDP.h
226 src/system/LLDPCallback.cpp
227 src/system/LLDPCallback.h
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100228 )
229target_link_libraries(velia-system
230 PUBLIC
231 velia-utils
232 PkgConfig::SYSREPO
233 PkgConfig::LIBYANG
Tomáš Pecka2d578c82021-02-23 19:01:35 +0100234 PkgConfig::LIBNL
Václav Kubernát6dd52c82021-01-21 08:38:42 +0100235 SDBusCpp::sdbus-c++
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100236 )
237
Václav Kubernátd386aba2021-01-19 10:03:28 +0100238# - firewall
239add_library(velia-firewall STATIC
240 src/firewall/Firewall.cpp
241 )
242target_link_libraries(velia-firewall
243 PUBLIC
244 velia-utils
245 PkgConfig::SYSREPO
246 PRIVATE
247 PkgConfig::LIBYANG
248 )
249
250
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100251# - daemons
Tomáš Peckacd19e622021-01-27 09:18:11 +0100252add_executable(veliad-health
253 src/main-health.cpp
Tomáš Pecka139e3612021-01-25 19:49:00 +0100254 src/health/Factory.cpp
255 src/health/Factory.h
256 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100257target_link_libraries(veliad-health
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100258 PUBLIC
Tomáš Peckad03044f2020-11-12 14:33:10 +0100259 velia-health
Tomáš Peckad03044f2020-11-12 14:33:10 +0100260 docopt
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100261 )
Tomáš Peckacd19e622021-01-27 09:18:11 +0100262add_dependencies(veliad-health target-VELIA_VERSION)
263target_include_directories(veliad-health PUBLIC ${CMAKE_BINARY_DIR})
Tomáš Peckad03044f2020-11-12 14:33:10 +0100264
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100265add_executable(veliad-system
266 src/main-system.cpp
267 )
268target_link_libraries(veliad-system
269 PUBLIC
270 velia-system
271 docopt
272 )
273add_dependencies(veliad-system target-VELIA_VERSION)
274target_include_directories(veliad-system PUBLIC ${CMAKE_BINARY_DIR})
275
Václav Kubernátd386aba2021-01-19 10:03:28 +0100276add_executable(veliad-firewall
277 src/main-firewall.cpp
278 )
279target_link_libraries(veliad-firewall
280 PUBLIC
281 velia-firewall
282 velia-utils
Václav Kubernátd386aba2021-01-19 10:03:28 +0100283 docopt
284 )
285add_dependencies(veliad-firewall target-VELIA_VERSION)
286target_include_directories(veliad-firewall PUBLIC ${CMAKE_BINARY_DIR})
287
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100288add_executable(veliad-hardware
289 src/main-hardware.cpp
290 src/ietf-hardware/Factory.cpp
291 src/ietf-hardware/Factory.h
292 )
293target_link_libraries(veliad-hardware
294 PUBLIC
295 velia-ietf-hardware
296 velia-ietf-hardware-sysrepo
297 docopt
298 )
299add_dependencies(veliad-hardware target-VELIA_VERSION)
300target_include_directories(veliad-hardware PUBLIC ${CMAKE_BINARY_DIR})
301
Tomáš Pecka5123e002020-06-05 15:29:21 +0200302# Testing
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200303include(CTest)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200304if(BUILD_TESTING)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200305 find_package(trompeloeil 33 REQUIRED)
306 find_package(doctest 2.3.1 REQUIRED)
307
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200308 option(TEST_NETWORK_WITH_SUDO "Include ietf-routing and ietf-interfaces tests that require root privileges" "OFF")
309
Tomáš Peckaefd88432020-06-17 15:31:39 +0200310 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/configure.cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/tests/configure.cmake.h)
311
Tomáš Pecka5123e002020-06-05 15:29:21 +0200312 add_library(DoctestIntegration STATIC
Tomáš Pecka261c8862020-11-05 11:23:08 +0100313 tests/doctest_integration.cpp
314 tests/trompeloeil_doctest.h
315 tests/wait-a-bit-longer.cpp
316 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200317 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100318 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/)
Tomáš Pecka5123e002020-06-05 15:29:21 +0200319 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
320
Tomáš Peckaa18702d2021-01-25 18:07:23 +0100321 add_library(SysrepoTesting STATIC
322 tests/mock/sysrepo/events.cpp
323 tests/mock/sysrepo/events.h
324 )
325 target_link_libraries(SysrepoTesting DoctestIntegration PkgConfig::SYSREPO)
326
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200327 add_library(DbusTesting STATIC
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100328 tests/dbus-helpers/dbus_rauc_server.cpp
329 tests/dbus-helpers/dbus_rauc_server.h
Tomáš Pecka79344c82021-09-16 18:25:59 +0200330 tests/dbus-helpers/dbus_resolve1_server.cpp
331 tests/dbus-helpers/dbus_resolve1_server.h
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200332 tests/dbus-helpers/dbus_semaphore_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100333 tests/dbus-helpers/dbus_semaphore_server.h
Tomáš Peckaccd80c32020-06-22 14:44:32 +0200334 tests/dbus-helpers/dbus_systemd_server.cpp
Tomáš Pecka261c8862020-11-05 11:23:08 +0100335 tests/dbus-helpers/dbus_systemd_server.h
336 )
337 target_link_libraries(DbusTesting
338 PUBLIC
339 velia-utils
340 SDBusCpp::sdbus-c++
341 )
Tomáš Pecka0a2e8902020-06-09 21:11:20 +0200342
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100343 add_library(FsTestUtils STATIC
344 tests/fs-helpers/FileInjector.cpp
345 tests/fs-helpers/FileInjector.h
346 tests/fs-helpers/utils.cpp
347 tests/fs-helpers/utils.h
348 )
349 target_link_libraries(FsTestUtils
350 PUBLIC
351 ${STD_FILESYSTEM_LIBRARY}
352 )
353
Tomáš Pecka5123e002020-06-05 15:29:21 +0200354 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100355 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
356 target_link_libraries(test-${name} DoctestIntegration ${ARGN})
357 target_include_directories(test-${name}
358 PUBLIC
359 ${CMAKE_CURRENT_SOURCE_DIR}
360 PRIVATE
361 ${CMAKE_BINARY_DIR}
362 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200363
364 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100365 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200366 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200367 endfunction()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200368
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100369 find_program(SYSREPOCTL sysrepoctl)
370 find_program(SYSREPOCFG sysrepocfg)
371
372 set(sysrepo_previous_fixture_name UNDEFINED)
373 function(sysrepo_fixture_env name)
374 set(test_name_init sysrepo:prep:${name})
375 set(test_name_cleanup sysrepo:clean:${name})
376 set(fixture_name sysrepo:env:${name})
377
378 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${ARGN})
379 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name} RESOURCE_LOCK sysrepo)
380 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${ARGN})
381 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name} RESOURCE_LOCK sysrepo)
382
383 if (sysrepo_previous_fixture_name)
384 set_tests_properties(${test_name_init} PROPERTIES DEPENDS sysrepo:clean:${sysrepo_previous_fixture_name})
385 endif ()
386
387 set(sysrepo_previous_fixture_name ${name} PARENT_SCOPE)
388 endfunction()
389
Tomáš Pecka261c8862020-11-05 11:23:08 +0100390 velia_test(health_state-manager velia-health)
391 velia_test(health_input-semaphore velia-health DbusTesting)
392 velia_test(health_input-systemd velia-health DbusTesting)
393 velia_test(health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100394
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100395 velia_test(system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100396 set_tests_properties(
397 test-system_rauc
398 PROPERTIES RESOURCE_LOCK dbus-rauc
399 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100400
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200401 velia_test(system_lldp velia-system DbusTesting)
402
403 sysrepo_fixture_env(sysrepo-czechlight-lldp YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-lldp@2020-11-04.yang)
404 velia_test(sysrepo_system-lldp velia-system DbusTesting)
405 target_link_libraries(test-sysrepo_system-lldp)
406 set_tests_properties(
407 test-sysrepo_system-lldp
408 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-lldp
409 RESOURCE_LOCK sysrepo
410 )
411
Tomáš Pecka9b1c9672020-11-11 15:24:06 +0100412 velia_test(hardware_emmc velia-ietf-hardware FsTestUtils)
413 velia_test(hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100414
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100415 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 +0100416 velia_test(sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100417 set_tests_properties(
Tomáš Peckaf976c5b2021-01-23 21:19:52 +0100418 test-sysrepo_system-ietfsystem
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100419 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-system
420 RESOURCE_LOCK sysrepo
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100421)
422
423 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 +0100424 velia_test(sysrepo_system-firmware velia-system DbusTesting)
425 target_link_libraries(test-sysrepo_system-firmware SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100426 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100427 test-sysrepo_system-firmware
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100428 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
429 RESOURCE_LOCK "sysrepo;dbus-rauc"
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100430 )
431
Václav Kubernátbabbab92021-01-27 09:25:05 +0100432 velia_test(sysrepo_authentication velia-system FsTestUtils)
433
434 set_tests_properties(
435 test-sysrepo_authentication
436 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
437 RESOURCE_LOCK sysrepo
438 )
439
Tomáš Pecka5be83e42021-04-21 17:26:40 +0200440 velia_test(sysrepo_system-leds velia-system FsTestUtils)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200441 set_tests_properties(
442 test-sysrepo_system-leds
443 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-czechlight-system
444 RESOURCE_LOCK sysrepo
445 )
446
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100447 sysrepo_fixture_env(sysrepo-czechlight-network
448 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
449 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
450 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +0200451 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
452 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
453 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100454 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200455
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100456 velia_test(sysrepo_system-ietfinterfaces velia-system)
457 set_tests_properties(
458 test-sysrepo_system-ietfinterfaces
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200459 PROPERTIES FIXTURES_REQUIRED "sysrepo:env:sysrepo-czechlight-network"
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100460 RESOURCE_LOCK sysrepo
461 )
462
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200463 if(TEST_NETWORK_WITH_SUDO)
464 find_program(SUDO_EXECUTABLE sudo REQUIRED)
465 find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
466 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
467
468 add_test(NAME network-czechlight0-prepare COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
469 add_test(NAME network-czechlight0-cleanup COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
470 set_tests_properties(network-czechlight0-prepare PROPERTIES FIXTURES_SETUP network-czechlight0)
471 set_tests_properties(network-czechlight0-cleanup PROPERTIES FIXTURES_CLEANUP network-czechlight0)
472
473 velia_test(sysrepo_system-ietfinterfaces-sudo velia-system)
474 set_tests_properties(
475 test-sysrepo_system-ietfinterfaces-sudo
476 PROPERTIES FIXTURES_REQUIRED "sysrepo:env:sysrepo-czechlight-network;network-czechlight0"
477 RESOURCE_LOCK sysrepo
478 )
479 endif()
480
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100481 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 +0100482 velia_test(hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils)
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100483 set_tests_properties(
484 test-hardware_ietf-hardware
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100485 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-ietf-hardware
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100486 RESOURCE_LOCK sysrepo
487 )
488
489 velia_test(sysrepo_two-daemons velia-ietf-hardware-sysrepo)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100490 # 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 +0100491 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
492 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
493
494 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
495 add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop)
496 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
497 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons RESOURCE_LOCK sysrepo)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100498
499 set_tests_properties(
500 test-sysrepo_two-daemons
501 PROPERTIES
502 FIXTURES_REQUIRED "sysrepo:two-daemons;sysrepo:env:sysrepo-ietf-hardware"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100503 RESOURCE_LOCK sysrepo
504 )
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100505 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
506 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware)
507 set_tests_properties(sysrepo:clean:sysrepo-ietf-hardware PROPERTIES DEPENDS sysrepo_test_merge-stop)
508
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100509
510 find_program(YANGLINT_PATH yanglint)
511 if (NOT YANGLINT_PATH)
512 message(FATAL_ERROR "Cannot find libyang's yanglint")
513 endif()
514 foreach(yang_file ${YANG_SRCS})
515 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
516 endforeach()
Václav Kubernátd386aba2021-01-19 10:03:28 +0100517
518 sysrepo_fixture_env(sysrepo-firewall
519 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
520 # imported) but I still need to install it myself to enable the features.
521 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
522 FEATURE eth
523 FEATURE match-on-eth
524 FEATURE match-on-ipv4
525 FEATURE ipv4
526 FEATURE match-on-ipv6
527 FEATURE ipv6
528 FEATURE mixed-eth-ipv4-ipv6
529 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
530 )
531
532 velia_test(sysrepo-firewall velia-firewall)
533 set_tests_properties(
534 test-sysrepo-firewall
535 PROPERTIES FIXTURES_REQUIRED sysrepo:env:sysrepo-firewall
536 RESOURCE_LOCK sysrepo
537 )
Tomáš Pecka261c8862020-11-05 11:23:08 +0100538endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200539
Tomáš Pecka5123e002020-06-05 15:29:21 +0200540if(WITH_DOCS)
541 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
542 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
543 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
544 add_custom_target(doc
545 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
546 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
547 COMMENT "Generating API documentation with Doxygen"
548 VERBATIM
549 SOURCES ${doxyfile_in}
550 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200551endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100552
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100553set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
554install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckaeb317722021-04-13 21:33:20 +0200555install(FILES ${CMAKE_SOURCE_DIR}/yang/ietf-ipv6-router-advertisements@2018-03-13.yang DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100556install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100557install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100558install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100559install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)