Commit 40c83506 authored by joreland@mysql.com's avatar joreland@mysql.com

ndb - bitfields ndbapi test prg + bug fixes

parent 56a4c21d
......@@ -17,6 +17,7 @@ void print(const Uint32 src[], Uint32 len, Uint32 pos = 0)
}
#ifndef __TEST_BITMASK__
void
BitmaskImpl::getFieldImpl(const Uint32 src[],
unsigned shiftL, unsigned len, Uint32 dst[])
......@@ -32,8 +33,15 @@ BitmaskImpl::getFieldImpl(const Uint32 src[],
len -= 32;
}
* dst++ |= (* src) << shiftL;
* dst = ((* src) >> shiftR) & ((1 << len) - 1) & undefined;
if(len < shiftR)
{
* dst |= ((* src) & ((1 << len) - 1)) << shiftL;
}
else
{
* dst++ |= ((* src) << shiftL);
* dst = ((* src) >> shiftR) & ((1 << (len - shiftR)) - 1) & undefined;
}
}
void
......@@ -57,10 +65,16 @@ BitmaskImpl::setFieldImpl(Uint32 dst[],
Uint32 mask = ((1 << len) -1);
* dst = (* dst & ~mask);
if(len < shiftR)
{
* dst |= ((* src++) >> shiftL) & mask;
* dst |= ((* src) << shiftR) & mask & undefined;
}
else
{
* dst |= ((* src++) >> shiftL);
* dst |= ((* src) & ((1 << (len - shiftR)) - 1)) << shiftR ;
}
}
#else
#define DEBUG 0
......@@ -135,9 +149,9 @@ void simple(int pos, int size)
const Uint32 sz = 4 * sz32;
Uint32 zero = 0;
_mask.fill(sz32, zero);
_src.fill(sz32, zero);
_dst.fill(sz32, zero);
_mask.fill(sz32+1, zero);
_src.fill(sz32+1, zero);
_dst.fill(sz32+1, zero);
Uint32 * src = _src.getBase();
Uint32 * dst = _dst.getBase();
......@@ -149,18 +163,18 @@ void simple(int pos, int size)
rand(src, size);
BitmaskImpl::setField(sz32, mask, pos, size, src);
BitmaskImpl::getField(sz32, mask, pos, size, dst);
printf("src: "); print(src, size); printf("\n");
printf("msk: "); print(mask, sz32 << 5); printf("\n");
printf("dst: "); print(dst, size); printf("\n");
require(cmp(src, dst, size));
printf("src: "); print(src, size+31); printf("\n");
printf("msk: "); print(mask, (sz32 << 5) + 31); printf("\n");
printf("dst: "); print(dst, size+31); printf("\n");
require(cmp(src, dst, size+31));
};
static void
do_test(int bitmask_size)
{
#if 0
#if 1
simple(rand() % 33, (rand() % 63)+1);
#else
//#else
Vector<Alloc> alloc_list;
bitmask_size = (bitmask_size + 31) & ~31;
Uint32 sz32 = (bitmask_size >> 5);
......@@ -235,8 +249,10 @@ do_test(int bitmask_size)
!BitmaskImpl::get(sz32, alloc_mask.getBase(), pos+free))
free++;
Uint32 sz = (lrand() % free);
Uint32 sz =
(free <= 64 && ((lrand() % 100) > 80)) ? free : (lrand() % free);
sz = sz ? sz : 1;
sz = pos + sz == bitmask_size ? sz - 1 : sz;
Alloc a;
a.pos = pos;
a.size = sz;
......
......@@ -1149,7 +1149,7 @@ Dbtup::updateBitsNULLable(Uint32* inBuffer,
inBuffer+indexBuf+1);
Uint32 newIndex = indexBuf + 1 + ((bitCount + 31) >> 5);
tInBufLen = newIndex;
tInBufIndex = newIndex;
return true;
} else {
Uint32 newIndex = tInBufIndex + 1;
......
......@@ -3,6 +3,7 @@
#include <ndb_opts.h>
#include <NDBT.hpp>
#include <NdbApi.hpp>
#include <HugoTransactions.hpp>
static const char* opt_connect_str= 0;
static const char* _dbname = "TEST_DB";
......@@ -129,13 +130,61 @@ static
const NdbDictionary::Table*
create_random_table(Ndb* pNdb)
{
NdbDictionary::Table tab;
Uint32 cols = 1 + (rand() % (NDB_MAX_ATTRIBUTES_IN_TABLE - 1));
Uint32 keys = NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY;
Uint32 length = 4096;
Uint32 key_size = NDB_MAX_KEYSIZE_IN_WORDS;
BaseString name;
name.assfmt("TAB_%d", rand() & 65535);
tab.setName(name.c_str());
for(int i = 0; i<cols && length > 0; i++)
{
NdbDictionary::Column col;
name.assfmt("COL_%d", i);
col.setName(name.c_str());
if(i == 0 || i == 1)
{
col.setType(NdbDictionary::Column::Unsigned);
col.setLength(1);
col.setNullable(false);
col.setPrimaryKey(i == 0);
tab.addColumn(col);
continue;
}
col.setType(NdbDictionary::Column::Bit);
Uint32 len = 1 + (rand() % 128); //(length - 1));
col.setLength(len); length -= len;
col.setNullable((rand() >> 16) & 1);
col.setPrimaryKey(false);
tab.addColumn(col);
}
ndbout << (NDBT_Table&)tab << endl;
if(pNdb->getDictionary()->createTable(tab) == 0)
{
return pNdb->getDictionary()->getTable(tab.getName());
}
return 0;
}
static
int
transactions(Ndb* pNdb, const NdbDictionary::Table* tab)
{
return 0;
int i = 0;
HugoTransactions trans(* tab);
i |= trans.loadTable(pNdb, 1000);
i |= trans.pkReadRecords(pNdb, 1000, 13);
i |= trans.scanReadRecords(pNdb, 1000, 25);
i |= trans.pkUpdateRecords(pNdb, 1000, 37);
i |= trans.scanUpdateRecords(pNdb, 1000, 25);
i |= trans.pkDelRecords(pNdb, 500, 23);
i |= trans.clearTable(pNdb);
return i;
}
static
......
......@@ -108,8 +108,14 @@ HugoCalculator::calcValue(int record,
// Calculate length of the string to create. We want the string
// length to be varied between max and min of this attribute.
Uint32 org = len;
if(attr->getType() == NdbDictionary::Column::Varchar)
len = val % (len + 1);
else
if((val % (len + 1)) == 0)
len = 0;
// If len == 0 return NULL if this is a nullable attribute
if (len == 0){
if(attr->getNullable() == true)
......@@ -120,6 +126,14 @@ HugoCalculator::calcValue(int record,
for(i=0; i < len; i++)
buf[i] = a[((val^i)%25)];
buf[len] = 0;
if(attr->getType() == NdbDictionary::Column::Bit)
{
Uint32 bits= attr->getLength();
Uint32 pos = bits >> 5;
Uint32 size = bits & 31;
((Uint32*)buf)[pos] &= ((1 << size) - 1);
}
}
return buf;
};
......@@ -154,16 +168,13 @@ HugoCalculator::verifyRowValues(NDBT_ResultRow* const pRow) const{
result = -1;
}
} else{
if (memcmp(res, pRow->attributeStore(i)->aRef(), pRow->attributeStore(i)->arraySize()) != 0){
if (memcmp(res, pRow->attributeStore(i)->aRef(), len) != 0){
// if (memcmp(res, pRow->attributeStore(i)->aRef(), pRow->attributeStore(i)->getLength()) != 0){
g_err << "arraySize(): "
<< pRow->attributeStore(i)->arraySize()
<< ", NdbDict::Column::getLength(): " << attr->getLength()
<< endl;
g_err << "Column: " << attr->getName() << endl;
const char* buf2 = pRow->attributeStore(i)->aRef();
for (Uint32 j = 0; j < pRow->attributeStore(i)->arraySize(); j++)
for (Uint32 j = 0; j < len; j++)
{
g_err << j << ":" << buf[j] << "[" << buf2[j] << "]";
g_err << j << ":" << hex << (int)buf[j] << "[" << hex << (int)buf2[j] << "]";
if (buf[j] != buf2[j])
{
g_err << "==>Match failed!";
......
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