Skip to content

Commit

Permalink
Add regression test for recursive iterator (#1981)
Browse files Browse the repository at this point in the history
Test plan:
```
% pip install torch==2.4.0; python test/check_binary_symbols.py 
lib: /home/nshulga/miniconda3/envs/py310-torch/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so
num_cxx11_symbols: 0
num_pre_cxx11_symbols: 1966
Traceback (most recent call last):
  File "/home/nshulga/git/pytorch/builder/test/check_binary_symbols.py", line 97, in <module>
    main()
  File "/home/nshulga/git/pytorch/builder/test/check_binary_symbols.py", line 93, in main
    check_lib_symbols_for_abi_correctness(libtorch_cpu_path, pre_cxx11_abi)
  File "/home/nshulga/git/pytorch/builder/test/check_binary_symbols.py", line 78, in check_lib_symbols_for_abi_correctness
    raise RuntimeError(f"Found use of recursive_directory_iterator in pre-CXX11 binaries, see; {rec_iter_symbols}")
RuntimeError: Found use of recursive_directory_iterator in pre-CXX11 binaries, see; ['std::filesystem::recursive_directory_iterator::recursion_pending() const', 'std::filesystem::recursive_directory_iterator::depth() const', 'std::filesystem::recursive_directory_iterator::options() const', 'std::filesystem::recursive_directory_iterator::operator*() const', 'std::filesystem::recursive_directory_iterator::disable_recursion_pending()', 'std::filesystem::recursive_directory_iterator::pop(std::error_code&)', 'std::filesystem::recursive_directory_iterator::pop()', 'std::filesystem::recursive_directory_iterator::pop() [clone .cold]', 'std::filesystem::recursive_directory_iterator::increment(std::error_code&)', 'std::filesystem::recursive_directory_iterator::increment(std::error_code&) [clone .cold]', 'std::filesystem::recursive_directory_iterator::recursive_directory_iterator(std::filesystem::path const&, std::filesystem::directory_options, std::error_code*)', 'std::filesystem::recursive_directory_iterator::recursive_directory_iterator(std::filesystem::path const&, std::filesystem::directory_options, std::error_code*)', 'std::filesystem::recursive_directory_iterator::recursive_directory_iterator(std::filesystem::path const&, std::filesystem::directory_options, std::error_code*) [clone .cold]', 'std::filesystem::recursive_directory_iterator::~recursive_directory_iterator()', 'std::filesystem::recursive_directory_iterator::~recursive_directory_iterator()', 'std::filesystem::recursive_directory_iterator::operator=(std::filesystem::recursive_directory_iterator&&)', 'std::filesystem::recursive_directory_iterator::operator=(std::filesystem::recursive_directory_iterator const&)', 'std::filesystem::recursive_directory_iterator::operator++()', 'std::filesystem::recursive_directory_iterator::operator++() [clone .cold]']
```


Fixes pytorch/pytorch#133437
  • Loading branch information
malfet committed Sep 7, 2024
1 parent 7ea3d75 commit bc03cdf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/check_binary_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _grep_symbols(symbols: List[Tuple[str, str, str]], patterns: List[Any]) -> L
tasks = [executor.submit(_grep_symbols, all_symbols[i * chunk_size : (i + 1) * chunk_size], patterns) for i in range(num_workers)]
return sum((x.result() for x in tasks), [])


def check_lib_symbols_for_abi_correctness(lib: str, pre_cxx11_abi: bool = True) -> None:
print(f"lib: {lib}")
cxx11_symbols = grep_symbols(lib, LIBTORCH_CXX11_PATTERNS)
Expand All @@ -71,12 +72,17 @@ def check_lib_symbols_for_abi_correctness(lib: str, pre_cxx11_abi: bool = True)
raise RuntimeError(f"Found cxx11 symbols, but there shouldn't be any, see: {cxx11_symbols[:100]}")
if num_pre_cxx11_symbols < 1000:
raise RuntimeError("Didn't find enough pre-cxx11 symbols.")
# Check for no recursive iterators, regression test for https://github.com/pytorch/pytorch/issues/133437
rec_iter_symbols = grep_symbols(lib, [re.compile("std::filesystem::recursive_directory_iterator.*")])
if len(rec_iter_symbols) > 0:
raise RuntimeError(f"Found use of recursive_directory_iterator in pre-CXX11 binaries, see; {rec_iter_symbols}")
else:
if num_pre_cxx11_symbols > 0:
raise RuntimeError(f"Found pre-cxx11 symbols, but there shouldn't be any, see: {pre_cxx11_symbols[:100]}")
if num_cxx11_symbols < 100:
raise RuntimeError("Didn't find enought cxx11 symbols")


def main() -> None:
if os.getenv("PACKAGE_TYPE") == "libtorch":
install_root = Path(os.getcwd())
Expand Down

0 comments on commit bc03cdf

Please sign in to comment.