Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/broken_nets/runner.py
169678 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 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 runner.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2007-10-25
18
19
from __future__ import absolute_import
20
from __future__ import print_function
21
22
import os
23
import subprocess
24
import sys
25
import xml.dom.minidom as dom
26
27
if "SUMO_HOME" in os.environ:
28
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
29
30
from sumolib import checkBinary # noqa
31
32
changes = [
33
["net/edge[0]@from", ""],
34
["net/edge[1]@from", ""],
35
["net/edge[0]@from", "a"],
36
["net/edge[1]@from", "a"],
37
["net/edge[0]@from", "<remove>"],
38
["net/edge[1]@from", "<remove>"],
39
["net/edge[0]@function", "a"],
40
["net/edge[1]@function", "a"],
41
["net/edge[0]@id", ""],
42
["net/edge[1]@id", ""],
43
["net/edge[0]@id", "a"],
44
["net/edge[1]@id", "a"],
45
["net/edge[0]@id", "<remove>"],
46
["net/edge[1]@id", "<remove>"],
47
["net/edge[0]@to", ""],
48
["net/edge[1]@to", ""],
49
["net/edge[0]@to", "a"],
50
["net/edge[1]@to", "a"],
51
["net/edge[0]@to", "<remove>"],
52
["net/edge[1]@to", "<remove>"],
53
["net/edge[0]", "<remove>"],
54
["net/edge[1]", "<remove>"],
55
["net/edge[0]", "<duplicate>"],
56
["net/edge[1]", "<duplicate>"],
57
58
["net/edge[0]/lane[0]@index", ""],
59
["net/edge[0]/lane[1]@index", ""],
60
["net/edge[1]/lane[0]@index", ""],
61
["net/edge[1]/lane[1]@index", ""],
62
["net/edge[0]/lane[0]@index", "a"],
63
["net/edge[0]/lane[1]@index", "a"],
64
["net/edge[1]/lane[0]@index", "a"],
65
["net/edge[1]/lane[1]@index", "a"],
66
["net/edge[0]/lane[0]@id", ""],
67
["net/edge[0]/lane[1]@id", ""],
68
["net/edge[1]/lane[0]@id", ""],
69
["net/edge[1]/lane[1]@id", ""],
70
["net/edge[0]/lane[0]@id", "a_0"],
71
["net/edge[0]/lane[1]@id", "a_1"],
72
["net/edge[1]/lane[0]@id", "a_0"],
73
["net/edge[1]/lane[1]@id", "a_1"],
74
["net/edge[0]/lane[0]@id", "<remove>"],
75
["net/edge[0]/lane[1]@id", "<remove>"],
76
["net/edge[1]/lane[0]@id", "<remove>"],
77
["net/edge[1]/lane[1]@id", "<remove>"],
78
["net/edge[0]/lane[0]@length", ""],
79
["net/edge[0]/lane[1]@length", ""],
80
["net/edge[1]/lane[0]@length", ""],
81
["net/edge[1]/lane[1]@length", ""],
82
["net/edge[0]/lane[0]@length", "a"],
83
["net/edge[0]/lane[1]@length", "a"],
84
["net/edge[1]/lane[0]@length", "a"],
85
["net/edge[1]/lane[1]@length", "a"],
86
["net/edge[0]/lane[0]@length", "<remove>"],
87
["net/edge[0]/lane[1]@length", "<remove>"],
88
["net/edge[1]/lane[0]@length", "<remove>"],
89
["net/edge[1]/lane[1]@length", "<remove>"],
90
["net/edge[0]/lane[0]@shape", ""],
91
["net/edge[0]/lane[1]@shape", ""],
92
["net/edge[1]/lane[0]@shape", ""],
93
["net/edge[1]/lane[1]@shape", ""],
94
["net/edge[0]/lane[0]@shape", "a"],
95
["net/edge[0]/lane[1]@shape", "a"],
96
["net/edge[1]/lane[0]@shape", "a"],
97
["net/edge[1]/lane[1]@shape", "a"],
98
["net/edge[0]/lane[0]@shape", "<remove>"],
99
["net/edge[0]/lane[1]@shape", "<remove>"],
100
["net/edge[1]/lane[0]@shape", "<remove>"],
101
["net/edge[1]/lane[1]@shape", "<remove>"],
102
["net/edge[0]/lane[0]@shape", "a,-4.95 100.00,-4.95"],
103
["net/edge[0]/lane[1]@shape", "a,-4.95 100.00,-4.95"],
104
["net/edge[1]/lane[0]@shape", "a,-4.95 100.00,-4.95"],
105
["net/edge[1]/lane[1]@shape", "a,-4.95 100.00,-4.95"],
106
["net/edge[0]/lane[0]@shape", "0.00,a 100.00,-4.95"],
107
["net/edge[0]/lane[1]@shape", "0.00,a 100.00,-4.95"],
108
["net/edge[1]/lane[0]@shape", "0.00,a 100.00,-4.95"],
109
["net/edge[1]/lane[1]@shape", "0.00,a 100.00,-4.95"],
110
["net/edge[0]/lane[0]@shape", "0.00,-4.95 a,-4.95"],
111
["net/edge[0]/lane[1]@shape", "0.00,-4.95 a,-4.95"],
112
["net/edge[1]/lane[0]@shape", "0.00,-4.95 a,-4.95"],
113
["net/edge[1]/lane[1]@shape", "0.00,-4.95 a,-4.95"],
114
["net/edge[0]/lane[0]@shape", "0.00,-4.95 a 100.00,-4.95"],
115
["net/edge[0]/lane[1]@shape", "0.00,-4.95 a 100.00,-4.95"],
116
["net/edge[1]/lane[0]@shape", "0.00,-4.95 a 100.00,-4.95"],
117
["net/edge[1]/lane[1]@shape", "0.00,-4.95 a 100.00,-4.95"],
118
["net/edge[0]/lane[0]@shape", "100.00,-4.95"],
119
["net/edge[0]/lane[1]@shape", "0100.00,-4.95"],
120
["net/edge[1]/lane[0]@shape", "100.00,-4.95"],
121
["net/edge[1]/lane[1]@shape", "100.00,-4.95"],
122
["net/edge[0]/lane[0]", "<remove>"],
123
["net/edge[0]/lane[1]", "<remove>"],
124
["net/edge[1]/lane[0]", "<remove>"],
125
["net/edge[1]/lane[1]", "<remove>"],
126
["net/edge[0]/lane[0]", "<duplicate>"],
127
["net/edge[0]/lane[1]", "<duplicate>"],
128
["net/edge[1]/lane[0]", "<duplicate>"],
129
["net/edge[1]/lane[1]", "<duplicate>"],
130
131
["net/junction[0]@id", ""],
132
["net/junction[1]@id", ""],
133
["net/junction[2]@id", ""],
134
["net/junction[0]@id", "a"],
135
["net/junction[1]@id", "a"],
136
["net/junction[2]@id", "a"],
137
["net/junction[0]@id", "<remove>"],
138
["net/junction[1]@id", "<remove>"],
139
["net/junction[2]@id", "<remove>"],
140
["net/junction[0]@type", ""],
141
["net/junction[1]@type", ""],
142
["net/junction[2]@type", ""],
143
["net/junction[0]@type", "a"],
144
["net/junction[1]@type", "a"],
145
["net/junction[2]@type", "a"],
146
["net/junction[0]@type", "<remove>"],
147
["net/junction[1]@type", "<remove>"],
148
["net/junction[2]@type", "<remove>"],
149
["net/junction[1]@incLanes", "a_0 1_1"],
150
["net/junction[1]@incLanes", "1_0 a_1"],
151
["net/junction[2]@incLanes", "a_0 2_1"],
152
["net/junction[2]@incLanes", "2_0 a_1"],
153
["net/junction[0]", "<remove>"],
154
["net/junction[1]", "<remove>"],
155
["net/junction[2]", "<remove>"],
156
["net/junction[0]", "<duplicate>"],
157
["net/junction[1]", "<duplicate>"],
158
["net/junction[2]", "<duplicate>"],
159
160
["net/connection[0]@from", ""],
161
["net/connection[1]@from", ""],
162
["net/connection[0]@from", "a"],
163
["net/connection[1]@from", "a"],
164
["net/connection[0]@from", "<remove>"],
165
["net/connection[1]@from", "<remove>"],
166
["net/connection[0]@to", ""],
167
["net/connection[1]@to", ""],
168
["net/connection[0]@to", "a"],
169
["net/connection[1]@to", "a"],
170
["net/connection[0]@to", "<remove>"],
171
["net/connection[1]@to", "<remove>"],
172
["net/connection[0]", "<duplicate>"],
173
["net/connection[1]", "<duplicate>"],
174
175
]
176
177
178
def tinyPath(xmlStruct, path, newValue):
179
attribute = None
180
if path.find("@") >= 0:
181
path, attribute = path.split("@")
182
defs = path.split("/")
183
item = xmlStruct
184
for d in defs:
185
if d.find("[") >= 0:
186
iname = d[:d.find("[")]
187
index = int(d[d.find("[") + 1:d.find("]")])
188
else:
189
iname = d
190
index = 0
191
items = item.getElementsByTagName(iname)
192
item = items[index]
193
if attribute:
194
if newValue == "<remove>":
195
item.removeAttribute(attribute)
196
else:
197
item.setAttribute(attribute, newValue)
198
else:
199
if newValue == "<remove>":
200
item.parentNode.removeChild(item)
201
elif newValue == "<duplicate>":
202
item.parentNode.insertBefore(item.cloneNode(True), item)
203
else:
204
print("Unsupported modification defined", file=sys.stderr)
205
206
207
if sys.argv[1] == "sumo":
208
call = [checkBinary('sumo'), "--no-step-log", "--no-duration-log"]
209
elif sys.argv[1] == "netconvert":
210
call = [checkBinary('netconvert'), "-o", "/dev/null"]
211
elif sys.argv[1] == "dfrouter":
212
call = [checkBinary('dfrouter'), "--detector-files", "input_additional.add.xml"]
213
elif sys.argv[1] == "duarouter" or sys.argv[1] == "jtrrouter":
214
call = [checkBinary(sys.argv[1]), "--no-step-log",
215
"-o", "dummy.xml", "-a", "input_additional.add.xml"]
216
else:
217
print("Unsupported application defined", file=sys.stderr)
218
call += sys.argv[2:] + ["-n"]
219
if sys.argv[1] == "netconvert":
220
call[-1] = "-s"
221
222
netconvertBinary = checkBinary('netconvert')
223
224
# build the correct network, first
225
print(">>> Building the correct network")
226
retcode = subprocess.call([netconvertBinary, "-c", "netconvert.netccfg"])
227
print(">>> Trying the correct network")
228
retcode = subprocess.call(call + ["correct.net.xml"])
229
if retcode != 0:
230
print("Error on processing the 'correct' network!")
231
sys.exit()
232
print(">>> ok...\n")
233
234
# check broken network processing
235
print("Running broken net")
236
for c in changes:
237
tree = dom.parse("correct.net.xml")
238
tinyPath(tree, c[0], c[1])
239
writer = open('mod.net.xml', 'w')
240
tree.writexml(writer)
241
writer.close()
242
print("------------------ " + c[0] + ":" + c[1], file=sys.stderr)
243
sys.stderr.flush()
244
retcode = subprocess.call(call + ["mod.net.xml"])
245
sys.stderr.flush()
246
sys.stdout.flush()
247
if retcode != 1:
248
print(" Wrong error code returned (%s)!" % retcode, file=sys.stderr)
249
250