[LNT] r306326 - Add postgres_wrapper.sh to enable tests without server
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 26 13:23:58 PDT 2017
Author: matze
Date: Mon Jun 26 13:23:58 2017
New Revision: 306326
URL: http://llvm.org/viewvc/llvm-project?rev=306326&view=rev
Log:
Add postgres_wrapper.sh to enable tests without server
Add a wrapper script that creates an ad-hoc postgres instance so you can
run the unittests without setting up a real server on your machine.
You still need to have postgres installed and need to enable the test
with `lit -Dpostgres=1`, but at least there is not need to setup and
start a server anymore.
Added:
lnt/trunk/tests/SharedInputs/postgres_wrapper.sh (with props)
lnt/trunk/tests/lnttool/PostgresDB.test.sh
Removed:
lnt/trunk/tests/lnttool/PostgresDB.py
Modified:
lnt/trunk/docs/developer_guide.rst
lnt/trunk/tests/SharedInputs/server_wrapper.sh
lnt/trunk/tests/lit.cfg
Modified: lnt/trunk/docs/developer_guide.rst
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/docs/developer_guide.rst?rev=306326&r1=306325&r2=306326&view=diff
==============================================================================
--- lnt/trunk/docs/developer_guide.rst (original)
+++ lnt/trunk/docs/developer_guide.rst Mon Jun 26 13:23:58 2017
@@ -54,14 +54,6 @@ on at least sqlite and postgres database
tests uses sqlite. To run the regression tests against a postgress database,
use a command like the following::
- PATH=$LLVMBUILD/bin:$PATH llvm-lit -sv -Dpostgres='postgresql://lnt:lnt@127.0.0.1' ../lnt/tests
-
-The argument to -Dpostgres needs to be a postgres URI for a postgres role
-that is allowed to create databases. One example to set up such a user is::
-
- sudo -u postgres psql
- CREATE USER lnt_test PASSWORD 'lnt_test';
- CREATE DATABASE lnt_test OWNER = lnt_test;
- ALTER USER lnt_test CREATEDB;
+ PATH=$LLVMBUILD/bin:$PATH llvm-lit -sv -Dpostgres=1 ../lnt/tests
You'll need to use at least postgres version 9.2 to run the regression tests.
Added: lnt/trunk/tests/SharedInputs/postgres_wrapper.sh
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/postgres_wrapper.sh?rev=306326&view=auto
==============================================================================
--- lnt/trunk/tests/SharedInputs/postgres_wrapper.sh (added)
+++ lnt/trunk/tests/SharedInputs/postgres_wrapper.sh Mon Jun 26 13:23:58 2017
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Setup minimalistic postgres instance in specified directory, start a server,
+# run the given command and shutdown the server. Use
+# `postgresql://pgtest@localhost:9100` to connect to the server.
+#
+# Example:
+# ./postgres_wrapper /tmp/myinstance 'createdb --maintenance-db=postgresql://pgtest@localhost:9100/postgres mydb; psql postgresql://pgtest@localhost:9100/mydb -c \"CREATE TABLE foo (id integer);\"'
+#
+# Inspired by https://github.com/tk0miya/testing.postgresql
+set -u
+
+DBDIR="$1"
+shift
+if [ -d "${DBDIR}" ]; then
+ echo 1>&2 "${DBDIR} already exists"
+ exit 1
+fi
+
+mkdir -p "${DBDIR}"
+
+INITDB_FLAGS+=" --pgdata=$DBDIR/db"
+INITDB_FLAGS+=" --xlogdir=$DBDIR/db"
+INITDB_FLAGS+=" --nosync"
+INITDB_FLAGS+=" --no-locale"
+INITDB_FLAGS+=" --auth=trust"
+INITDB_FLAGS+=" --username=pgtest"
+echo "$ initdb $INITDB_FLAGS >& $DBDIR/initdb_log.txt"
+initdb $INITDB_FLAGS >& $DBDIR/initdb_log.txt
+
+POSTGRES_FLAGS+=" -p 9100"
+POSTGRES_FLAGS+=" -D $DBDIR/db"
+POSTGRES_FLAGS+=" -k $DBDIR/db"
+POSTGRES_FLAGS+=" -h 127.0.0.1"
+POSTGRES_FLAGS+=" -F"
+POSTGRES_FLAGS+=" -c logging_collector=off"
+echo "$ postgres $POSTGRES_FLAGS >& $DBDIR/server_log.txt"
+postgres $POSTGRES_FLAGS >& $DBDIR/server_log.txt &
+PG_PID=$!
+sleep 1 # Give the server time to start.
+
+# Execute command
+eval "$@"
+RC=$?
+
+# Kill server
+kill -15 $PG_PID
+[ $? -ne 0 ] && (echo 1>&1 "Could not kill postgres server"; exit 1)
+wait $PG_PID
+exit $RC
Propchange: lnt/trunk/tests/SharedInputs/postgres_wrapper.sh
------------------------------------------------------------------------------
svn:executable = *
Modified: lnt/trunk/tests/SharedInputs/server_wrapper.sh
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/SharedInputs/server_wrapper.sh?rev=306326&r1=306325&r2=306326&view=diff
==============================================================================
--- lnt/trunk/tests/SharedInputs/server_wrapper.sh (original)
+++ lnt/trunk/tests/SharedInputs/server_wrapper.sh Mon Jun 26 13:23:58 2017
@@ -31,8 +31,8 @@ main() {
shift 2
lnt runserver $serverinstance --hostname localhost --port $portnr >& $serverinstance/server_wrapper_runserver.log &
- sleep 1 # Give the server some time to start.
local pid=$!
+ sleep 1 # Give the server some time to start.
# Execute command.
eval "$@"
Modified: lnt/trunk/tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lit.cfg?rev=306326&r1=306325&r2=306326&view=diff
==============================================================================
--- lnt/trunk/tests/lit.cfg (original)
+++ lnt/trunk/tests/lit.cfg Mon Jun 26 13:23:58 2017
@@ -17,7 +17,7 @@ execute_external = platform.system() !=
config.test_format = lit.formats.ShTest(execute_external)
# suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.py']
+config.suffixes = ['.py', '.test.sh']
# excludes: A list of individual files to exclude.
config.excludes = ['__init__.py', 'Inputs', 'SharedInputs']
@@ -46,12 +46,10 @@ config.substitutions.append(('%{test_exe
if lit_config.params.get('long', None):
config.available_features.add('long')
+# Enable postgres testing. This requires postgres binaries in PATH.
+# (You do not need to start a server, the tests will create ad-hoc instances).
if lit_config.params.get('postgres', None):
config.available_features.add('postgres')
- config.environment['LNT_POSTGRES_DB_URI'] = \
- lit_config.params.get('postgres')
- config.substitutions.append(('%{postgres_db_uri}',
- lit_config.params.get('postgres')))
config.available_features.add(platform.system())
Removed: lnt/trunk/tests/lnttool/PostgresDB.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lnttool/PostgresDB.py?rev=306325&view=auto
==============================================================================
--- lnt/trunk/tests/lnttool/PostgresDB.py (original)
+++ lnt/trunk/tests/lnttool/PostgresDB.py (removed)
@@ -1,45 +0,0 @@
-# RUN: rm -rf %t.install
-# RUN: dropdb --if-exists --maintenance-db=%{postgres_db_uri} \
-# RUN: lnt_regr_test_PostgresDB
-# RUN: createdb --maintenance-db=%{postgres_db_uri} \
-# RUN: lnt_regr_test_PostgresDB
-
-# RUN: lnt create %t.install --db-dir %{postgres_db_uri} \
-# RUN: --default-db lnt_regr_test_PostgresDB
-
-# Import a test set.
-# RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist \
-# RUN: --commit=1 --show-sample-count
-
-# Import a test set.
-# RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist \
-# RUN: --commit=1 --show-sample-count
-
-# Check that we remove both the sample and the run, and that we don't commit by
-# default.
-#
-# RUN: lnt updatedb %t.install --testsuite nts \
-# RUN: --delete-run 1 --show-sql > %t.out
-# RUN: FileCheck --check-prefix CHECK-RUNRM %s < %t.out
-
-# CHECK-RUNRM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."RunID" IN (%(RunID_1)s)
-# CHECK-RUNRM-NEXT: {'RunID_1': 1}
-# CHECK-RUNRM: DELETE FROM "NT_Run" WHERE "NT_Run"."ID" IN (%(ID_1)s)
-# CHECK-RUNRM-NEXT: {'ID_1': 1}
-# CHECK-RUNRM: ROLLBACK
-
-# Check that we remove runs when we remove a machine.
-#
-# RUN: lnt updatedb %t.install --testsuite nts \
-# RUN: --delete-machine "LNT SAMPLE MACHINE" --commit=1 --show-sql > %t.out
-# RUN: FileCheck --check-prefix CHECK-MACHINERM %s < %t.out
-
-# CHECK-MACHINERM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."RunID" IN (%(RunID_1)s)
-# CHECK-MACHINERM-NEXT: {'RunID_1': 1}
-# CHECK-MACHINERM: DELETE FROM "NT_Run" WHERE "NT_Run"."ID" IN (%(ID_1)s)
-# CHECK-MACHINERM-NEXT: {'ID_1': 1}
-# CHECK-MACHINERM: DELETE FROM "NT_Machine" WHERE "NT_Machine"."Name" = %(Name_1)s
-# CHECK-MACHINERM-NEXT: {'Name_1': 'LNT SAMPLE MACHINE'}
-# CHECK-MACHINERM: COMMIT
-
-# REQUIRES: postgres
Added: lnt/trunk/tests/lnttool/PostgresDB.test.sh
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lnttool/PostgresDB.test.sh?rev=306326&view=auto
==============================================================================
--- lnt/trunk/tests/lnttool/PostgresDB.test.sh (added)
+++ lnt/trunk/tests/lnttool/PostgresDB.test.sh Mon Jun 26 13:23:58 2017
@@ -0,0 +1,46 @@
+# REQUIRES: postgres
+# RUN: rm -rf "%t.install"
+# RUN: %{shared_inputs}/postgres_wrapper.sh "%t.install" /bin/sh %s "%t.install" postgresql://pgtest@localhost:9100 "%{shared_inputs}"
+set -eux
+
+TESTDIR="$1"
+PGURL="$2"
+SHARED_INPUTS="$3"
+dropdb --if-exists --maintenance-db="${PGURL}/postgres" lnt_regr_test_PostgresDB
+createdb --maintenance-db="${PGURL}/postgres" lnt_regr_test_PostgresDB
+
+lnt create "${TESTDIR}/instance" --db-dir ${PGURL} --default-db lnt_regr_test_PostgresDB
+
+# Import a test set.
+lnt import "${TESTDIR}/instance" "${SHARED_INPUTS}/sample-a-small.plist" --commit=1 --show-sample-count
+
+# Import a test set.
+lnt import "${TESTDIR}/instance" "${SHARED_INPUTS}/sample-a-small.plist" --commit=1 --show-sample-count
+
+# Check that we remove both the sample and the run, and that we don't commit by
+# default.
+#
+lnt updatedb "${TESTDIR}/instance" --testsuite nts --delete-run 1 \
+ --show-sql > "${TESTDIR}/runrm.out"
+# RUN: FileCheck --check-prefix CHECK-RUNRM %s < "%t.install/runrm.out"
+
+# CHECK-RUNRM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."RunID" IN (%(RunID_1)s)
+# CHECK-RUNRM-NEXT: {'RunID_1': 1}
+# CHECK-RUNRM: DELETE FROM "NT_Run" WHERE "NT_Run"."ID" IN (%(ID_1)s)
+# CHECK-RUNRM-NEXT: {'ID_1': 1}
+# CHECK-RUNRM: ROLLBACK
+
+# Check that we remove runs when we remove a machine.
+#
+lnt updatedb "${TESTDIR}/instance" --testsuite nts \
+ --delete-machine "LNT SAMPLE MACHINE" --commit=1 \
+ --show-sql > "${TESTDIR}/machinerm.out"
+# RUN: FileCheck --check-prefix CHECK-MACHINERM %s < "%t.install/machinerm.out"
+
+# CHECK-MACHINERM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."RunID" IN (%(RunID_1)s)
+# CHECK-MACHINERM-NEXT: {'RunID_1': 1}
+# CHECK-MACHINERM: DELETE FROM "NT_Run" WHERE "NT_Run"."ID" IN (%(ID_1)s)
+# CHECK-MACHINERM-NEXT: {'ID_1': 1}
+# CHECK-MACHINERM: DELETE FROM "NT_Machine" WHERE "NT_Machine"."Name" = %(Name_1)s
+# CHECK-MACHINERM-NEXT: {'Name_1': 'LNT SAMPLE MACHINE'}
+# CHECK-MACHINERM: COMMIT
More information about the llvm-commits
mailing list