blob: bdd1ba1fc465f0003ac641c22df7507ff00d5aaa [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áš Pecka6a266d82021-11-19 11:35:39 +010035find_package(sdbus-c++ "1.0.0" 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
Václav Kubernát5a745d22021-11-12 12:09:57 +0100354 find_program(SYSREPOCTL sysrepoctl)
355 find_program(SYSREPOCFG sysrepocfg)
356
Tomáš Pecka5123e002020-06-05 15:29:21 +0200357 function(velia_test name)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100358 add_executable(test-${name} ${CMAKE_SOURCE_DIR}/tests/${name}.cpp)
Václav Kubernát6677c222021-11-12 11:46:45 +0100359 target_link_libraries(test-${name} DoctestIntegration)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100360 target_include_directories(test-${name}
361 PUBLIC
362 ${CMAKE_CURRENT_SOURCE_DIR}
363 PRIVATE
364 ${CMAKE_BINARY_DIR}
365 )
Tomáš Pecka5123e002020-06-05 15:29:21 +0200366
367 if(NOT CMAKE_CROSSCOMPILING)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100368 add_test(test-${name} test-${name})
Tomáš Pecka5123e002020-06-05 15:29:21 +0200369 endif()
Tomáš Pecka5123e002020-06-05 15:29:21 +0200370
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100371 set(test_name_init sysrepo:prep:${name})
372 set(test_name_cleanup sysrepo:clean:${name})
373 set(fixture_name sysrepo:env:${name})
374
Václav Kubernát5a745d22021-11-12 12:09:57 +0100375 # How to do this:
376 # Check ARGN for name of fixture
377 # then take the args for manage module from variable "fixture{fixture_name}"
378 # and then add set env vars for sysrepo
379 # set them ALSO for the init/cleanup tests
380 if(ARGC GREATER 1)
381 set(wanted_fixture ${ARGV1})
382 add_test(NAME ${test_name_init} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} prepare ${${wanted_fixture}})
383 set_tests_properties(${test_name_init} PROPERTIES FIXTURES_SETUP ${fixture_name})
384 add_test(NAME ${test_name_cleanup} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL} ${SYSREPOCFG} uninstall ${${wanted_fixture}})
385 set_tests_properties(${test_name_cleanup} PROPERTIES FIXTURES_CLEANUP ${fixture_name})
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100386
Václav Kubernát5a745d22021-11-12 12:09:57 +0100387 set_tests_properties(test-${name} PROPERTIES FIXTURES_REQUIRED ${fixture_name})
388 set_property(TEST test-${name} ${test_name_init} ${test_name_cleanup} APPEND PROPERTY ENVIRONMENT
389 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_${name}"
390 "SYSREPO_SHM_PREFIX=velia_test_${name}"
391 )
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100392
Václav Kubernát5a745d22021-11-12 12:09:57 +0100393 endif()
394
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100395 endfunction()
396
Václav Kubernát6677c222021-11-12 11:46:45 +0100397 velia_test(health_state-manager)
398 target_link_libraries(test-health_state-manager velia-health)
399 velia_test(health_input-semaphore)
400 target_link_libraries(test-health_input-semaphore velia-health DbusTesting)
401 velia_test(health_input-systemd)
402 target_link_libraries(test-health_input-systemd velia-health DbusTesting)
403 velia_test(health_output-led)
404 target_link_libraries(test-health_output-led velia-health)
Tomáš Pecka491f4f22020-11-05 15:44:00 +0100405
Václav Kubernát6677c222021-11-12 11:46:45 +0100406 velia_test(system_rauc)
407 target_link_libraries(test-system_rauc velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100408 set_tests_properties(
409 test-system_rauc
410 PROPERTIES RESOURCE_LOCK dbus-rauc
411 )
Tomáš Pecka991e4d52021-01-11 10:03:14 +0100412
Václav Kubernát6677c222021-11-12 11:46:45 +0100413 velia_test(system_lldp)
414 target_link_libraries(test-system_lldp velia-system DbusTesting)
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200415
Václav Kubernát5a745d22021-11-12 12:09:57 +0100416 set(fixture_sysrepo-czechlight-lldp YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-lldp@2020-11-04.yang)
417 velia_test(sysrepo_system-lldp fixture_sysrepo-czechlight-lldp)
Václav Kubernát6677c222021-11-12 11:46:45 +0100418 target_link_libraries(test-sysrepo_system-lldp velia-system DbusTesting)
Tomáš Pecka7acf3922021-08-10 11:16:57 +0200419
Václav Kubernát6677c222021-11-12 11:46:45 +0100420 velia_test(hardware_emmc)
421 target_link_libraries(test-hardware_emmc velia-ietf-hardware FsTestUtils)
422 velia_test(hardware_hwmon)
423 target_link_libraries(test-hardware_hwmon velia-ietf-hardware FsTestUtils)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100424
Václav Kubernát5a745d22021-11-12 12:09:57 +0100425 set(fixture_sysrepo-ietf-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-system@2014-08-06.yang)
426 velia_test(sysrepo_system-ietfsystem fixture_sysrepo-ietf-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100427 target_link_libraries(test-sysrepo_system-ietfsystem velia-system DbusTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100428
Václav Kubernát5a745d22021-11-12 12:09:57 +0100429 set(fixture_sysrepo-czechlight-system YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-system@2021-01-13.yang)
430 velia_test(sysrepo_system-firmware fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100431 target_link_libraries(test-sysrepo_system-firmware velia-system DbusTesting SysrepoTesting)
Tomáš Peckacb7a5f82021-01-20 15:12:00 +0100432 set_tests_properties(
Tomáš Pecka594a6762021-01-29 11:06:08 +0100433 test-sysrepo_system-firmware
Václav Kubernát5a745d22021-11-12 12:09:57 +0100434 PROPERTIES RESOURCE_LOCK dbus-rauc
Tomáš Pecka292bc9c2021-01-11 22:03:11 +0100435 )
436
Václav Kubernát5a745d22021-11-12 12:09:57 +0100437 velia_test(sysrepo_authentication fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100438 target_link_libraries(test-sysrepo_authentication velia-system FsTestUtils)
Václav Kubernátbabbab92021-01-27 09:25:05 +0100439
Václav Kubernát5a745d22021-11-12 12:09:57 +0100440 velia_test(sysrepo_system-leds fixture_sysrepo-czechlight-system)
Václav Kubernát6677c222021-11-12 11:46:45 +0100441 target_link_libraries(test-sysrepo_system-leds velia-system FsTestUtils)
Tomáš Peckaaf7b7042021-04-20 20:14:13 +0200442
Václav Kubernát5a745d22021-11-12 12:09:57 +0100443 set(fixture_sysrepo-czechlight-network
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100444 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/iana-if-type@2017-01-19.yang
445 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-interfaces@2018-02-20.yang
446 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ip@2018-02-22.yang
Tomáš Pecka2a4ea7b2021-03-30 17:01:37 +0200447 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-routing@2018-03-13.yang
448 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv4-unicast-routing@2018-03-13.yang
449 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-ipv6-unicast-routing@2018-03-13.yang
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100450 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-network@2021-02-22.yang)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200451
Václav Kubernát5a745d22021-11-12 12:09:57 +0100452 velia_test(sysrepo_system-ietfinterfaces fixture_sysrepo-czechlight-network)
Václav Kubernát6677c222021-11-12 11:46:45 +0100453 target_link_libraries(test-sysrepo_system-ietfinterfaces velia-system)
Tomáš Peckaf10b9302021-02-23 19:02:02 +0100454
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200455 if(TEST_NETWORK_WITH_SUDO)
456 find_program(SUDO_EXECUTABLE sudo REQUIRED)
457 find_program(IPROUTE2_EXECUTABLE ip REQUIRED)
458 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.h.in ${CMAKE_CURRENT_BINARY_DIR}/test_vars.h @ONLY)
459
460 add_test(NAME network-czechlight0-prepare COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
461 add_test(NAME network-czechlight0-cleanup COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_system-ietfinterfaces-sudo.sh ${SUDO_EXECUTABLE})
462 set_tests_properties(network-czechlight0-prepare PROPERTIES FIXTURES_SETUP network-czechlight0)
463 set_tests_properties(network-czechlight0-cleanup PROPERTIES FIXTURES_CLEANUP network-czechlight0)
464
Václav Kubernát5a745d22021-11-12 12:09:57 +0100465 velia_test(sysrepo_system-ietfinterfaces-sudo fixture_sysrepo-czechlight-network)
Václav Kubernát6677c222021-11-12 11:46:45 +0100466 target_link_libraries(test-sysrepo_system-ietfinterfaces-sudo velia-system)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100467 set_property(TEST test-sysrepo_system-ietfinterfaces-sudo APPEND PROPERTY FIXTURES_REQUIRED network-czechlight0)
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +0200468 endif()
469
Václav Kubernát5a745d22021-11-12 12:09:57 +0100470 set(fixture_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)
471 velia_test(hardware_ietf-hardware fixture_sysrepo-ietf-hardware)
Václav Kubernát6677c222021-11-12 11:46:45 +0100472 target_link_libraries(test-hardware_ietf-hardware velia-ietf-hardware velia-ietf-hardware-sysrepo FsTestUtils)
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100473
Václav Kubernát5a745d22021-11-12 12:09:57 +0100474 velia_test(sysrepo_two-daemons fixture_sysrepo-ietf-hardware)
Václav Kubernát6677c222021-11-12 11:46:45 +0100475 target_link_libraries(test-sysrepo_two-daemons velia-ietf-hardware-sysrepo)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100476 # 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 +0100477 add_executable(test-sysrepo_test_merge-daemon ${CMAKE_SOURCE_DIR}/tests/sysrepo_two-daemons_daemon.cpp)
478 target_link_libraries(test-sysrepo_test_merge-daemon PkgConfig::SYSREPO PkgConfig::LIBYANG)
479
480 add_test(NAME sysrepo_test_merge-start COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh start)
481 add_test(NAME sysrepo_test_merge-stop COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepo_two-daemons_control.sh stop)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100482 set_tests_properties(sysrepo_test_merge-start PROPERTIES FIXTURES_SETUP sysrepo:two-daemons)
483 set_tests_properties(sysrepo_test_merge-stop PROPERTIES FIXTURES_CLEANUP sysrepo:two-daemons)
484 set_property(TEST sysrepo_test_merge-start sysrepo_test_merge-stop APPEND PROPERTY ENVIRONMENT
485 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_sysrepo_two-daemons"
486 "SYSREPO_SHM_PREFIX=velia_test_sysrepo_two-daemons"
487 )
Tomáš Pecka55f64f82020-12-10 19:03:30 +0100488
Václav Kubernát5a745d22021-11-12 12:09:57 +0100489 set_property(TEST test-sysrepo_two-daemons APPEND PROPERTY FIXTURES_REQUIRED sysrepo:two-daemons)
490
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100491 # ensure we run two-daemons merge test and ietf-hardware test sequentially and don't cleanup before everything ends
492 set_tests_properties(sysrepo_test_merge-start PROPERTIES DEPENDS test-hardware_ietf-hardware)
Václav Kubernát5a745d22021-11-12 12:09:57 +0100493 set_tests_properties(sysrepo:clean:sysrepo_two-daemons PROPERTIES DEPENDS sysrepo_test_merge-stop)
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100494
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100495
496 find_program(YANGLINT_PATH yanglint)
497 if (NOT YANGLINT_PATH)
498 message(FATAL_ERROR "Cannot find libyang's yanglint")
499 endif()
500 foreach(yang_file ${YANG_SRCS})
501 add_test(NAME yang-tree:${yang_file} COMMAND ${YANGLINT_PATH} -f tree ${CMAKE_CURRENT_SOURCE_DIR}/${yang_file})
502 endforeach()
Václav Kubernátd386aba2021-01-19 10:03:28 +0100503
Václav Kubernát5a745d22021-11-12 12:09:57 +0100504 set(fixture_sysrepo-firewall
Václav Kubernátd386aba2021-01-19 10:03:28 +0100505 # Installing czechlight-firewall automatically installs ietf-access-control-list as implemented (not just
506 # imported) but I still need to install it myself to enable the features.
507 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/ietf-access-control-list@2019-03-04.yang
Václav Kubernátd386aba2021-01-19 10:03:28 +0100508 FEATURE match-on-eth
Václav Kubernát2b073632021-11-25 15:39:42 +0100509 FEATURE eth
Václav Kubernátd386aba2021-01-19 10:03:28 +0100510 FEATURE match-on-ipv4
511 FEATURE ipv4
512 FEATURE match-on-ipv6
513 FEATURE ipv6
514 FEATURE mixed-eth-ipv4-ipv6
515 YANG ${CMAKE_CURRENT_SOURCE_DIR}/yang/czechlight-firewall@2021-01-25.yang
516 )
517
Václav Kubernát5a745d22021-11-12 12:09:57 +0100518 velia_test(sysrepo-firewall fixture_sysrepo-firewall)
Václav Kubernát6677c222021-11-12 11:46:45 +0100519 target_link_libraries(test-sysrepo-firewall velia-firewall)
Tomáš Pecka261c8862020-11-05 11:23:08 +0100520endif()
Tomáš Peckac927d662020-07-13 11:16:16 +0200521
Tomáš Pecka5123e002020-06-05 15:29:21 +0200522if(WITH_DOCS)
523 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
524 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
525 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
526 add_custom_target(doc
527 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
528 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
529 COMMENT "Generating API documentation with Doxygen"
530 VERBATIM
531 SOURCES ${doxyfile_in}
532 )
Tomáš Peckaa06d74d2020-06-14 18:18:13 +0200533endif()
Tomáš Pecka261c8862020-11-05 11:23:08 +0100534
Tomáš Pecka73a13cc2020-11-17 11:12:19 +0100535set(YANG_DIR ${CMAKE_INSTALL_PREFIX}/share/velia/yang)
536install(FILES ${YANG_SRCS} DESTINATION ${YANG_DIR})
Tomáš Peckaeb317722021-04-13 21:33:20 +0200537install(FILES ${CMAKE_SOURCE_DIR}/yang/ietf-ipv6-router-advertisements@2018-03-13.yang DESTINATION ${YANG_DIR})
Tomáš Peckacd19e622021-01-27 09:18:11 +0100538install(TARGETS veliad-health RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Pecka625b7a12021-01-23 20:55:51 +0100539install(TARGETS veliad-system RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +0100540install(TARGETS veliad-hardware RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)
Tomáš Peckafb14b182021-01-27 10:54:00 +0100541install(TARGETS veliad-firewall RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)