From 8ce0ff758c43f70900e2f20066c505d250cb0c5a Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Wed, 22 May 2024 16:37:48 +0200 Subject: [PATCH 01/22] update: taskfile.yml, meson.build modified, created: tests folder and tests files also wraps folder and files --- Taskfile.yml | 44 +++++++++++++++++--- meson.build | 67 +++++++++++++++++++++++++++++- meson_options.txt | 1 + tests/memory/memcpy/memcpy_basic.c | 6 +++ wraps/criterion.wrap | 4 ++ 5 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 meson_options.txt create mode 100644 tests/memory/memcpy/memcpy_basic.c create mode 100644 wraps/criterion.wrap diff --git a/Taskfile.yml b/Taskfile.yml index fa8a352..45e3510 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,19 +1,47 @@ version: '3' tasks: + help: + cmds: + - go-task -a + silent: true + desc: "Show this pages" + + default: + - task: help + build: + preconditions: + - sh: "test ! -d dist" + msg: "Nothing to be done." cmds: - - meson setup build --reconfigure --buildtype=release --prefix=$(pwd) + - meson setup build --buildtype=release --prefix=$(pwd) - ninja -C build install silent: true desc: "Build the project" + re: + cmds: + - meson setup build --reconfigure --buildtype=release --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Re build the project" + + tests: + cmds: + - meson setup build --reconfigure -Dbuild_tests=true --buildtype=release --prefix=$(pwd) + - ninja -C build install + silent: true + desc: "Build tests files" + install: 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/)" @@ -22,17 +50,23 @@ tasks: 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" prompt: "Do you want remove etheria-std library" + clean-test: + cmds: + - rm -rf ./tests/output/ + silent: true + desc: "Clean tests output directory" + 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 !" silent: true desc: "Clean build directory" @@ -42,8 +76,6 @@ tasks: - 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 !" silent: true desc: "Full clean remove build directory and dist directory" - prompt: "Do you want remove (build, dist)" diff --git a/meson.build b/meson.build index 9faacbb..17d5dce 100644 --- a/meson.build +++ b/meson.build @@ -2,14 +2,63 @@ project('Etheria-std', 'c', version : '0.1', default_options : ['warning_level=3']) +if (host_machine.system() == 'windows') + error('This project is not working on windows for the moment !') +endif + +###################################### +# +# +# COMPILER AND LINKER +# +# +###################################### cc = meson.get_compiler('c') linker = cc.get_linker_id() ld = find_program('ld', required : true) +###################################### +# +# +# DEPENDENCIES +# +# +###################################### + +criterion_dep = dependency('criterion', required: true) + +###################################### +# +# +# INCLUDES +# +# +###################################### + incdir = include_directories('inc') + +###################################### +# +# +# SOURCES +# +# +###################################### + srcs = files('src/memory/memcpy/memcpy.c') + +###################################### +# +# +# TESTS +# +# +###################################### + +tests = files('tests/memory/memcpy/memcpy_basic.c') + summary({ 'CPU': build_machine.cpu(), 'CPU Family': build_machine.cpu_family(), @@ -34,16 +83,30 @@ summary({ }, section: 'Project Overview') -shared_library('etheria-std', +lib_shared = shared_library('etheria-std', srcs, c_args: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-fPIE', '-shared'], install: true, install_dir: 'dist/shared', include_directories: incdir) -static_library('etheria-std', +lib_static = static_library('etheria-std', srcs, c_args: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-static-pie'], install: true, install_dir: 'dist/static', include_directories: incdir) + + +if get_option('build_tests') +foreach test_file : tests + test_name = 'test_' + test_file.full_path().split('.c')[0] + executable(test_name, + test_file, + c_args: ['-Werror', '-g3', '-O3', '-Oz'], + dependencies: [criterion_dep], + install: true, + install_dir: 'tests/output/', + pie: true) +endforeach +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..47e0321 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('build_tests', type: 'boolean', value: false, description: 'Build tests executables') diff --git a/tests/memory/memcpy/memcpy_basic.c b/tests/memory/memcpy/memcpy_basic.c new file mode 100644 index 0000000..3ad4c23 --- /dev/null +++ b/tests/memory/memcpy/memcpy_basic.c @@ -0,0 +1,6 @@ +#include + +Test(memcpy_basic_tests, memcpy_basic_one) +{ + cr_assert(1 == 1); +} diff --git a/wraps/criterion.wrap b/wraps/criterion.wrap new file mode 100644 index 0000000..2041825 --- /dev/null +++ b/wraps/criterion.wrap @@ -0,0 +1,4 @@ +[wrap-git] +url = https://github.com/Snaipe/Criterion.git +depth = 1 +method = meson From a9cf0ef07a39159167d50c6edfb6288ff3274e4e Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Wed, 22 May 2024 21:55:47 +0200 Subject: [PATCH 02/22] update: test in windows ENV --- Taskfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index 45e3510..c3ff6a2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -12,7 +12,7 @@ tasks: build: preconditions: - - sh: "test ! -d dist" + - sh: '{{if eq OS "windows"}} cmd.exe /c "WINDOWS" else "test ! -d dist"' msg: "Nothing to be done." cmds: - meson setup build --buildtype=release --prefix=$(pwd) From 9e547c07b29e006c4cd9e60b3a1cbba03c78aed6 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Thu, 23 May 2024 00:27:56 +0200 Subject: [PATCH 03/22] update: working on cross platform with msvc compiler that is take more time than expected :/ --- Taskfile.yml | 15 ++++++----- inc/eth-std.h | 10 +++++++- meson.build | 36 ++++++++++++++++++++------- src/memory/memcpy/memcpy.c | 25 ++++++++++++++++--- {wraps => subprojects}/criterion.wrap | 4 +++ 5 files changed, 70 insertions(+), 20 deletions(-) rename {wraps => subprojects}/criterion.wrap (59%) diff --git a/Taskfile.yml b/Taskfile.yml index c3ff6a2..960df08 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -12,7 +12,7 @@ tasks: build: preconditions: - - sh: '{{if eq OS "windows"}} cmd.exe /c "WINDOWS" else "test ! -d dist"' + - sh: '{{if eq OS "windows"}} cmd.exe /c echo "WINDOWS" {{else}} "test ! -d dist" {{end}}' msg: "Nothing to be done." cmds: - meson setup build --buildtype=release --prefix=$(pwd) @@ -35,6 +35,7 @@ tasks: desc: "Build tests files" install: + platforms: ["linux"] preconditions: - test -d dist cmds: @@ -47,6 +48,7 @@ tasks: 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 @@ -60,14 +62,14 @@ tasks: clean-test: cmds: - - rm -rf ./tests/output/ + - '{{if eq OS "windows"}} cmd.exe /c rmdir ./tests/output/ /S /Q {{else}} rm -rf ./tests/output/{{end}}' silent: true desc: "Clean tests output directory" clean: cmds: - - rm -rf build - - 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" @@ -75,7 +77,8 @@ tasks: deps: - clean cmds: - - rm -rf dist - - 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" diff --git a/inc/eth-std.h b/inc/eth-std.h index eca68f6..07230b6 100644 --- a/inc/eth-std.h +++ b/inc/eth-std.h @@ -24,6 +24,7 @@ typedef signed int eth_int32_t; typedef signed short eth_int16_t; typedef signed char eth_int8_t; +#if !defined(_MSC_VER) 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))); @@ -41,13 +42,14 @@ typedef signed long long eth_int64_512_t __attribute__ ((vector_size(64), ali 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))); - +#endif 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; +#if !defined(_MSC_VER) 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))); @@ -65,12 +67,18 @@ typedef unsigned long long eth_uint64_512_t __attribute__ ((vector_size(64), 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))); +#endif typedef unsigned char u8_t; typedef unsigned short u16_t; typedef unsigned int u32_t; typedef unsigned long u64_t; + +#if defined(__linux__) typedef unsigned long size_t; +#else +typedef unsigned long long size_t; +#endif /////////////////////////////////////// // diff --git a/meson.build b/meson.build index 17d5dce..504c6e2 100644 --- a/meson.build +++ b/meson.build @@ -2,9 +2,9 @@ project('Etheria-std', 'c', version : '0.1', default_options : ['warning_level=3']) -if (host_machine.system() == 'windows') - error('This project is not working on windows for the moment !') -endif +#if (host_machine.system() == 'windows') +# error('This project is not working on windows for the moment !') +#endif ###################################### # @@ -16,7 +16,10 @@ endif 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 ###################################### # @@ -26,7 +29,7 @@ ld = find_program('ld', required : true) # ###################################### -criterion_dep = dependency('criterion', required: true) +criterion_dep = dependency('criterion', required: false) ###################################### # @@ -61,16 +64,21 @@ tests = files('tests/memory/memcpy/memcpy_basic.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(), @@ -83,22 +91,32 @@ summary({ }, section: 'Project Overview') -lib_shared = shared_library('etheria-std', +if host_machine.system() == 'windows' + + static_library('etheria-std', + srcs, + link_args: ['/LIB'], + 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'], install: true, install_dir: 'dist/shared', include_directories: incdir) -lib_static = static_library('etheria-std', + lib_static = static_library('etheria-std', srcs, c_args: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-static-pie'], install: true, install_dir: 'dist/static', include_directories: incdir) +endif -if get_option('build_tests') +if get_option('build_tests') and host_machine.system() == 'linux' foreach test_file : tests test_name = 'test_' + test_file.full_path().split('.c')[0] executable(test_name, diff --git a/src/memory/memcpy/memcpy.c b/src/memory/memcpy/memcpy.c index 1b2d060..90b9eeb 100644 --- a/src/memory/memcpy/memcpy.c +++ b/src/memory/memcpy/memcpy.c @@ -6,8 +6,9 @@ // ////////////////////////////////////// -static void * -_eth_memcpy_naive (void *dst, const void *src, size_t size) +#if defined(__linux__) + +static void *_eth_memcpy_naive (void *dst, const void *src, size_t size) { if (!dst || !src || !size) return (dst); @@ -25,5 +26,21 @@ void *(*_eth_memcpy_ifunc (void)) (void *, const void *, 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 *dst, const void *src, size_t size) __attribute__((ifunc ("_eth_memcpy_ifunc"))); + +#else + +void * _eth_memcpy_naive (void *dst, const void *src, size_t size) +{ + if (!dst || !src || !size) + return (dst); + + u8_t *psrc = (u8_t *) src; + u8_t *pdst = (u8_t *) dst; + + while ((size > 0) && size--) + *pdst++ = *psrc++; + return (dst); +} + +#endif diff --git a/wraps/criterion.wrap b/subprojects/criterion.wrap similarity index 59% rename from wraps/criterion.wrap rename to subprojects/criterion.wrap index 2041825..bfea829 100644 --- a/wraps/criterion.wrap +++ b/subprojects/criterion.wrap @@ -1,4 +1,8 @@ [wrap-git] url = https://github.com/Snaipe/Criterion.git depth = 1 +revision = head method = meson + +[provide] +dependency_names = criterion From 6ad1f5189b678f8107736e59a6e0be70a9011f62 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Thu, 23 May 2024 15:13:37 +0200 Subject: [PATCH 04/22] update: add some tests and modification on meson build file and taskfile --- .gitignore | 2 + Taskfile.yml | 15 +- inc/eth-std.h | 138 +++++++++++------- meson.build | 19 ++- meson_options.txt | 1 + src/memory/memcpy/memcpy.c | 24 ++- subprojects/criterion.wrap | 2 +- tests/memory/memcpy/memcpy_basic.c | 6 - .../memory/memcpy/memcpy_naive/memcpy_naive.c | 78 ++++++++++ 9 files changed, 209 insertions(+), 76 deletions(-) delete mode 100644 tests/memory/memcpy/memcpy_basic.c create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive.c diff --git a/.gitignore b/.gitignore index 637f9d1..afec901 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .cache compile_commands.json build +./tests/output + # Prerequisites *.d diff --git a/Taskfile.yml b/Taskfile.yml index 960df08..18d26a1 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -12,7 +12,7 @@ tasks: build: preconditions: - - sh: '{{if eq OS "windows"}} cmd.exe /c echo "WINDOWS" {{else}} "test ! -d dist" {{end}}' + - sh: '{{if eq OS "windows"}} cmd.exe /c echo "WINDOWS" {{else}} test ! -d dist {{end}}' msg: "Nothing to be done." cmds: - meson setup build --buildtype=release --prefix=$(pwd) @@ -27,13 +27,22 @@ tasks: silent: true desc: "Re build the project" - tests: + build_tests: cmds: - - meson setup build --reconfigure -Dbuild_tests=true --buildtype=release --prefix=$(pwd) + - meson setup build --reconfigure -Dbuild_tests=true -Dno_static=true --buildtype=release --prefix=$(pwd) - ninja -C build install silent: true desc: "Build tests files" + run_tests: + preconditions: + - sh: '{{if eq OS "windows" }} cmd.exe /c IF EXIST build {{else}} test -d build {{end}}' + msg: "Build directory not exist please run build_tests before" + cmds: + - meson test -C build --verbose + silent: true + desc: "Run tests files" + install: platforms: ["linux"] preconditions: diff --git a/inc/eth-std.h b/inc/eth-std.h index 07230b6..856600c 100644 --- a/inc/eth-std.h +++ b/inc/eth-std.h @@ -13,71 +13,101 @@ /////////////////////////////////////// // -// TYPEDEFS +// TYPEDEFS SIGNED LEGACY // ////////////////////////////////////// -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; -#if !defined(_MSC_VER) -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))); -#endif +typedef signed int i32_t; +typedef signed short i16_t; +typedef signed char i8_t; -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; - -#if !defined(_MSC_VER) -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))); +#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 -typedef unsigned char u8_t; -typedef unsigned short u16_t; -typedef unsigned int u32_t; -typedef unsigned long u64_t; +/////////////////////////////////////// +// +// 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; #if defined(__linux__) -typedef unsigned long size_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 size_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 + +/////////////////////////////////////// +// +// TYPEDEFS SIGNED/UNSIGNED VECTOR +// +////////////////////////////////////// + +#if defined(_WIN32) && defined(_MSC_VER) +#include +#elif defined(__GNUC__) +typedef signed eth_int_128_t __attribute__ ((vector_size(16))); +typedef signed 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 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 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 eth_uint_128_t __attribute__ ((vector_size(16))); +typedef unsigned 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 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 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))); +#else +#warning "You don't support vector type" #endif /////////////////////////////////////// @@ -86,6 +116,10 @@ typedef unsigned long long size_t; // ////////////////////////////////////// +#ifdef NO_STATIC +void *_eth_memcpy_naive(void *dst, const void *src, size_t size); +#endif + void *eth_memcpy(void *dst, const void *src, size_t size); #endif diff --git a/meson.build b/meson.build index 504c6e2..d376e31 100644 --- a/meson.build +++ b/meson.build @@ -2,9 +2,6 @@ project('Etheria-std', 'c', version : '0.1', default_options : ['warning_level=3']) -#if (host_machine.system() == 'windows') -# error('This project is not working on windows for the moment !') -#endif ###################################### # @@ -60,7 +57,7 @@ srcs = files('src/memory/memcpy/memcpy.c') # ###################################### -tests = files('tests/memory/memcpy/memcpy_basic.c') +tests = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c') summary({ 'CPU': build_machine.cpu(), @@ -91,18 +88,21 @@ summary({ }, section: 'Project Overview') +if (get_option('no_static')) + add_project_arguments('-DNO_STATIC=1', language: 'c') +endif + if host_machine.system() == 'windows' static_library('etheria-std', srcs, - link_args: ['/LIB'], 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: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-fPIC', '-shared'], install: true, install_dir: 'dist/shared', include_directories: incdir) @@ -119,12 +119,15 @@ endif if get_option('build_tests') and host_machine.system() == 'linux' foreach test_file : tests test_name = 'test_' + test_file.full_path().split('.c')[0] - executable(test_name, + test_exec = executable(test_name, test_file, - c_args: ['-Werror', '-g3', '-O3', '-Oz'], + c_args: ['-Werror', '-O3', '-Oz', '-fPIC'], dependencies: [criterion_dep], + link_with: lib_static, + include_directories: incdir, install: true, install_dir: 'tests/output/', pie: true) + test(test_name, test_exec) endforeach endif diff --git a/meson_options.txt b/meson_options.txt index 47e0321..e4277cc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ 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') diff --git a/src/memory/memcpy/memcpy.c b/src/memory/memcpy/memcpy.c index 90b9eeb..4a36d97 100644 --- a/src/memory/memcpy/memcpy.c +++ b/src/memory/memcpy/memcpy.c @@ -8,18 +8,31 @@ #if defined(__linux__) +#ifdef NO_STATIC +void *_eth_memcpy_naive (void *dst, const void *src, size_t size) +{ + if (!dst || !src || !size) + return (dst); + + u8_t *ps = (u8_t *) src; + u8_t *pd = (u8_t *) dst; + + while (size--) *pd++ = *ps++; + return (dst); +} +#else static void *_eth_memcpy_naive (void *dst, const void *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); } +#endif void *(*_eth_memcpy_ifunc (void)) (void *, const void *, size_t) { @@ -38,8 +51,7 @@ void * _eth_memcpy_naive (void *dst, const void *src, size_t size) u8_t *psrc = (u8_t *) src; u8_t *pdst = (u8_t *) dst; - while ((size > 0) && size--) - *pdst++ = *psrc++; + while (size--) *pdst++ = *psrc++; return (dst); } diff --git a/subprojects/criterion.wrap b/subprojects/criterion.wrap index bfea829..a1a74d3 100644 --- a/subprojects/criterion.wrap +++ b/subprojects/criterion.wrap @@ -2,7 +2,7 @@ url = https://github.com/Snaipe/Criterion.git depth = 1 revision = head -method = meson +method = cmake [provide] dependency_names = criterion diff --git a/tests/memory/memcpy/memcpy_basic.c b/tests/memory/memcpy/memcpy_basic.c deleted file mode 100644 index 3ad4c23..0000000 --- a/tests/memory/memcpy/memcpy_basic.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -Test(memcpy_basic_tests, memcpy_basic_one) -{ - cr_assert(1 == 1); -} 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..3ba3b40 --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive.c @@ -0,0 +1,78 @@ +#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_assert(_eth_memcpy_naive(&b, &a, sizeof(a)) == &b); + cr_assert(a == b); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_null_dst) +{ + char buf[0x100]; + + memcpy(buf, "hello", 0x5); + + cr_assert(_eth_memcpy_naive(NULL, buf, 0xa) == NULL); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_null) +{ + cr_assert(_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_assert(_eth_memcpy_naive(buf, NULL, sizeof(buf)) == buf); + cr_assert(!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_assert(_eth_memcpy_naive(buf, src, 0) == buf); + cr_assert(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_assert(_eth_memcpy_naive(buf, ptr, strlen(ptr)) == buf); + cr_assert(!memcmp(buf, ptr, strlen(ptr))); +} + +Test(memcpy_naive_basic_tests, memcpy_naive_basic_overflow, .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)); +} + + From f43cbaf12c805809c5daeaa9ce950e9f5f33e47b Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Thu, 23 May 2024 16:48:06 +0200 Subject: [PATCH 05/22] todo: finish random buffer generator for test environment and construct CI/CD pipeline --- inc/eth-std.h | 6 + meson.build | 5 +- tests/etheria_test_utils.c | 9 ++ tests/etheria_test_utils.h | 20 ++++ .../memory/memcpy/memcpy_naive/memcpy_naive.c | 3 +- .../memcpy_naive_stack_buf_aligned_small.c | 110 ++++++++++++++++++ 6 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 tests/etheria_test_utils.c create mode 100644 tests/etheria_test_utils.h create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c diff --git a/inc/eth-std.h b/inc/eth-std.h index 856600c..1dd5602 100644 --- a/inc/eth-std.h +++ b/inc/eth-std.h @@ -47,13 +47,19 @@ 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; diff --git a/meson.build b/meson.build index d376e31..b507ad6 100644 --- a/meson.build +++ b/meson.build @@ -57,7 +57,8 @@ srcs = files('src/memory/memcpy/memcpy.c') # ###################################### -tests = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c') +tests = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c', + 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c') summary({ 'CPU': build_machine.cpu(), @@ -121,7 +122,7 @@ foreach test_file : tests test_name = 'test_' + test_file.full_path().split('.c')[0] test_exec = executable(test_name, test_file, - c_args: ['-Werror', '-O3', '-Oz', '-fPIC'], + c_args: ['-Werror', '-g3', '-O3', '-Oz', '-fPIC'], dependencies: [criterion_dep], link_with: lib_static, include_directories: incdir, diff --git a/tests/etheria_test_utils.c b/tests/etheria_test_utils.c new file mode 100644 index 0000000..3ebf957 --- /dev/null +++ b/tests/etheria_test_utils.c @@ -0,0 +1,9 @@ +#include "etheria_test_utils.h" + +#if defined (__linux__) && defined(__GNUC__) + +//byte_t *random_buffer(byte_t *buf, size_t size) +//{ +//} + +#endif diff --git a/tests/etheria_test_utils.h b/tests/etheria_test_utils.h new file mode 100644 index 0000000..02b4c7a --- /dev/null +++ b/tests/etheria_test_utils.h @@ -0,0 +1,20 @@ +#ifndef ETHERIA_TEST_UTILS_H +#define ETHERIA_TEST_UTILS_H + +/////////////////////////////////////// +// +// HEADER +// +////////////////////////////////////// + +#include "eth-std.h" + +#if defined(__linux__) && defined(__GNUC__) + +#include + +byte_t *random_buffer(byte_t *buf, size_t size); + +#endif + +#endif diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive.c index 3ba3b40..50e8269 100644 --- a/tests/memory/memcpy/memcpy_naive/memcpy_naive.c +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive.c @@ -66,7 +66,7 @@ Test(memcpy_naive_basic_tests, memcpy_naive_basic_string) cr_assert(!memcmp(buf, ptr, strlen(ptr))); } -Test(memcpy_naive_basic_tests, memcpy_naive_basic_overflow, .signal = SIGSEGV) +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"; @@ -75,4 +75,3 @@ Test(memcpy_naive_basic_tests, memcpy_naive_basic_overflow, .signal = SIGSEGV) _eth_memcpy_naive(str, buf, strlen(str)); } - 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..2651d2f --- /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_tests, memcpy_naive_stack_aligned_small_one) +{ + char buf[0x8]; + char src[0x8]; + + 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_tests, memcpy_naive_stack_aligned_small_two) +{ + char buf[0x10]; + char src[0x10]; + + 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_tests, memcpy_naive_stack_aligned_small_three) +{ + char buf[0x20]; + char src[0x20]; + + 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_tests, memcpy_naive_stack_aligned_small_four) +{ + char buf[0x40]; + char src[0x40]; + + 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_tests, memcpy_naive_stack_aligned_small_five) +{ + char buf[0x50]; + char src[0x50]; + + 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_tests, memcpy_naive_stack_aligned_small_six) +{ + char buf[0x60]; + char src[0x60]; + + 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_tests, memcpy_naive_stack_aligned_small_seven) +{ + char buf[0x70]; + char src[0x70]; + + 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_tests, memcpy_naive_stack_aligned_small_eight) +{ + char buf[0x80]; + char src[0x80]; + + 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_tests, memcpy_naive_stack_aligned_small_nine) +{ + char buf[0x90]; + char src[0x90]; + + 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_tests, memcpy_naive_stack_aligned_small_ten) +{ + char buf[0x100]; + char src[0x100]; + + memset(src, 'a', sizeof(src)); + cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); + cr_assert(!memcmp(buf, src, sizeof(buf))); +} + From 5c848477db76f6af5f0f05187e2191e17f9e374f Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Thu, 23 May 2024 23:42:56 +0200 Subject: [PATCH 06/22] finish writing memcpy naive tests --- .gitignore | 1 + meson.build | 7 +- tests/etheria_test_utils.c | 9 -- tests/etheria_test_utils.h | 20 ---- .../memcpy_naive/memcpy_naive_overlap.c | 16 +++ .../memcpy_naive_stack_buf_aligned_big.c | 78 +++++++++++++ .../memcpy_naive_stack_buf_aligned_mid.c | 110 ++++++++++++++++++ .../memcpy_naive_stack_buf_aligned_small.c | 60 +++++----- 8 files changed, 240 insertions(+), 61 deletions(-) delete mode 100644 tests/etheria_test_utils.c delete mode 100644 tests/etheria_test_utils.h create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_big.c create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_mid.c diff --git a/.gitignore b/.gitignore index afec901..fbba3d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .cache compile_commands.json build +dist ./tests/output # Prerequisites diff --git a/meson.build b/meson.build index b507ad6..d0e9ad2 100644 --- a/meson.build +++ b/meson.build @@ -58,7 +58,10 @@ srcs = files('src/memory/memcpy/memcpy.c') ###################################### tests = 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_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') summary({ 'CPU': build_machine.cpu(), @@ -119,7 +122,7 @@ endif if get_option('build_tests') and host_machine.system() == 'linux' foreach test_file : tests - test_name = 'test_' + test_file.full_path().split('.c')[0] + test_name = 'test_' + test_file.full_path().split('/')[-1].split('.c')[0] test_exec = executable(test_name, test_file, c_args: ['-Werror', '-g3', '-O3', '-Oz', '-fPIC'], diff --git a/tests/etheria_test_utils.c b/tests/etheria_test_utils.c deleted file mode 100644 index 3ebf957..0000000 --- a/tests/etheria_test_utils.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "etheria_test_utils.h" - -#if defined (__linux__) && defined(__GNUC__) - -//byte_t *random_buffer(byte_t *buf, size_t size) -//{ -//} - -#endif diff --git a/tests/etheria_test_utils.h b/tests/etheria_test_utils.h deleted file mode 100644 index 02b4c7a..0000000 --- a/tests/etheria_test_utils.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ETHERIA_TEST_UTILS_H -#define ETHERIA_TEST_UTILS_H - -/////////////////////////////////////// -// -// HEADER -// -////////////////////////////////////// - -#include "eth-std.h" - -#if defined(__linux__) && defined(__GNUC__) - -#include - -byte_t *random_buffer(byte_t *buf, size_t size); - -#endif - -#endif 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..4dad035 --- /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_assert(!memcmp(a, "aaaaaadd", 0x8)); +} 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..7dcfe64 --- /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_assert(_eth_memcpy_naive(buf, src, 0x100000) == buf); + cr_assert(!memcmp(buf, src, 0x100000)); + + 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_assert(_eth_memcpy_naive(buf, src, 0x1000000) == buf); + cr_assert(!memcmp(buf, src, 0x1000000)); + + 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_assert(_eth_memcpy_naive(buf, src, 0x10000000) == buf); + cr_assert(!memcmp(buf, src, 0x10000000)); + + 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..ef6331a --- /dev/null +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_mid.c @@ -0,0 +1,110 @@ +#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_small_one) +{ + char buf[0x8]; + char src[0x8]; + + 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_small_two) +{ + char buf[0x10]; + char src[0x10]; + + 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_small_three) +{ + char buf[0x20]; + char src[0x20]; + + 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_small_four) +{ + char buf[0x40]; + char src[0x40]; + + 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_small_five) +{ + char buf[0x50]; + char src[0x50]; + + 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_small_six) +{ + char buf[0x60]; + char src[0x60]; + + 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_small_seven) +{ + char buf[0x70]; + char src[0x70]; + + 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_small_eight) +{ + char buf[0x80]; + char src[0x80]; + + 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_small_nine) +{ + char buf[0x90]; + char src[0x90]; + + 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_small_ten) +{ + char buf[0x100]; + char src[0x100]; + + 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 index 2651d2f..270b2ff 100644 --- 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 @@ -7,10 +7,10 @@ #include "eth-std.h" -Test(memcpy_naive_stack_aligned_tests, memcpy_naive_stack_aligned_small_one) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_one) { - char buf[0x8]; - char src[0x8]; + char buf[0x200]; + char src[0x200]; memset(src, 'a', sizeof(src)); @@ -18,90 +18,90 @@ Test(memcpy_naive_stack_aligned_tests, memcpy_naive_stack_aligned_small_one) cr_assert(!memcmp(buf, src, sizeof(buf))); } -Test(memcpy_naive_stack_aligned_tests, memcpy_naive_stack_aligned_small_two) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_two) { - char buf[0x10]; - char src[0x10]; + 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_tests, memcpy_naive_stack_aligned_small_three) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_three) { - char buf[0x20]; - char src[0x20]; + 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_tests, memcpy_naive_stack_aligned_small_four) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_four) { - char buf[0x40]; - char src[0x40]; + 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_tests, memcpy_naive_stack_aligned_small_five) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_five) { - char buf[0x50]; - char src[0x50]; + 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_tests, memcpy_naive_stack_aligned_small_six) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_six) { - char buf[0x60]; - char src[0x60]; + 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_tests, memcpy_naive_stack_aligned_small_seven) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_seven) { - char buf[0x70]; - char src[0x70]; + 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_tests, memcpy_naive_stack_aligned_small_eight) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_eight) { - char buf[0x80]; - char src[0x80]; + 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_tests, memcpy_naive_stack_aligned_small_nine) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_nine) { - char buf[0x90]; - char src[0x90]; + char buf[0xFFFF]; + char src[0xFFFF]; 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_tests, memcpy_naive_stack_aligned_small_ten) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_ten) { - char buf[0x100]; - char src[0x100]; + char buf[0x10000]; + char src[0x10000]; memset(src, 'a', sizeof(src)); cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); From 55777cb2087bf6ec36c14d4c9691c6a030026fec Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Fri, 24 May 2024 15:12:51 +0200 Subject: [PATCH 07/22] update somes files and begin CI/CD pipeline --- Taskfile.yml | 51 +++++++++++++++++++++++++++++++------- meson.build | 8 +++--- src/memory/memcpy/memcpy.c | 10 ++++---- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 18d26a1..f4e955a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -27,14 +27,14 @@ tasks: silent: true desc: "Re build the project" - build_tests: + build-tests: cmds: - meson setup build --reconfigure -Dbuild_tests=true -Dno_static=true --buildtype=release --prefix=$(pwd) - - ninja -C build install + - ninja -C build silent: true desc: "Build tests files" - run_tests: + run-tests: preconditions: - sh: '{{if eq OS "windows" }} cmd.exe /c IF EXIST build {{else}} test -d build {{end}}' msg: "Build directory not exist please run build_tests before" @@ -43,6 +43,45 @@ tasks: 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" }} cmd.exe /c IF EXIST 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" }} cmd.exe /c IF EXIST 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: @@ -69,12 +108,6 @@ tasks: desc: "Remove installed etheria Standard library on the system" prompt: "Do you want remove etheria-std library" - clean-test: - cmds: - - '{{if eq OS "windows"}} cmd.exe /c rmdir ./tests/output/ /S /Q {{else}} rm -rf ./tests/output/{{end}}' - silent: true - desc: "Clean tests output directory" - clean: cmds: - '{{if eq OS "windows" }} cmd.exe /c rmdir build /S /Q {{else}} rm -rf build {{end}}' diff --git a/meson.build b/meson.build index d0e9ad2..3b940cf 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('Etheria-std', 'c', version : '0.1', - default_options : ['warning_level=3']) + default_options : ['warning_level=3', 'werror=true', 'optimization=3']) ###################################### @@ -106,14 +106,14 @@ if host_machine.system() == 'windows' else lib_shared = shared_library('etheria-std', srcs, - c_args: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-fPIC', '-shared'], + c_args: ['-nostdlib', '-nodefaultlibs', '-Oz', '-fPIC', '-shared'], install: true, install_dir: 'dist/shared', include_directories: incdir) lib_static = static_library('etheria-std', srcs, - c_args: ['-Werror', '-nostdlib', '-nodefaultlibs', '-O3', '-Oz', '-static-pie'], + c_args: ['-nostdlib', '-nodefaultlibs', '-Oz', '-static-pie'], install: true, install_dir: 'dist/static', include_directories: incdir) @@ -125,7 +125,7 @@ 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: ['-Werror', '-g3', '-O3', '-Oz', '-fPIC'], + c_args: ['-g3', '-Oz', '-fPIC'], dependencies: [criterion_dep], link_with: lib_static, include_directories: incdir, diff --git a/src/memory/memcpy/memcpy.c b/src/memory/memcpy/memcpy.c index 4a36d97..f821e27 100644 --- a/src/memory/memcpy/memcpy.c +++ b/src/memory/memcpy/memcpy.c @@ -9,7 +9,7 @@ #if defined(__linux__) #ifdef NO_STATIC -void *_eth_memcpy_naive (void *dst, const void *src, size_t size) +void *_eth_memcpy_naive (void *restrict dst, const void *restrict src, size_t size) { if (!dst || !src || !size) return (dst); @@ -21,7 +21,7 @@ void *_eth_memcpy_naive (void *dst, const void *src, size_t size) return (dst); } #else -static void *_eth_memcpy_naive (void *dst, const void *src, size_t size) +static void *_eth_memcpy_naive (void *restrict dst, const void *restrict src, size_t size) { if (!dst || !src || !size) return (dst); @@ -34,16 +34,16 @@ static void *_eth_memcpy_naive (void *dst, const void *src, size_t size) } #endif -void *(*_eth_memcpy_ifunc (void)) (void *, const void *, size_t) +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 *dst, const void *src, size_t size) +void * _eth_memcpy_naive (void *restrict dst, const void *restrict src, size_t size) { if (!dst || !src || !size) return (dst); From 1c7e0675261bf8e7f71c93115e0ca552dc1b7682 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sat, 25 May 2024 11:13:36 +0200 Subject: [PATCH 08/22] update cross build --- cross/x86_64/windows/x86_64-clang.txt | 23 +++++++++++++++++++++++ cross/x86_64/windows/x86_64-mingw.txt | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 cross/x86_64/windows/x86_64-clang.txt create mode 100644 cross/x86_64/windows/x86_64-mingw.txt 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..bb5f86b --- /dev/null +++ b/cross/x86_64/windows/x86_64-clang.txt @@ -0,0 +1,23 @@ +[binaries] +c = 'clang' +cpp = 'clang++' +ar = 'llvm-ar' +strip = 'llvm-strip' + +[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..43ca6e2 --- /dev/null +++ b/cross/x86_64/windows/x86_64-mingw.txt @@ -0,0 +1,23 @@ +[binaries] +c = 'gcc' +cpp = 'g++' +ar = 'ar' +strip = 'strip' + +[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' From 9b929f8b8318724abc4d6a1e7a0258d5f0442e1c Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sat, 25 May 2024 18:45:49 +0200 Subject: [PATCH 09/22] update cross files --- Taskfile.yml | 18 +- cross/x86_64/linux/x86_64-clang.txt | 25 ++ cross/x86_64/linux/x86_64-gcc.txt | 25 ++ cross/x86_64/linux/x86_64-mingw.txt | 23 ++ cross/x86_64/windows/x86_64-clang.txt | 2 + cross/x86_64/windows/x86_64-mingw.txt | 2 + cross/x86_64/windows/x86_64-msvc.txt | 25 ++ inc/eth-memory.h | 16 ++ inc/eth-std.h | 117 +--------- inc/eth-types.h | 323 ++++++++++++++++++++++++++ meson.build | 12 +- 11 files changed, 464 insertions(+), 124 deletions(-) create mode 100644 cross/x86_64/linux/x86_64-clang.txt create mode 100644 cross/x86_64/linux/x86_64-gcc.txt create mode 100644 cross/x86_64/linux/x86_64-mingw.txt create mode 100644 cross/x86_64/windows/x86_64-msvc.txt create mode 100644 inc/eth-memory.h create mode 100644 inc/eth-types.h diff --git a/Taskfile.yml b/Taskfile.yml index f4e955a..29778b9 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -12,7 +12,7 @@ tasks: build: preconditions: - - sh: '{{if eq OS "windows"}} cmd.exe /c echo "WINDOWS" {{else}} test ! -d dist {{end}}' + - 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) @@ -20,6 +20,16 @@ tasks: silent: true desc: "Build the project" + compile: + 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" + re: cmds: - meson setup build --reconfigure --buildtype=release --prefix=$(pwd) @@ -36,7 +46,7 @@ tasks: run-tests: preconditions: - - sh: '{{if eq OS "windows" }} cmd.exe /c IF EXIST build {{else}} test -d build {{end}}' + - 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 @@ -55,7 +65,7 @@ tasks: list-tests: preconditions: - - sh: '{{if eq OS "windows" }} cmd.exe /c IF EXIST build {{else}} test -d build {{end}}' + - 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 @@ -64,7 +74,7 @@ tasks: run-test-suite: preconditions: - - sh: '{{if eq OS "windows" }} cmd.exe /c IF EXIST build {{else}} test -d build {{end}}' + - 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}} 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 index bb5f86b..3f73219 100644 --- a/cross/x86_64/windows/x86_64-clang.txt +++ b/cross/x86_64/windows/x86_64-clang.txt @@ -3,6 +3,8 @@ c = 'clang' cpp = 'clang++' ar = 'llvm-ar' strip = 'llvm-strip' +cmake = 'cmake' +pkg-config = 'pkg-config' [host_machine] system = 'windows' diff --git a/cross/x86_64/windows/x86_64-mingw.txt b/cross/x86_64/windows/x86_64-mingw.txt index 43ca6e2..f974a83 100644 --- a/cross/x86_64/windows/x86_64-mingw.txt +++ b/cross/x86_64/windows/x86_64-mingw.txt @@ -3,6 +3,8 @@ c = 'gcc' cpp = 'g++' ar = 'ar' strip = 'strip' +cmake = 'cmake' +pkg-config = 'pkg-config' [host_machine] system = 'windows' 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 1dd5602..4815c64 100644 --- a/inc/eth-std.h +++ b/inc/eth-std.h @@ -3,118 +3,11 @@ /////////////////////////////////////// // -// DEFINES +// TYPEDEFS // ////////////////////////////////////// -#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 - -/////////////////////////////////////// -// -// TYPEDEFS SIGNED/UNSIGNED VECTOR -// -////////////////////////////////////// - -#if defined(_WIN32) && defined(_MSC_VER) -#include -#elif defined(__GNUC__) -typedef signed eth_int_128_t __attribute__ ((vector_size(16))); -typedef signed 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 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 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 eth_uint_128_t __attribute__ ((vector_size(16))); -typedef unsigned 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 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 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))); -#else -#warning "You don't support vector type" -#endif +#include "eth-types.h" /////////////////////////////////////// // @@ -122,10 +15,6 @@ typedef unsigned char eth_uint8_512_t __attribute__ ((vector_size(64) // ////////////////////////////////////// -#ifdef NO_STATIC -void *_eth_memcpy_naive(void *dst, const void *src, size_t size); -#endif - -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..3b55703 --- /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(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))); + +#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 3b940cf..43ca19e 100644 --- a/meson.build +++ b/meson.build @@ -106,17 +106,17 @@ if host_machine.system() == 'windows' else lib_shared = shared_library('etheria-std', srcs, - c_args: ['-nostdlib', '-nodefaultlibs', '-Oz', '-fPIC', '-shared'], + c_args: ['-nostdlib', '-nodefaultlibs', '-Oz', '-fPIC'], install: true, install_dir: 'dist/shared', include_directories: incdir) lib_static = static_library('etheria-std', - srcs, - c_args: ['-nostdlib', '-nodefaultlibs', '-Oz', '-static-pie'], - install: true, - install_dir: 'dist/static', - include_directories: incdir) + srcs, + c_args: ['-nostdlib', '-nodefaultlibs', '-Oz'], + install: true, + install_dir: 'dist/static', + include_directories: incdir) endif From d962c116c3d37719678f35442625f7306d8f62b0 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 13:48:27 +0200 Subject: [PATCH 10/22] add somes test --- Taskfile.yml | 50 +++++++- inc/eth-types.h | 40 +++---- meson.build | 12 +- .../memory/memcpy/memcpy_naive/memcpy_naive.c | 20 ++-- .../memcpy_naive/memcpy_naive_overlap.c | 2 +- .../memcpy_naive_stack_buf_aligned_big.c | 12 +- .../memcpy_naive_stack_buf_aligned_mid.c | 61 +++++----- .../memcpy_naive_stack_buf_aligned_small.c | 100 ++++++++-------- .../memcpy_naive_stack_buf_unaligned_big.c | 78 ++++++++++++ .../memcpy_naive_stack_buf_unaligned_mid.c | 111 ++++++++++++++++++ .../memcpy_naive_stack_buf_unaligned_small.c | 110 +++++++++++++++++ tests/types/types_basic_test.c | 20 ++++ 12 files changed, 494 insertions(+), 122 deletions(-) create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_big.c create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_mid.c create mode 100644 tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_small.c create mode 100644 tests/types/types_basic_test.c diff --git a/Taskfile.yml b/Taskfile.yml index 29778b9..e96d579 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -18,9 +18,29 @@ tasks: - meson setup build --buildtype=release --prefix=$(pwd) - ninja -C build install silent: true - desc: "Build the project" + desc: "Build the project in release build" - compile: + 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." @@ -28,7 +48,17 @@ tasks: - 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" + 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: @@ -37,6 +67,20 @@ tasks: silent: true 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) diff --git a/inc/eth-types.h b/inc/eth-types.h index 3b55703..1526456 100644 --- a/inc/eth-types.h +++ b/inc/eth-types.h @@ -94,11 +94,11 @@ typedef signed int eth_int32_128_t __attribute__ ((vector_size(0x10 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_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; @@ -130,12 +130,12 @@ typedef signed int eth_int32_256_t __attribute__ ((vector_size(0x20 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_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; @@ -173,7 +173,7 @@ typedef signed int eth_int32_512_t __attribute__ ((vector_size(0x40 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; +typedef eth_int_512_t eth_i512_t; #if defined (__BIGGEST_ALIGNMENT__) && __BIGGEST_ALIGNMENT__ >= 0x20 typedef eth_int256_512_t eth_i256_512_t; @@ -185,10 +185,10 @@ 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_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; @@ -244,10 +244,10 @@ typedef unsigned eth_uint_256_t __attribute__ ((vector_size(0x2 typedef unsigned eth_uint128_256_t __attribute__ ((vector_size(0x20), aligned(0x10))); #endif -typedef unsigned 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 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; diff --git a/meson.build b/meson.build index 43ca19e..6ff7d87 100644 --- a/meson.build +++ b/meson.build @@ -57,11 +57,19 @@ srcs = files('src/memory/memcpy/memcpy.c') # ###################################### -tests = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c', + +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_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 summary({ 'CPU': build_machine.cpu(), diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive.c index 50e8269..d9d2b2f 100644 --- a/tests/memory/memcpy/memcpy_naive/memcpy_naive.c +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive.c @@ -13,8 +13,8 @@ Test(memcpy_naive_basic_tests, memcpy_naive_basic_integer_copy) int a = 0x41414141; int b = 0; - cr_assert(_eth_memcpy_naive(&b, &a, sizeof(a)) == &b); - cr_assert(a == b); + cr_expect(_eth_memcpy_naive(&b, &a, sizeof(a)) == &b); + cr_expect(a == b); } Test(memcpy_naive_basic_tests, memcpy_naive_basic_null_dst) @@ -23,12 +23,12 @@ Test(memcpy_naive_basic_tests, memcpy_naive_basic_null_dst) memcpy(buf, "hello", 0x5); - cr_assert(_eth_memcpy_naive(NULL, buf, 0xa) == NULL); + cr_expect(_eth_memcpy_naive(NULL, buf, 0xa) == NULL); } Test(memcpy_naive_basic_tests, memcpy_naive_basic_null) { - cr_assert(_eth_memcpy_naive(NULL, NULL, 0) == NULL); + cr_expect(_eth_memcpy_naive(NULL, NULL, 0) == NULL); } Test(memcpy_naive_basic_tests, memcpy_naive_basic_null_src) @@ -39,8 +39,8 @@ Test(memcpy_naive_basic_tests, memcpy_naive_basic_null_src) memset(buf, 0, sizeof(buf)); memset(cmp, 0, sizeof(cmp)); - cr_assert(_eth_memcpy_naive(buf, NULL, sizeof(buf)) == buf); - cr_assert(!memcmp(buf, cmp, sizeof(buf))); + 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) @@ -51,8 +51,8 @@ Test(memcpy_naive_basic_tests, memcpy_naive_basic_zero_size) memset(buf, 0, sizeof(buf)); memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, 0) == buf); - cr_assert(memcmp(buf, src, 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) @@ -62,8 +62,8 @@ Test(memcpy_naive_basic_tests, memcpy_naive_basic_string) memset(buf, 0, sizeof(buf)); - cr_assert(_eth_memcpy_naive(buf, ptr, strlen(ptr)) == buf); - cr_assert(!memcmp(buf, ptr, strlen(ptr))); + 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) diff --git a/tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c b/tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c index 4dad035..b0a4b59 100644 --- a/tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c +++ b/tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c @@ -12,5 +12,5 @@ Test(memcpy_naive_overlap_test, memcpy_naive_overlap_test) cr_assert(_eth_memcpy_naive(a+2, a, 4) == a+2); - cr_assert(!memcmp(a, "aaaaaadd", 0x8)); + 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 index 7dcfe64..07b1645 100644 --- 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 @@ -21,8 +21,8 @@ Test(memcpy_naive_stack_aligned_big_tests, memcpy_naive_stack_aligned_big_one) memset(src, 'a', 0x100000); - cr_assert(_eth_memcpy_naive(buf, src, 0x100000) == buf); - cr_assert(!memcmp(buf, src, 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); @@ -44,8 +44,8 @@ Test(memcpy_naive_stack_aligned_big_tests, memcpy_naive_stack_aligned_big_two) memset(src, 'a', 0x1000000); - cr_assert(_eth_memcpy_naive(buf, src, 0x1000000) == buf); - cr_assert(!memcmp(buf, src, 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); @@ -67,8 +67,8 @@ Test(memcpy_naive_stack_aligned_big_tests, memcpy_naive_stack_aligned_big_three) memset(src, 'a', 0x10000000); - cr_assert(_eth_memcpy_naive(buf, src, 0x10000000) == buf); - cr_assert(!memcmp(buf, src, 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); 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 index ef6331a..55b1b5c 100644 --- 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 @@ -7,10 +7,10 @@ #include "eth-std.h" -Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_small_one) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_one) { - char buf[0x8]; - char src[0x8]; + char buf[0x200]; + char src[0x200]; memset(src, 'a', sizeof(src)); @@ -18,93 +18,94 @@ Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_small_one) cr_assert(!memcmp(buf, src, sizeof(buf))); } -Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_small_two) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_two) { - char buf[0x10]; - char src[0x10]; + 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_small_three) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_three) { - char buf[0x20]; - char src[0x20]; + 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_small_four) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_four) { - char buf[0x40]; - char src[0x40]; + 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_small_five) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_five) { - char buf[0x50]; - char src[0x50]; + 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_small_six) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_six) { - char buf[0x60]; - char src[0x60]; + 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_small_seven) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_seven) { - char buf[0x70]; - char src[0x70]; + 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_small_eight) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_eight) { - char buf[0x80]; - char src[0x80]; + 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_small_nine) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_nine) { - char buf[0x90]; - char src[0x90]; + 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_small_ten) +Test(memcpy_naive_stack_aligned_mid_tests, memcpy_naive_stack_aligned_mid_ten) { - char buf[0x100]; - char src[0x100]; + 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 index 270b2ff..ffd98f9 100644 --- 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 @@ -7,104 +7,104 @@ #include "eth-std.h" -Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_mid_one) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_one) { - char buf[0x200]; - char src[0x200]; + char buf[0x10]; + char src[0x10]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(buf)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_two) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_two) { - char buf[0x400]; - char src[0x400]; + char buf[0x20]; + char src[0x20]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_three) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_three) { - char buf[0x800]; - char src[0x800]; + char buf[0x30]; + char src[0x30]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_four) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_four) { - char buf[0x1000]; - char src[0x1000]; + char buf[0x40]; + char src[0x40]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_five) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_five) { - char buf[0x2000]; - char src[0x2000]; + char buf[0x50]; + char src[0x50]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_six) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_six) { - char buf[0x4000]; - char src[0x4000]; + char buf[0x60]; + char src[0x60]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_seven) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_seven) { - char buf[0x6000]; - char src[0x6000]; + char buf[0x70]; + char src[0x70]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_eight) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_eight) { - char buf[0x8000]; - char src[0x8000]; + char buf[0x80]; + char src[0x80]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_nine) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_nine) { - char buf[0xFFFF]; - char src[0xFFFF]; + char buf[0x90]; + char src[0x90]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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_mid_ten) +Test(memcpy_naive_stack_aligned_small_tests, memcpy_naive_stack_aligned_small_ten) { - char buf[0x10000]; - char src[0x10000]; + char buf[0x100]; + char src[0x100]; memset(src, 'a', sizeof(src)); - cr_assert(_eth_memcpy_naive(buf, src, sizeof(src)) == buf); - cr_assert(!memcmp(buf, src, sizeof(buf))); + 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); +} From b70dae5d1d483fd9396d837c367ae7eb4259b78f Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 16:11:36 +0200 Subject: [PATCH 11/22] add benchmarks --- Taskfile.yml | 18 +++++- benchmarks/memory/memcpy_naive/memcpy_naive.c | 55 +++++++++++++++++++ meson.build | 32 ++++++++++- meson_options.txt | 1 + 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 benchmarks/memory/memcpy_naive/memcpy_naive.c diff --git a/Taskfile.yml b/Taskfile.yml index e96d579..1e7da9e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -88,12 +88,28 @@ tasks: 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 --verbose + - meson test -C build silent: true desc: "Run tests files" 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/meson.build b/meson.build index 6ff7d87..053b817 100644 --- a/meson.build +++ b/meson.build @@ -71,6 +71,16 @@ memory_memcpy_naive = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c', tests = types_tests + memory_memcpy_naive +###################################### +# +# +# BENCHMARKS +# +# +###################################### + +benchmarks = files('./benchmarks/memory/memcpy_naive/memcpy_naive.c') + summary({ 'CPU': build_machine.cpu(), 'Endian': build_machine.endian(), @@ -140,6 +150,26 @@ foreach test_file : tests install: true, install_dir: 'tests/output/', pie: true) - test(test_name, test_exec) + 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 index e4277cc..7e57b86 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +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') From 528b81634393fda46cace5c19edc54535d2fb2a8 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 21:13:54 +0200 Subject: [PATCH 12/22] update actions --- .github/workflows/build.yml | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4d623e8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,64 @@ +name: Ubuntu-Latest GCC - Build Release + +on: + push: + 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@v1 + with: + version: 3.x + + - uses: actions/setup-python@v5 + with: + cache: 'pip' + + - 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: . From 5df3282beb0b43293feff124e8d0e63837f463b6 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 21:43:22 +0200 Subject: [PATCH 13/22] update add first workflow --- .github/workflows/build.yml | 2 ++ .github/workflows/memcpy_naive_test.yml | 42 +++++++++++++++++++++++++ .github/workflows/types_test.yml | 42 +++++++++++++++++++++++++ meson.build | 3 +- 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/memcpy_naive_test.yml create mode 100644 .github/workflows/types_test.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d623e8..125b374 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,8 @@ name: Ubuntu-Latest GCC - Build Release on: push: branches: ["main"] + pull_request: + branches: ["main"] permissions: contents: write diff --git a/.github/workflows/memcpy_naive_test.yml b/.github/workflows/memcpy_naive_test.yml new file mode 100644 index 0000000..f71a64a --- /dev/null +++ b/.github/workflows/memcpy_naive_test.yml @@ -0,0 +1,42 @@ +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@v1 + with: + version: 3.x + + - uses: actions/setup-python@v5 + with: + cache: 'pip' + + - 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 and run Memcpy Naive tests + run: | + echo "🏗️ Setting up Meson build system..." + task build-tests + echo "🎉 Build completed with Meson!" + 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..385c203 --- /dev/null +++ b/.github/workflows/types_test.yml @@ -0,0 +1,42 @@ +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@v1 + with: + version: 3.x + + - uses: actions/setup-python@v5 + with: + cache: 'pip' + + - 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 and run Memcpy Naive tests + run: | + echo "🏗️ Setting up Meson build system..." + task build-tests + echo "🎉 Build completed with Meson!" + task run-test-suite -- $(task list-tests | grep "test_types") diff --git a/meson.build b/meson.build index 053b817..b4acf64 100644 --- a/meson.build +++ b/meson.build @@ -147,8 +147,7 @@ foreach test_file : tests dependencies: [criterion_dep], link_with: lib_static, include_directories: incdir, - install: true, - install_dir: 'tests/output/', + install: false, pie: true) test(test_name, test_exec, verbose: true) endforeach From 5d2361b9f30680d2cf4d370eac499e069b806ec5 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 21:48:19 +0200 Subject: [PATCH 14/22] update: modify tests actions --- .github/workflows/memcpy_naive_test.yml | 6 +++++- .github/workflows/types_test.yml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/memcpy_naive_test.yml b/.github/workflows/memcpy_naive_test.yml index f71a64a..9ef80bd 100644 --- a/.github/workflows/memcpy_naive_test.yml +++ b/.github/workflows/memcpy_naive_test.yml @@ -34,9 +34,13 @@ jobs: sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc echo "✅ Dependencies installed!" - - name: Build tests and run Memcpy Naive tests + - 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 index 385c203..f0fcd68 100644 --- a/.github/workflows/types_test.yml +++ b/.github/workflows/types_test.yml @@ -34,9 +34,13 @@ jobs: sudo ln -s -f /usr/bin/gcc-12 /usr/bin/gcc echo "✅ Dependencies installed!" - - name: Build tests and run Memcpy Naive tests + - 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") From 5aeea7fbb7252683db696ca0d6ad9293c3c28ca0 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:00:00 +0200 Subject: [PATCH 15/22] add codeQL --- .github/workflows/build.yml | 2 - .github/workflows/codeQL.yml | 58 +++++++++++++++++++++++++ .github/workflows/memcpy_naive_test.yml | 2 - .github/workflows/types_test.yml | 2 - 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/codeQL.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 125b374..cfbbd4b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,8 +30,6 @@ jobs: version: 3.x - uses: actions/setup-python@v5 - with: - cache: 'pip' - name: 🔄 Installing Meson package build system... run: pip install meson diff --git a/.github/workflows/codeQL.yml b/.github/workflows/codeQL.yml new file mode 100644 index 0000000..dbcd121 --- /dev/null +++ b/.github/workflows/codeQL.yml @@ -0,0 +1,58 @@ +name: CodeQL + +on: push + +permissions: + actions: read + contents: read + security-events: write + +jobs: + + analyze: + runs-on: [ubuntu-latest] + + strategy: + fail-fast: false + matrix: + language: ['cpp'] + + 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@v1 + 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 + echo "🎉 Build completed with Meson!" + + - name: Initialize CodeQL + uses: github/codeql-action@v2 + with: + languages: ${{ matrix.language }} + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: ${{ matrix.language }} diff --git a/.github/workflows/memcpy_naive_test.yml b/.github/workflows/memcpy_naive_test.yml index 9ef80bd..ba96f84 100644 --- a/.github/workflows/memcpy_naive_test.yml +++ b/.github/workflows/memcpy_naive_test.yml @@ -20,8 +20,6 @@ jobs: version: 3.x - uses: actions/setup-python@v5 - with: - cache: 'pip' - name: 🔄 Installing Meson package build system... run: pip install meson diff --git a/.github/workflows/types_test.yml b/.github/workflows/types_test.yml index f0fcd68..d30dbca 100644 --- a/.github/workflows/types_test.yml +++ b/.github/workflows/types_test.yml @@ -20,8 +20,6 @@ jobs: version: 3.x - uses: actions/setup-python@v5 - with: - cache: 'pip' - name: 🔄 Installing Meson package build system... run: pip install meson From e9c2a08a2abf93fb599b30412f610085c25ad16c Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:01:03 +0200 Subject: [PATCH 16/22] add codeQL --- .github/workflows/codeQL.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeQL.yml b/.github/workflows/codeQL.yml index dbcd121..2903a23 100644 --- a/.github/workflows/codeQL.yml +++ b/.github/workflows/codeQL.yml @@ -48,7 +48,7 @@ jobs: echo "🎉 Build completed with Meson!" - name: Initialize CodeQL - uses: github/codeql-action@v2 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} From 61af36a385d7ff178e8b23729d8d3d4c72858763 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:08:01 +0200 Subject: [PATCH 17/22] add codeQL --- .github/workflows/codeQL.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeQL.yml b/.github/workflows/codeQL.yml index 2903a23..69ddf62 100644 --- a/.github/workflows/codeQL.yml +++ b/.github/workflows/codeQL.yml @@ -15,7 +15,8 @@ jobs: strategy: fail-fast: false matrix: - language: ['cpp'] + - language: c-cpp + build-mode: manual steps: - name: Checkout repository ${{ github.repository }} on a branch ${{ github.ref_name }} triggered by ${{ github.event_name }} @@ -48,11 +49,11 @@ jobs: echo "🎉 Build completed with Meson!" - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 with: category: ${{ matrix.language }} From a1e7bbca0c982ee49dd471ee09278e993491565d Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:09:08 +0200 Subject: [PATCH 18/22] add codeQL --- .github/workflows/codeQL.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeQL.yml b/.github/workflows/codeQL.yml index 69ddf62..f8b9b6c 100644 --- a/.github/workflows/codeQL.yml +++ b/.github/workflows/codeQL.yml @@ -15,8 +15,9 @@ jobs: strategy: fail-fast: false matrix: - - language: c-cpp - build-mode: manual + include: + - language: c-cpp + build-mode: manual steps: - name: Checkout repository ${{ github.repository }} on a branch ${{ github.ref_name }} triggered by ${{ github.event_name }} From d262e6f61f6582936a646bbe6d7cc46f54ed82f5 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:12:30 +0200 Subject: [PATCH 19/22] add codeQL --- .github/workflows/codeQL.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeQL.yml b/.github/workflows/codeQL.yml index f8b9b6c..f4ad395 100644 --- a/.github/workflows/codeQL.yml +++ b/.github/workflows/codeQL.yml @@ -43,17 +43,18 @@ jobs: 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 - echo "🎉 Build completed with Meson!" - 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: From 26066788950be62ecdd513b42fde0d965bcd5aad Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:17:12 +0200 Subject: [PATCH 20/22] update all workflows --- .github/workflows/build.yml | 2 +- .github/workflows/codeQL.yml | 2 +- .github/workflows/memcpy_naive_test.yml | 2 +- .github/workflows/types_test.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cfbbd4b..94838d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: - run: "echo the ${{ github.repository }} has been cloned in the container !" - name: 🔄 Installing task... - uses: arduino/setup-task@v1 + uses: arduino/setup-task@v2 with: version: 3.x diff --git a/.github/workflows/codeQL.yml b/.github/workflows/codeQL.yml index f4ad395..ad7f9c3 100644 --- a/.github/workflows/codeQL.yml +++ b/.github/workflows/codeQL.yml @@ -26,7 +26,7 @@ jobs: - run: "echo the ${{ github.repository }} has been cloned in the container !" - name: 🔄 Installing task... - uses: arduino/setup-task@v1 + uses: arduino/setup-task@v2 with: version: 3.x diff --git a/.github/workflows/memcpy_naive_test.yml b/.github/workflows/memcpy_naive_test.yml index ba96f84..02f0514 100644 --- a/.github/workflows/memcpy_naive_test.yml +++ b/.github/workflows/memcpy_naive_test.yml @@ -15,7 +15,7 @@ jobs: - run: "echo the ${{ github.repository }} has been cloned in the container !" - name: 🔄 Installing task... - uses: arduino/setup-task@v1 + uses: arduino/setup-task@v2 with: version: 3.x diff --git a/.github/workflows/types_test.yml b/.github/workflows/types_test.yml index d30dbca..464a056 100644 --- a/.github/workflows/types_test.yml +++ b/.github/workflows/types_test.yml @@ -15,7 +15,7 @@ jobs: - run: "echo the ${{ github.repository }} has been cloned in the container !" - name: 🔄 Installing task... - uses: arduino/setup-task@v1 + uses: arduino/setup-task@v2 with: version: 3.x From 76f33a46660cef787995f56cc7eaf3dd9b63ac87 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:49:50 +0200 Subject: [PATCH 21/22] update taskfile --- Taskfile.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Taskfile.yml b/Taskfile.yml index 1e7da9e..071b11f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -40,6 +40,16 @@ tasks: silent: true desc: "Build the project in dev build" + build-msvc: + 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-file ./cross/x86_64/windows/x86_64-msvc.txt build_vs --vsenv --buildtype=release --prefix=$(pwd) + - ninja -C build_vs install + silent: true + desc: "Build the project with MSVC in build" + cross-build: preconditions: - sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}' From 3970006291d2a5814e361c824558c9d247c460ff Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Sun, 26 May 2024 22:58:52 +0200 Subject: [PATCH 22/22] update --- Taskfile.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 071b11f..1e7da9e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -40,16 +40,6 @@ tasks: silent: true desc: "Build the project in dev build" - build-msvc: - 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-file ./cross/x86_64/windows/x86_64-msvc.txt build_vs --vsenv --buildtype=release --prefix=$(pwd) - - ninja -C build_vs install - silent: true - desc: "Build the project with MSVC in build" - cross-build: preconditions: - sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}'