Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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