Skip to content

WIP: Add CI capabilities with integration testing #332

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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eb758cf
Change format from Arch to Target when creating registers in test_wp_…
gltrost Jul 1, 2021
f33f26c
Add bin folder with bash files for running integration tests with sla…
gltrost Jul 12, 2021
bcf3fae
Delete unneeded file copies in bin
gltrost Jul 12, 2021
4233c3b
Add line in .gitlab-ci.yml to run integration tests
gltrost Jul 13, 2021
2fa6cb3
Fix report_to_slack bug by adding post_to_slack subcall
gltrost Jul 20, 2021
7e04003
Change utils testing timeout length from 20.0 to 30.0 seconds
gltrost Jul 21, 2021
0d76e09
Edit small typos in post_to_slack in slack.bash
gltrost Jul 28, 2021
c4b01e8
Add debugging information and functions for reading payload info
gltrost Jul 29, 2021
02aab63
Add curl update command to .gitlab-ci.yml
gltrost Jul 29, 2021
1e8e21a
Add --http1.1 to curl command in common-lib/slack.bash
gltrost Jul 29, 2021
bb26e3f
Fix --http1.1 newline error in common-lib/slack.bash
gltrost Jul 29, 2021
dd1867b
Add function descriptions to common-lib/slack.bash
gltrost Jul 29, 2021
24ce81e
Change print_payload functionality, up timeout for tests from 30.0 to…
gltrost Aug 4, 2021
68cf4a4
Add handling for git-branches, fix print_payload in slack.sh and prin…
gltrost Aug 4, 2021
279ba38
Change directory to wp to properly call test.plugin.integration in ru…
gltrost Aug 4, 2021
dc3a757
Add setup for boolector in bin/setup and add unit-test folder for uni…
gltrost Aug 5, 2021
e65a191
Fix unit messages in unit-tests/run-tests.bash
gltrost Aug 5, 2021
bf52de6
Add stage names to jobs in .gitlab-ci.yml
gltrost Aug 5, 2021
52ed22d
Add bin/common-lib/env.bash to handle boolector installation
gltrost Aug 23, 2021
6bc1ab6
Add APT dependencies to .gitlab-ci.yml to allow for cmake installation
gltrost Aug 24, 2021
e0b7e9f
Fix double-bracket error in slack.bash
gltrost Aug 24, 2021
097e453
Add spaces to line 52 bracks in slack.bash
gltrost Aug 24, 2021
86e3b35
Specify -C for make in intergration test job
jtpaasch Sep 29, 2021
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
45 changes: 39 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,54 @@
# by the CI docker runners.
image: "binaryanalysisplatform/bap:latest"

# JOB: run the tests for WP.
run_wp_tests:
# Order of job-executions (prevents jobs from running in parallel):
stages:
- build_bildb
- run_unit_tests
- run_integration_tests

# JOB: build BilDB.
build_bildb:
stage: build_bildb

tags:
- docker

script:
- make -C bildb

# JOB: run unit tests for WP.
run_unit_tests:
stage: run_unit_tests

tags:
- docker

script:
- make test -C wp

# JOB: build BilDB.
build_bildb:
- bash -x bin/unit-tests/run-tests.bash --report-results

# JOB: run integration tests for WP.
run_integration_tests:
stage: run_integration_tests

tags:
- docker

script:
- make -C bildb
# Install APT dependencies.
- >-
sudo -E apt install -y
qemu gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi cmake


# Install other dependencies (non-sudo).
- bash -x bin/setup/install-dependencies.bash --report-results

# Source environment variables and install cbat tools.
- . bin/common-lib/env.bash
- make -C wp

- make test -C wp
- bash -x bin/integration-tests/run-tests.bash --report-results

18 changes: 18 additions & 0 deletions bin/common-lib/env.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# --------------------------------------------------------------
#
# This script provides some environment variables
# used for running some of the tools.
#
# --------------------------------------------------------------

