autotest.sh 4.9 KB

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