]> git.sur5r.net Git - openldap/commitdiff
extra 'swamp' modes: -SS start searches and read responses; -SSS start all searches...
authorPierangelo Masarati <ando@openldap.org>
Tue, 10 Aug 2010 05:59:10 +0000 (05:59 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 10 Aug 2010 05:59:10 +0000 (05:59 +0000)
tests/progs/slapd-search.c

index 8d6b71a6ae98ade8be1ae790123ee77ac7984d7c..2bb98f6bd2d5c8f1dbf0264e288247b016fa71d6 100644 (file)
@@ -71,7 +71,7 @@ usage( char *name, char o )
                "[-C] "
                "[-F] "
                "[-N] "
-               "[-S] "
+               "[-S[S[S]]] "
                "[-i <ignore>] "
                "[-l <loops>] "
                "[-L <outerloops>] "
@@ -83,7 +83,10 @@ usage( char *name, char o )
        exit( EXIT_FAILURE );
 }
 
-/* Just send requests without reading responses */
+/* -S: just send requests without reading responses
+ * -SS: send all requests asynchronous and immediately start reading responses
+ * -SSS: send all requests asynchronous; then read responses
+ */
 static int swamp;
 
 int
@@ -389,7 +392,12 @@ do_search( char *uri, char *manager, struct berval *passwd,
        int     rc = LDAP_SUCCESS;
        int     version = LDAP_VERSION3;
        char    buf[ BUFSIZ ];
+       int             *msgids = NULL, active = 0;
 
+       /* make room for msgid */
+       if ( swamp > 1 ) {
+               msgids = (int *)calloc( sizeof(int), innerloop );
+       }
 
 retry:;
        if ( ld == NULL ) {
@@ -440,51 +448,161 @@ retry:;
                }
        }
 
