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.

пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 8 година
пре 12 година
пре 8 година
пре 8 година
пре 8 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 11 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. #!/usr/bin/env bash
  2. #
  3. # ownCloud
  4. #
  5. # @author Vincent Petry
  6. # @author Morris Jobke
  7. # @author Robin McCorkell
  8. # @author Thomas Müller
  9. # @author Andreas Fischer
  10. # @author Joas Schilling
  11. # @author Lukas Reschke
  12. # @author Jörn Friedrich Dreyer
  13. # @copyright 2012-2015 Thomas Müller thomas.mueller@tmit.eu
  14. #
  15. DATABASENAME=oc_autotest
  16. DATABASEUSER=oc_autotest
  17. DATABASEHOST=localhost
  18. ADMINLOGIN=admin
  19. BASEDIR=$PWD
  20. PRIMARY_STORAGE_CONFIGS="local swift"
  21. DBCONFIGS="sqlite mysql mariadb pgsql oci mysqlmb4"
  22. # $PHP_EXE is run through 'which' and as such e.g. 'php' is usually
  23. # sufficient. Due to the behaviour of 'which', $PHP_EXE may also be a path
  24. # (absolute or not) to an executable, e.g. ./code/projects/php-src/sapi/cli/php.
  25. if [ -z "$PHP_EXE" ]; then
  26. PHP_EXE=php
  27. fi
  28. PHP=$(which "$PHP_EXE")
  29. PHPUNIT=$(which phpunit)
  30. set -e
  31. _XDEBUG_CONFIG=$XDEBUG_CONFIG
  32. unset XDEBUG_CONFIG
  33. function print_syntax {
  34. echo -e "Syntax: ./autotest.sh [dbconfigname] [testfile]\n" >&2
  35. echo -e "\t\"dbconfigname\" can be one of: $DBCONFIGS" >&2
  36. echo -e "\t\"testfile\" is the name of a test file, for example lib/template.php" >&2
  37. echo -e "\nExample: ./autotest.sh sqlite lib/template.php" >&2
  38. echo "will run the test suite from \"tests/lib/template.php\"" >&2
  39. echo -e "\nIf no arguments are specified, all tests will be run with all database configs" >&2
  40. }
  41. if [ -x "$PHP" ]; then
  42. echo "Using PHP executable $PHP"
  43. else
  44. echo "Could not find PHP executable $PHP_EXE" >&2
  45. exit 3
  46. fi
  47. if ! [ -x "$PHPUNIT" ]; then
  48. echo "phpunit executable not found, please install phpunit version >= 6.5" >&2
  49. exit 3
  50. fi
  51. # PHPUnit might also be installed via a facade binary script
  52. if [[ "$PHPUNIT" =~ \.phar$ ]]; then
  53. PHPUNIT=( "$PHP" "$PHPUNIT" )
  54. else
  55. PHPUNIT=( "$PHPUNIT" )
  56. fi
  57. PHPUNIT_VERSION=$($PHPUNIT --version | cut -d" " -f2)
  58. PHPUNIT_MAJOR_VERSION=$(echo "$PHPUNIT_VERSION" | cut -d"." -f1)
  59. PHPUNIT_MINOR_VERSION=$(echo "$PHPUNIT_VERSION" | cut -d"." -f2)
  60. if ! [ "$PHPUNIT_MAJOR_VERSION" -gt 6 -o \( "$PHPUNIT_MAJOR_VERSION" -eq 6 -a "$PHPUNIT_MINOR_VERSION" -ge 5 \) ]; then
  61. echo "phpunit version >= 6.5 required. Version found: $PHPUNIT_VERSION" >&2
  62. exit 4
  63. fi
  64. if ! [ \( -w config -a ! -f config/config.php \) -o \( -f config/config.php -a -w config/config.php \) ]; then
  65. echo "Please enable write permissions on config and config/config.php" >&2
  66. exit 1
  67. fi
  68. if [ "$1" ]; then
  69. FOUND=0
  70. for DBCONFIG in $DBCONFIGS; do
  71. if [ "$1" = "$DBCONFIG" ]; then
  72. FOUND=1
  73. break
  74. fi
  75. done
  76. if [ $FOUND = 0 ]; then
  77. echo -e "Unknown database config name \"$1\"\n" >&2
  78. print_syntax
  79. exit 2
  80. fi
  81. fi
  82. if [ "$PRIMARY_STORAGE_CONFIG" ]; then
  83. FOUND=0
  84. for PSC in $PRIMARY_STORAGE_CONFIGS; do
  85. if [ "$PRIMARY_STORAGE_CONFIG" = "$PSC" ]; then
  86. FOUND=1
  87. break
  88. fi
  89. done
  90. if [ $FOUND = 0 ]; then
  91. echo -e "Unknown primary storage config name \"$PRIMARY_STORAGE_CONFIG\"\n" >&2
  92. print_syntax
  93. exit 2
  94. fi
  95. else
  96. PRIMARY_STORAGE_CONFIG="local"
  97. fi
  98. # Back up existing (dev) config if one exists and backup not already there
  99. if [ -f config/config.php ] && [ ! -f config/config-autotest-backup.php ]; then
  100. mv config/config.php config/config-autotest-backup.php
  101. fi
  102. function cleanup_config {
  103. if [ ! -z "$DOCKER_CONTAINER_ID" ]; then
  104. echo "Kill the docker $DOCKER_CONTAINER_ID"
  105. docker stop "$DOCKER_CONTAINER_ID"
  106. docker rm -f "$DOCKER_CONTAINER_ID"
  107. fi
  108. cd "$BASEDIR"
  109. if [ "$PRIMARY_STORAGE_CONFIG" == "swift" ] ; then
  110. echo "Kill the swift docker"
  111. tests/objectstore/stop-swift-ceph.sh
  112. fi
  113. # Restore existing config
  114. if [ -f config/config-autotest-backup.php ]; then
  115. mv config/config-autotest-backup.php config/config.php
  116. fi
  117. # Remove autotest config
  118. if [ -f config/autoconfig.php ]; then
  119. rm config/autoconfig.php
  120. fi
  121. # Remove autotest swift storage config
  122. if [ -f config/autotest-storage-swift.config.php ]; then
  123. rm config/autotest-storage-swift.config.php
  124. fi
  125. # Remove autotest redis config
  126. if [ -f config/redis.config.php ]; then
  127. rm config/redis.config.php
  128. fi
  129. # Remove mysqlmb4.config.php
  130. rm -f config/mysqlmb4.config.php
  131. }
  132. # restore config on exit
  133. trap cleanup_config EXIT
  134. # use tmpfs for datadir - should speedup unit test execution
  135. if [ -d /dev/shm ]; then
  136. DATADIR=/dev/shm/data-autotest$EXECUTOR_NUMBER
  137. else
  138. DATADIR=$BASEDIR/data-autotest
  139. fi
  140. echo "Using database $DATABASENAME"
  141. function execute_tests {
  142. DB=$1
  143. echo "Setup environment for $DB testing on $PRIMARY_STORAGE_CONFIG storage ..."
  144. # back to root folder
  145. cd "$BASEDIR"
  146. # revert changes to tests/data
  147. git checkout tests/data
  148. # reset data directory
  149. rm -rf "$DATADIR"
  150. mkdir "$DATADIR"
  151. if [ "$PRIMARY_STORAGE_CONFIG" == "swift" ] ; then
  152. tests/objectstore/start-swift-ceph.sh
  153. cp tests/objectstore/swift.config.php config/autotest-storage-swift.config.php
  154. fi
  155. cp tests/preseed-config.php config/config.php
  156. if [ "$ENABLE_REDIS" == "true" ] ; then
  157. cp tests/redis.config.php config/redis.config.php
  158. elif [ "$ENABLE_REDIS_CLUSTER" == "true" ] ; then
  159. cp tests/redis-cluster.config.php config/redis.config.php
  160. fi
  161. _DB=$DB
  162. # drop database
  163. if [ "$DB" == "mysql" ] ; then
  164. if [ ! -z "$USEDOCKER" ] ; then
  165. echo "Fire up the mysql docker"
  166. DOCKER_CONTAINER_ID=$(docker run \
  167. -v $BASEDIR/tests/docker/mariadb:/etc/mysql/conf.d \
  168. -e MYSQL_ROOT_PASSWORD=owncloud \
  169. -e MYSQL_USER="$DATABASEUSER" \
  170. -e MYSQL_PASSWORD=owncloud \
  171. -e MYSQL_DATABASE="$DATABASENAME" \
  172. -d mysql)
  173. DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
  174. else
  175. if [ -z "$DRONE" ] ; then # no need to drop the DB when we are on CI
  176. if [ "mysql" != "$(mysql --version | grep -o mysql)" ] ; then
  177. echo "Your mysql binary is not provided by mysql"
  178. echo "To use the docker container set the USEDOCKER environment variable"
  179. exit -1
  180. fi
  181. mysql -u "$DATABASEUSER" -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true
  182. else
  183. DATABASEHOST=mysql
  184. fi
  185. fi
  186. echo "Waiting for MySQL initialisation ..."
  187. if ! apps/files_external/tests/env/wait-for-connection $DATABASEHOST 3306 300; then
  188. echo "[ERROR] Waited 300 seconds, no response" >&2
  189. exit 1
  190. fi
  191. fi
  192. if [ "$DB" == "mysqlmb4" ] ; then
  193. if [ ! -z "$USEDOCKER" ] ; then
  194. echo "Fire up the mysql docker"
  195. DOCKER_CONTAINER_ID=$(docker run \
  196. -v $BASEDIR/tests/docker/mysqlmb4:/etc/mysql/conf.d \
  197. -e MYSQL_ROOT_PASSWORD=owncloud \
  198. -e MYSQL_USER="$DATABASEUSER" \
  199. -e MYSQL_PASSWORD=owncloud \
  200. -e MYSQL_DATABASE="$DATABASENAME" \
  201. -d mysql:5.7 \
  202. --innodb_large_prefix=true \
  203. --innodb_file_format=barracuda \
  204. --innodb_file_per_table=true)
  205. DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
  206. else
  207. if [ -z "$DRONE" ] ; then # no need to drop the DB when we are on CI
  208. if [ "mysql" != "$(mysql --version | grep -o mysql)" ] ; then
  209. echo "Your mysql binary is not provided by mysql"
  210. echo "To use the docker container set the USEDOCKER environment variable"
  211. exit -1
  212. fi
  213. mysql -u "$DATABASEUSER" -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true
  214. else
  215. DATABASEHOST=mysqlmb4
  216. fi
  217. fi
  218. echo "Waiting for MySQL(utf8mb4) initialisation ..."
  219. if ! apps/files_external/tests/env/wait-for-connection $DATABASEHOST 3306 300; then
  220. echo "[ERROR] Waited 300 seconds, no response" >&2
  221. exit 1
  222. fi
  223. sleep 1
  224. echo "MySQL(utf8mb4) is up."
  225. _DB="mysql"
  226. cp tests/docker/mysqlmb4.config.php config
  227. fi
  228. if [ "$DB" == "mariadb" ] ; then
  229. if [ ! -z "$USEDOCKER" ] ; then
  230. echo "Fire up the mariadb docker"
  231. DOCKER_CONTAINER_ID=$(docker run \
  232. -v $BASEDIR/tests/docker/mariadb:/etc/mysql/conf.d \
  233. -e MYSQL_ROOT_PASSWORD=owncloud \
  234. -e MYSQL_USER="$DATABASEUSER" \
  235. -e MYSQL_PASSWORD=owncloud \
  236. -e MYSQL_DATABASE="$DATABASENAME" \
  237. -d mariadb)
  238. DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
  239. echo "Waiting for MariaDB initialisation ..."
  240. if ! apps/files_external/tests/env/wait-for-connection $DATABASEHOST 3306 300; then
  241. echo "[ERROR] Waited 300 seconds, no response" >&2
  242. exit 1
  243. fi
  244. echo "MariaDB is up."
  245. else
  246. if [ -z "$DRONE" ] ; then # no need to drop the DB when we are on CI
  247. if [ "MariaDB" != "$(mysql --version | grep -o MariaDB)" ] ; then
  248. echo "Your mysql binary is not provided by MariaDB"
  249. echo "To use the docker container set the USEDOCKER environment variable"
  250. exit -1
  251. fi
  252. mysql -u "$DATABASEUSER" -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true
  253. else
  254. DATABASEHOST=mariadb
  255. fi
  256. fi
  257. echo "Waiting for MariaDB initialisation ..."
  258. if ! apps/files_external/tests/env/wait-for-connection $DATABASEHOST 3306 300; then
  259. echo "[ERROR] Waited 300 seconds, no response" >&2
  260. exit 1
  261. fi
  262. #Reset _DB to mysql since that is what we use internally
  263. _DB="mysql"
  264. fi
  265. if [ "$DB" == "pgsql" ] ; then
  266. if [ ! -z "$USEDOCKER" ] ; then
  267. echo "Fire up the postgres docker"
  268. DOCKER_CONTAINER_ID=$(docker run -e POSTGRES_USER="$DATABASEUSER" -e POSTGRES_PASSWORD=owncloud -d postgres)
  269. DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
  270. echo "Waiting for Postgres initialisation ..."
  271. # grep exits on the first match and then the script continues
  272. docker logs -f "$DOCKER_CONTAINER_ID" 2>&1 | grep -q "database system is ready to accept connections"
  273. echo "Postgres is up."
  274. else
  275. if [ ! -z "$DRONE" ] ; then
  276. DATABASEHOST="postgres-$POSTGRES"
  277. fi
  278. echo "Waiting for Postgres to be available ..."
  279. if ! apps/files_external/tests/env/wait-for-connection $DATABASEHOST 5432 60; then
  280. echo "[ERROR] Waited 60 seconds for $DATABASEHOST, no response" >&2
  281. exit 1
  282. fi
  283. echo "Give it 10 additional seconds ..."
  284. sleep 10
  285. if [ -z "$DRONE" ] ; then # no need to drop the DB when we are on CI
  286. dropdb -U "$DATABASEUSER" "$DATABASENAME" || true
  287. fi
  288. fi
  289. fi
  290. if [ "$DB" == "oci" ] ; then
  291. echo "Fire up the oracle docker"
  292. DOCKER_CONTAINER_ID=$(docker run -d deepdiver/docker-oracle-xe-11g)
  293. DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
  294. echo "Waiting for Oracle initialization ... "
  295. # Try to connect to the OCI host via sqlplus to ensure that the connection is already running
  296. for i in {1..48}
  297. do
  298. if sqlplus "autotest/owncloud@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=$DATABASEHOST)(Port=1521))(CONNECT_DATA=(SID=XE)))" < /dev/null | grep 'Connected to'; then
  299. break;
  300. fi
  301. sleep 5
  302. done
  303. DATABASEUSER=autotest
  304. DATABASENAME='XE'
  305. fi
  306. # trigger installation
  307. echo "Installing ...."
  308. "$PHP" ./occ maintenance:install -vvv --database="$_DB" --database-name="$DATABASENAME" --database-host="$DATABASEHOST" --database-user="$DATABASEUSER" --database-pass=owncloud --admin-user="$ADMINLOGIN" --admin-pass=admin --data-dir="$DATADIR"
  309. #test execution
  310. echo "Testing with $DB ..."
  311. cd tests
  312. rm -rf "coverage-html-$DB"
  313. mkdir "coverage-html-$DB"
  314. "$PHP" -f enable_all.php | grep -i -C9999 error && echo "Error during setup" && exit 101
  315. if [[ "$_XDEBUG_CONFIG" ]]; then
  316. export XDEBUG_CONFIG=$_XDEBUG_CONFIG
  317. fi
  318. GROUP=''
  319. if [ "$TEST_SELECTION" == "QUICKDB" ]; then
  320. GROUP='--group DB --exclude-group=SLOWDB'
  321. fi
  322. if [ "$TEST_SELECTION" == "DB" ]; then
  323. GROUP='--group DB,SLOWDB'
  324. fi
  325. if [ "$TEST_SELECTION" == "NODB" ]; then
  326. GROUP='--exclude-group DB,SLOWDB'
  327. fi
  328. if [ "$TEST_SELECTION" == "PRIMARY-s3" ]; then
  329. GROUP='--group PRIMARY-s3'
  330. fi
  331. if [ "$TEST_SELECTION" == "PRIMARY-azure" ]; then
  332. GROUP='--group PRIMARY-azure'
  333. fi
  334. if [ "$TEST_SELECTION" == "PRIMARY-swift" ]; then
  335. GROUP='--group PRIMARY-swift'
  336. fi
  337. COVER=''
  338. if [ -z "$NOCOVERAGE" ]; then
  339. COVER="--coverage-clover autotest-clover-$DB.xml --coverage-html coverage-html-$DB"
  340. else
  341. echo "No coverage"
  342. fi
  343. echo "${PHPUNIT[@]}" --configuration phpunit-autotest.xml $GROUP $COVER --log-junit "autotest-results-$DB.xml" "$2" "$3"
  344. "${PHPUNIT[@]}" --configuration phpunit-autotest.xml $GROUP $COVER --log-junit "autotest-results-$DB.xml" "$2" "$3"
  345. RESULT=$?
  346. if [ "$PRIMARY_STORAGE_CONFIG" == "swift" ] ; then
  347. cd ..
  348. echo "Kill the swift docker"
  349. tests/objectstore/stop-swift-ceph.sh
  350. fi
  351. if [ ! -z "$DOCKER_CONTAINER_ID" ] ; then
  352. echo "Kill the docker $DOCKER_CONTAINER_ID"
  353. docker stop $DOCKER_CONTAINER_ID
  354. docker rm -f $DOCKER_CONTAINER_ID
  355. unset DOCKER_CONTAINER_ID
  356. fi
  357. }
  358. #
  359. # start test execution
  360. #
  361. if [ -z "$1" ]
  362. then
  363. # run all known database configs
  364. for DBCONFIG in $DBCONFIGS; do
  365. execute_tests "$DBCONFIG"
  366. done
  367. else
  368. FILENAME="$2"
  369. if [ ! -z "$2" ] && [ ! -f "tests/$FILENAME" ] && [ "${FILENAME:0:2}" != "--" ]; then
  370. FILENAME="../$FILENAME"
  371. fi
  372. execute_tests "$1" "$FILENAME" "$3"
  373. fi
  374. #
  375. # NOTES on mysql:
  376. # - CREATE DATABASE oc_autotest;
  377. # - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud';
  378. # - grant all on oc_autotest.* to 'oc_autotest'@'localhost';
  379. #
  380. # - for parallel executor support with EXECUTOR_NUMBER=0:
  381. # - CREATE DATABASE oc_autotest0;
  382. # - CREATE USER 'oc_autotest0'@'localhost' IDENTIFIED BY 'owncloud';
  383. # - grant all on oc_autotest0.* to 'oc_autotest0'@'localhost';
  384. #
  385. # NOTES on pgsql:
  386. # - su - postgres
  387. # - createuser -P oc_autotest (enter password and enable superuser)
  388. # - to enable dropdb I decided to add following line to pg_hba.conf
  389. # (this is not the safest way but I don't care for the testing machine):
  390. # local all all trust
  391. #
  392. # - for parallel executor support with EXECUTOR_NUMBER=0:
  393. # - createuser -P oc_autotest0 (enter password and enable superuser)
  394. #
  395. # NOTES on oci:
  396. # - it's a pure nightmare to install Oracle on a Linux-System
  397. # - DON'T TRY THIS AT HOME!
  398. # - if you really need it: we feel sorry for you
  399. #