# Minizinc variables
MINIZINC_URL=https://github.com/MiniZinc/MiniZincIDE/releases/download/2.5.3/MiniZincIDE-2.5.3-bundle-linux-x86_64.tgz
MINIZINC_BUNDLE=MiniZincIDE-2.5.3-bundle-linux-x86_64
MINIZINC_DIR="${HOME}/${MINIZINC_BUNDLE}"
export PATH="${MINIZINC_DIR}/bin":"${PATH}"
export LD_LIBRARY_PATH="${MINIZINC_DIR}/lib":"${LD_LIBRARY_PATH}"

# Boolector variables
BOOLECTOR_URL=https://github.com/boolector/boolector
BOOLECTOR_DIR="${HOME}/boolector"
export PATH="${BOOLECTOR_DIR}/build/bin":"${PATH}"
96 changes: 96 additions & 0 deletions bin/common-lib/slack.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -------------------------------
#
# Utilities for slack integration
#
# -------------------------------

# DESC: Checks if SLACK_USERNAME is defined
# OUTPUT: 0 if SLACK_USERNAME is defined, 1 otherwise
there_is_a_SLACK_USERNAME () {
if [ -z "${SLACK_USERNAME+x}" ];
then return 1;
else return 0;
fi
}

# DESC: Checks if SLACK_URL is defined
# OUTPUT: 0 if SLACK_URL is defined, 1 otherwise
there_is_a_SLACK_URL () {
if [ -z "${SLACK_URL}" ];
then return 1;
else return 0;
fi
}

