From 15fbba7d2f2b2e49ad59accb6e36c42af9a8c8ce Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Tue, 22 Sep 2020 14:46:56 +0200 Subject: [PATCH] Bugged, do not use --- .gitignore | 1 + Makefile | 14 ++++---- include/gp/array.hpp | 17 ++++++--- include/gp/tagfs/tagfs.hpp | 71 +++++++++++++++++++------------------- tests/tagfs_test.cpp | 8 ++--- tests/test_scaffold.h | 6 +++- 6 files changed, 66 insertions(+), 51 deletions(-) diff --git a/.gitignore b/.gitignore index 1e68462..3f3a024 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ render.bmp README.html bin/tests.S bin/tests.S.zip +vgcore.* diff --git a/Makefile b/Makefile index befc071..536bb74 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,16 @@ -CXX= clang++-10 -CXXFLAGS= --std=c++20 -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=0 -pedantic \ - -frtti -fprofile-instr-generate -fcoverage-mapping -Wno-unknown-attributes \ - -fsanitize=address -fno-omit-frame-pointer +CXX= g++ +CXXFLAGS= --std=c++20 -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=1 -pedantic \ + +# -frtti -fprofile-instr-generate -fcoverage-mapping -Wno-unknown-attributes \ + +# -fsanitize=address -fno-omit-frame-pointer all: tests tests: bin/tests LLVM_PROFILE_FILE="./bin/tests.profraw" ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./bin/tests @llvm-profdata merge -sparse ./bin/tests.profraw -o ./bin/tests.profdata - @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp - @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' + @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp include/gp/tagfs/* + @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/allocator/*.hpp include/gp/tagfs/* | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' bin/tests: tests.cpp $(wildcard tests/*.cpp) $(wildcard include/*.hpp) ./tests/test_scaffold.h @mkdir -p $(@D) diff --git a/include/gp/array.hpp b/include/gp/array.hpp index b86d801..404a671 100644 --- a/include/gp/array.hpp +++ b/include/gp/array.hpp @@ -5,6 +5,8 @@ #include namespace gp{ + struct zero_t{}; + template class array{ public: @@ -36,8 +38,15 @@ namespace gp{ } } + constexpr array(zero_t) + { + for(auto& elem : ary) { + elem = 0; + } + } + template - array(U&& ...values) + constexpr array(U&& ...values) : ary{gp::move((T&&)values)...} {} @@ -49,14 +58,14 @@ namespace gp{ ); } - array(T (& oth)[sz]) { + constexpr array(T (& oth)[sz]) { gp::move_uninitialized( gp::nameless_range(oth, oth+sz), gp::nameless_range(begin(), end()) ); } - array(T (&& oth)[sz]) { + constexpr array(T (&& oth)[sz]) { gp::move_uninitialized( gp::nameless_range((T*)oth, (T*)oth+sz), gp::nameless_range(begin(), end()) @@ -160,7 +169,7 @@ namespace gp{ return !(*this == oth); } - gp::buffer as_buffer() + gp::buffer as_buffer() const { return gp::buffer{(T*)ary, (T*)ary+sz}; } diff --git a/include/gp/tagfs/tagfs.hpp b/include/gp/tagfs/tagfs.hpp index 6831b05..5cd8c1a 100644 --- a/include/gp/tagfs/tagfs.hpp +++ b/include/gp/tagfs/tagfs.hpp @@ -16,7 +16,7 @@ namespace gp { template class memory_vdisk { static_assert(sz%128 == 0, "in memory disk expects 128 bytes page alignment"); - alignas(128) gp::array data; + gp::array data{gp::zero_t{}}; public: gp::buffer read(gp::buffer buffer, uint64_t offset) { @@ -62,7 +62,7 @@ namespace gp { class tagfs { vdisk_ptr disk; constexpr static size_t page_size = gp::remove_reference::type::page_size(); - const gp::array empty_page; + constexpr static gp::array empty_page{gp::zero_t{}}; @@ -82,18 +82,17 @@ namespace gp { public: tagfs(vdisk_ptr&& _disk) : disk(gp::forward(disk)) - , empty_page{[](){return 0;}} {} private: disk_root get_disk_root() { - gp::array vret; - return *disk->read(vret.as_buffer().template cast(), 0).template cast().begin(); + disk_root vret; + disk->read(gp::buffer{&vret, 1}.template cast(), 0); + return vret; } void set_disk_root(disk_root& root) { - gp::array vpar{root}; - disk->write(vpar.as_buffer().template cast(), 0); + disk->write(gp::buffer{&root, 1}.template cast(), 0); } gp::optional try_set_bit(gp::buffer page) { @@ -193,36 +192,36 @@ namespace gp { return {allocator_pages, datapage_count}; } + public: + void format() { + auto sz = disk->size(); + auto page_sz = page_size; + auto page_count = sz /page_sz; + auto remaining_pages = page_count; + + disk_root root; + // tagmebro + root.magic = 0x7461676D6562726F; + root.page_count = page_count; + root.first_allocator_page = 1; + root.allocator_shuttle = 1; + + // Removing the root page + remaining_pages -= 1; + + // calculating datapages + auto [allocator_pages, datapage_count] = split_pages(remaining_pages); + static_assert(split_pages(page_size*8+1).first == 1, "ideal 1 allocator page split doesn't work"); + static_assert(split_pages(page_size*8+2).first == 2, "worst 2 allocator page split doesn't work"); + + root.allocator_page_count = allocator_pages; + + for(uint64_t offset = 0; offset < allocator_pages; ++offset) { + clear_page(root.first_allocator_page); + } - void format() { - auto sz = disk->size(); - auto page_sz = page_size; - auto page_count = sz /page_sz; - auto remaining_pages = page_count; - - disk_root root; - // tagmebro - root.magic = 0x7461676D6562726F; - root.page_count = page_count; - root.first_allocator_page = 1; - root.allocator_shuttle = 1; - - // Removing the root page - remaining_pages -= 1; - - // calculating datapages - auto [allocator_pages, datapage_count] = split_pages(remaining_pages); - static_assert(split_pages(page_size*8+1).first == 1, "ideal 1 allocator page split doesn't work"); - static_assert(split_pages(page_size*8+2).first == 2, "worst 2 allocator page split doesn't work"); - - root.allocator_page_count = allocator_pages; - - for(uint64_t offset = 0; offset < allocator_pages; ++offset) { - clear_page(root.first_allocator_page); + root.tag_list_node = 0; + set_disk_root(root); } - - root.tag_list_node = 0; - set_disk_root(root); - } }; } \ No newline at end of file diff --git a/tests/tagfs_test.cpp b/tests/tagfs_test.cpp index b163297..940a547 100644 --- a/tests/tagfs_test.cpp +++ b/tests/tagfs_test.cpp @@ -12,10 +12,10 @@ struct tagfs_test : public test_scaffold { virtual int run() { bool result = true; - - gp::memory_vdisk<128*1025> disk; - auto fs = gp::tagfs{&disk}; - + // auto disk = std::move(std::make_unique>()); + auto disk = new gp::memory_vdisk<128*1025>(); + auto fs = gp::tagfs*>{std::forward*>(disk)}; + fs.format(); return !result; } }; diff --git a/tests/test_scaffold.h b/tests/test_scaffold.h index 57e962e..8dc2423 100644 --- a/tests/test_scaffold.h +++ b/tests/test_scaffold.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #ifndef NO_BENCH #define NO_BENCH 1 @@ -25,10 +27,12 @@ struct test_scaffold{ virtual ~test_scaffold() = default; }; -std::vector> tests; +std::vector tests; struct append_test { append_test(test_scaffold* ptr) { + assert(ptr != nullptr); + std::cout << "ptr = " << intptr_t(ptr) << std::endl; tests.emplace_back(ptr); } }; \ No newline at end of file