Browse Source

Bugged, do not use

tagfs
Ludovic 'Archivist' Lagouardette 4 years ago
parent
commit
15fbba7d2f
6 changed files with 66 additions and 51 deletions
  1. +1
    -0
      .gitignore
  2. +8
    -6
      Makefile
  3. +13
    -4
      include/gp/array.hpp
  4. +35
    -36
      include/gp/tagfs/tagfs.hpp
  5. +4
    -4
      tests/tagfs_test.cpp
  6. +5
    -1
      tests/test_scaffold.h

+ 1
- 0
.gitignore View File

@ -41,3 +41,4 @@ render.bmp
README.html README.html
bin/tests.S bin/tests.S
bin/tests.S.zip bin/tests.S.zip
vgcore.*

+ 8
- 6
Makefile View File

@ -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 all: tests
tests: bin/tests tests: bin/tests
LLVM_PROFILE_FILE="./bin/tests.profraw" ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./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-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 bin/tests: tests.cpp $(wildcard tests/*.cpp) $(wildcard include/*.hpp) ./tests/test_scaffold.h
@mkdir -p $(@D) @mkdir -p $(@D)

+ 13
- 4
include/gp/array.hpp View File

@ -5,6 +5,8 @@
#include <initializer_list> #include <initializer_list>
namespace gp{ namespace gp{
struct zero_t{};
template<typename T, std::size_t sz> template<typename T, std::size_t sz>
class array{ class array{
public: public:
@ -36,8 +38,15 @@ namespace gp{
} }
} }
constexpr array(zero_t)
{
for(auto& elem : ary) {
elem = 0;
}
}
template<typename ...U> template<typename ...U>
array(U&& ...values)
k">constexpr array(U&& ...values)
: ary{gp::move((T&&)values)...} : ary{gp::move((T&&)values)...}
{} {}
@ -49,14 +58,14 @@ namespace gp{
); );
} }
array(T (& oth)[sz]) {
k">constexpr array(T (& oth)[sz]) {
gp::move_uninitialized<T>( gp::move_uninitialized<T>(
gp::nameless_range<int*>(oth, oth+sz), gp::nameless_range<int*>(oth, oth+sz),
gp::nameless_range<associated_iterator>(begin(), end()) gp::nameless_range<associated_iterator>(begin(), end())
); );
} }
array(T (&& oth)[sz]) {
k">constexpr array(T (&& oth)[sz]) {
gp::move_uninitialized( gp::move_uninitialized(
gp::nameless_range<int*>((T*)oth, (T*)oth+sz), gp::nameless_range<int*>((T*)oth, (T*)oth+sz),
gp::nameless_range<associated_iterator>(begin(), end()) gp::nameless_range<associated_iterator>(begin(), end())
@ -160,7 +169,7 @@ namespace gp{
return !(*this == oth); return !(*this == oth);
} }
gp::buffer<T> as_buffer()
gp::buffer<T> as_buffer() const
{ {
return gp::buffer<T>{(T*)ary, (T*)ary+sz}; return gp::buffer<T>{(T*)ary, (T*)ary+sz};
} }

+ 35
- 36
include/gp/tagfs/tagfs.hpp View File

@ -16,7 +16,7 @@ namespace gp {
template<size_t sz> template<size_t sz>
class memory_vdisk { class memory_vdisk {
static_assert(sz%128 == 0, "in memory disk expects 128 bytes page alignment"); static_assert(sz%128 == 0, "in memory disk expects 128 bytes page alignment");
k">alignas(128) gp::array<uint8_t, sz> data;
gp::array<uint8_t, sz> data{gp::zero_t{}};
public: public:
gp::buffer<uint8_t> read(gp::buffer<uint8_t> buffer, uint64_t offset) { gp::buffer<uint8_t> read(gp::buffer<uint8_t> buffer, uint64_t offset) {
@ -62,7 +62,7 @@ namespace gp {
class tagfs { class tagfs {
vdisk_ptr disk; vdisk_ptr disk;
constexpr static size_t page_size = gp::remove_reference<decltype(*disk)>::type::page_size(); constexpr static size_t page_size = gp::remove_reference<decltype(*disk)>::type::page_size();
const gp::array<uint8_t, page_size> empty_page;
constexpr static gp::array<uint8_t, page_size> empty_page{gp::zero_t{}};
@ -82,18 +82,17 @@ namespace gp {
public: public:
tagfs(vdisk_ptr&& _disk) tagfs(vdisk_ptr&& _disk)
: disk(gp::forward<vdisk_ptr>(disk)) : disk(gp::forward<vdisk_ptr>(disk))
, empty_page{[](){return 0;}}
{} {}
private: private:
disk_root get_disk_root() { disk_root get_disk_root() {
gp::array<disk_root, 1> vret;
return *disk->read(vret.as_buffer().template cast<uint8_t>(), 0).template cast<disk_root>().begin();
disk_root vret;
disk->read(gp::buffer<disk_root>{&vret, 1}.template cast<uint8_t>(), 0);
return vret;
} }
void set_disk_root(disk_root& root) { void set_disk_root(disk_root& root) {
gp::array<disk_root, 1> vpar{root};
disk->write(vpar.as_buffer().template cast<uint8_t>(), 0);
disk->write(gp::buffer<disk_root>{&root, 1}.template cast<uint8_t>(), 0);
} }
gp::optional<uint64_t> try_set_bit(gp::buffer<uint8_t> page) { gp::optional<uint64_t> try_set_bit(gp::buffer<uint8_t> page) {
@ -193,36 +192,36 @@ namespace gp {
return {allocator_pages, datapage_count}; 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);
}
}; };
} }

+ 4
- 4
tests/tagfs_test.cpp View File

@ -12,10 +12,10 @@ struct tagfs_test : public test_scaffold {
virtual int run() { virtual int run() {
bool result = true; bool result = true;
gp::memory_vdisk<128*1025> disk;
auto fs = gp::tagfs{&disk};
// auto disk = std::move(std::make_unique<gp::memory_vdisk<128*1025>>());
k">auto disk = new gp::memory_vdisk<128*1025>();
auto fs = gp::tagfso"><gp::memory_vdisk<128*1025>*>{n">std::forward&lt;an>gp::memory_vdiskpan><;mi">128*1025>*>(disk)};
fs.format();
return !result; return !result;
} }
}; };

+ 5
- 1
tests/test_scaffold.h View File

@ -4,6 +4,8 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream>
#include <cassert>
#ifndef NO_BENCH #ifndef NO_BENCH
#define NO_BENCH 1 #define NO_BENCH 1
@ -25,10 +27,12 @@ struct test_scaffold{
virtual ~test_scaffold() = default; virtual ~test_scaffold() = default;
}; };
std::vector<std::unique_ptr<test_scaffold>> tests;
std::vector<test_scaffold*> tests;
struct append_test { struct append_test {
append_test(test_scaffold* ptr) { append_test(test_scaffold* ptr) {
assert(ptr != nullptr);
std::cout << "ptr = " << intptr_t(ptr) << std::endl;
tests.emplace_back(ptr); tests.emplace_back(ptr);
} }
}; };

Loading…
Cancel
Save