MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / run_single_test_instance

Function run_single_test_instance

run_tests.py:93–132  ·  view source on GitHub ↗

Run a single instance of a test executable with specific arguments.

(executable, args, output_file, global_args, run_description)

Source from the content-addressed store, hash-verified

91 return executables
92
93def run_single_test_instance(executable, args, output_file, global_args, run_description):
94 """Run a single instance of a test executable with specific arguments."""
95 exe_path = str(executable)
96 exe_name = executable.name
97
98 safe_print(f"Starting {exe_name} {run_description}")
99
100 try:
101 cmd = [f"./{exe_name}"]
102 cmd.extend(args)
103 if global_args:
104 cmd.extend(global_args)
105
106 safe_print(f" Command ({exe_name} {run_description}): {' '.join(cmd)}")
107
108 # Run the executable in its own directory using cwd
109 with open(output_file, 'w') as f:
110 result = subprocess.run(
111 cmd,
112 stdout=f,
113 stderr=subprocess.STDOUT,
114 timeout=300, # 5 minute timeout
115 cwd=os.path.dirname(exe_path) # Execute in the executable's directory
116 )
117
118 if result.returncode == 0:
119 status = "Passed"
120 elif result.returncode == EXIT_WAIVED:
121 status = "Waived"
122 else:
123 status = "Failed"
124 safe_print(f" Finished {exe_name} {run_description}: {status} (code {result.returncode})")
125 return {"name": exe_name, "description": run_description, "return_code": result.returncode, "status": status}
126
127 except subprocess.TimeoutExpired:
128 safe_print(f"Error ({exe_name} {run_description}): Timed out after 5 minutes")
129 return {"name": exe_name, "description": run_description, "return_code": -1, "status": "Timeout"}
130 except Exception as e:
131 safe_print(f"Error running {exe_name} {run_description}: {str(e)}")
132 return {"name": exe_name, "description": run_description, "return_code": -1, "status": f"Error: {str(e)}"}
133
134def get_gpu_count():
135 """Return the number of NVIDIA GPUs visible on the system.

Callers

nothing calls this directly

Calls 1

safe_printFunction · 0.85

Tested by

no test coverage detected