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 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 and backup not already there
  59. if [ -f config/config.php ] && [ ! -f config/config-autotest-backup.php ]; then
  60. mv config/config.php config/config-autotest-backup.php
  61. fi
  62. function cleanup_config {
  63. cd "$BASEDIR"
  64. # Restore existing config
  65. if [ -f config/config-autotest-backup.php ]; then
  66. mv config/config-autotest-backup.php config/config.php
  67. fi
  68. # Remove autotest config
  69. if [ -f config/autoconfig.php ]; then
  70. rm config/autoconfig.php
  71. fi
  72. }
  73. # restore config on exit
  74. trap cleanup_config EXIT
  75. # use tmpfs for datadir - should speedup unit test execution
  76. if [ -d /dev/shm ]; then
  77. DATADIR=/dev/shm/data-autotest$EXECUTOR_NUMBER
  78. else
  79. DATADIR=$BASEDIR/data-autotest
  80. fi
  81. echo "Using database $DATABASENAME"
  82. # create autoconfig for sqlite, mysql and postgresql
  83. cat > ./tests/autoconfig-sqlite.php <<DELIM
  84. <?php
  85. \$AUTOCONFIG = array (
  86. 'installed' => false,
  87. 'dbtype' => 'sqlite',
  88. 'dbtableprefix' => 'oc_',
  89. 'adminlogin' => '$ADMINLOGIN',
  90. 'adminpass' => 'admin',
  91. 'directory' => '$DATADIR',
  92. );
  93. DELIM
  94. cat > ./tests/autoconfig-mysql.php <<DELIM
  95. <?php
  96. \$AUTOCONFIG = array (
  97. 'installed' => false,
  98. 'dbtype' => 'mysql',
  99. 'dbtableprefix' => 'oc_',
  100. 'adminlogin' => '$ADMINLOGIN',
  101. 'adminpass' => 'admin',
  102. 'directory' => '$DATADIR',
  103. 'dbuser' => '$DATABASEUSER',
  104. 'dbname' => '$DATABASENAME',
  105. 'dbhost' => 'localhost',
  106. 'dbpass' => 'owncloud',
  107. );
  108. DELIM
  109. cat > ./tests/autoconfig-pgsql.php <<DELIM
  110. <?php
  111. \$AUTOCONFIG = array (
  112. 'installed' => false,
  113. 'dbtype' => 'pgsql',
  114. 'dbtableprefix' => 'oc_',
  115. 'adminlogin' => '$ADMINLOGIN',
  116. 'adminpass' => 'admin',
  117. 'directory' => '$DATADIR',
  118. 'dbuser' => '$DATABASEUSER',
  119. 'dbname' => '$DATABASENAME',
  120. 'dbhost' => 'localhost',
  121. 'dbpass' => 'owncloud',
  122. );
  123. DELIM
  124. cat > ./tests/autoconfig-oci.php <<DELIM
  125. <?php
  126. \$AUTOCONFIG = array (
  127. 'installed' => false,
  128. 'dbtype' => 'oci',
  129. 'dbtableprefix' => 'oc_',
  130. 'adminlogin' => '$ADMINLOGIN',
  131. 'adminpass' => 'admin',
  132. 'directory' => '$DATADIR',
  133. 'dbuser' => '$DATABASENAME',
  134. 'dbname' => 'XE',
  135. 'dbhost' => 'localhost',
  136. 'dbpass' => 'owncloud',
  137. );
  138. DELIM
  139. function execute_tests {
  140. echo "Setup environment for $1 testing ..."
  141. # back to root folder
  142. cd "$BASEDIR"
  143. # revert changes to tests/data
  144. git checkout tests/data
  145. # reset data directory
  146. rm -rf "$DATADIR"
  147. mkdir "$DATADIR"
  148. # remove the old config file
  149. #rm -rf config/config.php
  150. cp tests/preseed-config.php config/config.php
  151. # drop database
  152. if [ "$1" == "mysql" ] ; then
  153. mysql -u $DATABASEUSER -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" || true
  154. fi
  155. if [ "$1" == "pgsql" ] ; then
  156. dropdb -U $DATABASEUSER $DATABASENAME || true
  157. fi
  158. if [ "$1" == "oci" ] ; then
  159. echo "drop the database"
  160. sqlplus -s -l / as sysdba <<EOF
  161. drop user $DATABASENAME cascade;
  162. EOF
  163. echo "create the database"
  164. sqlplus -s -l / as sysdba <<EOF
  165. create user $DATABASENAME identified by owncloud;
  166. alter user $DATABASENAME default tablespace users
  167. temporary tablespace temp
  168. quota unlimited on users;
  169. grant create session
  170. , create table
  171. , create procedure
  172. , create sequence
  173. , create trigger
  174. , create view
  175. , create synonym
  176. , alter session
  177. to $DATABASENAME;
  178. exit;
  179. EOF
  180. fi
  181. # copy autoconfig
  182. cp "$BASEDIR/tests/autoconfig-$1.php" "$BASEDIR/config/autoconfig.php"
  183. # trigger installation
  184. echo "INDEX"
  185. hhvm -f index.php | grep -i -C9999 error && echo "Error during setup" && exit 101
  186. echo "END INDEX"
  187. #test execution
  188. echo "Testing with $1 ..."
  189. cd tests
  190. rm -rf "coverage-html-$1"
  191. mkdir "coverage-html-$1"
  192. hhvm -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101
  193. if [ -z "$NOCOVERAGE" ]; then
  194. 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"
  195. RESULT=$?
  196. else
  197. echo "No coverage"
  198. hhvm "$PHPUNIT" --configuration phpunit-autotest.xml --log-junit "autotest-results-$1.xml" "$2" "$3"
  199. RESULT=$?
  200. fi
  201. }
  202. #
  203. # start test execution
  204. #
  205. if [ -z "$1" ]
  206. then
  207. # run all known database configs
  208. for DBCONFIG in $DBCONFIGS; do
  209. execute_tests $DBCONFIG
  210. done
  211. else
  212. execute_tests "$1" "$2" "$3"
  213. fi
  214. #
  215. # NOTES on mysql:
  216. # - CREATE DATABASE oc_autotest;
  217. # - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud';
  218. # - grant all on oc_autotest.* to 'oc_autotest'@'localhost';
  219. #
  220. # - for parallel executor support with EXECUTOR_NUMBER=0:
  221. # - CREATE DATABASE oc_autotest0;
  222. # - CREATE USER 'oc_autotest0'@'localhost' IDENTIFIED BY 'owncloud';
  223. # - grant all on oc_autotest0.* to 'oc_autotest0'@'localhost';
  224. #
  225. # NOTES on pgsql:
  226. # - su - postgres
  227. # - createuser -P oc_autotest (enter password and enable superuser)
  228. # - 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):
  229. # local all all trust
  230. #
  231. # - for parallel executor support with EXECUTOR_NUMBER=0:
  232. # - createuser -P oc_autotest0 (enter password and enable superuser)
  233. #
  234. # NOTES on oci:
  235. # - it's a pure nightmare to install Oracle on a Linux-System
  236. # - DON'T TRY THIS AT HOME!
  237. # - if you really need it: we feel sorry for you
  238. #