diff --git a/.gitignore b/.gitignore index 24eff39..565e013 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,4 @@ bin/tests.S bin/tests.S.zip vgcore.* doc/* -.vscode/launch.json \ No newline at end of file +.vscode/launch.json diff --git a/Makefile b/Makefile index 4b276dc..39aaf88 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,11 @@ tests: bin/tests @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata $(EVERY_USEFUL_FILE) @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata $(EVERY_USEFUL_FILE) | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' +extras: + @for dir in $(wildcard extra_tests/*/.); do \ + $(MAKE) -C $$dir; \ + done + bin/tests: tests.cpp $(TEST_OBJECTS) $(EVERY_USEFUL_FILE) ./tests/test_scaffold.h @mkdir -p $(@D) $(CXX) $(CXXFLAGS) -Itests -Iinclude tests.cpp $(TEST_OBJECTS) -o $@ diff --git a/extra_tests/001_test/.gitignore b/extra_tests/001_test/.gitignore new file mode 100644 index 0000000..19f5dbf --- /dev/null +++ b/extra_tests/001_test/.gitignore @@ -0,0 +1 @@ +./bin/* \ No newline at end of file diff --git a/extra_tests/001_test/Makefile b/extra_tests/001_test/Makefile new file mode 100644 index 0000000..35ee71c --- /dev/null +++ b/extra_tests/001_test/Makefile @@ -0,0 +1,17 @@ +CXX= clang++ +CXXFLAGS= --std=c++20 -target x86_64-none-linux-elf -Os -ffreestanding -nostdlib -pedantic \ + -Wno-unknown-attributes -fno-omit-frame-pointer -MD -fno-use-cxa-atexit -fno-rtti -I../../include -I. + +# -fsanitize=address -fsanitize-blacklist=blacklist.txt + +all: tests + +tests: bin/tests +# ./bin/tests + +bin/tests: main.cpp + @mkdir -p $(@D) + $(CXX) $(CXXFLAGS) main.cpp -o $@ + +clean: ./bin + @rm -rf $< \ No newline at end of file diff --git a/extra_tests/001_test/gp_config.hpp b/extra_tests/001_test/gp_config.hpp new file mode 100644 index 0000000..96036e3 --- /dev/null +++ b/extra_tests/001_test/gp_config.hpp @@ -0,0 +1,186 @@ +#pragma once + +#include +#include + +#include +#include + +#ifdef GP_TESTS + class static_mapper; +#else +namespace gp { + class c_allocator; +} +#endif + +/** + * @brief This namespace contains the configuration. + * + * This namespace is expected to be fully defined in an include accessible from the root + * of your header list: + * \code{.cpp} + * #include "gp_config.hpp" + * \endcode + * + * The code line above should always be the one including that config and that namespace. + */ +namespace gp_config{ + namespace rendering { + /** + * @brief The default type used for rendering processes + */ + using default_type = float; + + /** + * @brief The small enough value used in signed distance function resolution + */ + constexpr default_type epsilon = 0.01; + + /** + * @brief The default color type + */ + #define GP_CONFIG__RENDERING__COLOR_T vec4 + } + + /** + * @brief This namespace contains artificial limitations put on the runtime + */ + namespace limits { + /** + * @brief the total number of processes the system is allowed to have + */ + constexpr size_t max_processes = 4096; + + /** + * @brief the maximum size a channel can address + */ + constexpr size_t channel_max_size = 1 << 20; + + /** + * @brief the default size a channel will take + */ + constexpr size_t channel_default_size = 1 << 16; + + /** + * @brief the number of open files each process is allowed to have + */ + constexpr size_t max_fd_per_process = 128; + + /** + * @brief the stack size for the new stacks generated by the concurrency system + */ + constexpr size_t process_stack = 1024; + + /** + * @brief expected stack alignment + */ + constexpr size_t process_stack_align_to = 16; + + /** + * @brief presents the direction of stack growth + */ + constexpr size_t stack_grow_upwards = false; + + #if __cpp_lib_hardware_interference_size >= 201603 + constexpr size_t hardware_constructive_interference_size = std::hardware_constructive_interference_size; + constexpr size_t hardware_destructive_interference_size = std::hardware_destructive_interference_size; + #else + constexpr size_t hardware_constructive_interference_size = 128; + constexpr size_t hardware_destructive_interference_size = 128; + #endif + + constexpr size_t loggers_segment_size = 128; + } + + namespace memory_module{ + constexpr bool is_ok = true; + constexpr bool prefer_constant_memory = true; + } + + typedef uint32_t file_descriptor_t; + + /** + * @brief set to true to enable exceptions + */ + constexpr bool has_exceptions = false; + + /** + * @brief set to true to activate bounds checking + */ + constexpr bool has_buffer_bounds = true; + + // + // + // + /** + * @brief A value used to determine the strength used by random number generators + * + * Value of 8 is considered not cryptographically secure + * Value of 12 offers a good compromise of performance and robustness + * Value of 20 offers maximum robustness + */ + constexpr size_t arc4random_strength = 20; + + /** + * @brief an exception that represents an assertion failure + */ + struct assert_failure{ + assert_failure(const char* reason) + : what_str{reason} + {} + const char* what_str; + const char* what() {return what_str;} + }; + + /** + * @brief UNUSED + */ + constexpr size_t assert_buffer_size = 0; + + /** + * @brief an assertion function + */ + constexpr auto assertion = [](bool pred, const char* reason) -> void{ + if(!pred) { + //log_failure(reason); + if constexpr (has_exceptions) + throw assert_failure(reason); + } + }; + + enum class cbor_tag { + datetime = 0, + unix_time = 1, + ubignum = 2, + nbignum = 3, + decimal = 4, + bigfloat = 5, + cose_encrypt0 = 16, + cose_mac0 = 17, + cose_sign1 = 18, + expected_base64url = 21, + expected_base64 = 22, + expected_base16 = 23, + encoded_cbor = 24, + url = 32, + base64url = 33, + base64 = 34, + regexp = 35, + mime = 36, + cose_encrypt = 96, + cose_mac = 97, + cose_sign = 98, + signature = 55799 + }; +} + +/** + * @brief a list of error codes + */ +enum class gp_errorcodes : int { + /** + * @brief this error code is activated upon reaching a skipstone limit that seems like infinity. + */ + infinite_skipstone = 3000 +}; \ No newline at end of file diff --git a/extra_tests/001_test/main.cpp b/extra_tests/001_test/main.cpp new file mode 100644 index 0000000..892b7d4 --- /dev/null +++ b/extra_tests/001_test/main.cpp @@ -0,0 +1,11 @@ +#include +#include "syscall.hpp" + +gp::buffer hello = "Hello world\n"; + +extern "C" { +void _start() { + write(1, hello); + exit(0); +} +} \ No newline at end of file diff --git a/extra_tests/001_test/syscall.hpp b/extra_tests/001_test/syscall.hpp new file mode 100644 index 0000000..2620204 --- /dev/null +++ b/extra_tests/001_test/syscall.hpp @@ -0,0 +1,81 @@ +#pragma once +#include +#include +#include + +template +struct syscall; + +template +struct syscall { + int64_t operator()(int64_t p1) const { + int64_t ret; + asm volatile + ( + "syscall" + : "=a" (ret) + : "0"(syscall_id), "D"(p1) + : "rcx", "r11", "memory" + ); + return ret; + } +}; + +template +struct syscall { + int64_t operator()(int64_t p1,int64_t p2) const { + int64_t ret; + asm volatile + ( + "syscall" + : "=a" (ret) + : "0"(syscall_id), "D"(p1), "S"(p2) + : "rcx", "r11", "memory" + ); + return ret; + } +}; + +template +struct syscall { + int64_t operator()(int64_t p1,int64_t p2,int64_t p3) const { + int64_t ret; + asm volatile + ( + "syscall" + : "=a" (ret) + : "0"(syscall_id), "D"(p1), "S"(p2), "d"(p3) + : "rcx", "r11", "memory" + ); + return ret; + } +}; + +constexpr auto _read = syscall<0, 3>{}; +constexpr auto _write = syscall<1, 3>{}; +constexpr auto _exit = syscall<60, 1>{}; + +inline int read(int fd, char* buffer, size_t sz) { + return _read((int64_t)fd, (int64_t)buffer, (int64_t)sz); +} + +inline int write(int fd, char* buffer, size_t sz) { + return _write((int64_t)fd, (int64_t)buffer, (int64_t)sz); +} + +inline int read(int fd, gp::buffer buffer) { + return _read((int64_t)fd, (int64_t)buffer.begin().data, (int64_t)buffer.size()); +} + +inline int write(int fd, gp::buffer buffer) { + return _write((int64_t)fd, (int64_t)buffer.begin().data, (int64_t)buffer.size()); +} + +extern "C" { + +inline __attribute__ ((__noreturn__)) void exit(int status) { + _exit((int64_t)status); + while(true); +} + +} \ No newline at end of file