LbmIntersectExecStreamTest.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/test/LbmIntersectExecStreamTest.cpp#6 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2006-2009 LucidEra, Inc.
00005 // Copyright (C) 2006-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/LbmIntersectExecStream.h"
00025 #include <stdarg.h>
00026 
00027 #include <boost/test/test_tools.hpp>
00028 
00029 using namespace fennel;
00030 
00034 class LbmIntersectExecStreamTest : public LbmExecStreamTestBase
00035 {
00036     void testIntersect(
00037         uint nInputs, uint nRows, std::vector<InputData> const &inputData);
00038 
00039 public:
00040     explicit LbmIntersectExecStreamTest()
00041     {
00042         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, test2Inputs);
00043         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, test3Inputs);
00044         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, testGaps);
00045         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, testLargeOutput);
00046         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, testLargeInputs);
00047         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, testSingleBitmaps);
00048         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, testEmptyResult);
00049         FENNEL_UNIT_TEST_CASE(LbmIntersectExecStreamTest, testZeros);
00050     }
00051 
00052     void test2Inputs();
00053     void test3Inputs();
00054     void testGaps();
00055     void testLargeOutput();
00056     void testLargeInputs();
00057     void testSingleBitmaps();
00058     void testEmptyResult();
00059     void testZeros();
00060 };
00061 
00062 void LbmIntersectExecStreamTest::test2Inputs()
00063 {
00064     uint nInputs = 2;
00065     uint nRows = 1000;
00066     std::vector<InputData> inputData;
00067     InputData input;
00068 
00069     // bitmap input 1 -- all bits set
00070     input.bitmapSize = 4;
00071     input.startRid = LcsRid(10);
00072     input.skipRows = 1;
00073     inputData.push_back(input);
00074 
00075     // bitmap input 2 -- every other bit set
00076     input.bitmapSize = 8;
00077     input.startRid = LcsRid(0);
00078     input.skipRows = 2;
00079     inputData.push_back(input);
00080 
00081     // expected result -- every other bit set, starting at 10
00082     input.bitmapSize = resultBitmapSize(10, nRows);
00083     input.startRid = LcsRid(10);
00084     input.skipRows = 2;
00085     inputData.push_back(input);
00086 
00087     testIntersect(nInputs, nRows, inputData);
00088 }
00089 
00090 void LbmIntersectExecStreamTest::test3Inputs()
00091 {
00092     uint nInputs = 3;
00093     uint nRows = 1000;
00094     std::vector<InputData> inputData;
00095     InputData input;
00096 
00097     // bitmap input 1 -- every 2 rids set, starting at 22
00098     input.bitmapSize = 9;
00099     input.startRid = LcsRid(22);
00100     input.skipRows = 2;
00101     inputData.push_back(input);
00102 
00103     // bitmap input 2 -- every 3 rids set, starting at 30
00104     input.bitmapSize = 8;
00105     input.startRid = LcsRid(30);
00106     input.skipRows = 3;
00107     inputData.push_back(input);
00108 
00109     // bitmap input 3 -- every rid set, starting at 35
00110     input.bitmapSize = 10;
00111     input.startRid = LcsRid(35);
00112     input.skipRows = 1;
00113     inputData.push_back(input);
00114 
00115     // expected result -- every 6 rids set, starting at 36
00116     input.bitmapSize = resultBitmapSize(36, nRows);
00117     input.startRid = LcsRid(36);
00118     input.skipRows = 2*3;
00119     inputData.push_back(input);
00120 
00121     testIntersect(nInputs, nRows, inputData);
00122 }
00123 
00130 void LbmIntersectExecStreamTest::testGaps()
00131 {
00132     uint nInputs = 3;
00133     // ensure we have a result with 8 bits set
00134     uint nRows = 3*11*19*8;
00135     std::vector<InputData> inputData;
00136     InputData input;
00137 
00138     // bitmap input 1 -- every 3 rids set, starting at 3
00139     input.bitmapSize = 11;
00140     input.startRid = LcsRid(3);
00141     input.skipRows = 3;
00142     inputData.push_back(input);
00143 
00144     // bitmap input 2 -- every 11 rids set, starting at 11
00145     input.bitmapSize = 12;
00146     input.startRid = LcsRid(11);
00147     input.skipRows = 11;
00148     inputData.push_back(input);
00149 
00150     // bitmap input 3 -- every 19 rids set, starting at 19
00151     input.bitmapSize = 13;
00152     input.startRid = LcsRid(19);
00153     input.skipRows = 19;
00154     inputData.push_back(input);
00155 
00156     // expected result -- every 3*11*19 rids set, starting at 3*11*19
00157     input.bitmapSize = resultBitmapSize(3*11*19, nRows);
00158     input.startRid = LcsRid(3*11*19);
00159     input.skipRows = 3*11*19;
00160     inputData.push_back(input);
00161 
00162     testIntersect(nInputs, nRows, inputData);
00163 }
00164 
00169 void LbmIntersectExecStreamTest::testLargeOutput()
00170 {
00171     uint nInputs = 2;
00172     uint nRows = 100000;
00173     std::vector<InputData> inputData;
00174     InputData input;
00175 
00176     // bitmap input 1 -- all bits set
00177     input.bitmapSize = 1;
00178     input.startRid = LcsRid(0);
00179     input.skipRows = 1;
00180     inputData.push_back(input);
00181 
00182     // bitmap input 2 -- every 16 bits set
00183     input.bitmapSize = 1;
00184     input.startRid = LcsRid(0);
00185     input.skipRows = 16;
00186     inputData.push_back(input);
00187 
00188     // expected result -- every 16 bits set
00189     input.bitmapSize = resultBitmapSize(0, nRows);
00190     input.startRid = LcsRid(0);
00191     input.skipRows = 16;
00192     inputData.push_back(input);
00193 
00194     testIntersect(nInputs, nRows, inputData);
00195 }
00196 
00200 void LbmIntersectExecStreamTest::testLargeInputs()
00201 {
00202     uint nInputs = 2;
00203     uint nRows = 15*8*24*5;
00204     std::vector<InputData> inputData;
00205     InputData input;
00206 
00207     // bitmap input 1 -- every 8 bits set
00208     input.bitmapSize = 15*8*3;
00209     input.startRid = LcsRid(0);
00210     input.skipRows = 8;
00211     inputData.push_back(input);
00212 
00213     // bitmap input 2 -- every 15 bits set
00214     input.bitmapSize = 15*8*3;
00215     input.startRid = LcsRid(0);
00216     input.skipRows = 15;
00217     inputData.push_back(input);
00218 
00219     // expected result -- every 8*15 bits set
00220     input.bitmapSize = resultBitmapSize(0, nRows);
00221     input.startRid = LcsRid(0);
00222     input.skipRows = 8*15;
00223     inputData.push_back(input);
00224 
00225     testIntersect(nInputs, nRows, inputData);
00226 }
00227 
00231 void LbmIntersectExecStreamTest::testSingleBitmaps()
00232 {
00233     uint nInputs = 2;
00234     uint nRows = 20*8*5;
00235     std::vector<InputData> inputData;
00236     InputData input;
00237 
00238     // bitmap input 1 -- all even bits set
00239     input.bitmapSize = 20;
00240     input.startRid = LcsRid(0);
00241     input.skipRows = 2;
00242     inputData.push_back(input);
00243 
00244     // bitmap input 2 -- every 4 bits set
00245     input.bitmapSize = 20;
00246     input.startRid = LcsRid(0);
00247     input.skipRows = 4;
00248     inputData.push_back(input);
00249 
00250     // expected result -- every 4 bits set
00251     input.bitmapSize = resultBitmapSize(0, nRows);
00252     input.startRid = LcsRid(0);
00253     input.skipRows = 4;
00254     inputData.push_back(input);
00255 
00256     testIntersect(nInputs, nRows, inputData);
00257 }
00258 
00262 void LbmIntersectExecStreamTest::testEmptyResult()
00263 {
00264     uint nInputs = 2;
00265     uint nRows = 80;
00266     std::vector<InputData> inputData;
00267     InputData input;
00268 
00269     // bitmap input 1 -- all even bits set
00270     input.bitmapSize = 10;
00271     input.startRid = LcsRid(0);
00272     input.skipRows = 2;
00273     inputData.push_back(input);
00274 
00275     // bitmap input 2 -- all odd bits set
00276     input.bitmapSize = 10;
00277     input.startRid = LcsRid(1);
00278     input.skipRows = 2;
00279     inputData.push_back(input);
00280 
00281     // expected result -- empty result
00282     input.bitmapSize = 0;
00283     input.startRid = LcsRid(0);
00284     input.skipRows = 1;
00285     inputData.push_back(input);
00286 
00287     testIntersect(nInputs, nRows, inputData);
00288 }
00289 
00294 void LbmIntersectExecStreamTest::testZeros()
00295 {
00296     uint nInputs = 2;
00297     uint nRows = 4000;
00298     std::vector<InputData> inputData;
00299     InputData input;
00300 
00301     // bitmap input 1 -- every 3 bits set, starting at 3
00302     input.bitmapSize = 9;
00303     input.startRid = LcsRid(3);
00304     input.skipRows = 3;
00305     inputData.push_back(input);
00306 
00307     // bitmap input 2 -- every 4 bits set, starting at 4
00308     input.bitmapSize = 9;
00309     input.startRid = LcsRid(4);
00310     input.skipRows = 4;
00311     inputData.push_back(input);
00312 
00313     // expected result -- every 12 bits set, starting at 12
00314     input.bitmapSize = resultBitmapSize(12, nRows);
00315     input.startRid = LcsRid(12);
00316     input.skipRows = 12;
00317     inputData.push_back(input);
00318 
00319     testIntersect(nInputs, nRows, inputData);
00320 }
00321 
00322 void LbmIntersectExecStreamTest::testIntersect(
00323     uint nInputs, uint nRows, std::vector<InputData> const &inputData)
00324 {
00325     boost::scoped_array<BitmapInput> bmInputs;
00326     boost::scoped_array<ValuesExecStreamParams> valuesParams;
00327     std::vector<ExecStreamEmbryo> valuesStreamEmbryoList;
00328     ExecStreamEmbryo valuesStreamEmbryo;
00329 
00330     // +1 is for expected result
00331     assert(inputData.size() == nInputs + 1);
00332 
00333     bmInputs.reset(new BitmapInput[nInputs + 1]);
00334     valuesParams.reset(new ValuesExecStreamParams[nInputs]);
00335 
00336     // setup values exec stream for each input
00337     for (uint i = 0; i < nInputs; i++) {
00338         initBitmapInput(bmInputs[i], nRows, inputData[i]);
00339         initValuesExecStream(
00340             i, valuesParams[i], valuesStreamEmbryo, bmInputs[i]);
00341         valuesStreamEmbryoList.push_back(valuesStreamEmbryo);
00342     }
00343     // set up expected result
00344     if (inputData[nInputs].bitmapSize > 0) {
00345         initBitmapInput(bmInputs[nInputs], nRows, inputData[nInputs]);
00346     } else {
00347         bmInputs[nInputs].bufArray.reset();
00348         bmInputs[nInputs].nBitmaps = 0;
00349     }
00350 
00351     LbmIntersectExecStreamParams intersectParams;
00352     intersectParams.rowLimitParamId = DynamicParamId(1);
00353     intersectParams.startRidParamId = DynamicParamId(2);
00354     intersectParams.outputTupleDesc = bitmapTupleDesc;
00355     intersectParams.scratchAccessor =
00356         pSegmentFactory->newScratchSegment(pCache, 10);
00357 
00358     ExecStreamEmbryo intersectEmbryo;
00359     intersectEmbryo.init(new LbmIntersectExecStream(), intersectParams);
00360     intersectEmbryo.getStream()->setName("IntersectExecStream");
00361 
00362     SharedExecStream pOutputStream = prepareConfluenceGraph(
00363         valuesStreamEmbryoList, intersectEmbryo);
00364 
00365     verifyBufferedOutput(
00366         *pOutputStream, bitmapTupleDesc, bmInputs[nInputs].nBitmaps,
00367         bmInputs[nInputs].bufArray.get());
00368 }
00369 
00370 FENNEL_UNIT_TEST_SUITE(LbmIntersectExecStreamTest);
00371 
00372 
00373 // End LbmIntersectExecStreamTest.cpp

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