autotest.sh 5.7 KB

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