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

Jenkins Integration #186

Merged
18 commits merged into from
Dec 3, 2018
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
14 changes: 0 additions & 14 deletions .ci/coverage.py

This file was deleted.

46 changes: 46 additions & 0 deletions firmware/ec/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

node {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some headers for all the new files

currentBuild.result = 'SUCCESS'
withEnv(["UNITY_ROOT=$HOME/Unity", "TOOLCHAIN=$HOME/gcc-arm-none-eabi", "OCWARE_DIR=./"]) {
stage('Checkout') {
step([$class: 'WsCleanup'])
echo 'Checking out SCM'
checkout scm
}

try {
stage('Static Analysis') {
sh 'bash firmware/utilities/jenkins/clang_patch'
}
} catch (err) {
currentBuild.result = 'ERROR'
} finally {
archiveArtifacts '**/clang_format.patch'
}

try {
stage('Build and Unit Test') {
dir ("firmware/ec"){
sh 'make ci'
sh 'python3 ../utilities/jenkins/coverage.py'
}
}
} catch (err) {
currentBuild.result = 'FAILURE'
} finally {
warnings consoleParsers: [[parserName: 'GNU Make + GNU C Compiler (gcc)']]
junit 'firmware/ec/test/build/results/unit-test-results.xml'
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false,\
coberturaReportFile: '**/test-coverage.xml', failUnhealthy: false, failUnstable: false,\
maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
}
}
}
1 change: 1 addition & 0 deletions firmware/ec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ test:
cd test && $(MAKE) $(TESTFLAGS)

ci: TESTFLAGS = ci
ci: CFLAGS += -Wextra -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch-default -Wunreachable-code -Winit-self -Wno-missing-field-initializers -Wno-unknown-pragmas -Wstrict-prototypes -Wundef
ci: CFLAGS += -ftest-coverage
ci: all test

Expand Down
2 changes: 1 addition & 1 deletion firmware/ec/test/fake/fake_GPIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static int FakeGpio_setCallback(const OcGpio_Pin *pin,

if (pin->idx >= FAKE_GPIO_PIN_COUNT) {
return OCGPIO_FAILURE;
}
}

obj->callback[pin->idx].fn = callback;
obj->callback[pin->idx].context = context;
Expand Down
26 changes: 26 additions & 0 deletions firmware/utilities/jenkins/clang_patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#
# Copyright (c) 2018-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

# Get all files that are different from master and only lint those.
fileList=`git --no-pager diff --name-only HEAD origin/master ./firmware/ec | grep ".\.c$\|.\.h$"`
for f in $fileList; do
clang-format -style=file -i ${f}
done
echo "Linting the following files:"
echo $fileList
git diff > clang_format.patch

# Delete if 0 size and exit with 0
if [ ! -s clang_format.patch ]
then
exit 0
fi

# There were lint issues and should exit with error
exit 1
83 changes: 83 additions & 0 deletions firmware/utilities/jenkins/coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
#
# Copyright (c) 2018-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

""""
Script to convert lcov generated coverage data to Jenkins readable Cobertura
XML coverage formatted data.
"""

import argparse
import glob
import os
import sys
from lcov_cobertura import LcovCobertura


def main(args):
# Auto set arguments if none were provided

# If no sourcefile was provided, find the test-coverage.info file.
# This assumes that the first file found is the desired one, so if multiple
# exist then the sourceFile must be specified on the command line.
if not args.sourceFile:
f = glob.glob('**/test-coverage.info', recursive=True)
if f:
sourceFile = f[0]
else:
sys.exit("No lcov output file found below current directory.")
else:
sourceFile = args.sourceFile

# If no output file was provided, then place it in the same directory as
# the source file.
if not args.outFile:
outFile = os.path.dirname(sourceFile) + '/test-coverage.xml'
else:
outFile = args.outFile

# Read all the data from the lcov output file
with open(sourceFile) as fr:
data = fr.read()

# Create a converter and convert coverage data
converter = LcovCobertura(data)
res = converter.convert()

# Write all output data to the destination file.
with open(outFile, 'w') as fw:
fw.write(res)

if __name__ == "__main__":

parser = argparse.ArgumentParser()

# lcov data source file
parser.add_argument(
'-i',
dest='sourceFile',
action='store',
default='',
type=str,
help='lcov data file to extract coverage information from. If not \
provided, will recursively search from cwd for test-coverage.info\
to use. If it finds multiple, will use the first one found',
)

# Output file name
parser.add_argument(
'-o',
dest='outFile',
action='store',
default='',
type=str,
help='Name of file to write xml coverage data to. If not provided, will\
default to test-coverage.xml in the same directory as sourceFile',
)

main(parser.parse_args())