CalcExecStreamTestSuite.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/calctest/CalcExecStreamTestSuite.cpp#1 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2004-2009 SQLstream, Inc.
00006 // Copyright (C) 2009-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 2004-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/calctest/CalcExecStreamTestSuite.h"
00026 #include "fennel/calculator/CalcExecStream.h"
00027 #include "fennel/tuple/TupleOverflowExcn.h"
00028 #include "fennel/exec/MockProducerExecStream.h"
00029 #include "fennel/exec/ExecStreamEmbryo.h"
00030 
00031 using namespace fennel;
00032 
00033 CalcExecStreamTestSuite::CalcExecStreamTestSuite(bool addAllTests)
00034 {
00035     StandardTypeDescriptorFactory stdTypeFactory;
00036     TupleAttributeDescriptor attrDesc(
00037         stdTypeFactory.newDataType(STANDARD_TYPE_UINT_64));
00038     uint64Desc = attrDesc;
00039 
00040     if (addAllTests) {
00041         FENNEL_UNIT_TEST_CASE(CalcExecStreamTestSuite,testConstantOneForOne);
00042         FENNEL_UNIT_TEST_CASE(CalcExecStreamTestSuite,testEmptyInput);
00043         FENNEL_UNIT_TEST_CASE(CalcExecStreamTestSuite,testConstantTwoForOne);
00044         FENNEL_UNIT_TEST_CASE(CalcExecStreamTestSuite,testConstantOneForTwo);
00045         FENNEL_UNIT_TEST_CASE(CalcExecStreamTestSuite,testTupleOverflow);
00046     }
00047 }
00048 
00049 void CalcExecStreamTestSuite::testConstantOneForOneImpl(uint nRowsInput)
00050 {
00051     std::string program =
00052         "O u8; "
00053         "I u8; "
00054         "L u8; "
00055         "C u8; "
00056         "V 18446744073709551615; "
00057         "T; "
00058         "ADD L0, I0, C0; "
00059         "REF O0, L0; "
00060         "RETURN; ";
00061 
00062     TupleDescriptor tupleDesc;
00063     tupleDesc.push_back(uint64Desc);
00064 
00065     testConstant(program, tupleDesc, tupleDesc, sizeof(uint64_t), nRowsInput);
00066 }
00067 
00068 void CalcExecStreamTestSuite::testConstantOneForOne()
00069 {
00070     testConstantOneForOneImpl();
00071 }
00072 
00073 void CalcExecStreamTestSuite::testEmptyInput()
00074 {
00075     testConstantOneForOneImpl(0);
00076 }
00077 
00078 void CalcExecStreamTestSuite::testConstantTwoForOne()
00079 {
00080     std::string program =
00081         "O u8, u8; "
00082         "I u8; "
00083         "L u8; "
00084         "C u8; "
00085         "V 18446744073709551615; "
00086         "T; "
00087         "ADD L0, I0, C0; "
00088         "REF O0, L0; "
00089         "REF O1, L0; "
00090         "RETURN; ";
00091 
00092     TupleDescriptor outputDesc;
00093     outputDesc.push_back(uint64Desc);
00094     outputDesc.push_back(uint64Desc);
00095 
00096     TupleDescriptor inputDesc;
00097     inputDesc.push_back(uint64Desc);
00098 
00099     testConstant(program, inputDesc, outputDesc, 2*sizeof(uint64_t));
00100 }
00101 
00102 void CalcExecStreamTestSuite::testConstantOneForTwo()
00103 {
00104     std::string program =
00105         "O u8; "
00106         "I u8, u8; "
00107         "L u8, u8, u8; "
00108         "C u8; "
00109         "V 18446744073709551615; "
00110         "T; "
00111         "ADD L0, I0, C0; "
00112         "ADD L1, I0, I1; "
00113         "ADD L2, L0, L1; "
00114         "REF O0, L2; "
00115         "RETURN; ";
00116 
00117     TupleDescriptor outputDesc;
00118     outputDesc.push_back(uint64Desc);
00119 
00120     TupleDescriptor inputDesc;
00121     inputDesc.push_back(uint64Desc);
00122     inputDesc.push_back(uint64Desc);
00123 
00124     testConstant(program, inputDesc, outputDesc, sizeof(uint64_t));
00125 }
00126 
00127 void CalcExecStreamTestSuite::testTupleOverflow()
00128 {
00129     std::string program =
00130         "O c,40000; "
00131         "I u8; "
00132         "L c,40000; "
00133         "C vc, 5; "
00134         "V 0x68656C6C6F; "
00135         "T; "
00136         "CALL 'castA(L0, C0); "
00137         "REF O0, L0; "
00138         "RETURN; ";
00139 
00140     TupleDescriptor inputDesc;
00141     inputDesc.push_back(uint64Desc);
00142 
00143     TupleDescriptor outputDesc;
00144     StandardTypeDescriptorFactory stdTypeFactory;
00145     TupleAttributeDescriptor charDesc(
00146         stdTypeFactory.newDataType(STANDARD_TYPE_CHAR),
00147         false,
00148         40000);
00149     outputDesc.push_back(charDesc);
00150 
00151     BOOST_CHECK_THROW(
00152         testConstant(program, inputDesc, outputDesc, 0),
00153         TupleOverflowExcn);
00154 }
00155 
00156 void CalcExecStreamTestSuite::testConstant(
00157     std::string program,
00158     TupleDescriptor const &inputDesc,
00159     TupleDescriptor const &outputDesc,
00160     uint expectedFactor,
00161     uint nRowsInput)
00162 {
00163     MockProducerExecStreamParams mockParams;
00164     mockParams.outputTupleDesc = inputDesc;
00165     mockParams.nRows = nRowsInput;
00166 
00167     CalcExecStreamParams calcParams;
00168     calcParams.outputTupleDesc = outputDesc;
00169     calcParams.program = program;
00170     calcParams.isFilter = false;
00171 
00172     ExecStreamEmbryo mockStreamEmbryo;
00173     mockStreamEmbryo.init(new MockProducerExecStream(), mockParams);
00174     mockStreamEmbryo.getStream()->setName("MockProducerExecStream");
00175 
00176     ExecStreamEmbryo calcStreamEmbryo;
00177     calcStreamEmbryo.init(new CalcExecStream(), calcParams);
00178     calcStreamEmbryo.getStream()->setName("CalcExecStream");
00179 
00180     SharedExecStream pOutputStream = prepareTransformGraph(
00181         mockStreamEmbryo, calcStreamEmbryo);
00182 
00183 
00184     uint64_t fff = 0xFFFFFFFFFFFFFFFFLL;
00185     TupleData expectedTuple;
00186     expectedTuple.compute(outputDesc);
00187     for (uint i = 0; i < expectedTuple.size(); ++i) {
00188         expectedTuple[i].pData = reinterpret_cast<PBuffer>(&fff);
00189     }
00190     verifyConstantOutput(
00191         *pOutputStream,
00192         expectedTuple,
00193         mockParams.nRows);
00194 }
00195 
00196 // End CalcExecStreamTestSuite.cpp

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