From 508ba04ba460751dbe588648c93c5895f5738ce3 Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Sat, 11 Apr 2009 00:53:32 -0300
Subject: [PATCH 13/38] jiostress: Simplify content generation

There is no need for truly random data, and it takes some time to generate
it, so this patch replaces it with a simpler generator.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
---
 tests/stress/jiostress |   20 ++++++--------------
 1 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/tests/stress/jiostress b/tests/stress/jiostress
index e01d8d7..a930d96 100755
--- a/tests/stress/jiostress
+++ b/tests/stress/jiostress
@@ -26,19 +26,11 @@ except ImportError:
 # Auxiliary stuff
 #
 
-randsrc = open('/dev/urandom', mode = 'rb')
-def randbytes(n):
-	"Returns n random bytes"
-	if n < 64:
-		return randsrc.read(n)
-
-	# to avoid reading too much from urandom (which needlessly stresses
-	# the kernel), just get a small random stream and repeat it
-	s = randsrc.read(64)
-	while len(s) < n:
-		s += s + s[::-1]
-
-	return s[:n]
+gbcount = 0
+def getbytes(n):
+	global gbcount
+	gbcount = (gbcount + 1) % 10
+	return bytes(str(gbcount) * n, 'ascii')
 
 def randfrange(maxend, maxsize):
 	start = random.randint(0, maxend - 1)
@@ -93,7 +85,7 @@ class Stresser:
 				self.current_range = (estart, eend)
 				self.prev_data = self.pread(estart, eend)
 
-				nd = randbytes(end - start)
+				nd = getbytes(end - start)
 				self.new_data = \
 					self.prev_data[:start - estart] \
 					+ nd + self.prev_data[- (eend - end):]
-- 
1.6.2.2.646.gb214