# DESC: Creates a payload JSON file.
# ARGS: Takes in ${1} argument that must be "true" in order
# to print full report.
# OUTPUT: The exit code of the attempt to write the file.
build_slack_payload () {
local MESSAGE
local BAP
local BRANCH
local COMMIT
local DATA
local TEXT
local VERBOSE
VERBOSE="${1}"
MESSAGE="$(cat "${MSG_FILE}")"
BAP="$(cat "${BAP_VERSION_FILE}")"
BRANCH="$(cat "${GIT_BRANCH_FILE}")"
COMMIT="$(sed -z -e 's/\n/\\n/g' -e 's/\"/\\"/g' "${GIT_COMMIT_FILE}")"
DATA="$(sed -z \
-e 's/\n/\\n/g' \
-e 's/\"/\\"/g' \
-e 's/'\''/\'\''/g' \
-e 's/'\`'/'\`'/g' \
"${REPORT_FILE}")"
TEXT="STATUS: ${MESSAGE}"
TEXT="${TEXT}\nBAP: ${BAP}"
TEXT="${TEXT}\nBRANCH: ${BRANCH}"
TEXT="${TEXT}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`"
if [[ "${VERBOSE}" == "true" ]]; then
TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`"
fi
echo "{
\"username\":\"${SLACK_USERNAME}\",
\"text\":\"${TEXT}\"
}" > "${SLACK_FILE}"
}

#DESC: Prints the payload created in build_slack_payload
print_payload () {
echo "printing payload:"
echo "MESSAGE: $(cat "${MSG_FILE}")"
echo "BAP: $(cat "${BAP_VERSION_FILE}")"
echo "BRANCH: $(cat "${GIT_BRANCH_FILE}")"
echo "COMMIT: $(cat "${GIT_COMMIT_FILE}")"
echo "DATA: $(cat "${REPORT_FILE}")"
}

# DESC: Posts a message to slack
# OUTPUT: The exit code of the curl/POST command
post_to_slack () {
local OUTPUT
local RESULT
OUTPUT="$(curl \
--http1.1 \
-X POST \
-H "Content-Type: application/json" \
-d @"${SLACK_FILE}" \
"${SLACK_URL}")"
RESULT=${?}
echo "${OUTPUT}"
return ${RESULT}
}

# DESC: Reports the current status to slack
# ARGS: Takes in ${1} argument that must be "true" in order
# to print full report.
# OUTPUT: Exit code of the attempt to send status to slack
report_to_slack () {
build_slack_payload "${1}"
print_payload
post_to_slack
}

126 changes: 126 additions & 0 deletions bin/common-lib/utils.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# --------------------------------------------------------------
#
# This script provides some basic utilities
# (used when running system tests).
#
# --------------------------------------------------------------# DESC
# Check if this script is running with bash
# RETURNS
# - 0 if this script is running with bash
# - 1 if not
is_bash () {
if [ -z "${BASH_VERSION}" ];
then return 1;
else return 0;
fi
}
# DESC
# Returns the filename of this script
get_me () {
echo "$(basename "${0}")"
}
# DESC
# Prints a help hint
help_hint () {
local ME
ME="$(get_me)"
echo "See ${ME} --help for usage."
}
# DESC
# Constructs a tmp dir for use by this script
# RETURNS
# The tmp dir name
create_tmp_dir () {
local DIR_NAME
local ME
ME="$(get_me)"
DIR_NAME="$(mktemp -d "${TMPDIR:-/tmp/}${ME}.XXXXXXXXXXXX")"
echo "${DIR_NAME}"
}
# Setup tmp dir/files
TMP_SCRATCH_DIR="$(create_tmp_dir)"
MSG_FILE="${TMP_SCRATCH_DIR}/message.txt"
REPORT_FILE="${TMP_SCRATCH_DIR}/report.txt"
SLACK_FILE="${TMP_SCRATCH_DIR}/data.json"
BAP_VERSION_FILE="${TMP_SCRATCH_DIR}/bap-version.txt"
GIT_BRANCH_FILE="${TMP_SCRATCH_DIR}/git-branch.txt"
GIT_COMMIT_FILE="${TMP_SCRATCH_DIR}/git-commit.txt"
echo "Initializing message...no message yet" > "${MSG_FILE}"
echo "Initializing report...nothing to report yet" > "${REPORT_FILE}"
echo '{"username":"None yet","text":"Nothing yet"}' > "${SLACK_FILE}"
echo "No BAP version to report yet" > "${BAP_VERSION_FILE}"
echo "No branch to report yet" > "${GIT_BRANCH_FILE}"
echo "No commit to report yet" > "${GIT_COMMIT_FILE}"

# DESC
# Get filepath to the REPORT_FILE.
# ARGS
# - 1 : If "true" then return REPORT_FILE.
# Otherwise, return /dev/null.
report_file () {
if [[ "${1}" == "true" ]]; then
echo "${REPORT_FILE}"
else
echo "/dev/null"
fi
}
# DESC
# Record the BAP version
bap_version () {
bap --version > "${BAP_VERSION_FILE}"
echo "BAP_VERSION: $(cat "${BAP_VERSION_FILE}")"
}

# DESC
# Record the current GIT branch
git_branch () {
git branch > "${GIT_BRANCH_FILE}"
echo "GIT_BRANCH: $(cat "${GIT_BRANCH_FILE}")"
}

# DESC
# Record the current GIT commit
git_commit () {
git log -1 > "${GIT_COMMIT_FILE}"
if [[ -z "$(cat "${GIT_COMMIT_FILE}")" ]]; then
echo "${CI_COMMIT_MESSAGE}" > "${GIT_COMMIT_FILE}"
if [[ -z "$(cat "${GIT_COMMIT_FILE}")" ]]; then
echo "No commit message could be obtained" > "${GIT_COMMIT_FILE}"
fi
fi
echo -e "GIT_COMMIT:\n$(cat "${GIT_COMMIT_FILE}")"
}

# DESC
# Cleans up files we've written
clean_up () {
rm -rf "${TMP_SCRATCH_DIR}"
}
# DESC
# Print that we're halting, along with the contents of ${MSG_FILE}.
fail () {
echo "Halting"
echo "$(cat "${MSG_FILE}")"
}
# Ensure we're using Bash.
is_bash
if [ ${?} -ne 0 ]; then
echo "Halting."
echo "This script must be executed with Bash."
return 1
fi
# Where are we?
THIS_SCRIPT="${BASH_SOURCE[0]}"
COMMON_LIB_DIR="$(cd "$(dirname "${THIS_SCRIPT}")" && pwd)"
# Ensure we can find the root of the repo.
REPO_ROOT="$(cd "${COMMON_LIB_DIR}"/../../ && pwd)"
if [ ! -f "${REPO_ROOT}"/.gitlab-ci.yml ]; then
echo "Halting."
echo "Cannot find the repo root."
echo "Looked in REPO ROOT: '${REPO_ROOT}'"
echo "But could not find a .gitlab-ci.yml file."
exit 1
fi
# Where these scripts are all kept.
BIN_DIR="${REPO_ROOT}/bin"

Loading