autotest-hhvm.sh 6.8 KB

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