From eb758cfcb3417cd32bd4dc42c44f52969d8499c6 Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 1 Jul 2021 13:05:41 -0400 Subject: [PATCH 01/23] Change format from Arch to Target when creating registers in test_wp_integration.ml --- wp/plugin/tests/integration/test_wp_integration.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp/plugin/tests/integration/test_wp_integration.ml b/wp/plugin/tests/integration/test_wp_integration.ml index f1df6c9e..f8a01900 100644 --- a/wp/plugin/tests/integration/test_wp_integration.ml +++ b/wp/plugin/tests/integration/test_wp_integration.ml @@ -31,7 +31,7 @@ let integration_tests = List.append [ ~checker:(Some (check_list models)))); "Hash function" >: ( - let registers = get_register_args 5 `x86_64 in + let registers = get_register_args 5 X86_target.amd64 in test_plugin "hash_function" sat ~reg_list:(registers |> StringSet.of_list) ~checker:(Some (check_bad_hash_function registers))); From f33f26cedf275acf4283a00619c3ce7bc65bf106 Mon Sep 17 00:00:00 2001 From: gltrost Date: Mon, 12 Jul 2021 14:48:18 -0400 Subject: [PATCH 02/23] Add bin folder with bash files for running integration tests with slack apps and gitlab --- bin/common-lib/#new# | 1 + bin/common-lib/greg_utils.bash | 125 +++++++++++++++++++++++++++ bin/common-lib/slack.bash | 88 +++++++++++++++++++ bin/common-lib/slack.bash~ | 83 ++++++++++++++++++ bin/common-lib/utils.bash | 113 ++++++++++++++++++++++++ bin/common-lib/utils.bash~ | 113 ++++++++++++++++++++++++ bin/integration-tests/run-tests.bash | 119 +++++++++++++++++++++++++ 7 files changed, 642 insertions(+) create mode 100644 bin/common-lib/#new# create mode 100644 bin/common-lib/greg_utils.bash create mode 100644 bin/common-lib/slack.bash create mode 100644 bin/common-lib/slack.bash~ create mode 100644 bin/common-lib/utils.bash create mode 100644 bin/common-lib/utils.bash~ create mode 100644 bin/integration-tests/run-tests.bash diff --git a/bin/common-lib/#new# b/bin/common-lib/#new# new file mode 100644 index 00000000..2a48d46d --- /dev/null +++ b/bin/common-lib/#new# @@ -0,0 +1 @@ +0COMMIT="$(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' \ \ No newline at end of file diff --git a/bin/common-lib/greg_utils.bash b/bin/common-lib/greg_utils.bash new file mode 100644 index 00000000..f49bf13a --- /dev/null +++ b/bin/common-lib/greg_utils.bash @@ -0,0 +1,125 @@ +# -------------------------------------------- +# +# Basic utilities for bash system tests +# +# -------------------------------------------- + +# DESC: Check if this script is running with bash +# INPUT: this script +# OUTPUT: +# 0 if script is running with bash +# 1 otherwise +is_bash () { + if [-z "${BASH_VERSION}"]; + then return 1; + else return 0; + fi +} + +# DESC: Return file name +get_filename () { + echo "$(basename "${0}")"; +} + +# 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_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 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 commit +# CI_ names are defined in gitlab!!!!!! +# todo: look for predefined vars in gitlab docs +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 were 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"# Where the executables are kept. +EXES_DIR="$(cd "${REPO_ROOT}/resources/exes" && pwd)" diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash new file mode 100644 index 00000000..592f497e --- /dev/null +++ b/bin/common-lib/slack.bash @@ -0,0 +1,88 @@ +# ------------------------------- +# +# Utilities for slack integration +# +# ------------------------------- + +# Food for thought: how to check if var is und +# Idea: is it empty string? +# -z asks env to see if proceeding is empty string +# will return 1 if so, o.t. 0 (aka good) + + +# DESC: +# INPUT: +# OUTPUT: +there_is_a_SLACK_USERNAME () { + if [ -z "${SLACK_USERNAME}" ]; + then return 1; + else return 0; + fi +} + +# DESC: +# INPUT: +# OUTPUT: +there_is_a_SLACK_URL () { + if [ -z "${SLACK_URL}" ]; + then return 1; + else return 0; + fi +} + +# DESC: +# INPUT: +# OUTPUT: +build_slack_payload () { + local MESSAGE + local BAP + local BRANCH #------not used? + local COMMIT + local DATA + local TEXT + MESSAGE="$(cat "${MSG_FILE}")" + BAP="$(cat "${BAP_VERSION_FILE}")" + COMMIT="$(sed -z -e 's/\n/\\n/g' -e 's/\"/\\"/g' "${GIT_COMMIT_FILE}")" + #replace \n, \", '\'' and '\`' with \\n, \\", '\'' and '\`' respectively + 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}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" + TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" + echo "{ + \"username\":\"${SLACK_USERNAME}\", + \"text\":\"${TEXT}\" + }" > "${SLACK_FILE}" +} + +# DESC: Post a message to slack +# INPUT: - +# OUTPUT: The exit code of the curl/POST status +post_to_slack () { + local OUTPUT + local RESULT #------what's the difference between an output and result? + #------ curl (client url) allows you to communicate with a server + OUTPUT="$(curl \ + -X POST \ + -H "Content type: application/json" \ + -d @"${SLACK_FILE}" \ + "${SLACK_URL}")" + RESULT="${?}" + echo "${OUTPUT}" + return "${RESULT}" +} + + +# DESC: +# INPUT: +# OUTPUT: +report_to_slack () { + build_slack_payload + report_to_slack +} + diff --git a/bin/common-lib/slack.bash~ b/bin/common-lib/slack.bash~ new file mode 100644 index 00000000..46fb5612 --- /dev/null +++ b/bin/common-lib/slack.bash~ @@ -0,0 +1,83 @@ +# ------------------------------- +# +# Utilities for slack integration +# +# ------------------------------- + + +# DESC: +# INPUT: +# OUTPUT: +there_is_a_SLACK_USERNAME () { + if [ -z "${SLACK_USERNAME+x}" ]; + then return 1; + else return 0; + fi +} + +# DESC: +# INPUT: +# OUTPUT: +there_is_a_SLACK_URL () { + if [ -z "${SLACK_URL}" ]; + then return 1; + else return 0; + fi +} + +# DESC: +# INPUT: +# OUTPUT: +build_slack_payload () { + local MESSAGE + local BAP + local BRANCH #------not used? + local COMMIT + local DATA + local TEXT + MESSAGE="$(cat "${MSG_FILE}")" + BAP="$(cat "${BAP_VERSION_FILE}")" + COMMIT="$(sed -z -e 's/\n/\\n/g' -e 's/\"/\\"/g' "${GIT_COMMIT_FILE}")" + #replace \n, \", '\'' and '\`' with \\n, \\", '\'' and '\`' respectively + 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}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" + TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" + echo "{ + \"username\":\"${SLACK_USERNAME}\", + \"text\":\"${TEXT}\" + }" > "${SLACK_FILE}" +} + +# DESC: Post a message to slack +# INPUT: - +# OUTPUT: The exit code of the curl/POST status +post_to_slack () { + local OUTPUT + local RESULT #------what's the difference between an output and result? + #------ curl (client url) allows you to communicate with a server + OUTPUT="$(curl \ + -X POST \ + -H "Content type: application/json" \ + -d @"${SLACK_FILE}" \ + "${SLACK_URL}")" + RESULT="${?}" + echo "${OUTPUT}" + return "${RESULT}" +} + + +# DESC: +# INPUT: +# OUTPUT: +report_to_slack () { + build_slack_payload + report_to_slack +} + diff --git a/bin/common-lib/utils.bash b/bin/common-lib/utils.bash new file mode 100644 index 00000000..5eb1bb45 --- /dev/null +++ b/bin/common-lib/utils.bash @@ -0,0 +1,113 @@ +# -------------------------------------------------------------- +# +# 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_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 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 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" + diff --git a/bin/common-lib/utils.bash~ b/bin/common-lib/utils.bash~ new file mode 100644 index 00000000..986b7849 --- /dev/null +++ b/bin/common-lib/utils.bash~ @@ -0,0 +1,113 @@ +# -------------------------------------------------------------- +# +# 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_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 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 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" + diff --git a/bin/integration-tests/run-tests.bash b/bin/integration-tests/run-tests.bash new file mode 100644 index 00000000..f6cdb891 --- /dev/null +++ b/bin/integration-tests/run-tests.bash @@ -0,0 +1,119 @@ +# ------------------------- +# +# Run the integration tests +# +# ------------------------- + +# Define useful paths +THIS_SCRIPT="${BASH_SOURCE[0]}" +THIS_DIR="$(cd "$(dirname "${THIS_SCRIPT}")" && pwd)" +COMMON_LIB_DIR="$(cd "${THIS_DIR}/../common-lib" && pwd)" + +# Include needed libraries +. "${COMMON_LIB_DIR}/utils.bash" +. "${COMMON_LIB_DIR}/slack.bash" + +# Report progress to slack? +REPORT_PROGRESS="false" + +usage () { + echo "USAGE: bash [OPTIONS]" + echo "" + echo " Run the integration tests." + echo "" + echo "OPTIONS" + echo " -h | --help Print this help and exit" + echo " --report-results Report the results to slack" +} + + +#-----what does "#" do? +# # number of args +# todo: simple script using +# arith mode: (()) +while ((${#})); do + case "${1}" in + + -h|--help) + usage + exit 1 + ;; + + --report-results) + REPORT_RESULTS="true" + ;; + + *) + echo "Unrecognized input ${1}" + help_hint + exit 1 + ;; + esac + shift #remove front one and move up one, and then renumbering +done + +#Todo: exit 1 +#Todo: Try running ls -la /tmp + + +# Call `clean up` before the script ends +# When OS throws signal, one is exit. +# When throws exits, catch it, then call cleanup, +# Then rethrow exit +trap clean_up EXIT + +# Ensures we have a slack URL to post with +if [[ "${REPORT_RESULTS}"=="true" ]]; then + there_is_a_SLACK_USERNAME + # single [ is "test" + # todo: google "test" for command line + if [ ${?} -ne 0 ];then + echo "Halting." + echo "Need a SLACK_USERNAME environment variable." + echo "Export one to proceed." + exit 1 + fi + there_is_a_SLACK_URL + # maybe the same as (( ${?} = 0 )) + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_URL environment variable." + echo "Export one to proceed." + exit 1 + fi +fi + +# Where to record progress +REPORT="$(report_file "${REPORT_RESULTS}")" #------report_file + +# Record some useful info +bap_version +git_commit + +echo "" + +# Prep for the test runs. +#------REPO_ROOT +#------tee? +make clean "${REPO_ROOT}"/cbat_tools 2>&1 | tee "${REPORT_FILE}" + +# Todo: test global/context stuff with vars ??? + +# Run the integration tests. +make test.integration -C "${REPO_ROOT}" 2>&1 | tee -a "${REPORT_FILE}" +TEST_RESULT="${?}" +echo "REPORT:" +cat "${REPORT_FILE}" +if [[ "${TEST_RESULT}" != "0" ]]; then + echo "Integration tests failed" > "${MSG_FILE}" + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack + fi + fail + exit 1 +else + echo "Integration tests passed" > "${MSG_FILE}" + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack + fi +fi From bcf3fae2584277fdd07202f0a78f81327a8f4420 Mon Sep 17 00:00:00 2001 From: gltrost Date: Mon, 12 Jul 2021 17:19:42 -0400 Subject: [PATCH 03/23] Delete unneeded file copies in bin --- bin/common-lib/#new# | 1 - bin/common-lib/slack.bash~ | 83 -------------------- bin/common-lib/utils.bash~ | 113 --------------------------- bin/integration-tests/run-tests.bash | 1 - 4 files changed, 198 deletions(-) delete mode 100644 bin/common-lib/#new# delete mode 100644 bin/common-lib/slack.bash~ delete mode 100644 bin/common-lib/utils.bash~ diff --git a/bin/common-lib/#new# b/bin/common-lib/#new# deleted file mode 100644 index 2a48d46d..00000000 --- a/bin/common-lib/#new# +++ /dev/null @@ -1 +0,0 @@ -0COMMIT="$(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' \ \ No newline at end of file diff --git a/bin/common-lib/slack.bash~ b/bin/common-lib/slack.bash~ deleted file mode 100644 index 46fb5612..00000000 --- a/bin/common-lib/slack.bash~ +++ /dev/null @@ -1,83 +0,0 @@ -# ------------------------------- -# -# Utilities for slack integration -# -# ------------------------------- - - -# DESC: -# INPUT: -# OUTPUT: -there_is_a_SLACK_USERNAME () { - if [ -z "${SLACK_USERNAME+x}" ]; - then return 1; - else return 0; - fi -} - -# DESC: -# INPUT: -# OUTPUT: -there_is_a_SLACK_URL () { - if [ -z "${SLACK_URL}" ]; - then return 1; - else return 0; - fi -} - -# DESC: -# INPUT: -# OUTPUT: -build_slack_payload () { - local MESSAGE - local BAP - local BRANCH #------not used? - local COMMIT - local DATA - local TEXT - MESSAGE="$(cat "${MSG_FILE}")" - BAP="$(cat "${BAP_VERSION_FILE}")" - COMMIT="$(sed -z -e 's/\n/\\n/g' -e 's/\"/\\"/g' "${GIT_COMMIT_FILE}")" - #replace \n, \", '\'' and '\`' with \\n, \\", '\'' and '\`' respectively - 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}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" - TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" - echo "{ - \"username\":\"${SLACK_USERNAME}\", - \"text\":\"${TEXT}\" - }" > "${SLACK_FILE}" -} - -# DESC: Post a message to slack -# INPUT: - -# OUTPUT: The exit code of the curl/POST status -post_to_slack () { - local OUTPUT - local RESULT #------what's the difference between an output and result? - #------ curl (client url) allows you to communicate with a server - OUTPUT="$(curl \ - -X POST \ - -H "Content type: application/json" \ - -d @"${SLACK_FILE}" \ - "${SLACK_URL}")" - RESULT="${?}" - echo "${OUTPUT}" - return "${RESULT}" -} - - -# DESC: -# INPUT: -# OUTPUT: -report_to_slack () { - build_slack_payload - report_to_slack -} - diff --git a/bin/common-lib/utils.bash~ b/bin/common-lib/utils.bash~ deleted file mode 100644 index 986b7849..00000000 --- a/bin/common-lib/utils.bash~ +++ /dev/null @@ -1,113 +0,0 @@ -# -------------------------------------------------------------- -# -# 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_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 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 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" - diff --git a/bin/integration-tests/run-tests.bash b/bin/integration-tests/run-tests.bash index f6cdb891..9aac3b34 100644 --- a/bin/integration-tests/run-tests.bash +++ b/bin/integration-tests/run-tests.bash @@ -55,7 +55,6 @@ done #Todo: exit 1 #Todo: Try running ls -la /tmp - # Call `clean up` before the script ends # When OS throws signal, one is exit. # When throws exits, catch it, then call cleanup, From 4233c3b2c5d49525fd61750340abe18b1491edf1 Mon Sep 17 00:00:00 2001 From: gltrost Date: Tue, 13 Jul 2021 18:49:32 -0400 Subject: [PATCH 04/23] Add line in .gitlab-ci.yml to run integration tests --- .gitlab-ci.yml | 3 +- bin/common-lib/greg_utils.bash | 125 --------------------------------- 2 files changed, 2 insertions(+), 126 deletions(-) delete mode 100644 bin/common-lib/greg_utils.bash diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d223409e..b5147a1b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,8 @@ run_wp_tests: script: - make test -C wp - + - bash -x bin/integration-tests/run-tests.bash --report-results + # JOB: build BilDB. build_bildb: diff --git a/bin/common-lib/greg_utils.bash b/bin/common-lib/greg_utils.bash deleted file mode 100644 index f49bf13a..00000000 --- a/bin/common-lib/greg_utils.bash +++ /dev/null @@ -1,125 +0,0 @@ -# -------------------------------------------- -# -# Basic utilities for bash system tests -# -# -------------------------------------------- - -# DESC: Check if this script is running with bash -# INPUT: this script -# OUTPUT: -# 0 if script is running with bash -# 1 otherwise -is_bash () { - if [-z "${BASH_VERSION}"]; - then return 1; - else return 0; - fi -} - -# DESC: Return file name -get_filename () { - echo "$(basename "${0}")"; -} - -# 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_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 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 commit -# CI_ names are defined in gitlab!!!!!! -# todo: look for predefined vars in gitlab docs -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 were 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"# Where the executables are kept. -EXES_DIR="$(cd "${REPO_ROOT}/resources/exes" && pwd)" From 2fa6cb3c06511430b5190a9e9d5c4d4da0786221 Mon Sep 17 00:00:00 2001 From: gltrost Date: Tue, 20 Jul 2021 15:00:19 -0400 Subject: [PATCH 05/23] Fix report_to_slack bug by adding post_to_slack subcall --- bin/common-lib/slack.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 592f497e..345cd600 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -83,6 +83,6 @@ post_to_slack () { # OUTPUT: report_to_slack () { build_slack_payload - report_to_slack + post_to_slack } From 7e0400339920b1e8fd2a0a99337a9e3347009322 Mon Sep 17 00:00:00 2001 From: gltrost Date: Wed, 21 Jul 2021 11:58:23 -0400 Subject: [PATCH 06/23] Change utils testing timeout length from 20.0 to 30.0 seconds --- wp/plugin/tests/test_libs/test_wp_utils.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp/plugin/tests/test_libs/test_wp_utils.ml b/wp/plugin/tests/test_libs/test_wp_utils.ml index 1f4d2f5c..6cf966f2 100644 --- a/wp/plugin/tests/test_libs/test_wp_utils.ml +++ b/wp/plugin/tests/test_libs/test_wp_utils.ml @@ -293,9 +293,9 @@ let check_bad_hash_function (registers : string list) : ((string StringMap.t) -> - Short (60.0 s) - Long (600.0 s) - Huge (1800.0 s) - but by default, CBAT uses a custom length of 20.0 seconds. *) + but by default, CBAT uses a custom length of 30.0 seconds. *) let test_plugin - ?length:(length = Custom_length 20.0) + ?length:(length = Custom_length 30.0) ?script:(script = "run_wp.sh") ?args:(args = []) ?reg_list:(reg_list = StringSet.empty) From 0d76e09f6096246fb486b44a0c5727c1f95bfdf3 Mon Sep 17 00:00:00 2001 From: gltrost Date: Wed, 28 Jul 2021 18:01:41 -0400 Subject: [PATCH 07/23] Edit small typos in post_to_slack in slack.bash --- bin/common-lib/slack.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 345cd600..7e706241 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -72,9 +72,9 @@ post_to_slack () { -H "Content type: application/json" \ -d @"${SLACK_FILE}" \ "${SLACK_URL}")" - RESULT="${?}" + RESULT=${?} echo "${OUTPUT}" - return "${RESULT}" + return ${RESULT} } From c4b01e891abc41752e58162f1a550874fbe085df Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 29 Jul 2021 12:58:11 -0400 Subject: [PATCH 08/23] Add debugging information and functions for reading payload info --- bin/common-lib/slack.bash | 21 +++++++++++++++------ bin/integration-tests/run-tests.bash | 4 ++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 7e706241..13d4cc68 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -60,13 +60,22 @@ build_slack_payload () { }" > "${SLACK_FILE}" } -# DESC: Post a message to slack -# INPUT: - -# OUTPUT: The exit code of the curl/POST status +# The print_payload function is for debugging purposes: +print_payload () { + echo "printing payload:" + echo "MESSAGE: ${MESSAGE}" + echo "BAP: ${BAP}" + echo "BRANCH: ${BRANCH}" + echo "COMMIT: ${COMMIT}" + echo "DATA: ${DATA}" + echo "TEXT: ${TEXT}" +} + +# DESC: Posts a message to slack +# OUTPUT: The exit code of the curl/POST command post_to_slack () { local OUTPUT - local RESULT #------what's the difference between an output and result? - #------ curl (client url) allows you to communicate with a server + local RESULT OUTPUT="$(curl \ -X POST \ -H "Content type: application/json" \ @@ -77,12 +86,12 @@ post_to_slack () { return ${RESULT} } - # DESC: # INPUT: # OUTPUT: report_to_slack () { build_slack_payload + print_payload post_to_slack } diff --git a/bin/integration-tests/run-tests.bash b/bin/integration-tests/run-tests.bash index 9aac3b34..9c609663 100644 --- a/bin/integration-tests/run-tests.bash +++ b/bin/integration-tests/run-tests.bash @@ -116,3 +116,7 @@ else report_to_slack fi fi + +echo "curl version:" +curl --version +print_payload From 02aab63f6dc55296c4cda7d9223f902f77b52451 Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 29 Jul 2021 15:01:11 -0400 Subject: [PATCH 09/23] Add curl update command to .gitlab-ci.yml --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5147a1b..a98d08db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,6 +10,7 @@ run_wp_tests: - docker script: + - apk add --update curl && rm -rf /var/cache/apk/* - make test -C wp - bash -x bin/integration-tests/run-tests.bash --report-results From 1e8e21a68485d8992b8b7953ca9689f566cb53a4 Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 29 Jul 2021 15:51:38 -0400 Subject: [PATCH 10/23] Add --http1.1 to curl command in common-lib/slack.bash --- .gitlab-ci.yml | 1 - bin/common-lib/slack.bash | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a98d08db..b5147a1b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,6 @@ run_wp_tests: - docker script: - - apk add --update curl && rm -rf /var/cache/apk/* - make test -C wp - bash -x bin/integration-tests/run-tests.bash --report-results diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 13d4cc68..06835d81 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -77,6 +77,7 @@ post_to_slack () { local OUTPUT local RESULT OUTPUT="$(curl \ + --http1.1 -X POST \ -H "Content type: application/json" \ -d @"${SLACK_FILE}" \ From bb26e3fcbc6bef868a84950ca00507c0db733f2a Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 29 Jul 2021 15:53:06 -0400 Subject: [PATCH 11/23] Fix --http1.1 newline error in common-lib/slack.bash --- bin/common-lib/slack.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 06835d81..d71a9b96 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -77,7 +77,7 @@ post_to_slack () { local OUTPUT local RESULT OUTPUT="$(curl \ - --http1.1 + --http1.1 \ -X POST \ -H "Content type: application/json" \ -d @"${SLACK_FILE}" \ From dd1867b5a78001d989c23b98c0ab4bbccc471095 Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 29 Jul 2021 16:24:28 -0400 Subject: [PATCH 12/23] Add function descriptions to common-lib/slack.bash --- bin/common-lib/slack.bash | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index d71a9b96..12a756d3 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -4,15 +4,8 @@ # # ------------------------------- -# Food for thought: how to check if var is und -# Idea: is it empty string? -# -z asks env to see if proceeding is empty string -# will return 1 if so, o.t. 0 (aka good) - - -# DESC: -# INPUT: -# OUTPUT: +# 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}" ]; then return 1; @@ -20,9 +13,8 @@ there_is_a_SLACK_USERNAME () { fi } -# DESC: -# INPUT: -# OUTPUT: +# 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; @@ -30,9 +22,8 @@ there_is_a_SLACK_URL () { fi } -# DESC: -# INPUT: -# OUTPUT: +# DESC: Creates a payload JSON file. +# OUTPUT: The exit code of the attempt to write the file. build_slack_payload () { local MESSAGE local BAP @@ -60,7 +51,7 @@ build_slack_payload () { }" > "${SLACK_FILE}" } -# The print_payload function is for debugging purposes: +#DESC: Prints the payload created in build_slack_payload print_payload () { echo "printing payload:" echo "MESSAGE: ${MESSAGE}" @@ -87,9 +78,8 @@ post_to_slack () { return ${RESULT} } -# DESC: -# INPUT: -# OUTPUT: +# DESC: Reports the current status to slack +# OUTPUT: Exit code of the attempt to send status to slack report_to_slack () { build_slack_payload print_payload From 24ce81e78144d2719a4036b21dc0fae4ef85df98 Mon Sep 17 00:00:00 2001 From: gltrost Date: Wed, 4 Aug 2021 08:51:39 -0400 Subject: [PATCH 13/23] Change print_payload functionality, up timeout for tests from 30.0 to 40. seconds, and fix comments in bin/bash commands --- bin/common-lib/#utils.bash# | 112 +++++++++++++++++++++ bin/common-lib/new | 103 +++++++++++++++++++ bin/common-lib/new~ | 84 ++++++++++++++++ bin/common-lib/slack.bash | 31 +++--- bin/integration-tests/run-tests.bash | 81 ++++++--------- wp/plugin/tests/test_libs/test_wp_utils.ml | 4 +- 6 files changed, 349 insertions(+), 66 deletions(-) create mode 100644 bin/common-lib/#utils.bash# create mode 100644 bin/common-lib/new create mode 100644 bin/common-lib/new~ diff --git a/bin/common-lib/#utils.bash# b/bin/common-lib/#utils.bash# new file mode 100644 index 00000000..e2fe9e12 --- /dev/null +++ b/bin/common-lib/#utils.bash# @@ -0,0 +1,112 @@ +# -------------------------------------------------------------- +# +# 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_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 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 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" \ No newline at end of file diff --git a/bin/common-lib/new b/bin/common-lib/new new file mode 100644 index 00000000..6eb92a1d --- /dev/null +++ b/bin/common-lib/new @@ -0,0 +1,103 @@ +# -------------------------------------------------------------- +# +# Run the integration tests. +# +# -------------------------------------------------------------- + +# Define some paths. +THIS_SCRIPT="${BASH_SOURCE[0]}" +THIS_DIR="$(cd "$(dirname "${THIS_SCRIPT}")" && pwd)" +COMMON_LIB_DIR="$(cd "${THIS_DIR}/../common-lib" && pwd)" + +# Include the relevant libraries. +. "${COMMON_LIB_DIR}/utils.bash" +. "${COMMON_LIB_DIR}/slack.bash" + +# Report progress to slack? +REPORT_RESULTS="false" + +# Usage message +usage () { + echo "USAGE: bash $(get_me) [OPTIONS]" + echo "" + echo " Run the integration tests." + echo "" + echo "OPTIONS" + echo " -h | --help Print this help and exit" + echo " --report-results Report the results to slack" +} + +# Parse the command line arguments. +while (( "${#}" )); do + case "${1}" in + + -h|--help) + usage + exit 1 + ;; + + --report-results) + REPORT_RESULTS="true" + ;; + + *) + echo "Unrecognized argument: ${1}" + help_hint + exit 1 + ;; + + esac + shift +done + +# Call `clean_up` before the script exits. +trap clean_up EXIT + +# Ensure we have a slack username and URL to post with. +if [[ "${REPORT_RESULTS}" == "true" ]]; then + there_is_a_SLACK_USERNAME + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_USERNAME environment variable." + echo "Export one to proceed." + exit 1 + fi + there_is_a_SLACK_URL + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_URL environment variable." + echo "Export one to proceed." + exit 1 + fi +fi + +# Where to record progress. +REPORT="$(report_file "${REPORT_RESULTS}")" + +# Record some useful info. +bap_version +git_commit + +echo "" + +# Prep for test runs. +make clean -C "${REPO_ROOT}"/bap-vibes 2>&1 | tee "${REPORT_FILE}" + +# Run the integration tests. +make test.integration -C "${REPO_ROOT}" 2>&1 | tee -a "${REPORT_FILE}" +TEST_RESULT="${?}" +echo "REPORT:" +cat "${REPORT_FILE}" +if [[ "${TEST_RESULT}" != "0" ]]; then + echo "Integration tests failed" > "${MSG_FILE}" + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack + fi + fail + exit 1 +else + echo "Integration tests passed" > "${MSG_FILE}" + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack + fi +fi \ No newline at end of file diff --git a/bin/common-lib/new~ b/bin/common-lib/new~ new file mode 100644 index 00000000..65877d5a --- /dev/null +++ b/bin/common-lib/new~ @@ -0,0 +1,84 @@ +# -------------------------------------------------------------- +# +# +# -------------------------------------------------------------- + +# DESC +# RETURNS +# - 0 if it is defined/non-empty +# - 1 otherwise +there_is_a_SLACK_USERNAME () { + if [ -z "${SLACK_USERNAME+x}" ]; + then return 1; + else return 0; + fi +} + +# DESC +# Check if a SLACK_URL environment variable is defined/non-empty. +# RETURNS +# - 0 if it is defined/non-empty +# - 1 otherwise +there_is_a_SLACK_URL () { + if [ -z "${SLACK_URL}" ]; + then return 1; + else return 0; + fi +} + +# DESC +# Build a slack payload (a JSON file) to send. +# The contents are constructed from ${MSG_FILE} and ${REPORT_FILE}. +# RETURNS +# 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 + MESSAGE="$(cat "${MSG_FILE}")" + BAP="$(cat "${BAP_VERSION_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}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" + TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" + echo "{ + \"username\":\"${SLACK_USERNAME}\", + \"text\":\"${TEXT}\" + }" > "${SLACK_FILE}" +} + +# DESC +# Post a message to slack +# RETURNS +# The exit code of the curl/POST command +post_to_slack () { + local OUTPUT + local RESULT + OUTPUT="$(curl \ + -X POST \ + -H "Content-Type: application/json" \ + -d @"${SLACK_FILE}" \ + "${SLACK_URL}")" + RESULT=${?} + echo "${OUTPUT}" + return ${RESULT} +} + +# DESC +# Report the current status of things to slack. +# RETURNS +# The exit code of the attempt to send the message to slack. +report_to_slack () { + build_slack_payload + post_to_slack +} \ No newline at end of file diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 12a756d3..6c78e880 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -7,7 +7,7 @@ # 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}" ]; + if [ -z "${SLACK_USERNAME+x}" ]; then return 1; else return 0; fi @@ -27,14 +27,13 @@ there_is_a_SLACK_URL () { build_slack_payload () { local MESSAGE local BAP - local BRANCH #------not used? + local BRANCH local COMMIT local DATA local TEXT MESSAGE="$(cat "${MSG_FILE}")" BAP="$(cat "${BAP_VERSION_FILE}")" COMMIT="$(sed -z -e 's/\n/\\n/g' -e 's/\"/\\"/g' "${GIT_COMMIT_FILE}")" - #replace \n, \", '\'' and '\`' with \\n, \\", '\'' and '\`' respectively DATA="$(sed -z \ -e 's/\n/\\n/g' \ -e 's/\"/\\"/g' \ @@ -51,28 +50,28 @@ build_slack_payload () { }" > "${SLACK_FILE}" } -#DESC: Prints the payload created in build_slack_payload +#DESC: Prints the payload created in build_slack_payload print_payload () { echo "printing payload:" - echo "MESSAGE: ${MESSAGE}" - echo "BAP: ${BAP}" - echo "BRANCH: ${BRANCH}" - echo "COMMIT: ${COMMIT}" - echo "DATA: ${DATA}" - echo "TEXT: ${TEXT}" + echo "MESSAGE: $MESSAGE" + echo "BAP: $BAP" + echo "BRANCH: $BRANCH" + echo "COMMIT: $COMMIT" + echo "DATA: $DATA" + echo "TEXT: $TEXT" } # DESC: Posts a message to slack # OUTPUT: The exit code of the curl/POST command post_to_slack () { local OUTPUT - local RESULT + local RESULT OUTPUT="$(curl \ - --http1.1 \ - -X POST \ - -H "Content type: application/json" \ - -d @"${SLACK_FILE}" \ - "${SLACK_URL}")" + --http1.1 \ + -X POST \ + -H "Content-Type: application/json" \ + -d @"${SLACK_FILE}" \ + "${SLACK_URL}")" RESULT=${?} echo "${OUTPUT}" return ${RESULT} diff --git a/bin/integration-tests/run-tests.bash b/bin/integration-tests/run-tests.bash index 9c609663..e1e3f264 100644 --- a/bin/integration-tests/run-tests.bash +++ b/bin/integration-tests/run-tests.bash @@ -26,35 +26,29 @@ usage () { echo " --report-results Report the results to slack" } - -#-----what does "#" do? -# # number of args -# todo: simple script using -# arith mode: (()) -while ((${#})); do +# Parse command line arguments +while (( "${#}" )); do case "${1}" in - - -h|--help) - usage - exit 1 - ;; - - --report-results) - REPORT_RESULTS="true" - ;; - - *) - echo "Unrecognized input ${1}" - help_hint - exit 1 - ;; + + -h|--help) + usage + exit 1 + ;; + + --report-results) + REPORT_RESULTS="true" + ;; + + *) + echo "Unrecognized argument: ${1}" + help_hint + exit 1 + ;; + esac - shift #remove front one and move up one, and then renumbering + shift done -#Todo: exit 1 -#Todo: Try running ls -la /tmp - # Call `clean up` before the script ends # When OS throws signal, one is exit. # When throws exits, catch it, then call cleanup, @@ -62,28 +56,25 @@ done trap clean_up EXIT # Ensures we have a slack URL to post with -if [[ "${REPORT_RESULTS}"=="true" ]]; then +if [[ "${REPORT_RESULTS}" == "true" ]]; then there_is_a_SLACK_USERNAME - # single [ is "test" - # todo: google "test" for command line - if [ ${?} -ne 0 ];then - echo "Halting." - echo "Need a SLACK_USERNAME environment variable." - echo "Export one to proceed." - exit 1 + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_USERNAME environment variable." + echo "Export one to proceed." + exit 1 fi there_is_a_SLACK_URL - # maybe the same as (( ${?} = 0 )) if [ ${?} -ne 0 ]; then - echo "Halting." - echo "Need a SLACK_URL environment variable." - echo "Export one to proceed." - exit 1 + echo "Halting." + echo "Need a SLACK_URL environment variable." + echo "Export one to proceed." + exit 1 fi fi # Where to record progress -REPORT="$(report_file "${REPORT_RESULTS}")" #------report_file +REPORT="$(report_file "${REPORT_RESULTS}")" # Record some useful info bap_version @@ -92,8 +83,6 @@ git_commit echo "" # Prep for the test runs. -#------REPO_ROOT -#------tee? make clean "${REPO_ROOT}"/cbat_tools 2>&1 | tee "${REPORT_FILE}" # Todo: test global/context stuff with vars ??? @@ -102,21 +91,17 @@ make clean "${REPO_ROOT}"/cbat_tools 2>&1 | tee "${REPORT_FILE}" make test.integration -C "${REPO_ROOT}" 2>&1 | tee -a "${REPORT_FILE}" TEST_RESULT="${?}" echo "REPORT:" -cat "${REPORT_FILE}" +cat "${REPORT_FILE}" if [[ "${TEST_RESULT}" != "0" ]]; then echo "Integration tests failed" > "${MSG_FILE}" if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack + report_to_slack fi fail exit 1 else echo "Integration tests passed" > "${MSG_FILE}" if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack + report_to_slack fi fi - -echo "curl version:" -curl --version -print_payload diff --git a/wp/plugin/tests/test_libs/test_wp_utils.ml b/wp/plugin/tests/test_libs/test_wp_utils.ml index 6cf966f2..b2fefaec 100644 --- a/wp/plugin/tests/test_libs/test_wp_utils.ml +++ b/wp/plugin/tests/test_libs/test_wp_utils.ml @@ -293,9 +293,9 @@ let check_bad_hash_function (registers : string list) : ((string StringMap.t) -> - Short (60.0 s) - Long (600.0 s) - Huge (1800.0 s) - but by default, CBAT uses a custom length of 30.0 seconds. *) + but by default, CBAT uses a custom length of 40.0 seconds. *) let test_plugin - ?length:(length = Custom_length 30.0) + ?length:(length = Custom_length 40.0) ?script:(script = "run_wp.sh") ?args:(args = []) ?reg_list:(reg_list = StringSet.empty) From 68cf4a4ab6dae383c1140f797fa042399f0ed559 Mon Sep 17 00:00:00 2001 From: gltrost Date: Wed, 4 Aug 2021 12:12:13 -0400 Subject: [PATCH 14/23] Add handling for git-branches, fix print_payload in slack.sh and printing verbose information only when errors occur in tests --- bin/common-lib/#utils.bash# | 112 --------------------------- bin/common-lib/slack.bash | 27 ++++--- bin/common-lib/utils.bash | 15 +++- bin/integration-tests/run-tests.bash | 7 +- 4 files changed, 36 insertions(+), 125 deletions(-) delete mode 100644 bin/common-lib/#utils.bash# diff --git a/bin/common-lib/#utils.bash# b/bin/common-lib/#utils.bash# deleted file mode 100644 index e2fe9e12..00000000 --- a/bin/common-lib/#utils.bash# +++ /dev/null @@ -1,112 +0,0 @@ -# -------------------------------------------------------------- -# -# 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_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 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 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" \ No newline at end of file diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 6c78e880..1564fcb0 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -23,6 +23,8 @@ there_is_a_SLACK_URL () { } # 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 @@ -31,8 +33,11 @@ build_slack_payload () { 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' \ @@ -42,8 +47,11 @@ build_slack_payload () { "${REPORT_FILE}")" TEXT="STATUS: ${MESSAGE}" TEXT="${TEXT}\nBAP: ${BAP}" + TEXT="${TEXT}\nBRANCH: ${BRANCH}" TEXT="${TEXT}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" - TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" + if [["${VERBOSE}" == "true"]]; then + TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" + fi echo "{ \"username\":\"${SLACK_USERNAME}\", \"text\":\"${TEXT}\" @@ -53,12 +61,11 @@ build_slack_payload () { #DESC: Prints the payload created in build_slack_payload print_payload () { echo "printing payload:" - echo "MESSAGE: $MESSAGE" - echo "BAP: $BAP" - echo "BRANCH: $BRANCH" - echo "COMMIT: $COMMIT" - echo "DATA: $DATA" - echo "TEXT: $TEXT" + 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 @@ -78,9 +85,11 @@ post_to_slack () { } # 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 +report_to_slack () { + build_slack_payload "${1}" print_payload post_to_slack } diff --git a/bin/common-lib/utils.bash b/bin/common-lib/utils.bash index 5eb1bb45..4ddf4a51 100644 --- a/bin/common-lib/utils.bash +++ b/bin/common-lib/utils.bash @@ -43,12 +43,16 @@ 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 commit to report yet" > "${GIT_COMMIT_FILE}"# DESC +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. @@ -66,6 +70,14 @@ 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 () { @@ -78,6 +90,7 @@ git_commit () { fi echo -e "GIT_COMMIT:\n$(cat "${GIT_COMMIT_FILE}")" } + # DESC # Cleans up files we've written clean_up () { diff --git a/bin/integration-tests/run-tests.bash b/bin/integration-tests/run-tests.bash index e1e3f264..bb432cb0 100644 --- a/bin/integration-tests/run-tests.bash +++ b/bin/integration-tests/run-tests.bash @@ -78,6 +78,7 @@ REPORT="$(report_file "${REPORT_RESULTS}")" # Record some useful info bap_version +git_branch git_commit echo "" @@ -93,15 +94,15 @@ TEST_RESULT="${?}" echo "REPORT:" cat "${REPORT_FILE}" if [[ "${TEST_RESULT}" != "0" ]]; then - echo "Integration tests failed" > "${MSG_FILE}" + echo "Integration tests failed" > "${MSG_FILE}" #summary if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack + report_to_slack "true" fi fail exit 1 else echo "Integration tests passed" > "${MSG_FILE}" if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack + report_to_slack "false" fi fi From 279ba381c49d8c82eb8d4d01ee0cbad0491cdba3 Mon Sep 17 00:00:00 2001 From: gltrost Date: Wed, 4 Aug 2021 15:29:49 -0400 Subject: [PATCH 15/23] Change directory to wp to properly call test.plugin.integration in run-tests.bash --- bin/integration-tests/run-tests.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/integration-tests/run-tests.bash b/bin/integration-tests/run-tests.bash index bb432cb0..b12465f6 100644 --- a/bin/integration-tests/run-tests.bash +++ b/bin/integration-tests/run-tests.bash @@ -84,12 +84,12 @@ git_commit echo "" # Prep for the test runs. -make clean "${REPO_ROOT}"/cbat_tools 2>&1 | tee "${REPORT_FILE}" +make -C "${REPO_ROOT}"/wp clean 2>&1 | tee "${REPORT_FILE}" # Todo: test global/context stuff with vars ??? # Run the integration tests. -make test.integration -C "${REPO_ROOT}" 2>&1 | tee -a "${REPORT_FILE}" +make -C "${REPO_ROOT}"/wp test.plugin.integration 2>&1 | tee -a "${REPORT_FILE}" TEST_RESULT="${?}" echo "REPORT:" cat "${REPORT_FILE}" From dc3a757834fc957b8965a37ffa1af3f4ef1257bd Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 5 Aug 2021 14:31:08 -0400 Subject: [PATCH 16/23] Add setup for boolector in bin/setup and add unit-test folder for unit tests --- .gitlab-ci.yml | 31 ++++- bin/common-lib/new~ | 84 ----------- bin/integration-tests/run-tests.bash | 2 - bin/setup/install-dependencies.bash | 131 ++++++++++++++++++ bin/unit-tests/run-tests.bash | 106 ++++++++++++++ .../new => unit-tests/run-tests.bash~} | 49 ++++--- 6 files changed, 289 insertions(+), 114 deletions(-) delete mode 100644 bin/common-lib/new~ create mode 100644 bin/setup/install-dependencies.bash create mode 100644 bin/unit-tests/run-tests.bash rename bin/{common-lib/new => unit-tests/run-tests.bash~} (63%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5147a1b..71c8ce53 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,22 +3,41 @@ # 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: + + tags: + - docker + + script: + - make -C bildb + +# JOB: run unit tests for WP. +run_unit_tests: tags: - docker script: - make test -C wp - - bash -x bin/integration-tests/run-tests.bash --report-results + - bash -x bin/unit-tests/run-tests.bash --report-results -# JOB: build BilDB. -build_bildb: +# JOB: run integration tests for WP. +run_integration_tests: tags: - docker script: - - make -C bildb + # Install other dependencies (non-sudo). + - bash -x bin/setup/install-dependencies.bash --report-results + + - make test -C wp + - bash -x bin/integration-tests/run-tests.bash --report-results diff --git a/bin/common-lib/new~ b/bin/common-lib/new~ deleted file mode 100644 index 65877d5a..00000000 --- a/bin/common-lib/new~ +++ /dev/null @@ -1,84 +0,0 @@ -# -------------------------------------------------------------- -# -# -# -------------------------------------------------------------- - -# DESC -# RETURNS -# - 0 if it is defined/non-empty -# - 1 otherwise -there_is_a_SLACK_USERNAME () { - if [ -z "${SLACK_USERNAME+x}" ]; - then return 1; - else return 0; - fi -} - -# DESC -# Check if a SLACK_URL environment variable is defined/non-empty. -# RETURNS -# - 0 if it is defined/non-empty -# - 1 otherwise -there_is_a_SLACK_URL () { - if [ -z "${SLACK_URL}" ]; - then return 1; - else return 0; - fi -} - -# DESC -# Build a slack payload (a JSON file) to send. -# The contents are constructed from ${MSG_FILE} and ${REPORT_FILE}. -# RETURNS -# 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 - MESSAGE="$(cat "${MSG_FILE}")" - BAP="$(cat "${BAP_VERSION_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}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" - TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" - echo "{ - \"username\":\"${SLACK_USERNAME}\", - \"text\":\"${TEXT}\" - }" > "${SLACK_FILE}" -} - -# DESC -# Post a message to slack -# RETURNS -# The exit code of the curl/POST command -post_to_slack () { - local OUTPUT - local RESULT - OUTPUT="$(curl \ - -X POST \ - -H "Content-Type: application/json" \ - -d @"${SLACK_FILE}" \ - "${SLACK_URL}")" - RESULT=${?} - echo "${OUTPUT}" - return ${RESULT} -} - -# DESC -# Report the current status of things to slack. -# RETURNS -# The exit code of the attempt to send the message to slack. -report_to_slack () { - build_slack_payload - post_to_slack -} \ No newline at end of file diff --git a/bin/integration-tests/run-tests.bash b/bin/integration-tests/run-tests.bash index b12465f6..5e78849a 100644 --- a/bin/integration-tests/run-tests.bash +++ b/bin/integration-tests/run-tests.bash @@ -86,8 +86,6 @@ echo "" # Prep for the test runs. make -C "${REPO_ROOT}"/wp clean 2>&1 | tee "${REPORT_FILE}" -# Todo: test global/context stuff with vars ??? - # Run the integration tests. make -C "${REPO_ROOT}"/wp test.plugin.integration 2>&1 | tee -a "${REPORT_FILE}" TEST_RESULT="${?}" diff --git a/bin/setup/install-dependencies.bash b/bin/setup/install-dependencies.bash new file mode 100644 index 00000000..3b8ca257 --- /dev/null +++ b/bin/setup/install-dependencies.bash @@ -0,0 +1,131 @@ +# -------------------------------------------------------------- +# +# Install dependencies used by the tools. +# +# -------------------------------------------------------------- + +# Define some paths. +THIS_SCRIPT="${BASH_SOURCE[0]}" +THIS_DIR="$(cd "$(dirname "${THIS_SCRIPT}")" && pwd)" +COMMON_LIB_DIR="$(cd "${THIS_DIR}/../common-lib" && pwd)" + +# Include the relevant libraries. +. "${COMMON_LIB_DIR}/utils.bash" +. "${COMMON_LIB_DIR}/slack.bash" +. "${COMMON_LIB_DIR}/env.bash" + +# Report progress to slack? +REPORT_RESULTS="false" + +# Usage message +usage () { + echo "USAGE: bash $(get_me) [OPTIONS]" + echo "" + echo " Install dependencies for the tools." + echo "" + echo "OPTIONS" + echo " -h | --help Print this help and exit" + echo " --report-results Report the results to slack" +} + +# Parse the command line arguments. +while (( "${#}" )); do + case "${1}" in + + -h|--help) + usage + exit 1 + ;; + + --report-results) + REPORT_RESULTS="true" + ;; + + *) + echo "Unrecognized argument: ${1}" + help_hint + exit 1 + ;; + + esac + shift +done + +# Call `clean_up` before the script exits. +trap clean_up EXIT + +# Ensure we have a slack username and URL to post with. +if [[ "${REPORT_RESULTS}" == "true" ]]; then + there_is_a_SLACK_USERNAME + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_USERNAME environment variable." + echo "Export one to proceed." + exit 1 + fi + there_is_a_SLACK_URL + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_URL environment variable." + echo "Export one to proceed." + exit 1 + fi +fi + +# Where to record progress. +REPORT="$(report_file "${REPORT_RESULTS}")" + +# Record some useful info. +bap_version +git_commit + +echo "" + +# If boolector isn't already installed, install it. +which boolector > /dev/null 2>&1 +if [[ "${?}" != "0" ]]; then + CURRENT_DIR="$(pwd)" + cd "${HOME}" + if [ -d "${BOOLECTOR_DIR}" ]; then + echo "Can't git pull the boolector repo" > "${MSG_FILE}" + echo "Halting." >> "${REPORT_FILE}" + echo "Want to pull the boolector repo, but can't." >> "${REPORT_FILE}" + echo "${BOOLECTOR_DIR} already exists." >> "${REPORT_FILE}" + echo "$(cat "${MSG_FILE}")" + echo "$(cat "${REPORT_FILE}")" + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack + fi + exit 1 + fi + git clone "${BOOLECTOR_URL}" + cd boolector + ./contrib/setup-lingeling.sh + ./contrib/setup-btor2tools.sh + ./configure.sh && cd build && make + cd "${CURRENT_DIR}" +fi + +# Make sure boolector got installed. +which boolector > /dev/null 2>&1 +if [[ "${?}" != "0" ]]; then + echo "Unable to find boolector" > "${MSG_FILE}" + echo "Halting." > "${REPORT_FILE}" + echo "Boolector does not seem to be installed.." >> "${REPORT_FILE}" + echo "Tried 'which boolector' but got nothing." >> "${REPORT_FILE}" + echo "$(cat "${MSG_FILE}")" + echo "$(cat "${REPORT_FILE}")" + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack + fi + exit 1 +else + echo "- Boolector is installed." | tee -a "${REPORT_FILE}" +fi + +# Finish up. +echo "Done." | tee -a "${REPORT_FILE}" +if [[ "${REPORT_RESULTS}" == "true" ]]; then + echo "Installed dependencies" > "${MSG_FILE}" + report_to_slack +fi diff --git a/bin/unit-tests/run-tests.bash b/bin/unit-tests/run-tests.bash new file mode 100644 index 00000000..815ac37a --- /dev/null +++ b/bin/unit-tests/run-tests.bash @@ -0,0 +1,106 @@ +# ------------------------- +# +# Run the unit tests +# +# ------------------------- + +# Define useful paths +THIS_SCRIPT="${BASH_SOURCE[0]}" +THIS_DIR="$(cd "$(dirname "${THIS_SCRIPT}")" && pwd)" +COMMON_LIB_DIR="$(cd "${THIS_DIR}/../common-lib" && pwd)" + +# Include needed libraries +. "${COMMON_LIB_DIR}/utils.bash" +. "${COMMON_LIB_DIR}/slack.bash" + +# Report progress to slack? +REPORT_PROGRESS="false" + +usage () { + echo "USAGE: bash [OPTIONS]" + echo "" + echo " Run the unit tests." + echo "" + echo "OPTIONS" + echo " -h | --help Print this help and exit" + echo " --report-results Report the results to slack" +} + +# Parse command line arguments +while (( "${#}" )); do + case "${1}" in + + -h|--help) + usage + exit 1 + ;; + + --report-results) + REPORT_RESULTS="true" + ;; + + *) + echo "Unrecognized argument: ${1}" + help_hint + exit 1 + ;; + + esac + shift +done + +# Call `clean up` before the script ends +# When OS throws signal, one is exit. +# When throws exits, catch it, then call cleanup, +# Then rethrow exit +trap clean_up EXIT + +# Ensures we have a slack URL to post with +if [[ "${REPORT_RESULTS}" == "true" ]]; then + there_is_a_SLACK_USERNAME + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_USERNAME environment variable." + echo "Export one to proceed." + exit 1 + fi + there_is_a_SLACK_URL + if [ ${?} -ne 0 ]; then + echo "Halting." + echo "Need a SLACK_URL environment variable." + echo "Export one to proceed." + exit 1 + fi +fi + +# Where to record progress +REPORT="$(report_file "${REPORT_RESULTS}")" + +# Record some useful info +bap_version +git_branch +git_commit + +echo "" + +# Prep for the test runs. +make -C "${REPO_ROOT}"/wp clean 2>&1 | tee "${REPORT_FILE}" + +# Run the unit tests. +make -C "${REPO_ROOT}"/wp test 2>&1 | tee -a "${REPORT_FILE}" +TEST_RESULT="${?}" +echo "REPORT:" +cat "${REPORT_FILE}" +if [[ "${TEST_RESULT}" != "0" ]]; then + echo "Integration tests failed" > "${MSG_FILE}" #summary + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack "true" + fi + fail + exit 1 +else + echo "Integration tests passed" > "${MSG_FILE}" + if [[ "${REPORT_RESULTS}" == "true" ]]; then + report_to_slack "false" + fi +fi diff --git a/bin/common-lib/new b/bin/unit-tests/run-tests.bash~ similarity index 63% rename from bin/common-lib/new rename to bin/unit-tests/run-tests.bash~ index 6eb92a1d..b12465f6 100644 --- a/bin/common-lib/new +++ b/bin/unit-tests/run-tests.bash~ @@ -1,33 +1,32 @@ -# -------------------------------------------------------------- +# ------------------------- # -# Run the integration tests. +# Run the integration tests # -# -------------------------------------------------------------- +# ------------------------- -# Define some paths. +# Define useful paths THIS_SCRIPT="${BASH_SOURCE[0]}" THIS_DIR="$(cd "$(dirname "${THIS_SCRIPT}")" && pwd)" COMMON_LIB_DIR="$(cd "${THIS_DIR}/../common-lib" && pwd)" -# Include the relevant libraries. +# Include needed libraries . "${COMMON_LIB_DIR}/utils.bash" . "${COMMON_LIB_DIR}/slack.bash" # Report progress to slack? -REPORT_RESULTS="false" +REPORT_PROGRESS="false" -# Usage message usage () { - echo "USAGE: bash $(get_me) [OPTIONS]" + echo "USAGE: bash [OPTIONS]" echo "" echo " Run the integration tests." echo "" echo "OPTIONS" - echo " -h | --help Print this help and exit" + echo " -h | --help Print this help and exit" echo " --report-results Report the results to slack" } -# Parse the command line arguments. +# Parse command line arguments while (( "${#}" )); do case "${1}" in @@ -50,10 +49,13 @@ while (( "${#}" )); do shift done -# Call `clean_up` before the script exits. -trap clean_up EXIT +# Call `clean up` before the script ends +# When OS throws signal, one is exit. +# When throws exits, catch it, then call cleanup, +# Then rethrow exit +trap clean_up EXIT -# Ensure we have a slack username and URL to post with. +# Ensures we have a slack URL to post with if [[ "${REPORT_RESULTS}" == "true" ]]; then there_is_a_SLACK_USERNAME if [ ${?} -ne 0 ]; then @@ -71,33 +73,36 @@ if [[ "${REPORT_RESULTS}" == "true" ]]; then fi fi -# Where to record progress. +# Where to record progress REPORT="$(report_file "${REPORT_RESULTS}")" -# Record some useful info. +# Record some useful info bap_version +git_branch git_commit echo "" -# Prep for test runs. -make clean -C "${REPO_ROOT}"/bap-vibes 2>&1 | tee "${REPORT_FILE}" +# Prep for the test runs. +make -C "${REPO_ROOT}"/wp clean 2>&1 | tee "${REPORT_FILE}" + +# Todo: test global/context stuff with vars ??? # Run the integration tests. -make test.integration -C "${REPO_ROOT}" 2>&1 | tee -a "${REPORT_FILE}" +make -C "${REPO_ROOT}"/wp test.plugin.integration 2>&1 | tee -a "${REPORT_FILE}" TEST_RESULT="${?}" echo "REPORT:" cat "${REPORT_FILE}" if [[ "${TEST_RESULT}" != "0" ]]; then - echo "Integration tests failed" > "${MSG_FILE}" + echo "Integration tests failed" > "${MSG_FILE}" #summary if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack + report_to_slack "true" fi fail exit 1 else echo "Integration tests passed" > "${MSG_FILE}" if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack + report_to_slack "false" fi -fi \ No newline at end of file +fi From e65a1917b61b1aebcabdf9b152470223c5cc8e46 Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 5 Aug 2021 14:35:14 -0400 Subject: [PATCH 17/23] Fix unit messages in unit-tests/run-tests.bash --- bin/unit-tests/run-tests.bash | 4 +- bin/unit-tests/run-tests.bash~ | 108 --------------------------------- 2 files changed, 2 insertions(+), 110 deletions(-) delete mode 100644 bin/unit-tests/run-tests.bash~ diff --git a/bin/unit-tests/run-tests.bash b/bin/unit-tests/run-tests.bash index 815ac37a..11d74028 100644 --- a/bin/unit-tests/run-tests.bash +++ b/bin/unit-tests/run-tests.bash @@ -92,14 +92,14 @@ TEST_RESULT="${?}" echo "REPORT:" cat "${REPORT_FILE}" if [[ "${TEST_RESULT}" != "0" ]]; then - echo "Integration tests failed" > "${MSG_FILE}" #summary + echo "Unit tests failed" > "${MSG_FILE}" #summary if [[ "${REPORT_RESULTS}" == "true" ]]; then report_to_slack "true" fi fail exit 1 else - echo "Integration tests passed" > "${MSG_FILE}" + echo "Unit tests passed" > "${MSG_FILE}" if [[ "${REPORT_RESULTS}" == "true" ]]; then report_to_slack "false" fi diff --git a/bin/unit-tests/run-tests.bash~ b/bin/unit-tests/run-tests.bash~ deleted file mode 100644 index b12465f6..00000000 --- a/bin/unit-tests/run-tests.bash~ +++ /dev/null @@ -1,108 +0,0 @@ -# ------------------------- -# -# Run the integration tests -# -# ------------------------- - -# Define useful paths -THIS_SCRIPT="${BASH_SOURCE[0]}" -THIS_DIR="$(cd "$(dirname "${THIS_SCRIPT}")" && pwd)" -COMMON_LIB_DIR="$(cd "${THIS_DIR}/../common-lib" && pwd)" - -# Include needed libraries -. "${COMMON_LIB_DIR}/utils.bash" -. "${COMMON_LIB_DIR}/slack.bash" - -# Report progress to slack? -REPORT_PROGRESS="false" - -usage () { - echo "USAGE: bash [OPTIONS]" - echo "" - echo " Run the integration tests." - echo "" - echo "OPTIONS" - echo " -h | --help Print this help and exit" - echo " --report-results Report the results to slack" -} - -# Parse command line arguments -while (( "${#}" )); do - case "${1}" in - - -h|--help) - usage - exit 1 - ;; - - --report-results) - REPORT_RESULTS="true" - ;; - - *) - echo "Unrecognized argument: ${1}" - help_hint - exit 1 - ;; - - esac - shift -done - -# Call `clean up` before the script ends -# When OS throws signal, one is exit. -# When throws exits, catch it, then call cleanup, -# Then rethrow exit -trap clean_up EXIT - -# Ensures we have a slack URL to post with -if [[ "${REPORT_RESULTS}" == "true" ]]; then - there_is_a_SLACK_USERNAME - if [ ${?} -ne 0 ]; then - echo "Halting." - echo "Need a SLACK_USERNAME environment variable." - echo "Export one to proceed." - exit 1 - fi - there_is_a_SLACK_URL - if [ ${?} -ne 0 ]; then - echo "Halting." - echo "Need a SLACK_URL environment variable." - echo "Export one to proceed." - exit 1 - fi -fi - -# Where to record progress -REPORT="$(report_file "${REPORT_RESULTS}")" - -# Record some useful info -bap_version -git_branch -git_commit - -echo "" - -# Prep for the test runs. -make -C "${REPO_ROOT}"/wp clean 2>&1 | tee "${REPORT_FILE}" - -# Todo: test global/context stuff with vars ??? - -# Run the integration tests. -make -C "${REPO_ROOT}"/wp test.plugin.integration 2>&1 | tee -a "${REPORT_FILE}" -TEST_RESULT="${?}" -echo "REPORT:" -cat "${REPORT_FILE}" -if [[ "${TEST_RESULT}" != "0" ]]; then - echo "Integration tests failed" > "${MSG_FILE}" #summary - if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack "true" - fi - fail - exit 1 -else - echo "Integration tests passed" > "${MSG_FILE}" - if [[ "${REPORT_RESULTS}" == "true" ]]; then - report_to_slack "false" - fi -fi From bf52de6fffa8a0a3a94ec467ba3743cb9f0928c2 Mon Sep 17 00:00:00 2001 From: gltrost Date: Thu, 5 Aug 2021 14:44:12 -0400 Subject: [PATCH 18/23] Add stage names to jobs in .gitlab-ci.yml --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 71c8ce53..4b7c0076 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,6 +11,7 @@ stages: # JOB: build BilDB. build_bildb: + stage: build_bildb tags: - docker @@ -20,6 +21,7 @@ build_bildb: # JOB: run unit tests for WP. run_unit_tests: + stage: run_unit_tests tags: - docker @@ -30,6 +32,7 @@ run_unit_tests: # JOB: run integration tests for WP. run_integration_tests: + stage: run_integration_tests tags: - docker From 52ed22dd0fafc9717bf88dde0e322da8df9b0df6 Mon Sep 17 00:00:00 2001 From: gltrost Date: Mon, 23 Aug 2021 14:36:55 -0400 Subject: [PATCH 19/23] Add bin/common-lib/env.bash to handle boolector installation --- .gitlab-ci.yml | 4 ++++ bin/common-lib/env.bash | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 bin/common-lib/env.bash diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4b7c0076..aff7a07c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,6 +40,10 @@ run_integration_tests: script: # Install other dependencies (non-sudo). - bash -x bin/setup/install-dependencies.bash --report-results + + # Source environment variables and install the vibes tool. + - . bin/common-lib/env.bash + - make - make test -C wp - bash -x bin/integration-tests/run-tests.bash --report-results diff --git a/bin/common-lib/env.bash b/bin/common-lib/env.bash new file mode 100644 index 00000000..4044d7b6 --- /dev/null +++ b/bin/common-lib/env.bash @@ -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}" From 6bc1ab6f84db2491e8d3fb384d7748bddf04634d Mon Sep 17 00:00:00 2001 From: gltrost Date: Tue, 24 Aug 2021 13:22:19 -0400 Subject: [PATCH 20/23] Add APT dependencies to .gitlab-ci.yml to allow for cmake installation --- .gitlab-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aff7a07c..90363f9f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,6 +38,12 @@ run_integration_tests: - docker script: + # 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 From e0b7e9f48e83a3ed2ee62fdddc5c2917f7f50c12 Mon Sep 17 00:00:00 2001 From: gltrost Date: Tue, 24 Aug 2021 14:34:33 -0400 Subject: [PATCH 21/23] Fix double-bracket error in slack.bash --- .gitlab-ci.yml | 2 +- bin/common-lib/slack.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 90363f9f..0ae47ac5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,7 +47,7 @@ run_integration_tests: # Install other dependencies (non-sudo). - bash -x bin/setup/install-dependencies.bash --report-results - # Source environment variables and install the vibes tool. + # Source environment variables and install cbat tools. - . bin/common-lib/env.bash - make diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 1564fcb0..0917a372 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -49,7 +49,7 @@ build_slack_payload () { TEXT="${TEXT}\nBAP: ${BAP}" TEXT="${TEXT}\nBRANCH: ${BRANCH}" TEXT="${TEXT}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" - if [["${VERBOSE}" == "true"]]; then + if ["${VERBOSE}" == "true"]; then TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" fi echo "{ From 097e4537a02ed58358b4e4a6b976fa5d8208681d Mon Sep 17 00:00:00 2001 From: gltrost Date: Tue, 24 Aug 2021 15:14:12 -0400 Subject: [PATCH 22/23] Add spaces to line 52 bracks in slack.bash --- bin/common-lib/slack.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/common-lib/slack.bash b/bin/common-lib/slack.bash index 0917a372..7cdac93d 100644 --- a/bin/common-lib/slack.bash +++ b/bin/common-lib/slack.bash @@ -49,7 +49,7 @@ build_slack_payload () { TEXT="${TEXT}\nBAP: ${BAP}" TEXT="${TEXT}\nBRANCH: ${BRANCH}" TEXT="${TEXT}\nCOMMIT:\n\`\`\`\n${COMMIT}\n\`\`\`" - if ["${VERBOSE}" == "true"]; then + if [[ "${VERBOSE}" == "true" ]]; then TEXT="${TEXT}\nOUTPUT:\n\`\`\`\n${DATA}\n\`\`\`" fi echo "{ From 86e3b35a323736b23e63046e12317c48fdf87a5f Mon Sep 17 00:00:00 2001 From: JT Paasch Date: Wed, 29 Sep 2021 08:59:56 -0400 Subject: [PATCH 23/23] Specify -C for make in intergration test job --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0ae47ac5..6277150e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,7 +49,7 @@ run_integration_tests: # Source environment variables and install cbat tools. - . bin/common-lib/env.bash - - make + - make -C wp - make test -C wp - bash -x bin/integration-tests/run-tests.bash --report-results