Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/tracirunner.py
428236 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2026 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file tracirunner.py
15
# @author Friedemann Wesner
16
# @author Michael Behrisch
17
# @author Jakob Erdmann
18
# @date 2008-05-12
19
20
from __future__ import absolute_import
21
from __future__ import print_function
22
23
import os
24
import subprocess
25
import sys
26
import time
27
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
28
sys.path.append(os.path.join(THIS_DIR, '..', "tools"))
29
import sumolib # noqa
30
31
PORT = str(sumolib.miscutils.getFreeSocketPort())
32
server_args = sys.argv[1:] + ["--remote-port", PORT]
33
binaryDir, server = os.path.split(server_args[0])
34
35
client = "TraCITestClient"
36
if server.endswith("D") or server.endswith("D.exe"):
37
client += "D"
38
client_args = [os.path.join(binaryDir, client), "-def",
39
"testclient.prog", "-o", "testclient_out.txt", "-p", PORT]
40
41
# start sumo as server
42
serverProcess = subprocess.Popen(
43
server_args, stdout=sys.stdout, stderr=sys.stderr)
44
success = False
45
for retry in range(10):
46
time.sleep(retry * 0.1)
47
clientProcess = subprocess.Popen(
48
client_args, stdout=sys.stdout, stderr=sys.stderr)
49
if serverProcess.poll() is not None and clientProcess.poll() is None:
50
# the server is already through (either with error or success), let the client catch up
51
time.sleep(10)
52
if serverProcess.poll() is not None and clientProcess.poll() is None:
53
print("Client hangs but server terminated for unknown reason", file=sys.stderr)
54
clientProcess.kill()
55
break
56
result = clientProcess.wait()
57
if result == 0:
58
success = True
59
if result != 2:
60
break
61
62
if success:
63
serverProcess.wait()
64
else:
65
if serverProcess.poll() is None:
66
print("Server hangs and does not answer connection requests", file=sys.stderr)
67
serverProcess.kill()
68
69