-       for ( ; i < innerloop; i++ ) {
-               LDAPMessage *res = NULL;
-
-               if (swamp) {
-                       int msgid;
-                       rc = ldap_search_ext( ld, sbase, scope,
-                                       filter, NULL, noattrs, NULL, NULL,
-                                       NULL, LDAP_NO_LIMIT, &msgid );
-                       if ( rc == LDAP_SUCCESS ) continue;
-                       else break;
-               }
+       if ( swamp > 1 ) {
+               do {
+                       LDAPMessage *res = NULL;
+                       int j, msgid;
+
+                       if ( i < innerloop ) {
+                               rc = ldap_search_ext( ld, sbase, scope,
+                                               filter, NULL, noattrs, NULL, NULL,
+                                               NULL, LDAP_NO_LIMIT, &msgids[i] );
+
+                               active++;
+#if 0
+                               fprintf( stderr,
+                                       ">>> PID=%ld - Search(%d, %d, %d, %d): "
+                                       "base=\"%s\" scope=%s filter=\"%s\"\n",
+                                       (long) pid, innerloop, i, active, msgids[i],
+                                       sbase, ldap_pvt_scope2str( scope ), filter );
+#endif
+                               i++;
+
+                               if ( rc ) {
+                                       int first = tester_ignore_err( rc );
+                                       /* if ignore.. */
+                                       if ( first ) {
+                                               /* only log if first occurrence */
+                                               if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
+                                                       tester_ldap_error( ld, "ldap_search_ext", NULL );
+                                               }
+                                               continue;
+                                       }
+               
+                                       /* busy needs special handling */
+                                       snprintf( buf, sizeof( buf ),
+                                               "base=\"%s\" filter=\"%s\"\n",
+                                               sbase, filter );
+                                       tester_ldap_error( ld, "ldap_search_ext", buf );
+                                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                                               ldap_unbind_ext( ld, NULL, NULL );
+                                               ld = NULL;
+                                               do_retry--;
+                                               goto retry;
+                                       }
+                                       break;
+                               }
 
-               rc = ldap_search_ext_s( ld, sbase, scope,
-                               filter, attrs, noattrs, NULL, NULL,
-                               NULL, LDAP_NO_LIMIT, &res );
-               if ( res != NULL ) {
-                       ldap_msgfree( res );
-               }
+                               if ( swamp > 2 ) {
+                                       continue;
+                               }
+                       }
 
-               if ( rc ) {
-                       int first = tester_ignore_err( rc );
-                       /* if ignore.. */
-                       if ( first ) {
-                               /* only log if first occurrence */
-                               if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
-                                       tester_ldap_error( ld, "ldap_search_ext_s", NULL );
+                       rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res );
+                       switch ( rc ) {
+                       case -1:
+                               /* gone really bad */
+                               goto cleanup;
+       
+                       case 0:
+                               /* timeout (impossible) */
+                               break;
+       
+                       case LDAP_RES_SEARCH_ENTRY:
+                       case LDAP_RES_SEARCH_REFERENCE:
+                               /* ignore */
+                               break;
+       
+                       case LDAP_RES_SEARCH_RESULT:
+                               /* just remove, no error checking (TODO?) */
+                               msgid = ldap_msgid( res );
+
+                               /* linear search, bah */
+                               for ( j = 0; j < i; j++ ) {
+                                       if ( msgids[ j ] == msgid ) {
+                                               msgids[ j ] = -1;
+                                               active--;
+#if 0
+                                               fprintf( stderr,
+                                                       "<<< PID=%ld - SearchDone(%d, %d, %d, %d): "
+                                                       "base=\"%s\" scope=%s filter=\"%s\"\n",
+                                                       (long) pid, innerloop, j, active, msgid,
+                                                       sbase, ldap_pvt_scope2str( scope ), filter );
+#endif
+                                               break;
+                                       }
                                }
-                               continue;
+                               break;
+
+                       default:
+                               /* other messages unexpected */
+                               fprintf( stderr,
+                                       "### PID=%ld - Search(%d): "
+                                       "base=\"%s\" scope=%s filter=\"%s\" "
+                                       "attrs=%s%s. unexpected response tag=%d\n",
+                                       (long) pid, innerloop,
+                                       sbase, ldap_pvt_scope2str( scope ), filter,
+                                       attrs[0], attrs[1] ? " (more...)" : "", rc );
+                               break;
                        }
 
-                       /* busy needs special handling */
-                       snprintf( buf, sizeof( buf ),
-                               "base=\"%s\" filter=\"%s\"\n",
-                               sbase, filter );
-                       tester_ldap_error( ld, "ldap_search_ext_s", buf );
-                       if ( rc == LDAP_BUSY && do_retry > 0 ) {
-                               ldap_unbind_ext( ld, NULL, NULL );
-                               ld = NULL;
-                               do_retry--;
-                               goto retry;
+                       if ( res != NULL ) {
+                               ldap_msgfree( res );
+                       }
+               } while ( i < innerloop || active > 0 );
+
+       } else {
+               for ( ; i < innerloop; i++ ) {
+                       LDAPMessage *res = NULL;
+
+                       if (swamp) {
+                               int msgid;
+                               rc = ldap_search_ext( ld, sbase, scope,
+                                               filter, NULL, noattrs, NULL, NULL,
+                                               NULL, LDAP_NO_LIMIT, &msgid );
+                               if ( rc == LDAP_SUCCESS ) continue;
+                               else break;
+                       }
+       
+                       rc = ldap_search_ext_s( ld, sbase, scope,
+                                       filter, attrs, noattrs, NULL, NULL,
+                                       NULL, LDAP_NO_LIMIT, &res );
+                       if ( res != NULL ) {
+                               ldap_msgfree( res );
+                       }
+       
+                       if ( rc ) {
+                               int first = tester_ignore_err( rc );
+                               /* if ignore.. */
+                               if ( first ) {
+                                       /* only log if first occurrence */
+                                       if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
+                                               tester_ldap_error( ld, "ldap_search_ext_s", NULL );
+                                       }
+                                       continue;
+                               }
+       
+                               /* busy needs special handling */
+                               snprintf( buf, sizeof( buf ),
+                                       "base=\"%s\" filter=\"%s\"\n",
+                                       sbase, filter );
+                               tester_ldap_error( ld, "ldap_search_ext_s", buf );
+                               if ( rc == LDAP_BUSY && do_retry > 0 ) {
+                                       ldap_unbind_ext( ld, NULL, NULL );
+                                       ld = NULL;
+                                       do_retry--;
+                                       goto retry;
+                               }
+                               break;
                        }
-                       break;
                }
        }
 
+cleanup:;
+       if ( msgids != NULL ) {
+               free( msgids );
+       }
+
        if ( ldp != NULL ) {
                *ldp = ld;