diff test/state_test.c @ 0:d4bc23cb728b

Import from CVS (CVS_DB/member/atsuki/cbc/DPP)
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Wed, 16 Dec 2015 15:16:11 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/state_test.c	Wed Dec 16 15:16:11 2015 +0900
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include "memory.h"
+#include "state_db.h"
+
+static int array1[10];
+static int array2[10];
+static int array3[20];
+static int array4[20];
+
+MemoryPtr mem;         // memory range
+StateDB state_db;      // state database
+
+int main()
+{
+    StateDB s0;
+    StateNode st;
+    int ret;
+
+    // register memory fragments 
+    MemoryPtr a1 = add_memory_range(array1,sizeof(array1),&mem);
+    MemoryPtr a2 = add_memory_range(array2,sizeof(array2),&mem);
+    MemoryPtr a3 = add_memory_range(array3,sizeof(array3),&mem);
+    MemoryPtr a4 = add_memory_range(array4,sizeof(array4),&mem);
+    st.memory = mem;
+
+    printf("%d %d\n",a1->body==a2->body,a3->body==a4->body);
+    for(;;) {
+
+	// modify memory and calculate hash
+	array2[5] = (array2[5]+1)&0xf;
+	st.hash = get_memory_hash(mem,0);
+
+	// check if it is in the db
+	ret = lookup_StateDB(&st, &state_db, &s0);
+	printf("%0x %d\n",(int)s0,array2[5]);
+	if (ret) {
+	    printf("the same state %d\n", state_count());
+	    break;;
+	}
+    }
+
+    return 0;
+}
+
+/* end */