You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2007/10/17 07:49:07 UTC
svn commit: r585387 - in /apr/apr-util/trunk/test: testdate.c testreslist.c
Author: wrowe
Date: Tue Oct 16 22:49:06 2007
New Revision: 585387
URL: http://svn.apache.org/viewvc?rev=585387&view=rev
Log:
lose the last vestages of nonportable entropy and rely on
the testdate.c solution, with some extra typesafety and
alignment/signedness awareness.
Modified:
apr/apr-util/trunk/test/testdate.c
apr/apr-util/trunk/test/testreslist.c
Modified: apr/apr-util/trunk/test/testdate.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testdate.c?rev=585387&r1=585386&r2=585387&view=diff
==============================================================================
--- apr/apr-util/trunk/test/testdate.c (original)
+++ apr/apr-util/trunk/test/testdate.c Tue Oct 16 22:49:06 2007
@@ -136,7 +136,7 @@
apr_uint64_t z = a;
z *= 279470273;
z %= APR_UINT64_C(4294967291);
- return z;
+ return (apr_uint32_t)z;
}
static void test_date_parse_http(abts_case *tc, void *data)
@@ -158,7 +158,7 @@
apr_generate_random_bytes((unsigned char *)&guess, sizeof(guess));
for (i = 0; i < 10000; ++i) {
- guess = lgc(guess);
+ guess = (time_t)lgc((apr_uint32_t)guess);
if (guess < 0)
guess *= -1;
secstodate = guess + offset;
Modified: apr/apr-util/trunk/test/testreslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testreslist.c?rev=585387&r1=585386&r2=585387&view=diff
==============================================================================
--- apr/apr-util/trunk/test/testreslist.c (original)
+++ apr/apr-util/trunk/test/testreslist.c Tue Oct 16 22:49:06 2007
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include "apr_general.h"
#include "apu.h"
#include "apr_reslist.h"
#include "apr_thread_pool.h"
@@ -51,6 +52,15 @@
int id;
} my_resource_t;
+/* Linear congruential generator */
+static apr_uint32_t lgc(apr_uint32_t a)
+{
+ apr_uint64_t z = a;
+ z *= 279470273;
+ z %= APR_UINT64_C(4294967291);
+ return (apr_uint32_t)z;
+}
+
static apr_status_t my_constructor(void **resource, void *params,
apr_pool_t *pool)
{
@@ -88,16 +98,21 @@
apr_interval_time_t work_delay_sleep;
} my_thread_info_t;
+#define PERCENT95th ( ( 2u^31 / 10u ) * 19u )
+
static void * APR_THREAD_FUNC resource_consuming_thread(apr_thread_t *thd,
void *data)
{
int i;
+ apr_uint32_t chance;
void *vp;
apr_status_t rv;
my_resource_t *res;
my_thread_info_t *thread_info = data;
apr_reslist_t *rl = thread_info->reslist;
+ apr_generate_random_bytes((void*)&chance, sizeof(chance));
+
for (i = 0; i < CONSUMER_ITERATIONS; i++) {
rv = apr_reslist_acquire(rl, &vp);
ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
@@ -105,13 +120,14 @@
apr_sleep(thread_info->work_delay_sleep);
/* simulate a 5% chance of the resource being bad */
- if (drand48() < 0.95) {
- rv = apr_reslist_release(rl, res);
- ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
- } else {
- rv = apr_reslist_invalidate(rl, res);
- ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
- }
+ chance = lgc(chance);
+ if ( chance < PERCENT95th ) {
+ rv = apr_reslist_release(rl, res);
+ ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
+ } else {
+ rv = apr_reslist_invalidate(rl, res);
+ ABTS_INT_EQUAL(thread_info->tc, rv, APR_SUCCESS);
+ }
}
return APR_SUCCESS;
@@ -202,9 +218,6 @@
my_parameters_t *params;
apr_thread_pool_t *thrp;
my_thread_info_t thread_info[CONSUMER_THREADS];
-
- /* XXX: non-portable */
- srand48(time(0));
rv = apr_thread_pool_create(&thrp, CONSUMER_THREADS/2, CONSUMER_THREADS, p);
ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);