Skip to content

Commit

Permalink
Merge branch 'code-coverage-for-master' into 'master'
Browse files Browse the repository at this point in the history
Code coverage for master

See merge request eriknellessen/encrypting-cloud-storages!6
  • Loading branch information
eriknellessen committed Jan 17, 2022
2 parents d5c6da4 + 86b74d8 commit f927e88
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 41 deletions.
16 changes: 13 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include:
- template: Code-Quality.gitlab-ci.yml

before_script:
- apt update && apt -y install cmake libgpgme-dev libgcrypt-dev libfuse-dev makepasswd encfs python3-pgpdump opensc-pkcs11 libc6-dev pcscd automake libpcsclite-dev libgtk-3-dev libcriterion-dev
- apt update && apt -y install cmake libgpgme-dev libgcrypt-dev libfuse-dev makepasswd encfs python3-pgpdump opensc-pkcs11 libc6-dev pcscd automake libpcsclite-dev libgtk-3-dev libcmocka-dev gcovr
- ln -s /usr/lib/x86_64-linux-gnu/libopensc.so.7.0.0 /usr/lib/x86_64-linux-gnu/libopensc.so

build:
Expand All @@ -42,7 +42,16 @@ test:
stage: test
script:
- cd build
- make test
- CTEST_OUTPUT_ON_FAILURE=1 make test
- gcovr --exclude-unreachable-branches --exclude .*_test\.c --html-details -o coverage.html --root ${CI_PROJECT_DIR}
- gcovr --xml-pretty --exclude-unreachable-branches --exclude .*_test\.c --print-summary -o coverage.xml --root ${CI_PROJECT_DIR}
coverage: /^\s*lines:\s*\d+.\d+\%/
artifacts:
name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
reports:
cobertura: build/coverage.xml
paths:
- build/coverage.html
cache:
key: build-cache
paths:
Expand All @@ -55,4 +64,5 @@ code_quality:
variables:
REPORT_FORMAT: html
artifacts:
paths: [gl-code-quality-report.html]
paths:
- gl-code-quality-report.html
49 changes: 49 additions & 0 deletions CMake-Modules/FindCMocka.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# - Try to find CMocka
# Once done this will define
#
# CMOCKA_ROOT_DIR - Set this variable to the root installation of CMocka
#
# Read-Only variables:
# CMOCKA_FOUND - system has CMocka
# CMOCKA_INCLUDE_DIR - the CMocka include directory
# CMOCKA_LIBRARIES - Link these to use CMocka
# CMOCKA_DEFINITIONS - Compiler switches required for using CMocka
#
#=============================================================================
# Copyright (c) 2011-2012 Andreas Schneider <[email protected]>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
#

find_path(CMOCKA_INCLUDE_DIR
NAMES
cmocka.h
PATHS
${CMOCKA_ROOT_DIR}/include
)

find_library(CMOCKA_LIBRARY
NAMES
cmocka
PATHS
${CMOCKA_ROOT_DIR}/include
)

if(CMOCKA_LIBRARY)
set(CMOCKA_LIBRARIES
${CMOCKA_LIBRARIES}
${CMOCKA_LIBRARY}
)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CMocka DEFAULT_MSG CMOCKA_LIBRARIES CMOCKA_INCLUDE_DIR)

# show the CMOCKA_INCLUDE_DIR and CMOCKA_LIBRARIES variables only in the advanced view
mark_as_advanced(CMOCKA_INCLUDE_DIR CMOCKA_LIBRARIES)
27 changes: 0 additions & 27 deletions CMake-Modules/FindCriterion.cmake

This file was deleted.

8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ if(NOT GTK3_FOUND)
message(FATAL_ERROR "Could not find GTK3")
endif()

find_package(Criterion REQUIRED)
if(NOT CRITERION_FOUND)
message(FATAL_ERROR "Could not find criterion")
find_package(CMocka REQUIRED)
if(NOT CMOCKA_FOUND)
message(FATAL_ERROR "Could not find cmocka")
endif()

enable_testing()
add_compile_options(--coverage)
add_link_options(--coverage)
add_subdirectory(fuseecs)
add_subdirectory(share_a_folder)
2 changes: 1 addition & 1 deletion fuseecs/gpg_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ int directory_contains_authentic_file(char *encrypted_directory, char *file_name
int signer_verification_needed(const char *path){
//Not needed, if signature with our own private key or we already placed a signed file in the directory, which says, that we already checked the signature (containing the verified signer, we need to check if the current signer is the same)
return 1;
}
}
2 changes: 1 addition & 1 deletion fuseecs/gpg_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,4 @@ void sign_and_encrypt(const char *data, const char *public_key_fingerprint, cons
int directory_contains_authentic_file(char *encrypted_directory, char *file_name);
int signer_verification_needed(const char *path);

#endif
#endif
11 changes: 10 additions & 1 deletion fuseecs/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
cmake_minimum_required(VERSION 3.0.2)

add_executable(data_operations_test data_operations_test.c)
target_link_libraries(data_operations_test criterion)
target_link_libraries(data_operations_test cmocka)

add_test(NAME data_operations_test WORKING_DIRECTORY fuseecs/test COMMAND ./data_operations_test)

add_executable(gpg_operations_test ../gpg_operations.c gpg_operations_test.c)
set_target_properties(gpg_operations_test
PROPERTIES
LINK_FLAGS "-g -Wl,--wrap=access"
)
target_link_libraries(gpg_operations_test cmocka ${GPGME_VANILLA_LIBRARIES} showSigner)

add_test(NAME gpg_operations_test WORKING_DIRECTORY fuseecs/test COMMAND ./gpg_operations_test)
18 changes: 13 additions & 5 deletions fuseecs/test/data_operations_test.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#include <string.h>
#include <criterion/criterion.h>
#include <criterion/new/assert.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "../data_operations.h"

Test(data_operations_test_suite, local_string_concatenation_test) {
static void test_local_string_concatenation(void **state) {
LOCAL_STR_CAT("foo", "bar", concatenated_string)
cr_assert(eq(str, concatenated_string, "foobar"), "Did not concatenate strings as expected!");
assert_string_equal(concatenated_string, "foobar");
}

int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_local_string_concatenation),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
30 changes: 30 additions & 0 deletions fuseecs/test/gpg_operations_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "../gpg_operations.h"

int __real_access(const char *pathname, int how);
int __wrap_access(const char *pathname, int how) {
if (strlen(pathname) > 5 && !strcmp(pathname + strlen(pathname) - 5, ".gcda")) {
return __real_access(pathname, how);
}

return mock_type(int);
}

static void test_directory_contains_authentic_file(void **state) {
will_return(__wrap_access, 1);

char *encrypted_directory = "/foo/";
char *file_name = "bar.txt";
int return_value = directory_contains_authentic_file(encrypted_directory, file_name);
assert_int_equal(return_value, 0);
}

int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_directory_contains_authentic_file),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}

0 comments on commit f927e88

Please sign in to comment.