Skip to content

[Windows] Parse yaml functions are reliant on .py file associations for _gentest.py files #535

@ScottTodd

Description

@ScottTodd

See this search query: https://github.com/search?q=repo%3AROCm%2Frocm-libraries+%2Fexepath.*_gentest.py%2F&type=code, with these current results:

These translate to calls like system("/path/to/directory/foo_gentest.py --template ...)", which treat the .py files as executables. On Linux, the shebangs in the scripts handle running under the python interpreter (usually the system interpreter, so this may escape venv sandboxes?). On Windows, this relies on file associations for the .py extension.

On my developer machine, I have .py files associated with Visual Studio Code, rather than the python interpreter:

Image

This results in running test commands like rocblas-test.exe --yaml rocblas_smoke.yaml pausing during execution to open the gentest file in my editor, instead of running it.

One way to make this more robust is adding python to the command strings. I had a patch for that on ROCm/TheRock#783, like so:

 clients/common/rocblas_parse_data.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/clients/common/rocblas_parse_data.cpp b/clients/common/rocblas_parse_data.cpp
index 83039751..399a709f 100644
--- a/clients/common/rocblas_parse_data.cpp
+++ b/clients/common/rocblas_parse_data.cpp
@@ -47,15 +47,20 @@ static std::string rocblas_parse_yaml(const std::string& yaml)
         yaml_path = yaml;
     }

-    auto cmd = exepath + "rocblas_gentest.py --template " + exepath + "rocblas_template.yaml -o "
+#ifdef WIN32
+    // Windows prefers to only run certain file extensions as executables, so run under 'python'.
+    auto cmd = "python " + exepath + "rocblas_gentest.py --template " + exepath + "rocblas_template.yaml -o "
                + tmp + " " + yaml_path;
     rocblas_cerr << cmd << std::endl;
-
-#ifdef WIN32
     int status = std::system(cmd.c_str());
     if(status == -1)
         exit(EXIT_FAILURE);
 #else
+    // Linux can run the python script directly thanks to the `#!/usr/bin/env python3` shebang.
+    // If we ran 'python' as above, we might fail unless python-is-python3 (or equivalent) is configured.
+    auto cmd = exepath + "rocblas_gentest.py --template " + exepath + "rocblas_template.yaml -o "
+               + tmp + " " + yaml_path;
+    rocblas_cerr << cmd << std::endl;
     int status = system(cmd.c_str());
     if(status == -1 || !WIFEXITED(status) || WEXITSTATUS(status))
         exit(EXIT_FAILURE);
-- 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions