LbmNormalizerExecStreamTest.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/test/LbmNormalizerExecStreamTest.cpp#7 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 LucidEra, Inc.
00005 // Copyright (C) 2005-2009 The Eigenbase Project
00006 //
00007 // This program is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU General Public License as published by the Free
00009 // Software Foundation; either version 2 of the License, or (at your option)
00010 // any later version approved by The Eigenbase Project.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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         // must be generated in order
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     // test normalizer against the input
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 // End LbmNormalizerExecStreamTest.cpp

Generated on Mon Jun 22 04:00:20 2009 for Fennel by  doxygen 1.5.1