diff --git a/tests/fixtures/compiler/cpp_17.cu b/tests/fixtures/compiler/cpp_17.cu new file mode 100644 index 0000000..6aedd6f --- /dev/null +++ b/tests/fixtures/compiler/cpp_17.cu @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include + +#include + +struct S { + int n; + std::string s; + float d; + bool operator<(const S& rhs) const + { + // compares n to rhs.n, + // then s to rhs.s, + // then d to rhs.d + return std::tie(n, s, d) < std::tie(rhs.n, rhs.s, rhs.d); + } +}; + +int main() +{ + std::set mySet; + + // pre C++17: + { + S value{42, "Test", 3.14}; + std::set::iterator iter; + bool inserted; + + // unpacks the return val of insert into iter and inserted + std::tie(iter, inserted) = mySet.insert(value); + + if (inserted) + std::cout << "Value was inserted\n"; + } + + // with C++17: + { + S value{100, "abc", 100.0}; + const auto [iter, inserted] = mySet.insert(value); + + if (inserted) + std::cout << "Value(" << iter->n << ", " << iter->s << ", ...) was inserted" << "\n"; + } +} diff --git a/tests/fixtures/fixtures.py b/tests/fixtures/fixtures.py index 93b88fb..a1d4e17 100644 --- a/tests/fixtures/fixtures.py +++ b/tests/fixtures/fixtures.py @@ -27,10 +27,15 @@ def fixtures_path(tests_path): return os.path.join(tests_path, "fixtures") +@pytest.fixture(scope="session") +def compiler_cpp_17_fpath(fixtures_path: str): + return os.path.join(fixtures_path, "compiler", "cpp_17.cu") + + @pytest.fixture(scope="session") def sample_magic_cu_line(): # fmt: off - return '--profile --profiler-args "--metrics l1tex__t_sectors_pipe_lsu_mem_global_op_ld.sum"' # noqa: E501 + return '--profile --profiler-args "--metrics l1tex__t_sectors_pipe_lsu_mem_global_op_ld.sum" --compiler-args "--optimize 3"' # noqa: E501 # fmt: on diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 05d340e..2d6dbcb 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -3,6 +3,7 @@ import math import os import re import shutil +import subprocess from typing import List import pytest @@ -88,6 +89,21 @@ def test_compile( plugin._compile(gname) +def test_compile_args( + plugin: NVCCPlugin, + compiler_cpp_17_fpath: str, +): + gname = "test_compile_args" + copy_source_to_group(compiler_cpp_17_fpath, gname, plugin.workdir) + + exec_fpath = plugin._compile(gname, compiler_args="--std c++17") + assert os.path.exists(exec_fpath) + + # should fail due to the source file having c++ 17 features + with pytest.raises(subprocess.CalledProcessError): + exec_fpath = plugin._compile(gname, compiler_args="--std c++14") + + def test_run( plugin: NVCCPlugin, sample_cuda_fpath: str, @@ -143,7 +159,10 @@ def test_compile_and_run_multiple_files( for fpath in multiple_source_fpaths: copy_source_to_group(fpath, gname, plugin.workdir) output = plugin._compile_and_run( - gname, argparse.Namespace(timeit=False, profile=True, profiler_args="") + group_name=gname, + args=argparse.Namespace( + timeit=False, profile=True, profiler_args="", compiler_args="" + ), ) check_profiler_output(output) @@ -165,7 +184,10 @@ def test_compile_and_run_multiple_files_shared( else: copy_source_to_group(fpath, "shared", plugin.workdir) output = plugin._compile_and_run( - gname, argparse.Namespace(timeit=False, profile=True, profiler_args="") + group_name=gname, + args=argparse.Namespace( + timeit=False, profile=True, profiler_args="", compiler_args="" + ), ) check_profiler_output(output)