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

Fix and update Travis CI #116

Merged
merged 21 commits into from
Mar 15, 2020
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
137 changes: 0 additions & 137 deletions .travis-qemu.sh

This file was deleted.

95 changes: 46 additions & 49 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,54 @@ sudo: true

matrix:
include:
- compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
- george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-8 main'
key_url: https://apt.llvm.org/llvm-snapshot.gpg.key
packages:
- clang-3.6
- libjansson-dev
- valgrind
- cppcheck
- lcov
- cmake
- cmake-data
- clang-format-8
- compiler: gcc-6
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-8 main'
key_url: https://apt.llvm.org/llvm-snapshot.gpg.key
packages:
- gcc-6
- g++-6
- libjansson-dev
- valgrind
- cppcheck
- lcov
- cmake
- cmake-data
- clang-format-8
# Temporarily disabled due to slow performance and problems with Raspbian
# chroot (https://travis-ci.org/PJK/libcbor/jobs/281748138)
# - env: ARCH=arm
# addons:
# apt:
# sources:
# - george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3
# packages:
# - gcc-arm-linux-gnueabihf
# - libc6-dev-armhf-cross
# - cmake
# - cmake-data
- arch: amd64
os: linux
dist: bionic
sudo: required
compiler: clang
env: TRAVIS_ARCH="amd64"
- arch: amd64
os: linux
dist: bionic
sudo: required
compiler: gcc
env: TRAVIS_ARCH="amd64"
- arch: arm64
os: linux
dist: bionic
sudo: required
compiler: gcc
env: TRAVIS_ARCH="arm64"
# TODO: Add OSX support (might require some brew tweaking)

before_install:
- pushd ${HOME}
- git clone git://git.cryptomilk.org/projects/cmocka.git
- cd cmocka && mkdir build && cd build
- cmake .. && make -j2 && sudo make install
- cd .. && popd
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install -y clang-format-8 cppcheck; fi

script:
- "bash -ex .travis-qemu.sh"
- cppcheck . --error-exitcode=1 --force
# Fail if re-formatting creates diffs (implying bad formatting)
- ./clang-format.sh --verbose
- git diff-index --quiet HEAD
- mkdir build && cd build
- cmake -DWITH_TESTS=ON
-DCBOR_CUSTOM_ALLOC=ON
-DCMAKE_BUILD_TYPE=Debug
-DSANITIZE=OFF
..
- make VERBOSE=1
- ctest -VV
- ctest -T memcheck | tee memcheck.out
- >
if grep -q 'Memory Leak\|IPW\|Uninitialized Memory Conditional\|Uninitialized Memory Read' memcheck.out; then
exit 1
fi;

# TODO: Set up https://codecov.io/

notifications:
email: false
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.8)
project(libcbor)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
include(CTest)

SET(CBOR_VERSION_MAJOR "0")
Expand Down Expand Up @@ -72,8 +73,8 @@ else()

if(SANITIZE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} \
-fsanitize-trap=undefined -fsanitize=address \
-fsanitize-trap=bounds -fsanitize=alignment")
-fsanitize=undefined -fsanitize=address \
-fsanitize=bounds -fsanitize=alignment")
endif()
endif()

Expand Down
49 changes: 49 additions & 0 deletions CMakeModules/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 <asn@cryptomilk.org>
#
# 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 cmocka_shared
PATHS
${CMOCKA_ROOT_DIR}/include
)

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

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)
11 changes: 9 additions & 2 deletions clang-format.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/usr/bin/env bash

# Usage: ./clang-format.sh <extra arguments>

DIRS="src test examples demo"
SOURCES=$(find ${DIRS} -name "*.c")
SOURCES+=" $(find ${DIRS} -name "*.h")"
SOURCES+=" $(find ${DIRS} -name "*.cpp")"

# TravisCI workaround to use new clang-format while avoiding painful aliasing
# into the subshell
if which clang-format-8; then
clang-format-8 --verbose -style=file -i **/*.c **/*.h **/*.cpp
clang-format-8 $@ -style=file -i ${SOURCES}
else
clang-format --verbose -style=file -i **/*.c **/*.h **/*.cpp
clang-format $@ -style=file -i ${SOURCES}
fi

4 changes: 0 additions & 4 deletions cppcheck_suppressions.txt

This file was deleted.

2 changes: 1 addition & 1 deletion misc/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cd ..

# Run clang-format and add modified files
MODIFIED_UNSTAGED=$(git -C . diff --name-only)
MODIFIED_STAGED=$(git -C . diff --name-only --cached)
MODIFIED_STAGED=$(git -C . diff --name-only --cached --diff-filter=d)

./clang-format.sh

Expand Down
2 changes: 1 addition & 1 deletion src/cbor/internal/encoders.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ size_t _cbor_encode_uint64(uint64_t value, unsigned char *buffer,
buffer[0] = 0x1B + offset;

#ifdef IS_BIG_ENDIAN
memcpy(buffer + 1, &value, 8);
memcpy(buffer + 1, &value, 8);
#else
buffer[1] = value >> 56;
buffer[2] = value >> 48;
Expand Down
6 changes: 3 additions & 3 deletions src/cbor/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ bool cbor_string_add_chunk(cbor_item_t *item, cbor_item_t *chunk) {
return false;
}

size_t new_chunk_capacity = data->chunk_capacity == 0
? 1
: CBOR_BUFFER_GROWTH * (data->chunk_capacity);
size_t new_chunk_capacity =
data->chunk_capacity == 0 ? 1
: CBOR_BUFFER_GROWTH * (data->chunk_capacity);
cbor_item_t **new_chunks_data = _cbor_realloc_multiple(
data->chunks, sizeof(cbor_item_t *), new_chunk_capacity);

Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ file(GLOB TESTS "*_test.c")

find_package(CMocka REQUIRED)

message(STATUS "CMocka vars: ${CMOCKA_LIBRARIES} ${CMOCKA_INCLUDE_DIR}")

foreach (TEST ${TESTS})
string(REGEX REPLACE ".*/([^/]+).c" "\\1" NAME ${TEST})
message("Adding test ${NAME}")
Expand Down