MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / do_test

Function do_test

mysys/testhash.c:60–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60static int do_test()
61{
62 register uint i,j;
63 uint n1,n2,n3;
64 uint write_count,update,delete;
65 ulong pos;
66 unsigned long key_check;
67 char *record,*recpos,oldrecord[120],key[10];
68 HASH hash,hash2;
69 DBUG_ENTER("do_test");
70
71 write_count=update=delete=0;
72 key_check=0;
73 memset(key1, 0, sizeof(key1[0])*1000);
74
75 printf("- Creating hash\n");
76 if (hash_init(&hash, default_charset_info, recant/2, 0, 6, 0, free_record, 0))
77 goto err;
78 printf("- Writing records:\n");
79
80 for (i=0 ; i < recant ; i++)
81 {
82 n1=rnd(1000); n2=rnd(100); n3=rnd(min(recant*5,MAX_RECORDS));
83 record= (char*) my_malloc(reclength,MYF(MY_FAE));
84 sprintf(record,"%6d:%4d:%8d:Pos: %4d ",n1,n2,n3,write_count);
85 if (my_hash_insert(&hash,record))
86 {
87 printf("Error: %d in write at record: %d\n",my_errno,i);
88 goto err;
89 }
90 key1[n1]++;
91 key_check+=n1;
92 write_count++;
93 }
94 if (hash_check(&hash))
95 {
96 puts("Heap keys crashed");
97 goto err;
98 }
99 printf("- Delete\n");
100 for (i=0 ; i < write_count/10 ; i++)
101 {
102 for (j=rnd(1000) ; j>0 && key1[j] == 0 ; j--) ;
103 if (j != 0)
104 {
105 sprintf(key,"%6d",j);
106 if (!(recpos=hash_search(&hash,key,0)))
107 {
108 printf("can't find key1: \"%s\"\n",key);
109 goto err;
110 }
111 key1[atoi(recpos)]--;
112 key_check-=atoi(recpos);
113 memcpy(oldrecord,recpos,reclength);
114 if (hash_delete(&hash,recpos))
115 {
116 printf("error: %d; can't delete record: \"%s\"\n", my_errno,oldrecord);
117 goto err;

Callers 1

mainFunction · 0.70

Calls 6

rndFunction · 0.85
minFunction · 0.85
my_mallocFunction · 0.85
my_hash_insertFunction · 0.85
atoiFunction · 0.85
my_endFunction · 0.85

Tested by

no test coverage detected