ldap/servers/slapd/tools/ldclt/ldapfct.c | 34 +++++++++++-----------------
ldap/servers/slapd/tools/ldclt/threadMain.c | 18 ++++----------
ldap/servers/slapd/tools/ldclt/utils.c | 12 +++++++--
ldap/servers/slapd/tools/ldclt/utils.h | 1
4 files changed, 30 insertions(+), 35 deletions(-)
New commits:
commit 0472b98440698a2dd87b0eb17431c3eb99762e37
Author: Rich Megginson <rmeggins(a)redhat.com>
Date: Wed Mar 27 12:32:45 2013 -0600
Ticket #613 - ldclt: add timestamp, interval, nozeropad, other improvements
https://fedorahosted.org/389/ticket/613
Reviewed by: nhosoi (Thanks!)
Branch: master
Fix Description: Was not wrapping incremental value properly. Use better
modulo based algorithm and use a common function for this algorithm.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
diff --git a/ldap/servers/slapd/tools/ldclt/ldapfct.c
b/ldap/servers/slapd/tools/ldclt/ldapfct.c
index f83a456..1d0a0d4 100644
--- a/ldap/servers/slapd/tools/ldclt/ldapfct.c
+++ b/ldap/servers/slapd/tools/ldclt/ldapfct.c
@@ -1495,30 +1495,24 @@ buildRandomRdnOrFilter (
{
if (mctx.mode & COMMON_COUNTER) /*JLS 14-03-01*/
{ /*JLS 14-03-01*/
- int val; /*JLS 14-03-01*/
- val = incrementCommonCounter (tttctx); /*JLS 14-03-01*/
+ int val = incrementCommonCounter (tttctx); /*JLS 14-03-01*/
if (val == -1) /*JLS 14-03-01*/
return (-1); /*JLS 14-03-01*/
sprintf (tttctx->buf2, "%0*d", (mctx.mod2 & M2_NOZEROPAD) ? 0 :
mctx.randomNbDigit, val);/*JLS 14-03-01*/
} /*JLS 14-03-01*/
- else /*JLS 14-03-01*/
- { /*JLS 14-03-01*/
- tttctx->lastVal += mctx.incr;
- if (tttctx->lastVal > mctx.randomHigh)
- {
- if (!(mctx.mode & NOLOOP))
- tttctx->lastVal = mctx.randomLow;
- else
- {
- /*
- * Well, there is no clean way to exit. Let's use the error
- * condition and hope all will be ok.
- */
- printf ("ldclt[%d]: %s: Hit top incremental value\n",
- mctx.pid, tttctx->thrdId);
- return (-1);
- }
- }
+ else if ((mctx.mode & NOLOOP) && ((tttctx->lastVal + mctx.incr) >
mctx.randomHigh))
+ {
+ /*
+ * Well, there is no clean way to exit. Let's use the error
+ * condition and hope all will be ok.
+ */
+ printf ("ldclt[%d]: %s: Hit top incremental value %d > %d\n",
+ mctx.pid, tttctx->thrdId, (tttctx->lastVal + mctx.incr),
mctx.randomHigh);
+ return (-1);
+ }
+ else
+ {
+ tttctx->lastVal = incr_and_wrap(tttctx->lastVal, mctx.randomLow, mctx.randomHigh,
mctx.incr);
sprintf (tttctx->buf2, "%0*d", (mctx.mod2 & M2_NOZEROPAD) ? 0 :
mctx.randomNbDigit, tttctx->lastVal);
} /*JLS 14-03-01*/
diff --git a/ldap/servers/slapd/tools/ldclt/threadMain.c
b/ldap/servers/slapd/tools/ldclt/threadMain.c
index 3b53a62..7af76d4 100644
--- a/ldap/servers/slapd/tools/ldclt/threadMain.c
+++ b/ldap/servers/slapd/tools/ldclt/threadMain.c
@@ -343,19 +343,13 @@ incrementCommonCounter (
/*
* Compute next value
*/
- if ((mctx.mode & NOLOOP) && (mctx.lastVal >= mctx.randomHigh))
- val = -1;
+ if ((mctx.mode & NOLOOP) && ((mctx.lastVal + mctx.incr) >
mctx.randomHigh))
+ {
+ val = -1; /* out of range - cannot continue since not looping */
+ }
else
{
- mctx.lastVal += mctx.incr;
- if (mctx.lastVal > mctx.randomHigh)
- {
- if (mctx.mode & NOLOOP)
- val = -1;
- else
- mctx.lastVal -= (mctx.randomHigh-mctx.incr) + mctx.randomLow;
- }
- val = mctx.lastVal;
+ val = mctx.lastVal = incr_and_wrap(mctx.lastVal, mctx.randomLow, mctx.randomHigh,
mctx.incr);
}
/*
@@ -373,7 +367,7 @@ incrementCommonCounter (
* Maybe a message to print ?
*/
if (val < 0)
- printf ("ldclt[%d]: T%03d: Hit top incrementeal value\n", mctx.pid,
tttctx->thrdNum);
+ printf ("ldclt[%d]: T%03d: Hit top incremental value\n", mctx.pid,
tttctx->thrdNum);
return (val);
}
diff --git a/ldap/servers/slapd/tools/ldclt/utils.c
b/ldap/servers/slapd/tools/ldclt/utils.c
index 3e3d60b..80a429c 100644
--- a/ldap/servers/slapd/tools/ldclt/utils.c
+++ b/ldap/servers/slapd/tools/ldclt/utils.c
@@ -324,9 +324,15 @@ rndstr (
buf[charNum] = '\0';
}
-
-
-
+/* increment val - if val > max, wrap value around to start over at min */
+/* the range is max - min + 1 = number of possible values */
+/* the new value is (((val + incr) - min) % range) + min */
+int
+incr_and_wrap(int val, int min, int max, int incr)
+{
+ int range = max - min + 1;
+ return (((val + incr) - min) % range) + min;
+}
diff --git a/ldap/servers/slapd/tools/ldclt/utils.h
b/ldap/servers/slapd/tools/ldclt/utils.h
index 52b6e81..dfb8ef6 100644
--- a/ldap/servers/slapd/tools/ldclt/utils.h
+++ b/ldap/servers/slapd/tools/ldclt/utils.h
@@ -76,6 +76,7 @@ extern void rnd (char *buf, int low, int high, int ndigits);
extern int rndlim (int low, int high);
extern void rndstr (char *buf, int ndigits);
extern int utilsInit (void);
+extern int incr_and_wrap(int val, int min, int max, int incr);
/* End of file */