1
0

autotest-external.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #!/usr/bin/env bash
  2. #
  3. # ownCloud
  4. #
  5. # @author Thomas Müller
  6. # @author Morris Jobke
  7. # @copyright 2012-2015 Thomas Müller thomas.mueller@tmit.eu
  8. # @copyright 2014 Morris Jobke hey@morrisjobke.de
  9. #
  10. #$EXECUTOR_NUMBER is set by Jenkins and allows us to run autotest in parallel
  11. DATABASENAME=oc_autotest$EXECUTOR_NUMBER
  12. DATABASEUSER=oc_autotest$EXECUTOR_NUMBER
  13. ADMINLOGIN=admin$EXECUTOR_NUMBER
  14. BASEDIR=$PWD
  15. DBCONFIGS="sqlite mysql pgsql oci"
  16. PHPUNIT=$(which phpunit)
  17. _XDEBUG_CONFIG=$XDEBUG_CONFIG
  18. unset XDEBUG_CONFIG
  19. function print_syntax {
  20. echo -e "Syntax: ./autotest-external.sh [dbconfigname] [startfile]\n" >&2
  21. echo -e "\t\"dbconfigname\" can be one of: $DBCONFIGS" >&2
  22. echo -e "\t\"startfile\" is the name of a start file inside the env/ folder in the files_external tests" >&2
  23. echo -e "\nExample: ./autotest.sh sqlite webdav-ownCloud" >&2
  24. echo "will run the external suite from \"apps/files_external/tests/env/start-webdav-ownCloud.sh\"" >&2
  25. echo -e "\nIf no arguments are specified, all available external backends will be run with all database configs" >&2
  26. echo -e "\nIf you specify 'common-tests' as startfile it will just run the tests that are independent from the backends" >&2
  27. }
  28. if ! [ -x "$PHPUNIT" ]; then
  29. echo "phpunit executable not found, please install phpunit version >= 4.8" >&2
  30. exit 3
  31. fi
  32. PHPUNIT_VERSION=$("$PHPUNIT" --version | cut -d" " -f2)
  33. PHPUNIT_MAJOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f1)
  34. PHPUNIT_MINOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f2)
  35. if ! [ $PHPUNIT_MAJOR_VERSION -gt 4 -o \( $PHPUNIT_MAJOR_VERSION -eq 4 -a $PHPUNIT_MINOR_VERSION -ge 8 \) ]; then
  36. echo "phpunit version >= 4.8 required. Version found: $PHPUNIT_VERSION" >&2
  37. exit 4
  38. fi
  39. if ! [ \( -w config -a ! -f config/config.php \) -o \( -f config/config.php -a -w config/config.php \) ]; then
  40. echo "Please enable write permissions on config and config/config.php" >&2
  41. exit 1
  42. fi
  43. if [ "$1" ]; then
  44. FOUND=0
  45. for DBCONFIG in $DBCONFIGS; do
  46. if [ "$1" = $DBCONFIG ]; then
  47. FOUND=1
  48. break
  49. fi
  50. done
  51. if [ $FOUND = 0 ]; then
  52. echo -e "Unknown database config name \"$1\"\n" >&2
  53. print_syntax
  54. exit 2
  55. fi
  56. fi
  57. # Back up existing (dev) config if one exists and backup not already there
  58. if [ -f config/config.php ] && [ ! -f config/config-autotest-backup.php ]; then
  59. mv config/config.php config/config-autotest-backup.php
  60. fi
  61. function cleanup_config {
  62. cd "$BASEDIR"
  63. # Restore existing config
  64. if [ -f config/config-autotest-backup.php ]; then
  65. mv config/config-autotest-backup.php config/config.php
  66. fi
  67. # Remove autotest config
  68. if [ -f config/autoconfig.php ]; then
  69. rm config/autoconfig.php
  70. fi
  71. }
  72. # restore config on exit
  73. trap cleanup_config EXIT
  74. # use tmpfs for datadir - should speedup unit test execution
  75. if [ -d /dev/shm ]; then
  76. DATADIR=/dev/shm/data-autotest$EXECUTOR_NUMBER
  77. else
  78. DATADIR=$BASEDIR/data-autotest
  79. fi
  80. echo "Using database $DATABASENAME"
  81. function execute_tests {
  82. echo "Setup environment for $1 testing ..."
  83. # back to root folder
  84. cd "$BASEDIR"
  85. # revert changes to tests/data
  86. git checkout tests/data
  87. # reset data directory
  88. rm -rf "$DATADIR"
  89. mkdir "$DATADIR"
  90. # remove the old config file
  91. #rm -rf config/config.php
  92. cp tests/preseed-config.php config/config.php
  93. # drop database
  94. if [ "$1" == "mysql" ] ; then
  95. mysql -u $DATABASEUSER -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" || true
  96. fi
  97. if [ "$1" == "pgsql" ] ; then
  98. dropdb -U $DATABASEUSER $DATABASENAME || true
  99. fi
  100. if [ "$1" == "oci" ] ; then
  101. echo "drop the database"
  102. sqlplus -s -l / as sysdba <<EOF
  103. drop user $DATABASENAME cascade;
  104. EOF
  105. echo "create the database"
  106. sqlplus -s -l / as sysdba <<EOF
  107. create user $DATABASENAME identified by owncloud;
  108. alter user $DATABASENAME default tablespace users
  109. temporary tablespace temp
  110. quota unlimited on users;
  111. grant create session
  112. , create table
  113. , create procedure
  114. , create sequence
  115. , create trigger
  116. , create view
  117. , create synonym
  118. , alter session
  119. to $DATABASENAME;
  120. exit;
  121. EOF
  122. DATABASEUSER=$DATABASENAME
  123. DATABASENAME='XE'
  124. fi
  125. # copy autoconfig
  126. cp "$BASEDIR/tests/autoconfig-$1.php" "$BASEDIR/config/autoconfig.php"
  127. # trigger installation
  128. echo "Installing ...."
  129. ./occ maintenance:install -vvv --database=$1 --database-name=$DATABASENAME --database-host=localhost --database-user=$DATABASEUSER --database-pass=owncloud --database-table-prefix=oc_ --admin-user=$ADMINLOGIN --admin-pass=admin --data-dir=$DATADIR
  130. #test execution
  131. echo "Testing with $1 ..."
  132. if [ -n "$2" ]; then
  133. echo "Run only $2 ..."
  134. fi
  135. cd tests
  136. rm -rf "coverage-external-html-$1"
  137. mkdir "coverage-external-html-$1"
  138. # just enable files_external
  139. php ../occ app:enable -vvv files_external
  140. if [[ "$_XDEBUG_CONFIG" ]]; then
  141. export XDEBUG_CONFIG=$_XDEBUG_CONFIG
  142. fi
  143. if [ -z "$NOCOVERAGE" ]; then
  144. "$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1.xml" --coverage-clover "autotest-external-clover-$1.xml" --coverage-html "coverage-external-html-$1"
  145. else
  146. echo "No coverage"
  147. "$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1.xml"
  148. fi
  149. if [[ $? -ne 0 ]]; then
  150. echo "Error during phpunit execution ... terminating"
  151. exit 1
  152. fi
  153. if [ -n "$2" -a "$2" == "common-tests" ]; then
  154. return;
  155. fi
  156. FILES_EXTERNAL_BACKEND_PATH=../apps/files_external/tests/Storage
  157. FILES_EXTERNAL_BACKEND_ENV_PATH=../apps/files_external/tests/env
  158. for startFile in `ls -1 $FILES_EXTERNAL_BACKEND_ENV_PATH | grep start`; do
  159. name=`echo $startFile | sed 's/start-//' | sed 's/\.sh//'`
  160. if [ -n "$2" -a "$2" != "$name" ]; then
  161. echo "skip: $startFile"
  162. continue;
  163. fi
  164. echo "start: $startFile"
  165. echo "name: $name"
  166. # execute start file
  167. ./$FILES_EXTERNAL_BACKEND_ENV_PATH/$startFile
  168. if [ $? -eq 0 ]; then
  169. # getting backend to test from filename
  170. # it's the part between the dots startSomething.TestToRun.sh
  171. testToRun=`echo $startFile | cut -d '-' -f 2`
  172. # capitalize first letter
  173. testToRun="${testToRun^}"
  174. testToRun="${testToRun}Test.php"
  175. # run the specific test
  176. if [ -z "$NOCOVERAGE" ]; then
  177. rm -rf "coverage-external-html-$1-$name"
  178. mkdir "coverage-external-html-$1-$name"
  179. "$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1-$name.xml" --coverage-clover "autotest-external-clover-$1-$name.xml" --coverage-html "coverage-external-html-$1-$name" "$FILES_EXTERNAL_BACKEND_PATH/$testToRun"
  180. else
  181. echo "No coverage"
  182. "$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1-$name.xml" "$FILES_EXTERNAL_BACKEND_PATH/$testToRun"
  183. fi
  184. else
  185. DOEXIT=1
  186. fi
  187. if [[ $? -ne 0 ]]; then
  188. echo "Error during phpunit execution ... terminating"
  189. exit 1
  190. fi
  191. # calculate stop file
  192. stopFile=`echo "$startFile" | sed 's/start/stop/'`
  193. echo "stop: $stopFile"
  194. if [ -f $FILES_EXTERNAL_BACKEND_ENV_PATH/$stopFile ]; then
  195. # execute stop file if existent
  196. ./$FILES_EXTERNAL_BACKEND_ENV_PATH/$stopFile
  197. fi
  198. if [ "$DOEXIT" ]; then
  199. echo "Error during start file execution ... terminating"
  200. exit $DOEXIT
  201. fi
  202. done;
  203. }
  204. #
  205. # start test execution
  206. #
  207. if [ -z "$1" ]; then
  208. # run all known database configs
  209. for DBCONFIG in $DBCONFIGS; do
  210. execute_tests $DBCONFIG "$2"
  211. done
  212. else
  213. execute_tests "$1" "$2"
  214. fi
  215. #
  216. # NOTES on mysql:
  217. # - CREATE DATABASE oc_autotest;
  218. # - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud';
  219. # - grant all on oc_autotest.* to 'oc_autotest'@'localhost';
  220. #
  221. # - for parallel executor support with EXECUTOR_NUMBER=0:
  222. # - CREATE DATABASE oc_autotest0;
  223. # - CREATE USER 'oc_autotest0'@'localhost' IDENTIFIED BY 'owncloud';
  224. # - grant all on oc_autotest0.* to 'oc_autotest0'@'localhost';
  225. #
  226. # NOTES on pgsql:
  227. # - su - postgres
  228. # - createuser -P oc_autotest (enter password and enable superuser)
  229. # - to enable dropdb I decided to add following line to pg_hba.conf (this is not the safest way but I don't care for the testing machine):
  230. # local all all trust
  231. #
  232. # - for parallel executor support with EXECUTOR_NUMBER=0:
  233. # - createuser -P oc_autotest0 (enter password and enable superuser)
  234. #
  235. # NOTES on oci:
  236. # - it's a pure nightmare to install Oracle on a Linux-System
  237. # - DON'T TRY THIS AT HOME!
  238. # - if you really need it: we feel sorry for you
  239. #