Skip to content

Commit

Permalink
Run ShellSheck in Actions
Browse files Browse the repository at this point in the history
updated scripts to fix issues
  • Loading branch information
calccrypto committed Sep 13, 2023
1 parent f857bf1 commit 0b1270d
Show file tree
Hide file tree
Showing 22 changed files with 303 additions and 322 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: contrib/CI/centos8.sh

- name: Configure
run: cmake -B ${{github.workspace}}/build
run: cmake -B ${{github.workspace}}/build

- name: Make
run: make -C ${{github.workspace}}/build
Expand All @@ -38,6 +38,18 @@ jobs:
run: make -C ${{github.workspace}}/build install

- name: Run Tests
run: |
cd ${{github.workspace}}/build
run: |
cd ${{github.workspace}}/build
ctest --output-on-failure
shellcheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: apt update
run: sudo apt-get update
- name: Install ShellCheck
run: sudo apt -y install shellcheck
- name: Run ShellCheck
run: shellcheck -s bash -e SC1091 $(find -name "*.sh" | sort)
28 changes: 12 additions & 16 deletions src/bx/test_bxt.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* XDD - a data movement and benchmarking toolkit
*
* Copyright (C) 1992-23 I/O Performance, Inc.
* Copyright (C) 2009-23 UT-Battelle, LLC
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#
# XDD - a data movement and benchmarking toolkit
#
# Copyright (C) 1992-23 I/O Performance, Inc.
# Copyright (C) 2009-23 UT-Battelle, LLC
#
# This is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License version 2, as published by the Free Software
# Foundation. See file COPYING.
#
#
# --target # <in|out|int> #WorkerThreads <file|net|sg> <options>
# --target # <in|out|int> #WorkerThreads file <filename> <file_size> <transfer_size> <dio,null,sync>
# --target # <in|out|int> #WorkerThreads network <client|server> <user@hostname:port> <TCP|UDP|UDT>
Expand All @@ -19,7 +19,3 @@
--target 2 out 2 file /tmp/test_output_file2 1234567 1048576 bio \
--buffers 3 \
--sequence 0 1 2




52 changes: 28 additions & 24 deletions tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@
# - generates correct test data files
# - generates correct test file names
#
#
# curly braces with global variables
# break in this file for some reason

TESTNAME=$(basename $0 |cut -f 1 -d .)
TESTNAME=$(basename "$0" | cut -f 1 -d .)
common_next_file=""

