Bash Code Coverage Using Codecov with kcov & Travis CI

Brett Curtis
Google Cloud - Community
2 min readOct 25, 2017

I had some limitations around the VM build system in Travis CI and getting a current version of gcloud so I messed around a bit and diverted away from the Codecov bash example.

Here is a snip of my travis.yml that I’m currently using:

sudo: falseaddons:
apt:
packages:
- binutils-dev
- libcurl4-openssl-dev
- libdw-dev
- libiberty-dev
language: bashenv:
- PATH=${PATH}:${HOME}/kcov/bin
before_install:
- wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
install:
- tar xzf master.tar.gz
- cd kcov-master
- mkdir build
- cd build
- cmake -DCMAKE_INSTALL_PREFIX=${HOME}/kcov ..
- make
- make install
- cd ../..
- rm -rf kcov-master
- mkdir -p coverage
script:
- kcov coverage test.sh
after_success:
- bash <(curl -s https://codecov.io/bash)

This is working for me with no issues right now. It gets away from the VM Travis CI build system allowing me some flexibility around my gcloud install and it’s faster too! The support for installing packages on a container based environment make this possible, allowing me to satisfy the dependencies for kcov.

I’ve also been testing caching of kcov in Travis CI in a super simple stop watch kinda way.. Cached tests run around ~1.12 minutes while downloading and compiling each build takes around ~2:40 minutes.

Here is a more complete example of that travis.yml

sudo: falseaddons:
apt:
packages:
- binutils-dev
- libcurl4-openssl-dev
- libdw-dev
- libiberty-dev
language: bashcache:
directories:
- "${HOME}/google-cloud-sdk/"
- "${HOME}/kcov/"
env:
- PATH=$PATH:${HOME}/google-cloud-sdk/bin:${HOME}/kcov/bin CLOUDSDK_CORE_DISABLE_PROMPTS=1
before_install:
- openssl aes-256-cbc -K $encrypted_c4d8f070a225_key -iv $encrypted_c4d8f070a225_iv
-in credentials.tar.gz.enc -out credentials.tar.gz -d
- if [ ! -d "${HOME}/google-cloud-sdk/bin" ]; then rm -rf ${HOME}/google-cloud-sdk;
curl https://sdk.cloud.google.com | bash; fi
- if [ ! -d "${HOME}/kcov/bin" ]; then wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz;
tar xzf master.tar.gz;
cd kcov-master;
mkdir build;
cd build;
cmake -DCMAKE_INSTALL_PREFIX=${HOME}/kcov ..;
make;
make install;
cd ../..;
rm -rf kcov-master;
mkdir -p coverage; fi
- tar -xzf credentials.tar.gz
- gcloud auth activate-service-account --key-file client-secret.json
install:
- gcloud -q components update
script:
#- kcov --exclude-path=ops-common coverage test.sh
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
slack: lzysh:0nheJvFHhsWdYlVVfdX0mRNu

I’ll probably test this configuration out for a bit and see how it goes. If all is well, code up something quick to check for kcov updates and update if needed.

The value add of code coverage even on simple bash code for GCP infrastructure stuff is pretty high vs. the effort to implement it so I’d say go for it!

--

--

Brett Curtis
Google Cloud - Community

I drink coffee and do things with cloud infrastructure..