Skip to contentSkip to conversation

tabled: add checksumming to test/large-object.c

PATCH New Pete Zaitcev 1 participant 1 message Jan 6, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tabled: add checksumming to test/large-object.c

The block numbers do not give us comlete enough coverage, so add a simple checksum that includes all transmitted bytes. Keep block numbers though:
they are invaluable when comparing specific damage with a traces of events inside tabled.

---
 test/large-object.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

commit 713da3a60b5763a11ca63593965e31a5b924ca13

Author: Master <[email protected]>
Date:   Tue Jan 5 20:51:53 2010 -0700

Add checksums.

test/large-object.c +29 -0
index b656333..919bbc4 100644
@@ -44,12 +44,14 @@
 #define NBLKS2	30000
 
 struct put_ctx {
+	unsigned int csum;
 	unsigned int blksize;
 	unsigned long off;
 	unsigned long total;
 };
 
 struct get_ctx {
+	unsigned int csum;
 	unsigned int blksize;
 	unsigned long off;
 };
@@ -57,6 +59,22 @@ struct get_ctx {
 static char bucket[] = "test-large";
 static char key[] = "Key of Large Object";
 
+#define CSUM_INIT  0xFFFFFFFF
+
+static void incrsum(unsigned int *psum, unsigned char *data, size_t len)
+{
+	unsigned int sum;
+
+	sum = *psum;
+	while (len) {
+		sum ^= *data;
+		sum = sum << 1 | sum >> 31;
+		data++;
+		--len;
+	}
+	*psum = sum;
+}
+
 static size_t put_cb(void *ptr, size_t membsize, size_t nmemb, void *user_data)
 {
 	struct put_ctx *ctx = user_data;
@@ -84,6 +102,8 @@ static size_t put_cb(void *ptr, size_t membsize, size_t nmemb, void *user_data)
 	if (off == 0)
 		data[0] = num;
 
+	incrsum(&ctx->csum, data, rem);
+
 	ctx->off += rem;
 
 	return rem;
@@ -131,6 +151,8 @@ static size_t get_cb(void *ptr, size_t membsize, size_t nmemb, void *user_data)
 
 	OK(membsize == 1);
 
+	incrsum(&ctx->csum, ptr, nmemb);
+
 	togo = nmemb;
 	while (togo) {
 		len = get_one(ctx, ptr, togo);
@@ -144,11 +166,13 @@ static void runtest(struct httpstor_client *httpstor,
 		    size_t blklen, int nblks)
 {
 	off_t total = blklen * nblks;
+	unsigned int checksum;
 	struct put_ctx putctx;
 	struct get_ctx getctx;
 	bool rcb;
 
 	memset(&putctx, 0, sizeof(putctx));
+	putctx.csum = CSUM_INIT;
 	putctx.blksize = blklen;
 	putctx.total = total;
 
@@ -156,12 +180,17 @@ static void runtest(struct httpstor_client *httpstor,
 	OK(rcb);
 	OK(putctx.off == total);
 
+	checksum = putctx.csum;
+
 	memset(&getctx, 0, sizeof(getctx));
+	getctx.csum = CSUM_INIT;
 	getctx.blksize = blklen;
 
 	rcb = httpstor_get(httpstor, bucket, key, get_cb, &getctx, false);
 	OK(rcb);
 	OK(getctx.off == total);
+
+	OK(checksum == getctx.csum);
 }
 
 int main(int argc, char *argv[])