From fc5ecdb8b6134caae5f45ef185068b21ad4b0dde Mon Sep 17 00:00:00 2001 From: billsioros Date: Wed, 5 Dec 2018 18:54:29 +0200 Subject: [PATCH] testing loading relations done --- inc/relation.hpp | 7 ++- test/executioner_unit.cpp | 125 ++++++++++++++++++++++++++++++++++++++ test_data/files.txt | 30 ++++----- utility.sh | 2 +- 4 files changed, 146 insertions(+), 18 deletions(-) create mode 100644 test/executioner_unit.cpp diff --git a/inc/relation.hpp b/inc/relation.hpp index bf507bc..4d8baff 100644 --- a/inc/relation.hpp +++ b/inc/relation.hpp @@ -14,8 +14,11 @@ namespace RHJ { extern struct Meta { - uint64_t rowSize, columnSize; - tuple_key_t** columns; + __off_t mappingSize; + void * mapping; + + tuple_key_t rowSize, columnSize; + tuple_payload_t ** columns; } * meta; struct Relation { diff --git a/test/executioner_unit.cpp b/test/executioner_unit.cpp new file mode 100644 index 0000000..7e1ac22 --- /dev/null +++ b/test/executioner_unit.cpp @@ -0,0 +1,125 @@ + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include + +// Generate a list of the full paths of the relations and store it in files.txt +// for file in "$(ls ./test_data/small/r*)"; do echo "$(realpath $file)"; done > ./test_data/files.txt && echo "Done" >> ./test_data/files.txt + +// Macro used in order to exit if condition is met +#define exit_if(condition, message) \ +do \ +{ \ + if (condition) \ + { \ + std::perror(message); std::exit(errno); \ + } \ +} while (false) \ + +// Macro definition for consistency with above declaration +#define exit_if_not(condition) assert(condition) + +int main() +{ + utility::list paths; + + // Throw exception if any of the following flags are set for std::cin + std::cin.exceptions(std::ios_base::badbit | std::ios_base::failbit); + + while(true) + { + char buff[PATH_MAX + 1UL]; + + // Atempt to read the current line + try + { + std::cin.getline(buff, sizeof(buff)); + } + catch (std::ios_base::failure& f) + { + std::cerr + << "iteration: " << paths.size() + << " exception: " << f.what() + << std::endl; + + std::exit(f.code().value()); + } + + if (!std::strcmp(buff, "Done")) + break; + + paths.push_back(new char[std::strlen(buff) + 1UL]); + + std::strcpy(paths.back(), buff); + } + + std::size_t total = paths.size(); exit_if_not(total > 0UL); + + RHJ::meta = new RHJ::Meta[total]; + + for (std::size_t i = 0UL; i < total; i++) + { + // Open file + int fd = open(paths.front(), O_RDONLY); + exit_if(fd < 0, paths.front()); + + // Retrieve its size + struct stat st; + exit_if(fstat(fd, &st) < 0, paths.front()); + + // Map file to memory + RHJ::meta[i].mapping = mmap(nullptr, (RHJ::meta[i].mappingSize = st.st_size), PROT_READ, MAP_PRIVATE, fd, 0); + exit_if(RHJ::meta[i].mapping == MAP_FAILED, paths.front()); + + // Close file + exit_if(close(fd) < 0, paths.front()); + + // Deallocate uneccessary memory + delete[] paths.front(); paths.erase(paths.begin()); + + // Copy Metadata + void * mapping_clone = RHJ::meta[i].mapping; + + void * rsptr = reinterpret_cast(&RHJ::meta[i].rowSize); + std::memmove(rsptr, mapping_clone, sizeof(tuple_key_t)); + reinterpret_cast(mapping_clone)++; + + void * csptr = reinterpret_cast(&RHJ::meta[i].columnSize); + std::memmove(csptr, mapping_clone, sizeof(tuple_key_t)); + reinterpret_cast(mapping_clone)++; + + // Create Index + RHJ::meta[i].columns = new tuple_payload_t*[RHJ::meta[i].columnSize]; + for(tuple_key_t j = 0UL; j < RHJ::meta[i].columnSize; j++) + { + const tuple_key_t index = j * RHJ::meta[i].rowSize; + + tuple_payload_t * const mapping = &(reinterpret_cast(RHJ::meta[i].mapping)[index]); + + RHJ::meta[i].columns[j] = mapping; + } + } + + for(std::size_t i = 0; i < total; i++) + { + exit_if(munmap(RHJ::meta[i].mapping, RHJ::meta[i].mappingSize) < 0, ("munmap No." + std::to_string(i)).c_str()); + + delete[] RHJ::meta[i].columns; + } + + delete[] RHJ::meta; + + return 0; +} diff --git a/test_data/files.txt b/test_data/files.txt index 2cbd0a4..10553d1 100644 --- a/test_data/files.txt +++ b/test_data/files.txt @@ -1,15 +1,15 @@ -./test_data/small/r0 -./test_data/small/r1 -./test_data/small/r2 -./test_data/small/r3 -./test_data/small/r4 -./test_data/small/r5 -./test_data/small/r6 -./test_data/small/r7 -./test_data/small/r8 -./test_data/small/r9 -./test_data/small/r10 -./test_data/small/r11 -./test_data/small/r12 -./test_data/small/r13 -Done \ No newline at end of file +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r0 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r1 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r10 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r11 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r12 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r13 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r2 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r3 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r4 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r5 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r6 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r7 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r8 +/home/massiva/Documents/Courses/Application-Development-for-Information-Systems/test_data/small/r9 +Done diff --git a/utility.sh b/utility.sh index 46b1800..a342915 100755 --- a/utility.sh +++ b/utility.sh @@ -60,7 +60,7 @@ then confirm "${target////}.tar.gz" tar -zcvf "${target////}".tar.gz "$target" - fi + fi else echo "# Options:" echo "# -t, --transfer Transfer a file / directory over ssh"