#
# Initialize test
#
initialize_test() {
# Ensure that the test config has been sourced
if [ -z "$XDDTEST_LOG_DIR" ]; then
if [[ -z "$XDDTEST_LOG_DIR" ]]; then
echo "No properly sourced test_config during initialization. Missing log file path."
finalize_test 2
fi

# Create directories associated with local tests
mkdir -p $XDDTEST_LOCAL_MOUNT/$TESTNAME
if [ 0 -ne $? ]; then
if ! mkdir -p "$XDDTEST_LOCAL_MOUNT/$TESTNAME" ; then
echo "Unable to create $XDDTEST_LOCAL_MOUNT/$TESTNAME"
finalize_test 2
fi

# Create the log directory
mkdir -p $XDDTEST_LOG_DIR
mkdir -p "$XDDTEST_LOG_DIR"

# Initialize the uid for data files
common_next_file="0"
Expand All @@ -51,18 +53,18 @@ finalize_test() {
local message=$@

local rc=1
if [ $status -eq 0 ]; then
if [[ "${status}" -eq "0" ]]; then
pass
rc=0
elif [ $status -eq -1 ]; then
elif [[ "${status}" -eq "-1" ]]; then
skip $message
rc=255
else
fail $message
fi

cleanup_test_data
exit $rc
exit ${rc}
}

#
Expand All @@ -78,8 +80,8 @@ get_log_file() {
generate_local_filename() {
local varname="$1"
local name="$XDDTEST_LOCAL_MOUNT/$TESTNAME/file${common_next_file}.tdt"
eval "$varname=$name"
common_next_file=$((common_next_file + 1))
eval "${varname}=${name}"
common_next_file="$((common_next_file + 1))"
return 0
}

Expand All @@ -90,31 +92,32 @@ generate_local_file() {
local varname="$1"
local size="$2"

if [ -z "$size" ]; then
if [[ -z "${size}" ]]; then
echo "No test file data size specified."
finalize_test 2
fi

local lfname=""
generate_local_filename lfname
$XDDTEST_XDD_EXE -op write -target $lfname -reqsize 1 -blocksize $((1024*1024)) -bytes $size -datapattern random >/dev/null 2>&1
"${XDDTEST_XDD_EXE}" -op write -target "${lfname}" -reqsize 1 -blocksize "$((1024*1024))" -bytes "${size}" -datapattern random >/dev/null 2>&1

# Ensure the file size is correct
asize=$($XDDTEST_XDD_GETFILESIZE_EXE $lfname)
if [ "$asize" != "$size" ]; then
echo "Unable to generate test file data of size: $size"
# shellcheck disable=SC2086
asize="$(${XDDTEST_XDD_GETFILESIZE_EXE} ${lfname})"
if [[ "${asize}" != "${size}" ]]; then
echo "Unable to generate test file data of size: ${size}"
finalize_test 2
fi

# Ensure the file isn't all zeros
read -r -n 4 < /dev/zero
local data=$REPLY
read -r -n 4 < $lfname
if [ "$REPLY" = "$data" ]; then
local data="${REPLY}"
read -r -n 4 < "${lfname}"
if [[ "${REPLY}" = "${data}" ]]; then
echo "Unable to generate random test file data"
finalize_test 2
fi
eval "$varname=$lfname"
eval "${varname}=${lfname}"
return 0
}

Expand All @@ -123,28 +126,29 @@ generate_local_file() {
#
cleanup_test_data() {
# Remove files associated with local tests
rm -r $XDDTEST_LOCAL_MOUNT/$TESTNAME
# shellcheck disable=SC2115
rm -r "$XDDTEST_LOCAL_MOUNT/$TESTNAME"
}

#
# Indicate a test has failed
#
fail() {
local message=$@
printf "%-20s\t%10s: %s\n" $TESTNAME "FAIL" "$message"
printf "%-20s\t%10s: %s\n" "$TESTNAME" "FAIL" "$message"
}

#
# Indicate a test has passed
#
pass() {
printf "%-20s\t%10s\n" $TESTNAME "PASS"
printf "%-20s\t%10s\n" "$TESTNAME" "PASS"
}

#
# Indicate a test was skipped
#
skip() {
local message=$@
printf "%-20s\t%10s: %s\n" $TESTNAME "SKIPPED" "$message"
local message="$@"
printf "%-20s\t%10s: %s\n" "$TESTNAME" "SKIPPED" "$message"
}
16 changes: 2 additions & 14 deletions tests/debug/test_xdd_debug_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,9 @@ source ../common.sh

initialize_test

${XDDTEST_XDD_EXE} -op write -reqsize 128 -numreqs 1 -targets 1 /dev/null -verbose -debug INIT \
2>&1 | grep "bound to NUMA node"
("${XDDTEST_XDD_EXE}" -op write -reqsize 128 -numreqs 1 -targets 1 /dev/null -verbose -debug INIT 2>&1 | grep "bound to NUMA node") || finalize_test 1 "XDD output is missing NUMA node pinning info"

if [[ $? -ne 0 ]]; then
# test failed
finalize_test 1 "XDD output is missing NUMA node pinning info"
fi

${XDDTEST_XDD_EXE} -op write -reqsize 128 -numreqs 1 -targets 1 /dev/null -verbose \
2>&1 | grep "bound to NUMA node"

if [[ $? -ne 1 ]]; then
# test failed
finalize_test 1 "XDD output should not have NUMA node pinning info because -debug INIT was not used"
fi
("${XDDTEST_XDD_EXE}" -op write -reqsize 128 -numreqs 1 -targets 1 /dev/null -verbose 2>&1 | grep "bound to NUMA node") || finalize_test 1 "XDD output should not have NUMA node pinning info because -debug INIT was not used"

# test passed
finalize_test 0
18 changes: 9 additions & 9 deletions tests/functional/test_xdd_createnewfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ source ../common.sh

# Create the test location
initialize_test
data_file=$XDDTEST_LOCAL_MOUNT/$TESTNAME/test
data_file="${XDDTEST_LOCAL_MOUNT}/${TESTNAME}"/test

# ReqSize 4096, Bytes 1GiB, Targets 1, QueueDepth 4, Passes 4
$XDDTEST_XDD_EXE -op write -reqsize 4096 -mbytes 1024 -targets 1 $data_file -qd 4 -createnewfiles -passes 4 -datapattern random
"${XDDTEST_XDD_EXE}" -op write -reqsize 4096 -mbytes 1024 -targets 1 "${data_file}" -qd 4 -createnewfiles -passes 4 -datapattern random

# Validate output
test_passes=1
correct_size=1073741824
error_message=""

data_files="$data_file.00000001 $data_file.00000002 $data_file.00000003 $data_file.00000004"
for f in $data_files; do
file_size=$(stat -c %s $f)
if [ "$correct_size" != "$file_size" ]; then
data_files="${data_file}.00000001 ${data_file}.00000002 ${data_file}.00000003 ${data_file}.00000004"
for f in ${data_files}; do
file_size=$(stat -c '%s' "${f}")
if [[ "${correct_size}" != "${file_size}" ]]; then
test_passes=0
error_message="Incorrect file size for $f. Size is $file_size but should be $correct_size."
error_message="Incorrect file size for ${f}. Size is $file_size but should be ${correct_size}."
break
fi
done

# Output test result
if [ "1" == "$test_passes" ]; then
if [[ "1" == "${test_passes}" ]]; then
# test passed
finalize_test 0
else
# test failed
finalize_test 1 "$error_message"
finalize_test 1 "${error_message}"
fi
18 changes: 9 additions & 9 deletions tests/functional/test_xdd_createnewfiles2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ source ../test_config
source ../common.sh

initialize_test
data_file=$XDDTEST_LOCAL_MOUNT/$TESTNAME/test
data_file="${XDDTEST_LOCAL_MOUNT}/${TESTNAME}/test"

# ReqSize 4096, Bytes 1GiB, Targets 1, QueueDepth 4, Passes 4
$XDDTEST_XDD_EXE -op write -reqsize 4096 -bytes 100000000 -targets 1 $data_file -qd 4 -createnewfiles -passes 4 -datapattern random -dio
"${XDDTEST_XDD_EXE}" -op write -reqsize 4096 -bytes 100000000 -targets 1 "${data_file}" -qd 4 -createnewfiles -passes 4 -datapattern random -dio

# Validate output
test_passes=1
correct_size=100000000
error_message=""

data_files="$data_file.00000001 $data_file.00000002 $data_file.00000003 $data_file.00000004"
for f in $data_files; do
file_size=$(stat -c %s $f)
if [ "$correct_size" != "$file_size" ]; then
data_files="${data_file}.00000001 ${data_file}.00000002 ${data_file}.00000003 ${data_file}.00000004"
for f in ${data_files}; do
file_size=$(stat -c '%s' "${f}")
if [[ "${correct_size}" != "${file_size}" ]]; then
test_passes=0
error_message="Incorrect file size for $f. Size is $file_size but should be $correct_size."
error_message="Incorrect file size for ${f}. Size is ${file_size} but should be ${correct_size}."
fi
done

# Output test result
if [ "1" == "$test_passes" ]; then
if [[ "1" == "${test_passes}" ]]; then
# test passed
finalize_test 0
else
# test failed
finalize_test 1 "$error_message"
finalize_test 1 "${error_message}"
fi
Loading

0 comments on commit 0b1270d

Please sign in to comment.