00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "fennel/common/CommonPreamble.h"
00023 #include "fennel/lucidera/test/LbmExecStreamTestBase.h"
00024 #include "fennel/lucidera/bitmap/LbmByteSegment.h"
00025 #include "fennel/lucidera/bitmap/LbmNormalizerExecStream.h"
00026 #include <stdarg.h>
00027
00028 #include <boost/test/test_tools.hpp>
00029
00030 using namespace fennel;
00031
00035 class LbmNormalizerExecStreamTest : public LbmExecStreamTestBase
00036 {
00037 protected:
00058 void testNormalizer(
00059 uint nRows,
00060 uint nKeys,
00061 std::vector<int> const &repeatSeqValues);
00062
00063 public:
00064 explicit LbmNormalizerExecStreamTest()
00065 {
00066 FENNEL_UNIT_TEST_CASE(LbmNormalizerExecStreamTest, testBitsInByte);
00067 FENNEL_UNIT_TEST_CASE(LbmNormalizerExecStreamTest, testScanFullKey);
00068 FENNEL_UNIT_TEST_CASE(LbmNormalizerExecStreamTest, testScanPartKey);
00069 FENNEL_UNIT_TEST_CASE(LbmNormalizerExecStreamTest, testCloseRepeats);
00070 }
00071
00072 void testBitsInByte();
00073 void testScanFullKey();
00074 void testScanPartKey();
00075 void testCloseRepeats();
00076 };
00077
00081 uint getValueCount(uint nRows, uint interval, uint value)
00082 {
00083 uint nCopies = nRows / interval;
00084 if (value < nRows % interval) {
00085 nCopies++;
00086 }
00087 return nCopies;
00088 }
00089
00090 class NormalizerExecStreamGenerator : public MockProducerExecStreamGenerator
00091 {
00092 protected:
00093 uint nKeys;
00094 std::vector<int> repeatSeqValues;
00095 uint interval;
00096 boost::shared_array<uint> changeIndexes;
00097 uint current;
00098 uint lastRow;
00099
00100 public:
00101 NormalizerExecStreamGenerator(
00102 uint nRows, uint nKeys, std::vector<int> repeatSeqValues)
00103 {
00104 this->nKeys = nKeys;
00105 this->repeatSeqValues = repeatSeqValues;
00106 interval = LbmExecStreamTestBase::getTupleInterval(repeatSeqValues);
00107 changeIndexes.reset(new uint[interval]);
00108 changeIndexes[0] = getValueCount(nRows, interval, 0);
00109 for (uint i = 1; i < interval; i++) {
00110 changeIndexes[i] =
00111 changeIndexes[i - 1] + getValueCount(nRows, interval, i);
00112 }
00113 current = 0;
00114 lastRow = 0;
00115 }
00116
00117 virtual int64_t generateValue(uint iRow, uint iCol)
00118 {
00119
00120 assert (lastRow <= iRow);
00121 lastRow = iRow;
00122
00123 if (iRow >= changeIndexes[current]) {
00124 current++;
00125 assert (current < interval);
00126 }
00127 assert (iCol < nKeys);
00128 return current % repeatSeqValues[iCol];
00129 }
00130 };
00131
00132 void LbmNormalizerExecStreamTest::testBitsInByte()
00133 {
00134 LbmByteSegment::verifyBitsInByte();
00135 }
00136
00137 void LbmNormalizerExecStreamTest::testScanFullKey()
00138 {
00139 std::vector<int> repeatSeqValues;
00140 repeatSeqValues.push_back(1);
00141 repeatSeqValues.push_back(5);
00142 repeatSeqValues.push_back(9);
00143
00144 testNormalizer(1000, 3, repeatSeqValues);
00145 }
00146
00147 void LbmNormalizerExecStreamTest::testScanPartKey()
00148 {
00149 std::vector<int> repeatSeqValues;
00150 repeatSeqValues.push_back(1);
00151 repeatSeqValues.push_back(5);
00152 repeatSeqValues.push_back(9);
00153
00154 testNormalizer(1000, 2, repeatSeqValues);
00155 }
00156
00157 void LbmNormalizerExecStreamTest::testCloseRepeats()
00158 {
00159 std::vector<int> repeatSeqValues;
00160 repeatSeqValues.push_back(1);
00161 repeatSeqValues.push_back(2);
00162 repeatSeqValues.push_back(3);
00163
00164 testNormalizer(1000, 3, repeatSeqValues);
00165 }
00166
00167 void LbmNormalizerExecStreamTest::testNormalizer(
00168 uint nRows,
00169 uint nKeys,
00170 std::vector<int> const &repeatSeqValues)
00171 {
00172 initKeyBitmap(nRows, repeatSeqValues);
00173
00174
00175 ValuesExecStreamParams valuesParams;
00176 valuesParams.outputTupleDesc = keyBitmapTupleDesc;
00177 valuesParams.pTupleBuffer = keyBitmapBuf;
00178 valuesParams.bufSize = keyBitmapBufSize;
00179
00180 ExecStreamEmbryo valuesStreamEmbryo;
00181 valuesStreamEmbryo.init(new ValuesExecStream(), valuesParams);
00182 valuesStreamEmbryo.getStream()->setName("ValuesExecStream");
00183
00184 ExecStreamEmbryo normalizerEmbryo;
00185 LbmNormalizerExecStreamParams normalizerParams;
00186 initNormalizerExecStream(normalizerParams, normalizerEmbryo, nKeys);
00187
00188 SharedExecStream pOutputStream = prepareTransformGraph(
00189 valuesStreamEmbryo, normalizerEmbryo);
00190 NormalizerExecStreamGenerator verifier(nRows, nKeys, repeatSeqValues);
00191 verifyOutput(*pOutputStream, nRows, verifier);
00192 }
00193
00194 FENNEL_UNIT_TEST_SUITE(LbmNormalizerExecStreamTest);
00195
00196