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 12, 2023
1 parent 6b84daa commit 627d933
Show file tree
Hide file tree
Showing 23 changed files with 288 additions and 296 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@ jobs:
- name: run tests
run: ctest --output-on-failure
working-directory: ${{github.workspace}}/build

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: set -e; find -name "*.sh" -exec shellcheck -s bash -e SC1091 {} \;
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




50 changes: 27 additions & 23 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_OUTPUT_DIR" ]; then
if [[ -z "$XDDTEST_OUTPUT_DIR" ]]; then
echo "No properly sourced test_config during initialization"
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_OUTPUT_DIR
mkdir -p "$XDDTEST_OUTPUT_DIR"

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

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
rc=0
else
fail
fi

cleanup_test_data
exit $rc
exit ${rc}
}

#
Expand All @@ -69,8 +71,8 @@ finalize_test() {
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 @@ -81,31 +83,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 @@ -114,26 +117,27 @@ 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() {
printf "%-20s\t%10s\n" $TESTNAME "FAIL"
printf "%-20s\t%10s\n" "$TESTNAME" "FAIL"
}

#
# 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() {
printf "%-20s\t%10s\n" $TESTNAME "SKIPPED"
printf "%-20s\t%10s\n" "$TESTNAME" "SKIPPED"
}
10 changes: 2 additions & 8 deletions tests/debug/test_xdd_debug_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ initialize_test

echo "Foobar and I am here motherfucker"

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

if [[ $? -ne 0 ]]; then
if ! ("${XDDTEST_XDD_EXE}" -op write -reqsize 128 -numreqs 1 -targets 1 /dev/null -verbose -debug INIT 2>&1 | grep "bound to NUMA node") ; then
# test failed
finalize_test 1
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
if ! ("${XDDTEST_XDD_EXE}" -op write -reqsize 128 -numreqs 1 -targets 1 /dev/null -verbose 2>&1 | grep "bound to NUMA node") ; then
# test failed
finalize_test 1
fi
Expand Down
16 changes: 8 additions & 8 deletions tests/functional/test_xdd_createnewfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ 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

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
echo "Incorrect file size for $f. Size is $file_size but should be $correct_size."
echo "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
Expand Down
16 changes: 8 additions & 8 deletions tests/functional/test_xdd_createnewfiles2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ 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

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
echo "Incorrect file size for $f. Size is $file_size but should be $correct_size."
echo "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
Expand Down
Loading

0 comments on commit 627d933

Please sign in to comment.