You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autotest-hhvm.sh 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/bin/bash
  2. #
  3. # ownCloud
  4. #
  5. # @author Vincent Petry
  6. # @author Morris Jobke
  7. # @author Robin McCorkell
  8. # @author Thomas Müller
  9. # @author Andreas Fischer
  10. # @author Joas Schilling
  11. # @author Lukas Reschke
  12. # @copyright 2012-2015 Thomas Müller thomas.mueller@tmit.eu
  13. #
  14. set -e
  15. #$EXECUTOR_NUMBER is set by Jenkins and allows us to run autotest in parallel
  16. DATABASENAME=oc_autotest$EXECUTOR_NUMBER
  17. DATABASEUSER=oc_autotest$EXECUTOR_NUMBER
  18. ADMINLOGIN=admin$EXECUTOR_NUMBER
  19. BASEDIR=$PWD
  20. DBCONFIGS="sqlite mysql pgsql oci"
  21. PHPUNIT=$(which phpunit)
  22. HHVM=$(which hhvm)
  23. function print_syntax {
  24. echo -e "Syntax: ./autotest-hhvm.sh [dbconfigname] [testfile]\n" >&2
  25. echo -e "\t\"dbconfigname\" can be one of: $DBCONFIGS" >&2
  26. echo -e "\t\"testfile\" is the name of a test file, for example lib/template.php" >&2
  27. echo -e "\nExample: ./autotest.sh sqlite lib/template.php" >&2
  28. echo "will run the test suite from \"tests/lib/template.php\"" >&2
  29. echo -e "\nIf no arguments are specified, all tests will be run with all database configs" >&2
  30. }
  31. if ! [ -x "$PHPUNIT" ]; then
  32. echo "phpunit executable not found, please install phpunit version >= 3.7" >&2
  33. exit 3
  34. fi
  35. if ! [ -x "$HHVM" ]; then
  36. echo "hhvm executable not found, please install hhvm" >&2
  37. exit 3
  38. fi
  39. PHPUNIT_VERSION=$(hhvm "$PHPUNIT" --version | cut -d" " -f2)
  40. PHPUNIT_MAJOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f1)
  41. PHPUNIT_MINOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f2)
  42. if ! [ $PHPUNIT_MAJOR_VERSION -gt 3 -o \( $PHPUNIT_MAJOR_VERSION -eq 3 -a $PHPUNIT_MINOR_VERSION -ge 7 \) ]; then
  43. echo "phpunit version >= 3.7 required. Version found: $PHPUNIT_VERSION" >&2
  44. exit 4
  45. fi
  46. if ! [ -w config -a -w config/config.php ]; then
  47. echo "Please enable write permissions on config and config/config.php" >&2
  48. exit 1
  49. fi
  50. if [ "$1" ]; then
  51. FOUND=0
  52. for DBCONFIG in $DBCONFIGS; do
  53. if [ "$1" = $DBCONFIG ]; then
  54. FOUND=1
  55. break
  56. fi
  57. done
  58. if [ $FOUND = 0 ]; then
  59. echo -e "Unknown database config name \"$1\"\n" >&2
  60. print_syntax
  61. exit 2
  62. fi
  63. fi
  64. # Back up existing (dev) config if one exists and backup not already there
  65. if [ -f config/config.php ] && [ ! -f config/config-autotest-backup.php ]; then
  66. mv config/config.php config/config-autotest-backup.php
  67. fi
  68. function cleanup_config {
  69. cd "$BASEDIR"
  70. # Restore existing config
  71. if [ -f config/config-autotest-backup.php ]; then
  72. mv config/config-autotest-backup.php config/config.php
  73. fi
  74. # Remove autotest config
  75. if [ -f config/autoconfig.php ]; then
  76. rm config/autoconfig.php
  77. fi
  78. }
  79. # restore config on exit
  80. trap cleanup_config EXIT
  81. # use tmpfs for datadir - should speedup unit test execution
  82. if [ -d /dev/shm ]; then
  83. DATADIR=/dev/shm/data-autotest$EXECUTOR_NUMBER
  84. else
  85. DATADIR=$BASEDIR/data-autotest
  86. fi
  87. echo "Using database $DATABASENAME"
  88. function execute_tests {
  89. echo "Setup environment for $1 testing ..."
  90. # back to root folder
  91. cd "$BASEDIR"
  92. # revert changes to tests/data
  93. git checkout tests/data
  94. # reset data directory
  95. rm -rf "$DATADIR"
  96. mkdir "$DATADIR"
  97. # remove the old config file
  98. #rm -rf config/config.php
  99. cp tests/preseed-config.php config/config.php
  100. # drop database
  101. if [ "$1" == "mysql" ] ; then
  102. mysql -u $DATABASEUSER -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" || true
  103. fi
  104. if [ "$1" == "pgsql" ] ; then
  105. dropdb -U $DATABASEUSER $DATABASENAME || true
  106. fi
  107. if [ "$1" == "oci" ] ; then
  108. echo "drop the database"
  109. sqlplus -s -l / as sysdba <<EOF
  110. drop user $DATABASENAME cascade;
  111. EOF
  112. echo "create the database"
  113. sqlplus -s -l / as sysdba <<EOF
  114. create user $DATABASENAME identified by owncloud;
  115. alter user $DATABASENAME default tablespace users
  116. temporary tablespace temp
  117. quota unlimited on users;
  118. grant create session
  119. , create table
  120. , create procedure
  121. , create sequence
  122. , create trigger
  123. , create view
  124. , create synonym
  125. , alter session
  126. to $DATABASENAME;
  127. exit;
  128. EOF
  129. DATABASEUSER=$DATABASENAME
  130. DATABASENAME='XE'
  131. fi
  132. # copy autoconfig
  133. cp "$BASEDIR/tests/autoconfig-$1.php" "$BASEDIR/config/autoconfig.php"
  134. # trigger installation
  135. echo "Installing ...."
  136. hhvm ./occ maintenance:install --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
  137. #test execution
  138. echo "Testing with $1 ..."
  139. cd tests
  140. rm -rf "coverage-html-$1"
  141. mkdir "coverage-html-$1"
  142. hhvm -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101
  143. if [ -z "$NOCOVERAGE" ]; then
  144. hhvm "$PHPUNIT" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" --coverage-clover "autotest-clover-$1.xml" --coverage-html "coverage-html-$1" "$2" "$3"
  145. RESULT=$?
  146. else
  147. echo "No coverage"
  148. hhvm "$PHPUNIT" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3"
  149. RESULT=$?
  150. fi
  151. }
  152. #
  153. # start test execution
  154. #
  155. if [ -z "$1" ]
  156. then
  157. # run all known database configs
  158. for DBCONFIG in $DBCONFIGS; do
  159. execute_tests $DBCONFIG
  160. done
  161. else
  162. execute_tests "$1" "$2" "$3"
  163. fi
  164. #
  165. # NOTES on mysql:
  166. # - CREATE DATABASE oc_autotest;
  167. # - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud';
  168. # - grant all on oc_autotest.* to 'oc_autotest'@'localhost';
  169. #
  170. # - for parallel executor support with EXECUTOR_NUMBER=0:
  171. # - CREATE DATABASE oc_autotest0;
  172. # - CREATE USER 'oc_autotest0'@'localhost' IDENTIFIED BY 'owncloud';
  173. # - grant all on oc_autotest0.* to 'oc_autotest0'@'localhost';
  174. #
  175. # NOTES on pgsql:
  176. # - su - postgres
  177. # - createuser -P oc_autotest (enter password and enable superuser)
  178. # - 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):
  179. # local all all trust
  180. #
  181. # - for parallel executor support with EXECUTOR_NUMBER=0:
  182. # - createuser -P oc_autotest0 (enter password and enable superuser)
  183. #
  184. # NOTES on oci:
  185. # - it's a pure nightmare to install Oracle on a Linux-System
  186. # - DON'T TRY THIS AT HOME!
  187. # - if you really need it: we feel sorry for you
  188. #