diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..94838d4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,64 @@ +name: Ubuntu-Latest GCC - Build Release + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +permissions: + contents: write + actions: write + id-token: write + attestations: write + packages: write + deployments: write + +jobs: + + build: + runs-on: [ubuntu-latest] + steps: + - name: Checkout repository ${{ github.repository }} on a branch ${{ github.ref_name }} triggered by ${{ github.event_name }} + uses: actions/checkout@v4 + + - run: "echo the ${{ github.repository }} has been cloned in the container !" + + - name: 🔄 Installing task... + uses: arduino/setup-task@v2 + with: + version: 3.x + + - uses: actions/setup-python@v5 + + - name: 🔄 Installing Meson package build system... + run: pip install meson + + - name: 🔄 Installing Dependencies... + run: | + sudo apt-get update + echo "📦 Installing libcriterion-dev, Ninja, GCC New Version" + sudo apt-get install -y libcriterion-dev ninja-build gcc-12 + sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc + echo "✅ Dependencies installed!" + + - name: Run build release task... + run: | + echo "🏗️ Setting up Meson build system..." + task build fclean + echo "🎉 Build completed with Meson!" + + deployments: + runs-on: [ubuntu-latest] + needs: build + steps: + - name: Checkout repository ${{ github.repository }} on a branch ${{ github.ref_name }} triggered by ${{ github.event_name }} + uses: actions/checkout@v4 + + - run: "echo the ${{ github.repository }} has been cloned in the container !" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: etheria-std + path: . diff --git a/.github/workflows/codeQL.yml b/.github/workflows/codeQL.yml new file mode 100644 index 0000000..ad7f9c3 --- /dev/null +++ b/.github/workflows/codeQL.yml @@ -0,0 +1,61 @@ +name: CodeQL + +on: push + +permissions: + actions: read + contents: read + security-events: write + +jobs: + + analyze: + runs-on: [ubuntu-latest] + + strategy: + fail-fast: false + matrix: + include: + - language: c-cpp + build-mode: manual + + steps: + - name: Checkout repository ${{ github.repository }} on a branch ${{ github.ref_name }} triggered by ${{ github.event_name }} + uses: actions/checkout@v4 + + - run: "echo the ${{ github.repository }} has been cloned in the container !" + + - name: 🔄 Installing task... + uses: arduino/setup-task@v2 + with: + version: 3.x + + - uses: actions/setup-python@v5 + + - name: 🔄 Installing Meson package build system... + run: pip install meson + + - name: 🔄 Installing Dependencies... + run: | + sudo apt-get update + echo "📦 Installing libcriterion-dev, Ninja, GCC New Version" + sudo apt-get install -y libcriterion-dev ninja-build gcc-12 + sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc + echo "✅ Dependencies installed!" + + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + + - name: Run build release task... + run: | + echo "🏗️ Setting up Meson build system..." + task build + echo "🎉 Build completed with Meson!" + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: ${{ matrix.language }} diff --git a/.github/workflows/memcpy_naive_test.yml b/.github/workflows/memcpy_naive_test.yml new file mode 100644 index 0000000..02f0514 --- /dev/null +++ b/.github/workflows/memcpy_naive_test.yml @@ -0,0 +1,44 @@ +name: Ubuntu - Memcpy Naive implementation Tests + +on: push + +permissions: + contents: write + +jobs: + build: + runs-on: [ubuntu-latest] + steps: + - name: Checkout repository ${{ github.repository }} on a branch ${{ github.ref_name }} triggered by ${{ github.event_name }} + uses: actions/checkout@v4 + + - run: "echo the ${{ github.repository }} has been cloned in the container !" + + - name: 🔄 Installing task... + uses: arduino/setup-task@v2 + with: + version: 3.x + + - uses: actions/setup-python@v5 + + - name: 🔄 Installing Meson package build system... + run: pip install meson + + - name: 🔄 Installing Dependencies... + run: | + sudo apt-get update + echo "📦 Installing libcriterion-dev, Ninja, GCC New Version" + sudo apt-get install -y libcriterion-dev ninja-build gcc-12 + sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc + echo "✅ Dependencies installed!" + + - name: Build tests + run: | + echo "🏗️ Setting up Meson build system..." + task build-tests + echo "🎉 Build completed with Meson!" + + - name: Run test memcpy naive tests + run: | + echo "🏗️ Run naive memcpy tests..." + task run-test-suite -- $(task list-tests | grep "test_memcpy_naive") diff --git a/.github/workflows/types_test.yml b/.github/workflows/types_test.yml new file mode 100644 index 0000000..464a056 --- /dev/null +++ b/.github/workflows/types_test.yml @@ -0,0 +1,44 @@ +name: Ubuntu - Types Tests + +on: push + +permissions: + contents: write + +jobs: + build: + runs-on: [ubuntu-latest] + steps: + - name: Checkout repository ${{ github.repository }} on a branch ${{ github.ref_name }} triggered by ${{ github.event_name }} + uses: actions/checkout@v4 + + - run: "echo the ${{ github.repository }} has been cloned in the container !" + + - name: 🔄 Installing task... + uses: arduino/setup-task@v2 + with: + version: 3.x + + - uses: actions/setup-python@v5 + + - name: 🔄 Installing Meson package build system... + run: pip install meson + + - name: 🔄 Installing Dependencies... + run: | + sudo apt-get update + echo "📦 Installing libcriterion-dev, Ninja, GCC New Version" + sudo apt-get install -y libcriterion-dev ninja-build gcc-12 + sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc + echo "✅ Dependencies installed!" + + - name: Build tests + run: | + echo "🏗️ Setting up Meson build system..." + task build-tests + echo "🎉 Build completed with Meson!" + + - name: Run Types tests + run: | + echo "🏗️ Setting up Meson build system..." + task run-test-suite -- $(task list-tests | grep "test_types") diff --git a/.gitignore b/.gitignore index 637f9d1..fbba3d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .cache compile_commands.json build +dist +./tests/output + # Prerequisites *.d diff --git a/Taskfile.yml b/Taskfile.yml index fa8a352..1e7da9e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,29 +1,178 @@ version: '3' tasks: + help: + cmds: + - go-task -a + silent: true + desc: "Show this pages" + + default: + - task: help + build: + preconditions: + - sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}' + msg: "Nothing to be done." + cmds: + - meson setup build --buildtype=release --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Build the project in release build" + + build-strip: + preconditions: + - sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}' + msg: "Nothing to be done." + cmds: + - meson setup build --buildtype=release --strip --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Build the project in release build in stripped mode" + + build-dev: + preconditions: + - sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}' + msg: "Nothing to be done." + cmds: + - meson setup build --buildtype=debug --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Build the project in dev build" + + cross-build: + preconditions: + - sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}' + msg: "Nothing to be done." + cmds: + - meson setup --cross {{.CLI_ARGS}} build --buildtype=release --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Build the project with the compiler of your choice in release mode" + + cross-build-dev: + preconditions: + - sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}' + msg: "Nothing to be done." + cmds: + - meson setup --cross {{.CLI_ARGS}} build --buildtype=debug --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Build the project with the compiler of your choice in dev mode" + + re: cmds: - meson setup build --reconfigure --buildtype=release --prefix=$(pwd) - ninja -C build install silent: true - desc: "Build the project" + desc: "Re build the project" + + re-dev: + cmds: + - meson setup build --reconfigure --buildtype=debug --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Re build the project in dev mode" + + re-strip: + cmds: + - meson setup build --reconfigure --buildtype=release --strip --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Re build the project with strip" + + build-tests: + cmds: + - meson setup build --reconfigure -Dbuild_tests=true -Dno_static=true --buildtype=release --prefix=$(pwd) + - ninja -C build + silent: true + desc: "Build tests files" + + build-bench: + cmds: + - meson setup build --reconfigure -Dbuild_tests=true -Dbuild_bench=true -Dno_static=true --buildtype=release --prefix=$(pwd) + - ninja -C build + silent: true + desc: "Build benchmarks files" + + run-bench: + preconditions: + - sh: '{{if eq OS "windows" }} powershell.exe -Command Test-Path build {{else}} test -d build {{end}}' + msg: "Build directory not exist please run build_tests before" + cmds: + - meson test --benchmark -C build + silent: true + desc: "Run benchmarks files" + + run-tests: + preconditions: + - sh: '{{if eq OS "windows" }} powershell.exe -Command Test-Path build {{else}} test -d build {{end}}' + msg: "Build directory not exist please run build_tests before" + cmds: + - meson test -C build + silent: true + desc: "Run tests files" + + run-tests-valgrind: + platforms: ["linux"] + preconditions: + - sh: 'test -d build && test -f /usr/bin/valgrind' + msg: "Build directory not exist please run build_tests before or valgrind is missing !" + cmds: + - meson test -C build --verbose --wrapper=valgrind + silent: true + desc: "Run tests files with valgrind" + + list-tests: + preconditions: + - sh: '{{if eq OS "windows" }} powershell.exe -Command Test-Path build {{else}} test -d build {{end}}' + msg: "Build directory not exist please run build_tests before" + cmds: + - meson test -C build --list + silent: true + desc: "List all tests" + + run-test-suite: + preconditions: + - sh: '{{if eq OS "windows" }} powershell.exe -Command Test-Path build {{else}} test -d build {{end}}' + msg: "Build directory not exist please run build_tests before" + cmds: + - meson test -C build --verbose {{.CLI_ARGS}} + silent: true + desc: "Run specified tests suite" + + run-test-suite-valgrind: + platforms: ["linux"] + preconditions: + - sh: 'test -d build && test -d /usr/bin/valgrind' + msg: "Build directory not exist please run build_tests before" + cmds: + - meson test -C build --verbose --wrapper=valgrind {{.CLI_ARGS}} + silent: true + desc: "Run specified tests suite with valgrind" + install: + platforms: ["linux"] preconditions: - test -d dist cmds: - sudo cp ./dist/shared/*.so ./dist/static/*.a /usr/lib/ - - echo -e "[\033[32m+\033[00m] Installed successfully at \033[32m/usr/lib/\033[00m !" + - sudo mkdir -p /usr/include/etheria/ + - sudo cp ./inc/eth-std.h /usr/include/etheria/ + - echo -e "[\033[32m+\033[00m] Installed successfully at \033[32m$(ls /usr/lib/ | grep libetheria)\033[00m !" silent: true desc: "Install library on the system" prompt: "Do you want install in (/usr/lib/)" rm_install: + platforms: ["linux"] preconditions: - test -f /usr/lib/libetheria-std.a - test -f /usr/lib/libetheria-std.so + - test -d /usr/include/etheria/ cmds: - - sudo rm -rf /usr/lib/libetheria-std.a /usr/lib/libetheria-std.so + - sudo rm -rf /usr/lib/libetheria-std.a /usr/lib/libetheria-std.so /usr/include/etheria/ - echo -e "[\033[32m+\033[00m] Removed successfully !" silent: true desc: "Remove installed etheria Standard library on the system" @@ -31,9 +180,8 @@ tasks: clean: cmds: - - rm -rf build - - echo -e "[\033[32m+\033[00m] clean \033[32mbuild\033[00m directory..." - - echo -e "[\033[32m+\033[00m] clean \033[32mbuild\033[00m directory removed \033[32msuccessully\033[00m !" + - '{{if eq OS "windows" }} cmd.exe /c rmdir build /S /Q {{else}} rm -rf build {{end}}' + - '{{if eq OS "windows" }} cmd.exe /c echo clean build directory removed {{else}} echo -e "[\033[32m+\033[00m] clean \033[32mbuild\033[00m directory removed \033[32msuccessully\033[00m !" {{end}}' silent: true desc: "Clean build directory" @@ -41,9 +189,8 @@ tasks: deps: - clean cmds: - - rm -rf dist - - echo -e "[\033[32m+\033[00m] clean \033[32mdist\033[00m directory..." - - echo -e "[\033[32m+\033[00m] clean \033[32mdist\033[00m directory removed \033[32msuccessully\033[00m !" + - cmd: '{{if eq OS "windows"}} cmd.exe /c rmdir dist /S /Q {{else}} rm -rf dist {{end}}' + ignore_error: true + - '{{if eq OS "windows"}} cmd.exe /c echo clean dist directory removed ! {{else}} echo -e "[\033[32m+\033[00m] clean \033[32mdist\033[00m directory removed \033[32msuccessully\033[00m !"{{end}}' silent: true desc: "Full clean remove build directory and dist directory" - prompt: "Do you want remove (build, dist)" diff --git a/benchmarks/memory/memcpy_naive/memcpy_naive.c b/benchmarks/memory/memcpy_naive/memcpy_naive.c new file mode 100644 index 0000000..d64bdeb --- /dev/null +++ b/benchmarks/memory/memcpy_naive/memcpy_naive.c @@ -0,0 +1,55 @@ +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#ifndef MEMCPY_NAIVE_BUF_SIZE +#define MEMCPY_NAIVE_BUF_SIZE 0x100 +#endif + +#include "eth-std.h" +#include +#include +#include +#include + +static void show_help(void) +{ + printf("--help | show this pages\n" + "--stack | used a stack buffer\n" + "--malloc | used a heap buffer\n"); +} + +static void do_stack_copy(const char *str, size_t size) +{ + char buf[MEMCPY_NAIVE_BUF_SIZE]; + + _eth_memcpy_naive(buf, str, size); +} + +static void do_heap_copy(const char *str, size_t size) +{ + char *ptr = calloc(sizeof(char), MEMCPY_NAIVE_BUF_SIZE); + + assert(ptr != NULL); + + _eth_memcpy_naive(ptr, str, size); + + free(ptr); +} + +int main(int ac, char **av) +{ + if (ac < 2) { + fprintf(stderr, "usage %s --help\n", av[0]); + return (1); + } + + if (ac == 2 && !strcmp(av[1], "--help")) + show_help(); + + if (ac == 3 && !strcmp(av[1], "--stack")) + do_stack_copy(av[2], strlen(av[2])); + else if (ac == 3 && !strcmp(av[1], "--heap")) + do_heap_copy(av[2], strlen(av[2])); + return (0); +} diff --git a/cross/x86_64/linux/x86_64-clang.txt b/cross/x86_64/linux/x86_64-clang.txt new file mode 100644 index 0000000..aa8cf18 --- /dev/null +++ b/cross/x86_64/linux/x86_64-clang.txt @@ -0,0 +1,25 @@ +[binaries] +c = 'clang' +cpp = 'clang++' +ar = 'llvm-ar' +strip = 'llvm-strip' +cmake = 'cmake' +pkg-config = 'pkg-config' + +[host_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[build_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[target_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/cross/x86_64/linux/x86_64-gcc.txt b/cross/x86_64/linux/x86_64-gcc.txt new file mode 100644 index 0000000..6fdb65e --- /dev/null +++ b/cross/x86_64/linux/x86_64-gcc.txt @@ -0,0 +1,25 @@ +[binaries] +c = 'gcc' +cpp = 'g++' +ar = 'ar' +strip = 'strip' +cmake = 'cmake' +pkg-config = 'pkg-config' + +[host_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[build_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[target_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/cross/x86_64/linux/x86_64-mingw.txt b/cross/x86_64/linux/x86_64-mingw.txt new file mode 100644 index 0000000..14e1953 --- /dev/null +++ b/cross/x86_64/linux/x86_64-mingw.txt @@ -0,0 +1,23 @@ +[binaries] +c = 'x86_64-w64-mingw32-gcc' +cpp = 'x86_64-w64-mingw32-g++' +ar = 'x86_64-w64-mingw32-ar' +strip = 'x86_64-w64-mingw32-strip' + +[host_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[build_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[target_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/cross/x86_64/windows/x86_64-clang.txt b/cross/x86_64/windows/x86_64-clang.txt new file mode 100644 index 0000000..3f73219 --- /dev/null +++ b/cross/x86_64/windows/x86_64-clang.txt @@ -0,0 +1,25 @@ +[binaries] +c = 'clang' +cpp = 'clang++' +ar = 'llvm-ar' +strip = 'llvm-strip' +cmake = 'cmake' +pkg-config = 'pkg-config' + +[host_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[build_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[target_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/cross/x86_64/windows/x86_64-mingw.txt b/cross/x86_64/windows/x86_64-mingw.txt new file mode 100644 index 0000000..f974a83 --- /dev/null +++ b/cross/x86_64/windows/x86_64-mingw.txt @@ -0,0 +1,25 @@ +[binaries] +c = 'gcc' +cpp = 'g++' +ar = 'ar' +strip = 'strip' +cmake = 'cmake' +pkg-config = 'pkg-config' + +[host_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[build_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[target_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/cross/x86_64/windows/x86_64-msvc.txt b/cross/x86_64/windows/x86_64-msvc.txt new file mode 100644 index 0000000..c4fc44a --- /dev/null +++ b/cross/x86_64/windows/x86_64-msvc.txt @@ -0,0 +1,25 @@ +[binaries] +c = 'cl' +cpp = 'cl' +ar = 'lib' +strip = 'strip' +cmake = 'cmake' +pkg-config = 'pkg-config' + +[host_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[build_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' + +[target_machine] +system = 'windows' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/inc/eth-memory.h b/inc/eth-memory.h new file mode 100644 index 0000000..f28cdc6 --- /dev/null +++ b/inc/eth-memory.h @@ -0,0 +1,16 @@ +#ifndef ETH_MEMORY_H +#define ETH_MEMORY_H + +/////////////////////////////////////// +// +// MEMORY +// +////////////////////////////////////// + +#ifdef NO_STATIC +void *_eth_memcpy_naive(void *restrict dst, const void *restrict src, size_t size); +#endif + +void *eth_memcpy(void *restrict dst, const void *restrict src, size_t size); + +#endif diff --git a/inc/eth-std.h b/inc/eth-std.h index eca68f6..4815c64 100644 --- a/inc/eth-std.h +++ b/inc/eth-std.h @@ -3,74 +3,11 @@ /////////////////////////////////////// // -// DEFINES +// TYPEDEFS // ////////////////////////////////////// -#ifndef ETH_NULL -#define ETH_NULL (void*)0 -#endif - -/////////////////////////////////////// -// -// TYPEDEFS -// -////////////////////////////////////// - -typedef unsigned long eth_size_t; - -typedef signed long long eth_int64_t; -typedef signed int eth_int32_t; -typedef signed short eth_int16_t; -typedef signed char eth_int8_t; - -typedef signed eth_int_128_t __attribute__ ((vector_size(16))); -typedef signed long long eth_int64_128_t __attribute__ ((vector_size(16), aligned(8))); -typedef signed int eth_int32_128_t __attribute__ ((vector_size(16), aligned(4))); -typedef signed short eth_int16_128_t __attribute__ ((vector_size(16), aligned(2))); -typedef signed char eth_int8_128_t __attribute__ ((vector_size(16), aligned(1))); - -typedef signed eth_int_256_t __attribute__ ((vector_size(32))); -typedef signed long long eth_int64_256_t __attribute__ ((vector_size(32), aligned(8))); -typedef signed int eth_int32_256_t __attribute__ ((vector_size(32), aligned(4))); -typedef signed short eth_int16_256_t __attribute__ ((vector_size(32), aligned(2))); -typedef signed char eth_int8_256_t __attribute__ ((vector_size(32), aligned(1))); - -typedef signed eth_int_512_t __attribute__ ((vector_size(64))); -typedef signed long long eth_int64_512_t __attribute__ ((vector_size(64), aligned(8))); -typedef signed int eth_int32_512_t __attribute__ ((vector_size(64), aligned(4))); -typedef signed short eth_int16_512_t __attribute__ ((vector_size(64), aligned(2))); -typedef signed char eth_int8_512_t __attribute__ ((vector_size(64), aligned(1))); - - -typedef unsigned long long eth_uint64_t; -typedef unsigned int eth_uint32_t; -typedef unsigned short eth_uint16_t; -typedef unsigned char eth_uint8_t; - -typedef unsigned eth_uint_128_t __attribute__ ((vector_size(16))); -typedef unsigned long long eth_uint64_128_t __attribute__ ((vector_size(16), aligned(8))); -typedef unsigned int eth_uint32_128_t __attribute__ ((vector_size(16), aligned(4))); -typedef unsigned short eth_uint16_128_t __attribute__ ((vector_size(16), aligned(2))); -typedef unsigned char eth_uint8_128_t __attribute__ ((vector_size(16), aligned(1))); - -typedef unsigned eth_uint_256_t __attribute__ ((vector_size(32))); -typedef unsigned long long eth_uint64_256_t __attribute__ ((vector_size(32), aligned(8))); -typedef unsigned int eth_uint32_256_t __attribute__ ((vector_size(32), aligned(4))); -typedef unsigned short eth_uint16_256_t __attribute__ ((vector_size(32), aligned(2))); -typedef unsigned char eth_uint8_256_t __attribute__ ((vector_size(32), aligned(1))); - -typedef unsigned eth_uint_512_t __attribute__ ((vector_size(64))); -typedef unsigned long long eth_uint64_512_t __attribute__ ((vector_size(64), aligned(8))); -typedef unsigned int eth_uint32_512_t __attribute__ ((vector_size(64), aligned(4))); -typedef unsigned short eth_uint16_512_t __attribute__ ((vector_size(64), aligned(2))); -typedef unsigned char eth_uint8_512_t __attribute__ ((vector_size(64), aligned(1))); - -typedef unsigned char u8_t; -typedef unsigned short u16_t; -typedef unsigned int u32_t; -typedef unsigned long u64_t; -typedef unsigned long size_t; +#include "eth-types.h" /////////////////////////////////////// // @@ -78,6 +15,6 @@ typedef unsigned long size_t; // ////////////////////////////////////// -void *eth_memcpy(void *dst, const void *src, size_t size); +#include "eth-memory.h" #endif diff --git a/inc/eth-types.h b/inc/eth-types.h new file mode 100644 index 0000000..1526456 --- /dev/null +++ b/inc/eth-types.h @@ -0,0 +1,323 @@ +#ifndef ETH_TYPES_H +#define ETH_TYPES_H + +/////////////////////////////////////// +// +// DEFINES +// +////////////////////////////////////// + +#ifndef ETH_NULL +#define ETH_NULL (void*)0 +#endif + +/////////////////////////////////////// +// +// TYPEDEFS SIGNED LEGACY +// +////////////////////////////////////// + +typedef signed int eth_int32_t; +typedef signed short eth_int16_t; +typedef signed char eth_int8_t; + +typedef signed int i32_t; +typedef signed short i16_t; +typedef signed char i8_t; + +#if defined(__linux__) +typedef signed long i64_t; +typedef signed long eth_int64_t; +#else +typedef signed long long i64_t; +typedef signed long long eth_int64_t; +#endif + +/////////////////////////////////////// +// +// TYPEDEFS UNSIGNED LEGACY +// +////////////////////////////////////// + +typedef unsigned int eth_uint32_t; +typedef unsigned short eth_uint16_t; +typedef unsigned char eth_uint8_t; + +typedef unsigned int u32_t; +typedef unsigned short u16_t; +typedef unsigned char u8_t; + +typedef unsigned int dword_t; +typedef unsigned short word_t; +typedef unsigned char byte_t; + +#if defined(__linux__) +typedef unsigned long qword_t; +typedef unsigned long eth_size_t; +typedef unsigned long size_t; +typedef unsigned long u64_t; +typedef unsigned long uint64_t; +typedef unsigned long eth_uint64_t; +#else +typedef unsigned long long qword_t; +typedef unsigned long long eth_size_t; +typedef unsigned long long size_t; +typedef unsigned long long u64_t; +typedef unsigned long long uint64_t; +typedef unsigned long long eth_uint64_t; +#endif + + +#if defined(__x86_64__) || defined(__GNUC__) || defined (__clang__) || defined(__MINGW64__) || defined(__MINGW32__) + +/////////////////////////////////////// +// +// TYPEDEFS SIGNED SIMD REGISTERS +// +////////////////////////////////////// + + +/////////////////////////////////////// +// +// 128 BITS SIGNED +// +////////////////////////////////////// + +#if defined(__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x10 +typedef signed eth_int_128_t __attribute__ ((vector_size(0x10), aligned(0x10))); +#else +typedef signed eth_int_128_t __attribute__ ((vector_size(0x10), aligned(__BIGGEST_ALIGNMENT__))); +#endif + +typedef signed long eth_int64_128_t __attribute__ ((vector_size(0x10), aligned(0x8))); +typedef signed int eth_int32_128_t __attribute__ ((vector_size(0x10), aligned(0x4))); +typedef signed short eth_int16_128_t __attribute__ ((vector_size(0x10), aligned(0x2))); +typedef signed char eth_int8_128_t __attribute__ ((vector_size(0x10), aligned(0x1))); + +typedef eth_int_128_t eth_i128_t; +typedef eth_int64_128_t eth_i64_128_t; +typedef eth_int32_128_t eth_i32_128_t; +typedef eth_int16_128_t eth_i16_128_t; +typedef eth_int8_128_t eth_i8_128_t; + +typedef eth_i128_t i128_t; +typedef eth_i64_128_t i64_128_t; +typedef eth_i32_128_t i32_128_t; +typedef eth_i16_128_t i16_128_t; +typedef eth_i8_128_t i8_128_t; + + +/////////////////////////////////////// +// +// 256 BITS SIGNED +// +////////////////////////////////////// + +#if defined(__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x20 +typedef signed eth_int_256_t __attribute__ ((vector_size(0x20), aligned(0x20))); +#elif defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ == 0x10 +typedef signed eth_int_256_t __attribute__ ((vector_size(0x20), aligned(0x10))); +#else +typedef signed eth_int_256_t __attribute__ ((vector_size(0x20), aligned(__BIGGEST_ALIGNMENT__))); +#endif + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x10 +typedef signed eth_int128_256_t __attribute__((vector_size(0x20), aligned(0x10))); +#endif + +typedef signed long eth_int64_256_t __attribute__ ((vector_size(0x20), aligned(8))); +typedef signed int eth_int32_256_t __attribute__ ((vector_size(0x20), aligned(4))); +typedef signed short eth_int16_256_t __attribute__ ((vector_size(0x20), aligned(2))); +typedef signed char eth_int8_256_t __attribute__ ((vector_size(0x20), aligned(1))); + +typedef eth_int_256_t eth_i256_t; +typedef eth_int128_256_t eth_i128_256_t; +typedef eth_int64_256_t eth_i64_256_t; +typedef eth_int32_256_t eth_i32_256_t; +typedef eth_int16_256_t eth_i16_256_t; +typedef eth_int8_256_t eth_i8_256_t; + +typedef eth_i256_t i256_t; +typedef eth_i128_256_t i128_256_t; +typedef eth_i64_256_t i64_256_t; +typedef eth_i32_256_t i32_256_t; +typedef eth_i16_256_t i16_256_t; +typedef eth_i8_256_t i8_256_t; + +/////////////////////////////////////// +// +// 512 BITS SIGNED +// +////////////////////////////////////// + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x40 +typedef signed eth_int_512_t __attribute__ ((vector_size(0x40), aligned(0x40))); +#elif defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ == 0x20 +typedef signed eth_int_512_t __attribute__ ((vector_size(0x40), aligned(0x20))); +#elif defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ == 0x10 +typedef signed eth_int_512_t __attribute__ ((vector_size(0x40), aligned(0x10))); +#else +typedef signed eth_int_512_t __attribute__ ((vector_size(0x40), aligned(__BIGGEST_ALIGNMENT__))); +#endif + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x20 +typedef signed eth_int256_512_t __attribute__ ((vector_size(0x40), aligned(0x20))); +#endif + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x10 +typedef signed eth_int128_512_t __attribute__ ((vector_size(0x40), aligned(0x10))); +#endif + +typedef signed long eth_int64_512_t __attribute__ ((vector_size(0x40), aligned(8))); +typedef signed int eth_int32_512_t __attribute__ ((vector_size(0x40), aligned(4))); +typedef signed short eth_int16_512_t __attribute__ ((vector_size(0x40), aligned(2))); +typedef signed char eth_int8_512_t __attribute__ ((vector_size(0x40), aligned(1))); + +typedef eth_int_512_t eth_i512_t; + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x20 +typedef eth_int256_512_t eth_i256_512_t; +typedef eth_i256_512_t i256_512_t; +#endif + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x10 +typedef eth_int128_512_t eth_i128_512_t; +typedef eth_int128_512_t i128_512_t; +#endif + +typedef eth_int64_512_t eth_i64_512_t; +typedef eth_int32_512_t eth_i32_512_t; +typedef eth_int16_512_t eth_i16_512_t; +typedef eth_int8_512_t eth_i8_512_t; + +typedef eth_i512_t i512_t; +typedef eth_int64_512_t i64_512_t; +typedef eth_int32_512_t i32_512_t; +typedef eth_int16_512_t i16_512_t; +typedef eth_int8_512_t i8_512_t; + +/////////////////////////////////////// +// +// TYPEDEFS UNSIGNED SIMD REGISTERS +// +////////////////////////////////////// + + +/////////////////////////////////////// +// +// 128 BITS UNSIGNED +// +////////////////////////////////////// + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x10 +typedef unsigned eth_uint_128_t __attribute__ ((vector_size(0x10), aligned(0x10))); +#else +typedef unsigned eth_uint_128_t __attribute__ ((vector_size(16), aligned(0x8))); +#endif + +typedef unsigned long eth_uint64_128_t __attribute__ ((vector_size(0x10), aligned(8))); +typedef unsigned int eth_uint32_128_t __attribute__ ((vector_size(0x10), aligned(4))); +typedef unsigned short eth_uint16_128_t __attribute__ ((vector_size(0x10), aligned(2))); +typedef unsigned char eth_uint8_128_t __attribute__ ((vector_size(0x10), aligned(1))); + +typedef eth_uint_128_t eth_u128_t; +typedef eth_uint64_128_t eth_u64_128_t; +typedef eth_uint32_128_t eth_u32_128_t; +typedef eth_uint16_128_t eth_u16_128_t; +typedef eth_uint8_128_t eth_u8_128_t; + +typedef eth_u128_t u128_t; +typedef eth_u64_128_t u64_128_t; +typedef eth_u32_128_t u32_128_t; +typedef eth_u16_128_t u16_128_t; +typedef eth_u8_128_t u8_128_t; + +/////////////////////////////////////// +// +// 256 BITS UNSIGNED +// +////////////////////////////////////// + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x20 +typedef unsigned eth_uint_256_t __attribute__ ((vector_size(0x20), aligned(0x20))); +#elif defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x10 +typedef unsigned eth_uint128_256_t __attribute__ ((vector_size(0x20), aligned(0x10))); +#endif + +typedef unsigned long eth_uint64_256_t __attribute__ ((vector_size(0x20), aligned(0x8))); +typedef unsigned int eth_uint32_256_t __attribute__ ((vector_size(0x20), aligned(0x4))); +typedef unsigned short eth_uint16_256_t __attribute__ ((vector_size(0x20), aligned(0x2))); +typedef unsigned char eth_uint8_256_t __attribute__ ((vector_size(0x20), aligned(0x1))); + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x20 +typedef eth_uint_256_t eth_u256_t; +typedef eth_u256_t u256_t; +#endif + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x10 +typedef eth_uint128_256_t eth_u128_256_t; +typedef eth_u128_256_t u128_256_t; +#endif + +typedef eth_uint64_256_t eth_u64_256_t; +typedef eth_uint32_256_t eth_u32_256_t; +typedef eth_uint16_256_t eth_u16_256_t; +typedef eth_uint8_256_t eth_u8_256_t; + +typedef eth_u64_256_t u64_256_t; +typedef eth_u32_256_t u32_256_t; +typedef eth_u16_256_t u16_256_t; +typedef eth_u8_256_t u8_256_t; + +/////////////////////////////////////// +// +// 512 BITS UNSIGNED +// +////////////////////////////////////// + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x40 +typedef unsigned eth_uint_512_t __attribute__ ((vector_size(0x40), aligned(0x40))); +#elif defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ == 0x20 +typedef unsigned eth_uint_512_t __attribute__ ((vector_size(0x40), aligned(0x20))); +#elif defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ == 0x10 +typedef unsigned eth_uint_512_t __attribute__ ((vector_size(0x40), aligned(0x10))); +#else +typedef unsigned eth_uint_512_t __attribute__ ((vector_size(0x40), aligned(__BIGGEST_ALIGNMENT__))); +#endif + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ == 0x20 +typedef unsigned eth_uint256_512_t __attribute__ ((vector_size(0x40), aligned(0x20))); +typedef eth_uint256_512_t eth_u256_512_t; +typedef eth_u256_512_t u256_512_t; +#endif + +#if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ == 0x10 +typedef unsigned eth_uint128_512_t __attribute__ ((vector_size(0x40), aligned(0x10))); +typedef eth_uint128_512_t eth_u128_512_t; +typedef eth_u128_512_t u128_512_t; +#endif + +typedef unsigned long eth_uint64_512_t __attribute__ ((vector_size(0x40), aligned(8))); +typedef unsigned int eth_uint32_512_t __attribute__ ((vector_size(0x40), aligned(4))); +typedef unsigned short eth_uint16_512_t __attribute__ ((vector_size(0x40), aligned(2))); +typedef unsigned char eth_uint8_512_t __attribute__ ((vector_size(0x40), aligned(1))); + +typedef eth_uint_512_t eth_u512_t; +typedef eth_uint64_512_t eth_u64_512_t; +typedef eth_uint32_512_t eth_u32_512_t; +typedef eth_uint16_512_t eth_u16_512_t; +typedef eth_uint8_512_t eth_u8_512_t; + +typedef eth_u512_t u512_t; +typedef eth_uint64_512_t u64_512_t; +typedef eth_uint32_512_t u32_512_t; +typedef eth_uint16_512_t u16_512_t; +typedef eth_uint8_512_t u8_512_t; + +#elif defined(_WIN32) && defined(_MSC_VER) +#include +#else +#warning "You don't support vector type" +#endif + +#endif diff --git a/meson.build b/meson.build index 9faacbb..b4acf64 100644 --- a/meson.build +++ b/meson.build @@ -1,27 +1,103 @@ project('Etheria-std', 'c', version : '0.1', - default_options : ['warning_level=3']) + default_options : ['warning_level=3', 'werror=true', 'optimization=3']) +###################################### +# +# +# COMPILER AND LINKER +# +# +###################################### + cc = meson.get_compiler('c') linker = cc.get_linker_id() -ld = find_program('ld', required : true) + +if (host_machine.system() == 'linux') + ld = find_program('ld', required : true) +endif + +###################################### +# +# +# DEPENDENCIES +# +# +###################################### + +criterion_dep = dependency('criterion', required: false) + +###################################### +# +# +# INCLUDES +# +# +###################################### incdir = include_directories('inc') + +###################################### +# +# +# SOURCES +# +# +###################################### + srcs = files('src/memory/memcpy/memcpy.c') + +###################################### +# +# +# TESTS +# +# +###################################### + + +types_tests = files('tests/types/types_basic_test.c') + +memory_memcpy_naive = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_mid.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_big.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_small.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_mid.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_big.c') + +tests = types_tests + memory_memcpy_naive + +###################################### +# +# +# BENCHMARKS +# +# +###################################### + +benchmarks = files('./benchmarks/memory/memcpy_naive/memcpy_naive.c') + summary({ 'CPU': build_machine.cpu(), - 'CPU Family': build_machine.cpu_family(), 'Endian': build_machine.endian(), 'System': build_machine.system() }, section: 'Machine Information') +if (host_machine.system() == 'linux') summary({ 'C Compiler': cc.get_id() + ' ' + cc.version(), 'Dynamic linker path': ld, 'Dynamic linker': ld.version(), }, section: 'Compiler and Linker Information') +else +summary({ + 'C Compiler': cc.get_id() + ' ' + cc.version(), + }, section: 'Compiler Information') +endif summary({ 'Name': meson.project_name(), @@ -34,16 +110,65 @@ summary({ }, section: 'Project Overview') -shared_library('etheria-std', +if (get_option('no_static')) + add_project_arguments('-DNO_STATIC=1', language: 'c') +endif + +if host_machine.system() == 'windows' + + static_library('etheria-std', + srcs, + install: true, + install_dir: 'dist', + include_directories: incdir) +else + lib_shared = shared_library('etheria-std', srcs, - c_args: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-fPIE', '-shared'], + c_args: ['-nostdlib', '-nodefaultlibs', '-Oz', '-fPIC'], install: true, install_dir: 'dist/shared', include_directories: incdir) -static_library('etheria-std', - srcs, - c_args: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-static-pie'], - install: true, - install_dir: 'dist/static', - include_directories: incdir) + lib_static = static_library('etheria-std', + srcs, + c_args: ['-nostdlib', '-nodefaultlibs', '-Oz'], + install: true, + install_dir: 'dist/static', + include_directories: incdir) +endif + + +if get_option('build_tests') and host_machine.system() == 'linux' +foreach test_file : tests + test_name = 'test_' + test_file.full_path().split('/')[-1].split('.c')[0] + test_exec = executable(test_name, + test_file, + c_args: ['-g3', '-Oz', '-fPIC'], + dependencies: [criterion_dep], + link_with: lib_static, + include_directories: incdir, + install: false, + pie: true) + test(test_name, test_exec, verbose: true) +endforeach + +if get_option('build_bench') and host_machine.system() == 'linux' +foreach bench_file: benchmarks + bench_name = 'bench_' + bench_file.full_path().split('/')[-1].split('.c')[0] + + bench_exec = executable(bench_name, bench_file, + c_args: ['-Oz', '-fPIC'], + link_with: lib_static, + include_directories: incdir, + install: true, + install_dir: 'benchmarks/output/', + pie: true) + + benchmark(bench_name, bench_exec, args: ['--stack', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'], verbose: true) + benchmark(bench_name, bench_exec, args: ['--stack', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'], verbose: true) + benchmark(bench_name, bench_exec, args: ['--stack', 'HELLO'], verbose: true) + benchmark(bench_name, bench_exec, args: ['--stack', 'PWDPWD'], verbose: true) +endforeach +endif + +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..7e57b86 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,3 @@ +option('build_tests', type: 'boolean', value: false, description: 'Build tests executables') +option('no_static', type: 'boolean', value: false, description: 'Use no static to enable static functions') +option('build_bench', type: 'boolean', value: false, description: 'Build benchmark test') diff --git a/src/memory/memcpy/memcpy.c b/src/memory/memcpy/memcpy.c index 1b2d060..f821e27 100644 --- a/src/memory/memcpy/memcpy.c +++ b/src/memory/memcpy/memcpy.c @@ -6,24 +6,53 @@ // ////////////////////////////////////// -static void * -_eth_memcpy_naive (void *dst, const void *src, size_t size) +#if defined(__linux__) + +#ifdef NO_STATIC +void *_eth_memcpy_naive (void *restrict dst, const void *restrict src, size_t size) { if (!dst || !src || !size) return (dst); - u8_t *psrc = (u8_t *) src; - u8_t *pdst = (u8_t *) dst; + u8_t *ps = (u8_t *) src; + u8_t *pd = (u8_t *) dst; - while ((size > 0) && size--) - *pdst++ = *psrc++; + while (size--) *pd++ = *ps++; return (dst); } +#else +static void *_eth_memcpy_naive (void *restrict dst, const void *restrict src, size_t size) +{ + if (!dst || !src || !size) + return (dst); -void *(*_eth_memcpy_ifunc (void)) (void *, const void *, size_t) + u8_t *ps = (u8_t *) src; + u8_t *pd = (u8_t *) dst; + + while (size--) *pd++ = *ps++; + return (dst); +} +#endif + +void *(*_eth_memcpy_ifunc (void)) (void *restrict, const void *restrict, size_t) { return (_eth_memcpy_naive); } -void *eth_memcpy (void *dst, const void *src, size_t size) - __attribute__((ifunc ("_eth_memcpy_ifunc"))); +void *eth_memcpy (void *restrict dst, const void *restrict src, size_t size) __attribute__((ifunc ("_eth_memcpy_ifunc"))); + +#else + +void * _eth_memcpy_naive (void *restrict dst, const void *restrict src, size_t size) +{ + if (!dst || !src || !size) + return (dst); + + u8_t *psrc = (u8_t *) src; + u8_t *pdst = (u8_t *) dst; + + while (size--) *pdst++ = *psrc++; + return (dst); +} + +#endif diff --git a/subprojects/criterion.wrap b/subprojects/criterion.wrap new file mode 100644 index 0000000..a1a74d3 --- /dev/null +++ b/subprojects/criterion.wrap @@ -0,0 +1,8 @@ +[wrap-git] +url = https://github.com/Snaipe/Criterion.git +depth = 1 +revision = head +method = cmake + +[provide] +dependency_names = criterion diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive.c new file mode 100644 index 0000000..d9d2b2f --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive.c @@ -0,0 +1,77 @@ +#include +#include +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_integer_copy) +{ + int a = 0x41414141; + int b = 0; + + cr_expect(_eth_memcpy_naive(&b, &a, sizeof(a)) == &b); + cr_expect(a == b); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_null_dst) +{ + char buf[0x100]; + + memcpy(buf, "hello", 0x5); + + cr_expect(_eth_memcpy_naive(NULL, buf, 0xa) == NULL); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_null) +{ + cr_expect(_eth_memcpy_naive(NULL, NULL, 0) == NULL); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_null_src) +{ + char buf[0x100]; + char cmp[0x100]; + + memset(buf, 0, sizeof(buf)); + memset(cmp, 0, sizeof(cmp)); + + cr_expect(_eth_memcpy_naive(buf, NULL, sizeof(buf)) == buf); + cr_expect(!memcmp(buf, cmp, sizeof(buf))); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_zero_size) +{ + char buf[0x100]; + char src[0x100]; + + memset(buf, 0, sizeof(buf)); + memset(src, 'a', sizeof(src)); + + cr_expect(_eth_memcpy_naive(buf, src, 0) == buf); + cr_expect(memcmp(buf, src, sizeof(src))); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_string) +{ + char buf[0x100]; + char *ptr = "hello world"; + + memset(buf, 0, sizeof(buf)); + + cr_expect(_eth_memcpy_naive(buf, ptr, strlen(ptr)) == buf); + cr_expect(!memcmp(buf, ptr, strlen(ptr))); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_dst_segfault, .signal = SIGSEGV) +{ + char buf[0x100]; + char *str = "This is a read only string in .rodata section"; + + memset(buf, 'a', sizeof(buf)); + _eth_memcpy_naive(str, buf, strlen(str)); +} + diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c new file mode 100644 index 0000000..b0a4b59 --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c @@ -0,0 +1,16 @@ +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_overlap_test, memcpy_naive_overlap_test) +{ + char a[] = "aabbccdd"; + + cr_assert(_eth_memcpy_naive(a+2, a, 4) == a+2); + + cr_expect(!memcmp(a, "aaaaaadd", 0x8), "aabbccdd must be aaaaaadd."); +} diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_big.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_big.c new file mode 100644 index 0000000..07b1645 --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_big.c @@ -0,0 +1,78 @@ +#include +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_stack_aligned_big_tests, memcpy_naive_stack_aligned_big_one) +{ + char *buf = NULL, *src = NULL; + + buf = (char *)malloc(sizeof(char) * 0x100000); + + cr_assert(buf != NULL); + + src = (char*)malloc(sizeof(char) * 0x100000); + + cr_assert(src != NULL); + + memset(src, 'a', 0x100000); + + cr_expect(_eth_memcpy_naive(buf, src, 0x100000) == buf, "the return of _eth_memcpy_naive is not the first parameter."); + cr_expect(!memcmp(buf, src, 0x100000), "the result of memcmp is not zero"); + + free(buf); + free(src); + + buf = NULL, src = NULL; +} + +Test(memcpy_naive_stack_aligned_big_tests, memcpy_naive_stack_aligned_big_two) +{ + char *buf = NULL, *src = NULL; + + buf = (char *)malloc(sizeof(char) * 0x1000000); + + cr_assert(buf != NULL); + + src = (char*)malloc(sizeof(char) * 0x1000000); + + cr_assert(src != NULL); + + memset(src, 'a', 0x1000000); + + cr_expect(_eth_memcpy_naive(buf, src, 0x1000000) == buf, "the return of _eth_memcpy_naive is not the first parameter"); + cr_expect(!memcmp(buf, src, 0x1000000), "the return of memcmp is not zero."); + + free(buf); + free(src); + + buf = NULL, src = NULL; +} + +Test(memcpy_naive_stack_aligned_big_tests, memcpy_naive_stack_aligned_big_three) +{ + char *buf = NULL, *src = NULL; + + buf = (char *)malloc(sizeof(char) * 0x10000000); + + cr_assert(buf != NULL); + + src = (char*)malloc(sizeof(char) * 0x10000000); + + cr_assert(src != NULL); + + memset(src, 'a', 0x10000000); + + cr_expect(_eth_memcpy_naive(buf, src, 0x10000000) == buf, "the return of _eth_memcpy_naive is not the first parameter"); + cr_expect(!memcmp(buf, src, 0x10000000), "the result of memcmp is no zero."); + + free(buf); + free(src); + + buf = NULL, src = NULL; +} + diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_mid.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_mid.c new file mode 100644 index 0000000..55b1b5c --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_mid.c @@ -0,0 +1,111 @@ +#include +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_one) +{ + char buf[0x200]; + char src[0x200]; + + memset(src, 'a', sizeof(src)); + + cr_assert(_eth_memcpy_naive(buf, src, sizeof(buf)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_two) +{ + char buf[0x400]; + char src[0x400]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_three) +{ + char buf[0x800]; + char src[0x800]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_four) +{ + char buf[0x1000]; + char src[0x1000]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_five) +{ + char buf[0x2000]; + char src[0x2000]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_six) +{ + char buf[0x4000]; + char src[0x4000]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_seven) +{ + char buf[0x6000]; + char src[0x6000]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_eight) +{ + char buf[0x8000]; + char src[0x8000]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_nine) +{ + char buf[0x10000]; + char src[0x10000]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_ten) +{ + char buf[0x12000]; + char src[0x12000]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + + diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c new file mode 100644 index 0000000..ffd98f9 --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c @@ -0,0 +1,110 @@ +#include +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_one) +{ + char buf[0x10]; + char src[0x10]; + + memset(src, 'a', sizeof(src)); + + cr_expect(_eth_memcpy_naive(buf, src, sizeof(buf)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_two) +{ + char buf[0x20]; + char src[0x20]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_three) +{ + char buf[0x30]; + char src[0x30]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_four) +{ + char buf[0x40]; + char src[0x40]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_five) +{ + char buf[0x50]; + char src[0x50]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_six) +{ + char buf[0x60]; + char src[0x60]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_seven) +{ + char buf[0x70]; + char src[0x70]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_eight) +{ + char buf[0x80]; + char src[0x80]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_nine) +{ + char buf[0x90]; + char src[0x90]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_ten) +{ + char buf[0x100]; + char src[0x100]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_big.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_big.c new file mode 100644 index 0000000..855f3c9 --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_big.c @@ -0,0 +1,78 @@ +#include +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_stack_unaligned_big_tests, memcpy_naive_stack_unaligned_big_one) +{ + char *buf = NULL, *src = NULL; + + buf = (char *)malloc(sizeof(char) * 0x100346); + + cr_assert(buf != NULL); + + src = (char*)malloc(sizeof(char) * 0x100346); + + cr_assert(src != NULL); + + memset(src, 'a', 0x100346); + + cr_expect(_eth_memcpy_naive(buf, src, 0x100346) == buf, "the return of _eth_memcpy_naive is not the first parameter."); + cr_expect(!memcmp(buf, src, 0x100346), "the result of memcmp is not zero"); + + free(buf); + free(src); + + buf = NULL, src = NULL; +} + +Test(memcpy_naive_stack_unaligned_big_tests, memcpy_naive_stack_unaligned_big_two) +{ + char *buf = NULL, *src = NULL; + + buf = (char *)malloc(sizeof(char) * 0x1002345); + + cr_assert(buf != NULL); + + src = (char*)malloc(sizeof(char) * 0x1002345); + + cr_assert(src != NULL); + + memset(src, 'a', 0x1002345); + + cr_expect(_eth_memcpy_naive(buf, src, 0x1002345) == buf, "the return of _eth_memcpy_naive is not the first parameter"); + cr_expect(!memcmp(buf, src, 0x1002345), "the return of memcmp is not zero."); + + free(buf); + free(src); + + buf = NULL, src = NULL; +} + +Test(memcpy_naive_stack_unaligned_big_tests, memcpy_naive_stack_unaligned_big_three) +{ + char *buf = NULL, *src = NULL; + + buf = (char *)malloc(sizeof(char) * 0x10034521); + + cr_assert(buf != NULL); + + src = (char*)malloc(sizeof(char) * 0x10034521); + + cr_assert(src != NULL); + + memset(src, 'a', 0x10034521); + + cr_expect(_eth_memcpy_naive(buf, src, 0x10034521) == buf, "the return of _eth_memcpy_naive is not the first parameter"); + cr_expect(!memcmp(buf, src, 0x10034521), "the result of memcmp is no zero."); + + free(buf); + free(src); + + buf = NULL, src = NULL; +} + diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_mid.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_mid.c new file mode 100644 index 0000000..2db1337 --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_mid.c @@ -0,0 +1,111 @@ +#include +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_one) +{ + char buf[0x204]; + char src[0x204]; + + memset(src, 'a', sizeof(src)); + + cr_assert(_eth_memcpy_naive(buf, src, sizeof(buf)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_two) +{ + char buf[0x416]; + char src[0x416]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_three) +{ + char buf[0x817]; + char src[0x817]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_four) +{ + char buf[0x1234]; + char src[0x1234]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_five) +{ + char buf[0x2089]; + char src[0x2089]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_six) +{ + char buf[0x4277]; + char src[0x4277]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_seven) +{ + char buf[0x6005]; + char src[0x6005]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_eight) +{ + char buf[0x8076]; + char src[0x8076]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_nine) +{ + char buf[0x10329]; + char src[0x10329]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_mid_tests, memcpy_naive_stack_unaligned_mid_ten) +{ + char buf[0x12045]; + char src[0x12045]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + + diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_small.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_small.c new file mode 100644 index 0000000..bfa19fb --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_small.c @@ -0,0 +1,110 @@ +#include +#include + +#ifndef NO_STATIC +#define NO_STATIC 1 +#endif + +#include "eth-std.h" + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_one) +{ + char buf[0x13]; + char src[0x13]; + + memset(src, 'a', sizeof(src)); + + cr_expect(_eth_memcpy_naive(buf, src, sizeof(buf)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_two) +{ + char buf[0x26]; + char src[0x26]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_three) +{ + char buf[0x35]; + char src[0x35]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_four) +{ + char buf[0x47]; + char src[0x47]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_five) +{ + char buf[0x51]; + char src[0x51]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_six) +{ + char buf[0x62]; + char src[0x62]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_seven) +{ + char buf[0x76]; + char src[0x76]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_eight) +{ + char buf[0x88]; + char src[0x88]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_nine) +{ + char buf[0x93]; + char src[0x93]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + +Test(memcpy_naive_stack_unaligned_small_tests, memcpy_naive_stack_unaligned_small_ten) +{ + char buf[0x109]; + char src[0x109]; + + memset(src, 'a', sizeof(src)); + cr_expect(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_expect(!memcmp(buf, src, sizeof(buf))); +} + diff --git a/tests/types/types_basic_test.c b/tests/types/types_basic_test.c new file mode 100644 index 0000000..3749971 --- /dev/null +++ b/tests/types/types_basic_test.c @@ -0,0 +1,20 @@ +#include "eth-types.h" +#include + +Test(types_basic_tests, type_test_legacy_signed_integer) +{ + eth_int64_t i64 = 0x7FFFFFFFFFFFFFFF; + eth_int32_t i32 = 0x7FFFFFFF; + eth_int16_t i16 = 0x7FFF; + eth_int8_t i8 = 0x7F; + + cr_expect(sizeof(i64) == 0x8, "the size in bytes of eth_int64_t is %#zx. expected %#x\n", sizeof(i64), 8); + cr_expect(sizeof(i32) == 0x4, "the size in bytes of eth_int32_t is %#zx. expected %#x\n", sizeof(i32), 4); + cr_expect(sizeof(i16) == 0x2, "the size in bytes of eth_int16_t is %#zx. expected %#x\n", sizeof(i16), 2); + cr_expect(sizeof(i8) == 0x1, "the size in bytes of eth_int8_t is %#zx. expected %#x\n", sizeof(i8), 1); + + cr_expect(i64 == 0x7FFFFFFFFFFFFFFF, "the value of i64 is %#lx. expected %#lx", i64, 0x7FFFFFFFFFFFFFFF); + cr_expect(i32 == 0x7FFFFFFF, "the value of i32 is %#x. expected %#x", i32, 0x7FFFFFFF); + cr_expect(i16 == 0x7FFF, "the value of i16 is %#x. expected %#x", i16, 0x7FFF); + cr_expect(i8 == 0x7F, "the value of i8 is %#x. expected %#x", i8, 0x7F); +}