2020-05-21 13:14:40 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-12-07 09:43:00 +00:00
|
|
|
|
2021-04-09 02:17:28 +00:00
|
|
|
echo "First arg:"
|
|
|
|
echo $1
|
|
|
|
|
|
|
|
os='linux'
|
2023-08-11 04:00:23 +00:00
|
|
|
if [ "X$1" = "X-w" ]; then
|
2024-05-10 06:11:28 +00:00
|
|
|
os='windows'
|
2021-04-09 02:17:28 +00:00
|
|
|
fi
|
|
|
|
echo "OS:" $os
|
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
src_dir=$(pwd)
|
|
|
|
test_root=build/lib/tests
|
2023-08-11 04:00:23 +00:00
|
|
|
if [ "X$os" = "Xwindows" ]; then
|
2024-05-10 06:11:28 +00:00
|
|
|
test_root=$test_root/Debug
|
2021-04-09 02:17:28 +00:00
|
|
|
fi
|
|
|
|
|
2023-08-11 04:00:23 +00:00
|
|
|
if [ "X$os" = "Xlinux" ]; then
|
2024-05-10 06:11:28 +00:00
|
|
|
drogon_ctl_exec=$(pwd)/build/drogon_ctl/drogon_ctl
|
|
|
|
else
|
|
|
|
drogon_ctl_exec=$(pwd)/build/drogon_ctl/Debug/drogon_ctl.exe
|
|
|
|
export PATH=$PATH:$src_dir/install/bin
|
2020-03-16 16:54:30 +00:00
|
|
|
fi
|
2024-05-10 06:11:28 +00:00
|
|
|
echo "drogon_ctl_exec: " ${drogon_ctl_exec}
|
2020-03-16 16:54:30 +00:00
|
|
|
|
2021-05-27 12:09:57 +00:00
|
|
|
#Make integration_test_server run as a daemon
|
2024-05-10 06:11:28 +00:00
|
|
|
function do_integration_test()
|
|
|
|
{
|
|
|
|
pushd $test_root
|
|
|
|
if [ "X$os" = "Xlinux" ]; then
|
|
|
|
sed -i -e "s/\"run_as_daemon.*$/\"run_as_daemon\": true\,/" config.example.json
|
|
|
|
fi
|
|
|
|
sed -i -e "s/\"relaunch_on_error.*$/\"relaunch_on_error\": true\,/" config.example.json
|
|
|
|
sed -i -e "s/\"threads_num.*$/\"threads_num\": 0\,/" config.example.json
|
|
|
|
sed -i -e "s/\"use_brotli.*$/\"use_brotli\": true\,/" config.example.json
|
2019-03-26 07:25:22 +00:00
|
|
|
|
2024-07-03 03:31:39 +00:00
|
|
|
if [ "$1" = "stream_mode" ]; then
|
|
|
|
sed -i -e "s/\"enable_request_stream.*$/\"enable_request_stream\": true\,/" config.example.json
|
|
|
|
else
|
|
|
|
sed -i -e "s/\"enable_request_stream.*$/\"enable_request_stream\": false\,/" config.example.json
|
|
|
|
fi
|
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ ! -f "integration_test_client" ]; then
|
|
|
|
echo "Build failed"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
if [ ! -f "integration_test_server" ]; then
|
|
|
|
echo "Build failed"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-03-26 07:25:22 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
killall -9 integration_test_server
|
|
|
|
./integration_test_server &
|
2019-04-07 04:15:02 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
sleep 4
|
2019-04-07 04:15:02 +00:00
|
|
|
|
2024-07-03 03:31:39 +00:00
|
|
|
echo "Running the integration test $1"
|
2024-05-10 06:11:28 +00:00
|
|
|
./integration_test_client -s
|
2019-03-26 07:25:22 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2024-07-03 03:31:39 +00:00
|
|
|
echo "Integration test failed $1"
|
2024-05-10 06:11:28 +00:00
|
|
|
exit -1
|
|
|
|
fi
|
2019-03-26 07:25:22 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
killall -9 integration_test_server
|
|
|
|
popd
|
|
|
|
}
|
2019-03-30 16:27:12 +00:00
|
|
|
|
|
|
|
#Test drogon_ctl
|
2024-05-10 06:11:28 +00:00
|
|
|
function do_drogon_ctl_test()
|
|
|
|
{
|
|
|
|
echo "Testing drogon_ctl"
|
|
|
|
pushd $test_root
|
|
|
|
rm -rf drogon_test
|
|
|
|
|
|
|
|
${drogon_ctl_exec} create project drogon_test
|
|
|
|
|
|
|
|
ls -la
|
|
|
|
cd drogon_test/controllers
|
|
|
|
|
|
|
|
${drogon_ctl_exec} create controller Test::SimpleCtrl
|
|
|
|
${drogon_ctl_exec} create controller -h Test::HttpCtrl
|
|
|
|
${drogon_ctl_exec} create controller -w Test::WebsockCtrl
|
|
|
|
${drogon_ctl_exec} create controller SimpleCtrl
|
|
|
|
${drogon_ctl_exec} create controller -h HttpCtrl
|
|
|
|
${drogon_ctl_exec} create controller -w WebsockCtrl
|
|
|
|
|
|
|
|
if [ ! -f "Test_SimpleCtrl.h" -o ! -f "Test_SimpleCtrl.cc" -o ! -f "Test_HttpCtrl.h" -o ! -f "Test_HttpCtrl.cc" -o ! -f "Test_WebsockCtrl.h" -o ! -f "Test_WebsockCtrl.cc" ]; then
|
|
|
|
echo "Failed to create controllers"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-03-30 16:27:12 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ ! -f "SimpleCtrl.h" -o ! -f "SimpleCtrl.cc" -o ! -f "HttpCtrl.h" -o ! -f "HttpCtrl.cc" -o ! -f "WebsockCtrl.h" -o ! -f "WebsockCtrl.cc" ]; then
|
|
|
|
echo "Failed to create controllers"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-03-30 16:27:12 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
cd ../filters
|
2019-05-05 07:43:17 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
${drogon_ctl_exec} create filter Test::TestFilter
|
2019-05-05 07:43:17 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ ! -f "Test_TestFilter.h" -o ! -f "Test_TestFilter.cc" ]; then
|
|
|
|
echo "Failed to create filters"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-05-05 07:43:17 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
cd ../plugins
|
2020-10-12 13:51:39 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
${drogon_ctl_exec} create plugin Test::TestPlugin
|
2020-10-12 13:51:39 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ ! -f "Test_TestPlugin.h" -o ! -f "Test_TestPlugin.cc" ]; then
|
|
|
|
echo "Failed to create plugins"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-03-30 16:27:12 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
cd ../views
|
|
|
|
|
|
|
|
echo "Hello, world!" >>hello.csp
|
|
|
|
|
|
|
|
cd ../build
|
|
|
|
|
|
|
|
make_flags=''
|
|
|
|
cmake_gen=''
|
|
|
|
parallel=1
|
|
|
|
|
|
|
|
# simulate ninja's parallelism
|
|
|
|
case $(nproc) in
|
|
|
|
1)
|
|
|
|
parallel=$(($(nproc) + 1))
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
parallel=$(($(nproc) + 1))
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
parallel=$(($(nproc) + 2))
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "X$os" = "Xlinux" ]; then
|
|
|
|
if [ -f /bin/ninja ]; then
|
|
|
|
cmake_gen='-G Ninja'
|
|
|
|
else
|
|
|
|
make_flags="$make_flags -j$parallel"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
cmake_gen="$cmake_gen -DCMAKE_TOOLCHAIN_FILE=$src_dir/conan_toolchain.cmake \
|
|
|
|
-DCMAKE_PREFIX_PATH=$src_dir/install \
|
|
|
|
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW \
|
|
|
|
-DCMAKE_CXX_STANDARD=17"
|
|
|
|
fi
|
|
|
|
cmake .. $cmake_gen
|
2019-03-30 16:27:12 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Failed to run CMake for example project"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-03-30 16:27:12 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
cmake --build . -- $make_flags
|
2019-03-30 16:27:12 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in testing"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-03-30 16:27:12 +00:00
|
|
|
|
2024-05-10 06:11:28 +00:00
|
|
|
if [ "X$os" = "Xlinux" ]; then
|
|
|
|
if [ ! -f "drogon_test" ]; then
|
|
|
|
echo "Failed to build drogon_test"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ ! -f "Debug\drogon_test.exe" ]; then
|
|
|
|
echo "Failed to build drogon_test"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
fi
|
2019-03-31 10:30:06 +00:00
|
|
|
|
2021-05-27 12:09:57 +00:00
|
|
|
cd ../../
|
2024-05-10 06:11:28 +00:00
|
|
|
rm -rf drogon_test
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
#unit testing
|
|
|
|
function do_unittest()
|
|
|
|
{
|
2019-12-07 09:43:00 +00:00
|
|
|
echo "Unit testing"
|
2024-05-10 06:11:28 +00:00
|
|
|
pushd $src_dir/build
|
|
|
|
|
2022-06-29 09:29:20 +00:00
|
|
|
ctest . --output-on-failure
|
2019-12-07 09:43:00 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in unit testing"
|
|
|
|
exit -1
|
|
|
|
fi
|
2024-05-10 06:11:28 +00:00
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_db_test()
|
|
|
|
{
|
|
|
|
pushd $src_dir/build
|
2021-03-24 02:32:55 +00:00
|
|
|
if [ -f "./orm_lib/tests/db_test" ]; then
|
|
|
|
echo "Test database"
|
2021-05-27 12:09:57 +00:00
|
|
|
./orm_lib/tests/db_test -s
|
2021-03-24 02:32:55 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in testing"
|
|
|
|
exit -1
|
|
|
|
fi
|
2019-08-16 15:41:03 +00:00
|
|
|
fi
|
2022-06-05 13:10:42 +00:00
|
|
|
if [ -f "./orm_lib/tests/pipeline_test" ]; then
|
2023-01-04 15:50:49 +00:00
|
|
|
echo "Test pipeline mode"
|
|
|
|
./orm_lib/tests/pipeline_test -s
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in testing"
|
|
|
|
exit -1
|
2022-06-05 13:10:42 +00:00
|
|
|
fi
|
2023-01-04 15:50:49 +00:00
|
|
|
fi
|
|
|
|
if [ -f "./orm_lib/tests/db_listener_test" ]; then
|
|
|
|
echo "Test DbListener"
|
|
|
|
./orm_lib/tests/db_listener_test -s
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in testing"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
fi
|
2024-05-23 06:03:28 +00:00
|
|
|
if [ -f "./orm_lib/tests/conn_options_test" ]; then
|
|
|
|
echo "Test connection options"
|
|
|
|
./orm_lib/tests/conn_options_test -s
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in testing"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
fi
|
2024-05-28 16:23:43 +00:00
|
|
|
if [ -f "./orm_lib/tests/db_api_test" ]; then
|
|
|
|
echo "Test getDbClient() api"
|
|
|
|
./orm_lib/tests/db_api_test -s
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in testing"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
fi
|
2021-03-13 11:13:54 +00:00
|
|
|
if [ -f "./nosql_lib/redis/tests/redis_test" ]; then
|
|
|
|
echo "Test redis"
|
2021-05-27 12:09:57 +00:00
|
|
|
./nosql_lib/redis/tests/redis_test -s
|
2021-03-13 11:13:54 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error in testing"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
fi
|
2024-05-10 06:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ! drogon_ctl -v > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
echo "Warning: No drogon_ctl, skip integration test and drogon_ctl test"
|
|
|
|
else
|
|
|
|
do_integration_test
|
2024-07-03 03:31:39 +00:00
|
|
|
do_integration_test stream_mode
|
2024-05-10 06:11:28 +00:00
|
|
|
do_drogon_ctl_test
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "X$1" = "X-t" ]; then
|
|
|
|
do_unittest
|
|
|
|
do_db_test
|
2019-08-16 15:41:03 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-30 16:27:12 +00:00
|
|
|
echo "Everything is ok!"
|
2019-03-26 07:25:22 +00:00
|
|
|
exit 0
|