Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/asciidoctor-ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
runs-on: ${{ github.repository_owner == 'intel' && 'intel-' || '' }}ubuntu-24.04
steps:
- name: Checkout source
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
Expand Down
31 changes: 26 additions & 5 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ jobs:
- name: Install build tools
run: |
${{ matrix.install }}
sudo apt install -y ninja-build
sudo apt install -y ninja-build python3-venv python3-pip
python3 -m venv ${{github.workspace}}/test_venv
source ${{github.workspace}}/test_venv/bin/activate
pip install -r ${{github.workspace}}/requirements.txt
echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH


- name: Restore CPM cache
env:
Expand Down Expand Up @@ -177,7 +182,11 @@ jobs:
- name: Install build tools
run: |
${{ matrix.install }}
sudo apt install -y ninja-build
sudo apt install -y ninja-build python3-venv python3-pip
python3 -m venv ${{github.workspace}}/test_venv
source ${{github.workspace}}/test_venv/bin/activate
pip install -r ${{github.workspace}}/requirements.txt
echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH

- name: Restore CPM cache
env:
Expand Down Expand Up @@ -292,7 +301,11 @@ jobs:
- name: Install build tools
run: |
${{ matrix.install }}
sudo apt install -y ninja-build
sudo apt install -y ninja-build python3-venv python3-pip
python3 -m venv ${{github.workspace}}/test_venv
source ${{github.workspace}}/test_venv/bin/activate
pip install -r ${{github.workspace}}/requirements.txt
echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH

- name: Restore CPM cache
env:
Expand Down Expand Up @@ -338,7 +351,11 @@ jobs:

- name: Install build tools
run: |
sudo apt update && sudo apt install -y gcc-${{env.DEFAULT_GCC_VERSION}} g++-${{env.DEFAULT_GCC_VERSION}} ninja-build valgrind
sudo apt update && sudo apt install -y gcc-${{env.DEFAULT_GCC_VERSION}} g++-${{env.DEFAULT_GCC_VERSION}} ninja-build valgrind python3-venv python3-pip
python3 -m venv ${{github.workspace}}/test_venv
source ${{github.workspace}}/test_venv/bin/activate
pip install -r ${{github.workspace}}/requirements.txt
echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH

- name: Restore CPM cache
env:
Expand Down Expand Up @@ -409,7 +426,11 @@ jobs:

- name: Install build tools
run: |
sudo apt update && sudo apt install -y clang-${{env.MULL_LLVM_VERSION}} ninja-build
sudo apt update && sudo apt install -y clang-${{env.MULL_LLVM_VERSION}} ninja-build python3-venv python3-pip
python3 -m venv ${{github.workspace}}/test_venv
source ${{github.workspace}}/test_venv/bin/activate
pip install -r ${{github.workspace}}/requirements.txt
echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH

- name: Install mull
env:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
.cmake-format.yaml
CMakePresets.json
/toolchains
__pycache__
.mypy_cache
.pytest_cache
.hypothesis
20 changes: 10 additions & 10 deletions include/stdx/tuple_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,16 @@ template <tuplelike... Ts> constexpr auto cartesian_product_copy(Ts &&...ts) {
return []<typename First, typename... Rest>(First &&first,
Rest &&...rest) {
auto const c = cartesian_product_copy(std::forward<Rest>(rest)...);
return std::forward<First>(first).apply(
[&]<typename... Elems>(Elems &&...elems) {
auto const prepend = [&]<typename E>(E &&e) {
return c.apply([&](auto... subs) {
return make_tuple(tuple_cat(
make_tuple(std::forward<E>(e)), subs)...);
});
};
return tuple_cat(prepend(std::forward<Elems>(elems))...);
});
return std::forward<First>(first).apply([&]<typename... Elems>(
Elems &&...elems) {
[[maybe_unused]] auto const prepend = [&]<typename E>(E &&e) {
return c.apply([&](auto... subs) {
return make_tuple(
tuple_cat(make_tuple(std::forward<E>(e)), subs)...);
});
};
return tuple_cat(prepend(std::forward<Elems>(elems))...);
});
}(std::forward<Ts>(ts)...);
}
}
Expand Down
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pytest==8.3.3
pytest-forked==1.6.0
pytest-xdist==3.6.1
hypothesis==6.112.5
attrs==24.2.0
execnet==2.1.1
pluggy==1.5.0
sortedcontainers==2.4.0
iniconfig==2.0.0
packaging==24.1
py==1.11.0
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 20)
endif()

