Skip to content

Commit 8605f97

Browse files
committed
windows tests
1 parent d1cab76 commit 8605f97

2 files changed

Lines changed: 63 additions & 5 deletions

File tree

open-codegen/opengen/tcp/optimizer_tcp_manager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,16 @@ def __load_tcp_details(self):
9191
with open(yaml_file, 'r') as stream:
9292
self.__optimizer_details = yaml.safe_load(stream)
9393

94+
@staticmethod
95+
def __client_ip_for_connection(ip):
96+
# `0.0.0.0` is a valid bind address for the server, but it is not a
97+
# routable destination for a client connection on Windows.
98+
return '127.0.0.1' if ip == '0.0.0.0' else ip
99+
94100
@retry(tries=10, delay=1)
95101
def __obtain_socket_connection(self):
96102
tcp_data = self.__optimizer_details
97-
ip = tcp_data['tcp']['ip']
103+
ip = self.__client_ip_for_connection(tcp_data['tcp']['ip'])
98104
port = tcp_data['tcp']['port']
99105
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
100106
try:
@@ -132,7 +138,7 @@ def ping(self):
132138

133139
def __check_if_server_is_running(self):
134140
tcp_data = self.__optimizer_details
135-
ip = tcp_data['tcp']['ip']
141+
ip = self.__client_ip_for_connection(tcp_data['tcp']['ip'])
136142
port = tcp_data['tcp']['port']
137143
with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as s:
138144
result = 0 == s.connect_ex((ip, port))

open-codegen/test/test.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,54 @@ def rebuild_generated_staticlib(optimizer_name):
821821

822822
@staticmethod
823823
def c_bindings_helper(optimizer_name):
824+
if sys.platform == "win32":
825+
result = RustBuildTestCase.c_bindings_cmake_helper(
826+
optimizer_name=optimizer_name,
827+
build_dir_name="cmake-build-run")
828+
compile_stdout = result["configure_stdout"] + result["build_stdout"]
829+
compile_stderr = result["configure_stderr"] + result["build_stderr"]
830+
compile_returncode = (
831+
result["configure_returncode"]
832+
if result["configure_returncode"] != 0
833+
else result["build_returncode"]
834+
)
835+
836+
run_stdout = ""
837+
run_stderr = ""
838+
run_returncode = None
839+
if compile_returncode == 0:
840+
executable_candidates = [
841+
os.path.join(result["build_dir"], "Debug", "optimizer.exe"),
842+
os.path.join(result["build_dir"], "optimizer.exe"),
843+
os.path.join(result["build_dir"], "Debug", "optimizer"),
844+
os.path.join(result["build_dir"], "optimizer"),
845+
]
846+
executable_path = next(
847+
(candidate for candidate in executable_candidates if os.path.exists(candidate)),
848+
None,
849+
)
850+
if executable_path is None:
851+
raise RuntimeError("Could not locate built optimizer executable")
852+
853+
run_process = subprocess.Popen(
854+
[executable_path],
855+
stdout=subprocess.PIPE,
856+
stderr=subprocess.PIPE,
857+
)
858+
run_stdout_bytes, run_stderr_bytes = run_process.communicate()
859+
run_stdout = run_stdout_bytes.decode()
860+
run_stderr = run_stderr_bytes.decode()
861+
run_returncode = run_process.returncode
862+
863+
return {
864+
"compile_returncode": compile_returncode,
865+
"compile_stdout": compile_stdout,
866+
"compile_stderr": compile_stderr,
867+
"run_returncode": run_returncode,
868+
"run_stdout": run_stdout,
869+
"run_stderr": run_stderr,
870+
}
871+
824872
compile_process = subprocess.Popen(
825873
["/usr/bin/gcc",
826874
RustBuildTestCase.TEST_DIR + "/" + optimizer_name + "/example_optimizer.c",
@@ -880,13 +928,13 @@ def patch_c_bindings_example_parameter_initializer(optimizer_name, replacement_l
880928
return original_line
881929

882930
@staticmethod
883-
def c_bindings_cmake_helper(optimizer_name):
931+
def c_bindings_cmake_helper(optimizer_name, build_dir_name="cmake-build-test"):
884932
cmake_executable = shutil.which("cmake")
885933
if cmake_executable is None:
886934
raise unittest.SkipTest("cmake is not available in PATH")
887935

888936
optimizer_dir = os.path.join(RustBuildTestCase.TEST_DIR, optimizer_name)
889-
build_dir = os.path.join(optimizer_dir, "cmake-build-test")
937+
build_dir = os.path.join(optimizer_dir, build_dir_name)
890938
if os.path.isdir(build_dir):
891939
shutil.rmtree(build_dir)
892940
os.makedirs(build_dir)
@@ -903,8 +951,11 @@ def c_bindings_cmake_helper(optimizer_name):
903951
build_stderr = b""
904952
build_returncode = None
905953
if configure_process.returncode == 0:
954+
build_command = [cmake_executable, "--build", "."]
955+
if sys.platform == "win32":
956+
build_command.extend(["--config", "Debug"])
906957
build_process = subprocess.Popen(
907-
[cmake_executable, "--build", "."],
958+
build_command,
908959
cwd=build_dir,
909960
stdout=subprocess.PIPE,
910961
stderr=subprocess.PIPE,
@@ -919,6 +970,7 @@ def c_bindings_cmake_helper(optimizer_name):
919970
"build_returncode": build_returncode,
920971
"build_stdout": build_stdout.decode(),
921972
"build_stderr": build_stderr.decode(),
973+
"build_dir": build_dir,
922974
}
923975

924976
def test_c_bindings(self):

0 commit comments

Comments
 (0)