Skip to content

Commit

Permalink
Fix and update Travis CI (#116)
Browse files Browse the repository at this point in the history
* Remove out of date cppcheck suppressions; fix hook for deleted files

* Stop using suppressions

* Try adding custom findcmocka

* Vain attempt to debug deps bs

* Vain attempt to debug deps bs #2

* Deps BS: Try stealing a simpler travis setup

* Deps BS: Add find module (facepalm)

* GCC: Update sanitizer specs

* CI: Add arm64 target

* CI: Migrate rest of script

* CI: Debug clang formaat

* CI: Try different multine strings

* CI: Explicitly install clangf8

* CI: Explicitly install clangf8

* CI: More clf8 tweaks

* CI: Install cppcheck

* CI: Fix YAML syntax

* CI: Get rid of the qemu hack

* CI: Build cmocka in a separte dir to avoid confusing cppcheck

* CI: Fix format hook to find the right files

* CI: Make format hook chatty in CI
  • Loading branch information
PJK authored Mar 15, 2020
1 parent 3b41770 commit 5eefe85
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 199 deletions.
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

0 comments on commit 5eefe85

Please sign in to comment.