| 1 | #! /bin/sh |
| 2 | # $OpenLDAP$ |
| 3 | ## This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 | ## |
| 5 | ## Copyright 1998-2024 The OpenLDAP Foundation. |
| 6 | ## All rights reserved. |
| 7 | ## |
| 8 | ## Redistribution and use in source and binary forms, with or without |
| 9 | ## modification, are permitted only as authorized by the OpenLDAP |
| 10 | ## Public License. |
| 11 | ## |
| 12 | ## A copy of this license is available in the file LICENSE in the |
| 13 | ## top-level directory of the distribution or, alternatively, at |
| 14 | ## <http://www.OpenLDAP.org/license.html>. |
| 15 | |
| 16 | echo "running defines.sh" |
| 17 | . $SRCDIR/scripts/defines.sh |
| 18 | |
| 19 | if test $BACKSQL = "sqlno" ; then |
| 20 | echo "SQL backend not available, test skipped" |
| 21 | exit 0 |
| 22 | fi |
| 23 | |
| 24 | if test $RDBMS = "rdbmsno" ; then |
| 25 | echo "SQL test not requested, test skipped" |
| 26 | exit 0 |
| 27 | fi |
| 28 | |
| 29 | if test "x$TESTLOOPS" = "x" ; then |
| 30 | TESTLOOPS=5 |
| 31 | fi |
| 32 | |
| 33 | if test "x$CHILDREN" = "x" ; then |
| 34 | CHILDREN="-j 4" |
| 35 | else |
| 36 | CHILDREN="-j $CHILDREN" |
| 37 | fi |
| 38 | |
| 39 | SQLDATADIR=$TESTDIR/sql-concurrency |
| 40 | mkdir -p $TESTDIR $SQLDATADIR |
| 41 | |
| 42 | echo "Starting slapd on TCP/IP port $PORT1..." |
| 43 | . $CONFFILTER $BACKEND < $SQLCONF > $CONF1 |
| 44 | $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & |
| 45 | PID=$! |
| 46 | if test $WAIT != 0 ; then |
| 47 | echo PID $PID |
| 48 | read foo |
| 49 | fi |
| 50 | KILLPIDS="$PID" |
| 51 | |
| 52 | echo "Testing SQL backend concurrency..." |
| 53 | for i in 0 1 2 3 4 5; do |
| 54 | $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ |
| 55 | 'objectclass=*' > /dev/null 2>&1 |
| 56 | RC=$? |
| 57 | if test $RC = 0 ; then |
| 58 | break |
| 59 | fi |
| 60 | echo "Waiting 5 seconds for slapd to start..." |
| 61 | sleep 5 |
| 62 | done |
| 63 | |
| 64 | if test $RC != 0 ; then |
| 65 | echo "ldapsearch failed ($RC)!" |
| 66 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 67 | exit $RC |
| 68 | fi |
| 69 | |
| 70 | echo "Using ldapsearch to retrieve all the entries..." |
| 71 | $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ |
| 72 | '(objectClass=*)' > $SEARCHOUT 2>&1 |
| 73 | RC=$? |
| 74 | |
| 75 | if test $RC != 0 ; then |
| 76 | echo "ldapsearch failed ($RC)!" |
| 77 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 78 | exit $RC |
| 79 | fi |
| 80 | |
| 81 | echo "Filtering original ldif used to create database..." |
| 82 | $LDIFFILTER < $SEARCHOUT > $LDIFFLT |
| 83 | |
| 84 | if test "${RDBMSWRITE}" != "yes"; then |
| 85 | echo "write test disabled for ${RDBMS}; set SLAPD_USE_SQLWRITE=yes to enable" |
| 86 | cp $SQLCONCURRENCYDIR/do_read* $SQLCONCURRENCYDIR/do_search* \ |
| 87 | $SQLCONCURRENCYDIR/do_bind* $SQLDATADIR |
| 88 | else |
| 89 | case ${RDBMS} in |
| 90 | # list here the RDBMSes whose mapping allows writes |
| 91 | pgsql|ibmdb2) |
| 92 | cp $SQLCONCURRENCYDIR/do_* $SQLDATADIR |
| 93 | ;; |
| 94 | *) |
| 95 | echo "write is not supported for ${RDBMS}; performing read-only concurrency test" |
| 96 | cp $SQLCONCURRENCYDIR/do_read* $SQLCONCURRENCYDIR/do_search* \ |
| 97 | $SQLCONCURRENCYDIR/do_bind* $SQLDATADIR |
| 98 | ;; |
| 99 | esac |
| 100 | fi |
| 101 | |
| 102 | echo "Using tester for concurrent server access..." |
| 103 | $SLAPDTESTER -P "$PROGDIR" -d "$SQLDATADIR" \ |
| 104 | -H $URI1 -D "$MANAGERDN" -w $PASSWD \ |
| 105 | -l $TESTLOOPS $CHILDREN -FF |
| 106 | RC=$? |
| 107 | |
| 108 | if test $RC != 0 ; then |
| 109 | echo "slapd-tester failed ($RC)!" |
| 110 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 111 | exit $RC |
| 112 | fi |
| 113 | |
| 114 | echo "Using ldapsearch to retrieve all the entries..." |
| 115 | $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ |
| 116 | '(objectClass=*)' > $SEARCHOUT 2>&1 |
| 117 | RC=$? |
| 118 | |
| 119 | test $KILLSERVERS != no && kill -HUP $KILLPIDS |
| 120 | |
| 121 | if test $RC != 0 ; then |
| 122 | echo "ldapsearch failed ($RC)!" |
| 123 | exit $RC |
| 124 | fi |
| 125 | |
| 126 | echo "Filtering ldapsearch results..." |
| 127 | $LDIFFILTER < $SEARCHOUT > $SEARCHFLT |
| 128 | echo "Comparing filter output..." |
| 129 | $CMP $SEARCHFLT $LDIFFLT > $CMPOUT |
| 130 | |
| 131 | if test $? != 0 ; then |
| 132 | echo "comparison failed - database was not created correctly" |
| 133 | exit 1 |
| 134 | fi |
| 135 | |
| 136 | echo ">>>>> Test succeeded" |
| 137 | exit 0 |
| 138 |