add_subdirectory(fail)
add_subdirectory(pbt)
16 changes: 16 additions & 0 deletions test/pbt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 20)
add_executable(pbt_prototype_driver EXCLUDE_FROM_ALL
pbt_prototype_driver.cpp)
target_link_libraries(pbt_prototype_driver PUBLIC sanitizers warnings stdx)

add_unit_test(
tuple
PYTEST
FILES
tuple.py
EXTRA_ARGS
-vv
-n2
--compile-commands=${CMAKE_BINARY_DIR}/compile_commands.json
--prototype-driver=${CMAKE_CURRENT_SOURCE_DIR}/pbt_prototype_driver.cpp)
endif()
98 changes: 98 additions & 0 deletions test/pbt/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import pytest
import hypothesis
import json
import subprocess
import tempfile
import os
import re

hypothesis.settings.register_profile("ci", max_examples=500)
hypothesis.settings.register_profile("fast", max_examples=10)



def pytest_addoption(parser):
parser.addoption("--compiler", action="store", help="C++ compiler", default=None, required=False)
parser.addoption("--compiler-args", action="store", help="C++ compiler arguments", default="", required=False)
parser.addoption("--includes", action="store", help="C++ include directories", default="", required=False)

parser.addoption("--compile-commands", action="store", help="cmake compiler commands", default=None, required=False)
parser.addoption("--prototype-driver", action="store", help="Prototype .cpp filename to gather compilation command from", default=None, required=False)

@pytest.fixture(scope="module")
def cmake_compilation_command(pytestconfig):
compile_commands_filename = pytestconfig.getoption("compile_commands")
prototype_driver_filename = pytestconfig.getoption("prototype_driver")

if compile_commands_filename is None or prototype_driver_filename is None:
return None

def f(filename):
with open(compile_commands_filename, "r") as f:
db = json.load(f)
for obj in db:
if obj["file"] == prototype_driver_filename:
cmd = obj["command"]
cmd = cmd.replace(prototype_driver_filename, filename)
cmd = re.sub(r"-o .*?\.cpp\.o", f"-o {filename}.o", cmd)
return cmd.split(" ")

return f

@pytest.fixture(scope="module")
def args_compilation_command(pytestconfig):
compiler = pytestconfig.getoption("compiler")
if compiler is None:
return None

include_dirs = [f"-I{i}" for i in pytestconfig.getoption("includes").split(",") if i]
compiler_args = [i for i in pytestconfig.getoption("compiler_args").split(",") if i]

def f(filename):
compile_command = [
compiler, temp_cpp_file_path,
"-o", temp_cpp_file_path + ".o"
] + compiler_args + include_args
return compile_command

return f



@pytest.fixture(scope="module")
def compile(cmake_compilation_command, args_compilation_command):
cmd = cmake_compilation_command
if cmd is None:
cmd = args_compilation_command

def f(code_str):
code_str += "\n"
with tempfile.NamedTemporaryFile(delete=False, suffix=".cpp") as temp_cpp_file:
temp_cpp_file.write(code_str.encode('utf-8'))
temp_cpp_file_path = temp_cpp_file.name

try:
compile_command = cmd(temp_cpp_file_path)
result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if result.returncode == 0:
return True
else:
error_message = (
f"Compiler returned non-zero exit code: {result.returncode}\n"
f"Compilation command: {' '.join(compile_command)}\n"
f"Source code:\n{code_str}\n"
f"Compiler stderr:\n{result.stderr.decode('utf-8')}\n"
f"Compiler stdout:\n{result.stdout.decode('utf-8')}\n"
)
pytest.fail(error_message)

except Exception as e:
pytest.fail(str(e))
finally:
os.remove(temp_cpp_file_path)
if os.path.exists(temp_cpp_file_path + ".out"):
os.remove(temp_cpp_file_path + ".out")

return f

1 change: 1 addition & 0 deletions test/pbt/pbt_prototype_driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int main() {}
Loading