Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a gvm_libs_version function #301

Merged
merged 7 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- checkout
- run:
name: Configure and run unit tests
command: mkdir build && cd build/ && cmake -DCMAKE_BUILD_TYPE=Release .. && make install && make tests && CTEST_OUTPUT_ON_FAILURE=1 make test
command: mkdir build && cd build/ && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=1 .. && make install && make tests && CTEST_OUTPUT_ON_FAILURE=1 make test
build_gcc_core:
docker:
- image: greenbone/build-env-gvm-libs-master-debian-stretch-gcc-core
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Add option to set finished hosts in OSP targets [#298](https://github.com/greenbone/gvm-libs/pull/298)
- Add a fast memory-only XML parser [#299](https://github.com/greenbone/gvm-libs/pull/299)
- Add new function gvm_libs_version [#301](https://github.com/greenbone/gvm-libs/pull/301)

### Fixed
- Fix sigsegv when no plugin_feed_info.inc file present. [#278](https://github.com/greenbone/gvm-libs/pull/278)
Expand Down
24 changes: 14 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ endif (NOT CMAKE_BUILD_TYPE)

OPTION(BUILD_STATIC "Build static versions of the libraries" OFF)
OPTION(ENABLE_COVERAGE "Enable support for coverage analysis" OFF)
OPTION(BUILD_TESTS "Build tests for the libraries" OFF)

if (NOT BUILD_STATIC)
set (BUILD_SHARED ON)
Expand Down Expand Up @@ -211,7 +212,7 @@ else (PROJECT_BETA_RELEASE)
set (LIBGVMCONFIG_VERSION "${PROJECT_VERSION_STRING}")
endif (PROJECT_BETA_RELEASE)

set (GVMLIB_VERSION "${LIBGVMCONFIG_VERSION}")
add_definitions(-DGVM_LIBS_VERSION="${LIBGVMCONFIG_VERSION}")

# Configure Doxyfile with version number
configure_file (doc/Doxyfile.in ${CMAKE_BINARY_DIR}/doc/Doxyfile @ONLY)
Expand All @@ -221,10 +222,15 @@ configure_file (VERSION.in ${CMAKE_BINARY_DIR}/VERSION @ONLY)

## Testing

enable_testing ()
if (BUILD_TESTS AND NOT SKIP_SRC)
enable_testing ()

add_custom_target (tests
DEPENDS array-test xmlutils-test)
find_package (cgreen REQUIRED)

add_custom_target (tests
DEPENDS array-test xmlutils-test version-test)

endif (BUILD_TESTS AND NOT SKIP_SRC)

## Program

Expand All @@ -239,11 +245,9 @@ endif (NOT SKIP_SRC)

add_subdirectory (doc)

## Tests

add_subdirectory (tests)
add_test (NAME testhosts COMMAND test-hosts localhost)

enable_testing ()
if (BUILD_TESTS AND NOT SKIP_SRC)
add_subdirectory (tests)
add_test (NAME testhosts COMMAND test-hosts localhost)
endif (BUILD_TESTS AND NOT SKIP_SRC)

## End
28 changes: 21 additions & 7 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ include_directories (${GLIB_INCLUDE_DIRS})

set (FILES array.c credentials.c cvss.c drop_privileges.c hosts.c logging.c
networking.c nvti.c pidfile.c prefs.c proctitle.c pwpolicy.c
settings.c strings.c)
settings.c strings.c version.c)

set (HEADERS array.h credentials.h cvss.h drop_privileges.h hosts.h logging.h
networking.h nvti.h pidfile.h prefs.h proctitle.h pwpolicy.h
settings.h strings.h)
settings.h strings.h version.h)

if (BUILD_STATIC)
set (LIBGVM_BASE_NAME gvm_base_static)
Expand Down Expand Up @@ -72,13 +72,27 @@ endif (GVM_SYSCONF_DIR)

## Tests

add_executable (array-test
EXCLUDE_FROM_ALL
array_tests.c)
if (BUILD_TESTS)
add_executable (array-test
EXCLUDE_FROM_ALL
array_tests.c)

add_test (array-test array-test)
add_test (array-test array-test)

target_link_libraries (array-test cgreen ${GLIB_LDFLAGS} ${LINKER_HARDENING_FLAGS})
target_include_directories (array-test PRIVATE ${CGREEN_INCLUDE_DIRS})

target_link_libraries (array-test ${CGREEN_LIBRARIES} ${GLIB_LDFLAGS} ${LINKER_HARDENING_FLAGS})

add_executable (version-test
EXCLUDE_FROM_ALL
version_tests.c)

add_test (version-test version-test)

target_include_directories (version-test PRIVATE ${CGREEN_INCLUDE_DIRS})

target_link_libraries (version-test ${CGREEN_LIBRARIES} ${GLIB_LDFLAGS} ${LINKER_HARDENING_FLAGS})
endif (BUILD_TESTS)


## Install
Expand Down
26 changes: 26 additions & 0 deletions base/version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "version.h"

const char *
gvm_libs_version (void)
{
return GVM_LIBS_VERSION;
}
31 changes: 31 additions & 0 deletions base/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/**
* @file
* @brief Version utilities.
*/

#ifndef _GVM_VERSION_H
#define _GVM_VERSION_H

const char *
gvm_libs_version (void);

#endif
52 changes: 52 additions & 0 deletions base/version_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "version.c"

#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>

Describe (version);
BeforeEach (version)
{
}
AfterEach (version)
{
}

Ensure (version, gvm_libs_versions_returns_correct_version)
{
assert_that (strcmp (gvm_libs_version (), GVM_LIBS_VERSION) == 0)
}

int
main (int argc, char **argv)
{
TestSuite *suite;

suite = create_test_suite ();

add_test_with_context (suite, version,
gvm_libs_versions_returns_correct_version);

if (argc > 1)
return run_single_test (suite, argv[1], create_text_reporter ());

return run_test_suite (suite, create_text_reporter ());
}
28 changes: 16 additions & 12 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,26 @@ endif (BUILD_SHARED)

## Tests

add_executable (xmlutils-test
EXCLUDE_FROM_ALL
xmlutils_tests.c)
if (BUILD_TESTS)
add_executable (xmlutils-test
EXCLUDE_FROM_ALL
xmlutils_tests.c)

add_test (xmlutils-test xmlutils-test)
add_test (xmlutils-test xmlutils-test)

target_link_libraries (xmlutils-test cgreen
${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${GPGME_LDFLAGS} ${ZLIB_LDFLAGS}
${RADIUS_LDFLAGS} ${LIBSSH_LDFLAGS} ${GNUTLS_LDFLAGS}
${GCRYPT_LDFLAGS} ${LDAP_LDFLAGS} ${REDIS_LDFLAGS}
${LIBXML2_LDFLAGS} ${UUID_LDFLAGS}
${LINKER_HARDENING_FLAGS})
target_include_directories (xmlutils-test PRIVATE ${CGREEN_INCLUDE_DIRS})

add_custom_target (tests-xmlutils
DEPENDS xmlutils-test)
target_link_libraries (xmlutils-test ${CGREEN_LIBRARIES}
${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${GPGME_LDFLAGS} ${ZLIB_LDFLAGS}
${RADIUS_LDFLAGS} ${LIBSSH_LDFLAGS} ${GNUTLS_LDFLAGS}
${GCRYPT_LDFLAGS} ${LDAP_LDFLAGS} ${REDIS_LDFLAGS}
${LIBXML2_LDFLAGS} ${UUID_LDFLAGS}
${LINKER_HARDENING_FLAGS})

add_custom_target (tests-xmlutils
DEPENDS xmlutils-test)

endif (BUILD_TESTS)

## Install
configure_file (libgvm_util.pc.in ${CMAKE_BINARY_DIR}/libgvm_util.pc @ONLY)
Expand Down