Commit b354238c authored by yiwenshao's avatar yiwenshao

use random str in test_layer

parent 7f05f8a6
...@@ -138,7 +138,7 @@ main(int argc,char**argv) { ...@@ -138,7 +138,7 @@ main(int argc,char**argv) {
return 0; return 0;
} }
for(int i=1;i<=100;i++) { for(int i=1;i<=100;i++) {
std::string input(length*i,'a') ; std::string input = ggetpRandomName(length*i);
Item* plain = getItemString(input) ; Item* plain = getItemString(input) ;
control(ds, plain, num_of_tests, length*i) ; control(ds, plain, num_of_tests, length*i) ;
} }
......
...@@ -131,7 +131,7 @@ main(int argc,char** argv) { ...@@ -131,7 +131,7 @@ main(int argc,char** argv) {
} }
for(int i=1;i<=100;i++) { for(int i=1;i<=100;i++) {
std::string input(length*i,'a'); std::string input = ggetpRandomName(length*i);
Item* plain = getItemString(input); Item* plain = getItemString(input);
control(op, plain, num_of_tests, length*i); control(op, plain, num_of_tests, length*i);
} }
......
...@@ -142,7 +142,7 @@ main(int argc,char**argv) { ...@@ -142,7 +142,7 @@ main(int argc,char**argv) {
} }
for(int i=1;i<=100;i++) { for(int i=1;i<=100;i++) {
std::string input(length*i,'a'); std::string input = ggetpRandomName(length*i);
Item* plain = getItemString(input); Item* plain = getItemString(input);
control(rs, plain, num_of_tests, length*i); control(rs, plain, num_of_tests, length*i);
} }
......
...@@ -19,12 +19,6 @@ ...@@ -19,12 +19,6 @@
#include "util/onions.hh" #include "util/onions.hh"
#include <sys/time.h> #include <sys/time.h>
static
uint64_t cur_usec() {
struct timeval tv;
gettimeofday(&tv, 0);
return ((uint64_t)tv.tv_sec) * 1000000 + tv.tv_usec;
}
using std::cout; using std::cout;
using std::cin; using std::cin;
using std::endl; using std::endl;
...@@ -37,33 +31,7 @@ static std::map<std::string, WrapperState*> clients; ...@@ -37,33 +31,7 @@ static std::map<std::string, WrapperState*> clients;
//This connection mimics the behaviour of MySQL-Proxy //This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn; Connect *globalConn;
static
std::string
getpRandomName(int out_length = 10){
static const char valids[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char output[out_length + 1];
// std::function<bool()> wrap_srand =[](){srand(time(NULL)); return true;};
std::function<bool()> wrap_srand =[](){srand(cur_usec()); return true;};
std::function<void(bool)> do_nothing = [] (bool b) {return;};
static bool danger_will_robinson = wrap_srand();
do_nothing(danger_will_robinson);
for (int i = 0; i < out_length; ++i) {
output[i] = valids[rand() % strlen(valids)];
}
output[out_length] = 0;
return std::string(output);
}
/*for each field, convert the format to FieldMeta_Wrapper*/ /*for each field, convert the format to FieldMeta_Wrapper*/
static void init(){ static void init(){
std::string client="192.168.1.1:1234"; std::string client="192.168.1.1:1234";
//one Wrapper per user. //one Wrapper per user.
...@@ -168,7 +136,7 @@ main(int argc,char**argv) { ...@@ -168,7 +136,7 @@ main(int argc,char**argv) {
} }
for(int i=1;i<=100;i++) { for(int i=1;i<=100;i++) {
std::string input = getpRandomName(length*i); std::string input = ggetpRandomName(length*i);
Item* plain = getItemString(input); Item* plain = getItemString(input);
auto res = tokenize(input); auto res = tokenize(input);
control(sw, plain, num_of_tests, length*i,res->size()); control(sw, plain, num_of_tests, length*i,res->size());
......
OBJDIRS += util OBJDIRS += util
UTILSRC := onions.cc cryptdb_log.cc ctr.cc util.cc version.cc constants.cc log.cc UTILSRC := onions.cc cryptdb_log.cc ctr.cc util.cc version.cc constants.cc log.cc timer.cc
all: $(OBJDIR)/libedbutil.so $(OBJDIR)/libedbutil.a all: $(OBJDIR)/libedbutil.so $(OBJDIR)/libedbutil.a
......
#include "util/timer.hh"
#include <functional>
#include <string>
#include <string.h>
uint64_t gcur_usec(){
struct timeval tv;
gettimeofday(&tv, 0);
return ((uint64_t)tv.tv_sec) * 1000000 + tv.tv_usec;
}
std::string
ggetpRandomName(int out_length){
static const char valids[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char output[out_length + 1];
std::function<bool()> wrap_srand =[](){srand(gcur_usec()); return true;};
std::function<void(bool)> do_nothing = [] (bool b) {return;};
static bool danger_will_robinson = wrap_srand();
do_nothing(danger_will_robinson);
for (int i = 0; i < out_length; ++i) {
output[i] = valids[rand() % strlen(valids)];
}
output[out_length] = 0;
return std::string(output);
}
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <stdint.h>
#include <string>
class timer { class timer {
private: private:
...@@ -26,3 +28,12 @@ class timer { ...@@ -26,3 +28,12 @@ class timer {
unsigned long start; unsigned long start;
}; };
uint64_t gcur_usec();
std::string
ggetpRandomName(int out_length = 10);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment