Commit 7201cb3c authored by yiwenshao's avatar yiwenshao

add more tests

parent 4fb44f22
#include "parser/sql_utils.hh"
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include "main/CryptoHandlers.hh"
#include "wrapper/reuse.hh"
#include "wrapper/common.hh"
#include "wrapper/insert_lib.hh"
#include "util/constants.hh"
#include "util/timer.hh"
#include "util/log.hh"
#include "util/onions.hh"
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
using std::to_string;
static std::string embeddedDir="/t/cryt/shadow";
static std::map<std::string, WrapperState*> clients;
//This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn;
/*for each field, convert the format to FieldMeta_Wrapper*/
static void init(){
std::string client="192.168.1.1:1234";
//one Wrapper per user.
clients[client] = new WrapperState();
//Connect phase
ConnectionInfo ci("localhost", "root", "letmein",3306);
const std::string master_key = "113341234";
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
embeddedDir = std::string(buffer)+"/shadow";
free(buffer);
SharedProxyState *shared_ps =
new SharedProxyState(ci, embeddedDir , master_key,
determineSecurityRating());
assert(0 == mysql_thread_init());
//we init embedded database here.
clients[client]->ps = std::unique_ptr<ProxyState>(new ProxyState(*shared_ps));
clients[client]->ps->safeCreateEmbeddedTHD();
//Connect end!!
globalConn = new Connect(ci.server, ci.user, ci.passwd, ci.port);
}
static
Item *
getItemInt(std::string input) {
return new (current_thd->mem_root)
Item_int(static_cast<ulonglong>(valFromStr(input)));
}
static
Item *
getItemIntNew(std::string input){
return ::new Item_int(static_cast<ulonglong>(valFromStr(input)));
}
static
Create_field* getUnsignedIntField(){
Create_field *f = new Create_field;
f->sql_type = MYSQL_TYPE_LONG;
f->flags |= UNSIGNED_FLAG;
return f;
}
int
main(int argc, char**argv) {
UNUSED(getItemInt);
UNUSED(getItemIntNew);
UNUSED(getUnsignedIntField);
//still has 80B memory leak
init();
create_embedded_thd(0);
std::string key = "key";
Create_field *cf = getUnsignedIntField();
RND_int* ri = new RND_int(*cf, key);
Item * plain = ::new Item_int(static_cast<ulonglong>(valFromStr("123456789")));
// Item * plain = getItemIntNew("123456789");
// plain = getItemIntNew("1233344");
// Item * enc = NULL;
// Item * dec = NULL;
// enc = ri->encrypt(*plain,0u);
// dec = ri->decrypt(*enc,0u);
// delete ri;
// delete cf;
UNUSED(plain);
UNUSED(cf);
UNUSED(ri);
return 0;
}
//main/schema.cc:83 is use to create layers of encryption
...@@ -79,7 +79,7 @@ getInnoDBPlugin() ...@@ -79,7 +79,7 @@ getInnoDBPlugin()
query_parse::query_parse(const std::string &db, const std::string &q) query_parse::query_parse(const std::string &db, const std::string &q)
{ {
assert(create_embedded_thd(0)); assert(create_embedded_thd(0));
//类内自带的THD* t结构. //THD* t.
t = current_thd; t = current_thd;
assert(t != NULL); assert(t != NULL);
......
...@@ -15,7 +15,7 @@ class query_parse { ...@@ -15,7 +15,7 @@ class query_parse {
LEX *lex(); LEX *lex();
private: private:
void cleanup(); void cleanup();
THD *t; THD *t; /*used to hold current_thd*/
Parser_state ps; /*这里包含了词法分析和语法分析时候, 使用的内部状态*/ Parser_state ps; /*the internal state used by parser*/
}; };
#include <string>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include "parser/sql_utils.hh"
#include "parser/lex_util.hh"
#include "parser/embedmysql.hh"
#include "util/util.hh"
#include "util/constants.hh"
static std::string embeddedDir="/t/cryt/shadow";
int main() {
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
embeddedDir = std::string(buffer)+"/shadow";
free(buffer);
init_mysql(embeddedDir);//0;0;15,246,176
std::string line = "show databases;";
std::unique_ptr<query_parse> p;
p = std::unique_ptr<query_parse>(new query_parse("tdb", line));//0;0;15,246,552
UNUSED(p);
return 0;
}
#include <string>
#include <iostream>
#include <vector>
#include <functional>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <main/Connect.hh>
#include <main/rewrite_util.hh>
#include <main/sql_handler.hh>
#include <main/dml_handler.hh>
#include <main/ddl_handler.hh>
#include <main/CryptoHandlers.hh>
#include "util/util.hh"
#include "util/constants.hh"
static std::string embeddedDir="/t/cryt/shadow";
int main() {
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
embeddedDir = std::string(buffer)+"/shadow";
free(buffer);
// init_mysql(embeddedDir);
std::string filename = std::string(cryptdb_dir)+"/test_parser/"+"template";
std::string line="show databases;";
std::unique_ptr<query_parse> p;
p = std::unique_ptr<query_parse>(new query_parse("tdb", line));
LEX *const lex = p->lex();
UNUSED(lex);
return 0;
}
...@@ -34,21 +34,13 @@ static std::string getInsertResults(Analysis a,LEX* lex){ ...@@ -34,21 +34,13 @@ static std::string getInsertResults(Analysis a,LEX* lex){
lex->select_lex.table_list.first->db; lex->select_lex.table_list.first->db;
//from databasemeta to tablemeta. //from databasemeta to tablemeta.
const TableMeta &tm = a.getTableMeta(db_name, table); const TableMeta &tm = a.getTableMeta(db_name, table);
//rewrite table name //rewrite table name
new_lex->select_lex.table_list.first = new_lex->select_lex.table_list.first =
rewrite_table_list(lex->select_lex.table_list.first, a); rewrite_table_list(lex->select_lex.table_list.first, a);
std::vector<FieldMeta *> fmVec; std::vector<FieldMeta *> fmVec;
std::vector<Item *> implicit_defaults;
// No field list, use the table order.
assert(fmVec.empty());
std::vector<FieldMeta *> fmetas = tm.orderedFieldMetas(); std::vector<FieldMeta *> fmetas = tm.orderedFieldMetas();
fmVec.assign(fmetas.begin(), fmetas.end()); fmVec.assign(fmetas.begin(), fmetas.end());
if (lex->many_values.head()) { if (lex->many_values.head()) {
//start processing many values
auto it = List_iterator<List_item>(lex->many_values); auto it = List_iterator<List_item>(lex->many_values);
List<List_item> newList; List<List_item> newList;
for (;;) { for (;;) {
...@@ -58,34 +50,27 @@ static std::string getInsertResults(Analysis a,LEX* lex){ ...@@ -58,34 +50,27 @@ static std::string getInsertResults(Analysis a,LEX* lex){
} }
List<Item> *const newList0 = new List<Item>(); List<Item> *const newList0 = new List<Item>();
if (li->elements != fmVec.size()) { if (li->elements != fmVec.size()) {
TEST_TextMessageError(0 == li->elements exit(0);
&& NULL == lex->field_list.head(),
"size mismatch between fields"
" and values!");
} else { } else {
auto it0 = List_iterator<Item>(*li); auto it0 = List_iterator<Item>(*li);
auto fmVecIt = fmVec.begin(); auto fmVecIt = fmVec.begin();
for (;;) { for (;;) {
const Item *const i = it0++; const Item *const i = it0++;
assert(!!i == (fmVec.end() != fmVecIt)); assert(!!i == (fmVec.end() != fmVecIt));
if (!i) { if (!i) {
break; break;
} }
//fetch values, and use fieldMeta to facilitate rewrite
//every filed should be encrypted with onions of encryption
myRewriteInsertHelper(*i, **fmVecIt, a, newList0); myRewriteInsertHelper(*i, **fmVecIt, a, newList0);
++fmVecIt; ++fmVecIt;
} }
for (auto def_it : implicit_defaults) {
newList0->push_back(def_it);
}
} }
newList.push_back(newList0); newList.push_back(newList0);
} }
new_lex->many_values = newList; new_lex->many_values = newList;
} }
return lexToQuery(*new_lex); return lexToQuery(*new_lex);
return "aa";
} }
...@@ -106,11 +91,14 @@ static void testInsertHandler(std::string query){ ...@@ -106,11 +91,14 @@ static void testInsertHandler(std::string query){
//just like what we do in Rewrite::rewrite,dispatchOnLex //just like what we do in Rewrite::rewrite,dispatchOnLex
Analysis analysis(std::string("tdb"),*schema,TK, Analysis analysis(std::string("tdb"),*schema,TK,
SECURITY_RATING::SENSITIVE); SECURITY_RATING::SENSITIVE);
(void)analysis;
std::unique_ptr<query_parse> p; std::unique_ptr<query_parse> p;
p = std::unique_ptr<query_parse>( p = std::unique_ptr<query_parse>(
new query_parse("tdb", query)); new query_parse("tdb", query));
LEX *const lex = p->lex(); LEX *const lex = p->lex();
std::cout<<getInsertResults(analysis,lex)<<std::endl; std::cout<<getInsertResults(analysis,lex)<<std::endl;
(void)lex;
} }
int int
...@@ -132,13 +120,14 @@ main() { ...@@ -132,13 +120,14 @@ main() {
assert(shared_ps!=NULL); assert(shared_ps!=NULL);
UNUSED(testInsertHandler); UNUSED(testInsertHandler);
UNUSED(getInsertResults); UNUSED(getInsertResults);
// std::string query1 = "insert into student values(1,\"zhangfei\")"; std::string query1 = "insert into student values(1,\"zhangfei\")";
/* std::vector<std::string> querys{query1}; std::vector<std::string> queries{query1};
for(auto item:querys){ for(unsigned int i=0u;i<100u;i++){
std::cout<<item<<std::endl; //queries.push_back(query1);
}
for(auto item:queries){
testInsertHandler(item); testInsertHandler(item);
std::cout<<std::endl;
} }
*/
return 0; return 0;
} }
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