Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT, TST: printf spam in test suite output #132

Open
tylerjereddy opened this issue Dec 9, 2022 · 0 comments
Open

MAINT, TST: printf spam in test suite output #132

tylerjereddy opened this issue Dec 9, 2022 · 0 comments

Comments

@tylerjereddy
Copy link
Contributor

Mostly just an annoyance, but we should clean it up eventually. When you run python runtests.py it will spam a bunch of printf 50 times after the test suite summary output, with this line showing up over and over:

Testing printf: 7

The stdout spam comes from this test: tests/test_AST_translator.py::TestASTTranslator::test_call. I tried a number of ways to suppress or intercept the stream with pytest, but it was hopeless, I think because it is coming from compiled Kokkos/C++ stuff in other threads. Normal Python prints are easy to intercept and assert on with pytest using i.e., capsys fixtures.

In the absence of that option, perhaps we could support stream redirection. This is a bit of a hack below, but an improved version may work? Even just the hack version reduces the number of visible prints from 50 to 1, though I don't yet know how to assert on them b/c they don't show up in that file locally. Probably thread-related or something. Perhaps that's enough of a hint to give a C++/Kokkos guru a better idea.

diff --git a/pykokkos/core/translators/symbols_pass.py b/pykokkos/core/translators/symbols_pass.py
index be7acd5..0d503a2 100644
--- a/pykokkos/core/translators/symbols_pass.py
+++ b/pykokkos/core/translators/symbols_pass.py
@@ -115,6 +115,8 @@ class SymbolsPass:
             elif isinstance(node, ast.FunctionDef):
                 if self.is_nested_call(node):
                     symbols.add(node.name)
+        symbols.add("freopen")
+        symbols.add("stdout")
 
         return symbols
 
diff --git a/pykokkos/core/visitors/visitors_util.py b/pykokkos/core/visitors/visitors_util.py
index 8f2b7d4..07ec300 100644
--- a/pykokkos/core/visitors/visitors_util.py
+++ b/pykokkos/core/visitors/visitors_util.py
@@ -111,6 +111,7 @@ math_functions: Set = {
     "tanh",
     "trunc",
     "nan",
+    "freopen",
 }
 
 math_constants: Dict[str, str] = {
diff --git a/tests/test_AST_translator.py b/tests/test_AST_translator.py
index ed4efd4..5dfef14 100644
--- a/tests/test_AST_translator.py
+++ b/tests/test_AST_translator.py
@@ -112,6 +112,7 @@ class ASTTestReduceFunctor:
 
     @pk.workunit
     def call(self, tid: int, acc: pk.Acc[pk.double]) -> None:
+        freopen("temp.txt", "w", stdout);
         pk.printf("Testing printf: %d\n", self.i_1)
         acc += abs(- self.i_1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant