Skip to content

Commit

Permalink
ci: add unit test to github action (OpenAtomFoundation#1604)
Browse files Browse the repository at this point in the history
* ci: add unit test in github workflow
  • Loading branch information
machinly authored Jun 11, 2023
1 parent 8f7f056 commit 253c705
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 43 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/pika.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

- name: Unit Test
working-directory: ${{github.workspace}}
run: |
./pikatests.sh all
build_on_centos:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
Expand Down Expand Up @@ -101,4 +106,5 @@ jobs:
run: |
cd ${{github.workspace}}/build
source /opt/rh/devtoolset-10/enable
ctest -C ${{env.BUILD_TYPE}}
ctest -C ${{env.BUILD_TYPE}}
81 changes: 72 additions & 9 deletions pikatests.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,73 @@
#!/bin/bash
rm -rf ./log
rm -rf .db
cp output/pika src/redis-server
cp conf/pika.conf tests/assets/default.conf

tclsh tests/test_helper.tcl --clients 1 --single unit/$1
rm src/redis-server
rm -rf ./log
rm -rf ./db

# clear the log file
function cleanup() {
rm -rf ./log
rm -rf db
rm -rf dbsync/
rm src/redis-server
}

# check if tcl is installed
function check_tcl {
if [ -z "$(which tclsh)" ]; then
echo "tclsh is not installed"
exit 1
fi
}

# handle different build directories.
function setup_build_dir {
BUILD_DIR=""
if [ -d "./build" ] && [ -d "./output" ]; then
echo "Both build and output directories exist. Please remove one of them."
exit 1
fi
if [ -d "./build" ]; then
BUILD_DIR="build"
fi

if [ -d "./output" ]; then
BUILD_DIR="output"
fi
if [ -z "$BUILD_DIR" ]; then
echo "No build directory found. Please build the project first."
exit 1
fi
echo "BUILD_DIR: $BUILD_DIR"
}

# setup pika bin and conf
function setup_pika_bin {
PIKA_BIN="./$BUILD_DIR/pika"
if [ ! -f "$PIKA_BIN" ]; then
echo "pika bin not found"
exit 1
fi
cp $PIKA_BIN src/redis-server
cp conf/pika.conf tests/assets/default.conf
}


cleanup

check_tcl

setup_build_dir

setup_pika_bin

echo "run pika tests $1"

if [ "$1" == "all" ]; then
tclsh tests/test_helper.tcl --clients 1
else
tclsh tests/test_helper.tcl --clients 1 --single unit/$1
fi

if [ $? -ne 0 ]; then
echo "pika tests failed"
cleanup
exit 1
fi
cleanup
71 changes: 38 additions & 33 deletions tests/test_helper.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,48 @@ source tests/support/test.tcl
source tests/support/util.tcl

set ::all_tests {
unit/printver
unit/auth
unit/protocol
unit/basic
unit/scan
unit/type/list
# unit/printver
# unit/auth
# unit/protocol
# unit/basic
# unit/scan
# unit/type/list
unit/type/list-2
unit/type/list-3
unit/type/set
# unit/type/set
unit/type/zset
unit/type/hash
unit/sort
unit/expire
unit/other
unit/multi
unit/quit
unit/aofrw
integration/replication
integration/replication-2
integration/replication-3
integration/replication-4
integration/replication-psync
integration/aof
integration/rdb
integration/convert-zipmap-hash-on-load
unit/pubsub
unit/slowlog
unit/scripting
unit/maxmemory
unit/introspection
unit/limits
unit/obuf-limits
unit/dump
unit/bitops
unit/memefficiency
unit/hyperloglog
# unit/type/hash
# unit/sort
# unit/expire
# unit/other
# unit/multi
# unit/quit
# unit/aofrw
# integration/replication
# integration/replication-2
# integration/replication-3
# integration/replication-4
# integration/replication-psync
# integration/aof
# integration/rdb
# integration/convert-zipmap-hash-on-load
# unit/pubsub
# unit/slowlog
# unit/scripting
# unit/maxmemory
# unit/introspection
# unit/limits
# unit/obuf-limits
# unit/dump
# unit/bitops
# unit/memefficiency
# unit/hyperloglog
}

# because the comment not works in tcl list, use regsub to ignore the item starting with '#'
regsub -all {#.*?\n} $::all_tests {} ::all_tests


# Index to the next test to run in the ::all_tests list.
set ::next_test 0

Expand Down

0 comments on commit 253c705

Please sign in to comment.