Commit 13f3f9c9 authored by Philipp Götze's avatar Philipp Götze
Browse files

🚀 Added test case and accelerated Catch test cases in general

parent 32df83b9
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#============================================= #=============================================
macro( build_executable arg ) macro( build_executable arg )
include_directories("${PROJECT_SOURCE_DIR}/test") include_directories("${PROJECT_SOURCE_DIR}/test")
add_executable( ${arg} "${arg}.cpp" ) add_executable( ${arg} "${arg}.cpp" $<TARGET_OBJECTS:MainTest>)
target_link_libraries( ${arg} target_link_libraries( ${arg}
ptable ptable
${NVML_LIBRARIES} ${NVML_LIBRARIES}
${BENCHMARK_LIB} ${BENCHMARK_LIB}
) )
endmacro( build_executable ) endmacro( build_executable )
#============================================= #=============================================
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifndef BDCCInfo_hpp_ #ifndef BDCCInfo_hpp_
#define BDCCInfo_hpp_ #define BDCCInfo_hpp_
#include <bitset>
#include <map> #include <map>
#include <numeric> #include <numeric>
...@@ -39,7 +40,7 @@ using nvml::obj::p; ...@@ -39,7 +40,7 @@ using nvml::obj::p;
* key: Column ID * key: Column ID
* value: <number of BDCC bits , bit alignment when applying mask on value> * value: <number of BDCC bits , bit alignment when applying mask on value>
*****************************************************************************/ *****************************************************************************/
using Dimensions = std::map<uint16_t, std::pair<uint16_t, uint16_t>>; using Dimensions = std::vector<std::tuple<uint16_t, uint16_t, uint16_t>>;
/**************************************************************************//** /**************************************************************************//**
* \brief Info structure about the BDCC meta data. * \brief Info structure about the BDCC meta data.
...@@ -63,7 +64,7 @@ class BDCCInfo { ...@@ -63,7 +64,7 @@ class BDCCInfo {
explicit BDCCInfo(const Dimensions &_bitMap) : explicit BDCCInfo(const Dimensions &_bitMap) :
numberOfBins(std::accumulate(_bitMap.begin(), _bitMap.end(), 0, numberOfBins(std::accumulate(_bitMap.begin(), _bitMap.end(), 0,
[](const size_t sum, decltype(*_bitMap.begin()) p) { [](const size_t sum, decltype(*_bitMap.begin()) p) {
return sum + p.second.first; return sum + std::get<1>(p);
})), })),
dimensions() { deriveMasks(_bitMap); } dimensions() { deriveMasks(_bitMap); }
...@@ -77,7 +78,7 @@ class BDCCInfo { ...@@ -77,7 +78,7 @@ class BDCCInfo {
void deriveMasks(Dimensions dims) { void deriveMasks(Dimensions dims) {
/* Initialize */ /* Initialize */
for (const auto &dim: dims) { for (const auto &dim: dims) {
dimensions.get_rw().emplace_back(dim.first, dim.second.first, std::bitset<32>(), dim.second.second); dimensions.get_rw().emplace_back(std::get<0>(dim), std::get<1>(dim), std::bitset<32>(), std::get<2>(dim));
} }
/* Round robin the bins for mapping */ /* Round robin the bins for mapping */
...@@ -85,10 +86,11 @@ class BDCCInfo { ...@@ -85,10 +86,11 @@ class BDCCInfo {
while (bdccSize > 0) { while (bdccSize > 0) {
auto i = 0ul; auto i = 0ul;
for (auto &dim: dims) { for (auto &dim: dims) {
if (dim.second.first > 0) { if (std::get<1>(dim) > 0) {
--dim.second.first; --std::get<1>(dim);
std::get<2>(dimensions.get_rw()[i++])[--bdccSize] = 1; std::get<2>(dimensions.get_rw()[i])[--bdccSize] = 1;
} }
++i;
} }
} }
} }
......
/*
* Copyright (C) 2017 DBIS Group - TU Ilmenau, All Rights Reserved.
*
* This file is part of PTable.
*
* PTable is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PTable is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PTable. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include "catch.hpp"
#include "config.h"
#include "core/BDCCInfo.hpp"
#include "core/PTableException.hpp"
//#include <libpmemobj++/pool.hpp>
using namespace ptable;
using nvml::obj::pool;
TEST_CASE("Testing to create a new BDCCInfo instance", "[BDCCInfo]") {
struct root {
persistent_ptr<BDCCInfo> bdccInfo;
};
pool<root> pop;
const std::string path = gPmemPath + "bdccInfo";
auto dims = Dimensions({{0, 4, 4}, {3, 6, 6}});
if (access(path.c_str(), F_OK) != 0) {
pop = pool<root>::create(path, "BDCCInfo", 8 * 1024 * 1024);
transaction::exec_tx(pop, [&] {
pop.get_root()->bdccInfo = make_persistent<BDCCInfo>(dims);
});
} else {
throw PTableException("bdccInfo pool should not exist");
}
auto bdccInfo = pop.get_root()->bdccInfo;
REQUIRE(bdccInfo->numBins() == 10);
std::bitset<32> expected[2] = {
0b0000000000000000001010101000,
0b0000000000000000000101010111
};
auto i = 0u;
for(const auto &dim : *bdccInfo) {
REQUIRE(std::get<0>(dim) == std::get<0>(dims[i]));
REQUIRE(std::get<1>(dim) == std::get<1>(dims[i]));
REQUIRE(std::get<3>(dim) == std::get<2>(dims[i]));
REQUIRE(std::get<2>(dim) == expected[i]);
++i;
}
transaction::exec_tx(pop, [&] {
delete_persistent<BDCCInfo>(bdccInfo);
});
pop.close();
std::remove(path.c_str());
}
TEST_CASE("Testing to apply a mask to various value types", "[BDCCInfo]") {
auto mask = 0b10101010; /* 170/AA (dec/hex) */
int value1 = 240; /* -> 240 = F0/11110000 (hex/bin) */
REQUIRE(applyMask(value1, mask) == 0b10100000);
double value2 = 240.5; /* -> 240 = F0/11110000 (hex/bin) */
REQUIRE(applyMask(value2, mask) == 0b10100000);
std::string value3 = "240"; /* -> "2" = 32/00110010 (hex/bin) */
REQUIRE(applyMask(value3, mask) == 0b00100010);
}
...@@ -5,5 +5,7 @@ include(../../cmake/Testing.cmake.in) ...@@ -5,5 +5,7 @@ include(../../cmake/Testing.cmake.in)
#add_definitions(-DTEST_DATA_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/test_data/") #add_definitions(-DTEST_DATA_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/test_data/")
if (BUILD_TEST_CASES) if (BUILD_TEST_CASES)
add_library(MainTest OBJECT MainTest.cpp)
do_test(BDCCInfoTest)
do_test(PTableTest) do_test(PTableTest)
endif () endif ()
/*
* Copyright (C) 2017 DBIS Group - TU Ilmenau, All Rights Reserved.
*
* This file is part of PTable.
*
* PTable is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PTable is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PTable. If not, see <http://www.gnu.org/licenses/>.
*/
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
\ No newline at end of file
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
* along with PTable. If not, see <http://www.gnu.org/licenses/>. * along with PTable. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do
// this in one cpp file
#include <unistd.h> #include <unistd.h>
#include "catch.hpp" #include "catch.hpp"
...@@ -53,7 +50,7 @@ TEST_CASE("Testing storing tuples in PTable", "[PTable]") { ...@@ -53,7 +50,7 @@ TEST_CASE("Testing storing tuples in PTable", "[PTable]") {
{"c", String_Type}, {"c", String_Type},
{"d", Double_Type} {"d", Double_Type}
}, Int_Type); }, Int_Type);
auto dims = Dimensions({{0, {4, 4}}, {3, {6, 6}}}); auto dims = Dimensions({{0, 4, 4}, {3, 6, 6}});
pop.get_root()->pTable = make_persistent<PTableType>(tInfo, dims); pop.get_root()->pTable = make_persistent<PTableType>(tInfo, dims);
}); });
} else { } else {
......
Supports Markdown
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