Newer
Older
from .utils import run_ioc_get_output
RE_MISSING_FILE = "No rule to make target [`']{filename}'"
def create_patch_file(path, desc):
path.parent.mkdir(parents=True, exist_ok=True)
patch_file_contents = """
diff --git database.db database.db
index 1806ff6..8701832 100644
--- database.db
+++ database.db
@@ -1,3 +1,3 @@
record(ai, "TEST") {{
f.write(patch_file_contents.format(desc=desc))
db_file_contents = """record(ai, "TEST") {
}
"""
create_patch_file(patch_dir / "apply.p0.patch", "OK")
create_patch_file(patch_dir / MODULE_VERSION / "do-not-apply.p0.patch", "Bad")
rc, _, _ = wrapper.run_make("patch", module_version=MODULE_VERSION)
db_contents = f.read()
assert 'field(DESC, "OK")' in db_contents
rc, _, _ = wrapper.run_make("build", module_version=MODULE_VERSION)
rc, _, _ = wrapper.run_make("cellinstall", module_version=MODULE_VERSION)
assert any((wrapper.path / "cellMods").glob("**/*.db"))
def test_local_module(wrapper):
rc, outs, _ = wrapper.run_make(
"init",
module_version=MODULE_VERSION,
)
assert rc == 0
assert "You are in the local source mode" in outs
wrapper.add_var_to_makefile("DBDS", "nonexistent.dbd")
assert rc == 2
assert re.search(
RE_MISSING_FILE.format(filename=re.escape("../nonexistent.dbd")),
)
def test_missing_source_file(wrapper):
wrapper.add_var_to_makefile("SOURCES", "nonexistent.c")
assert rc == 2
assert re.search(
RE_MISSING_FILE.format(filename=re.escape("nonexistent.o")),
def test_missing_requirement(wrapper):
assert rc == 0
assert 'Invalid dependency "FOO_DEP_VERSION"; pruning' in errs
def test_header_install_location(wrapper):
subdir = wrapper.module_dir / "db" / "subdir"
subdir.mkdir(parents=True)
extensions = ["h", "hpp", "hxx", "hh"]
wrapper.add_var_to_makefile("HEADERS", f"db/subdir/header.{ext}")
wrapper.add_var_to_makefile("KEEP_HEADER_SUBDIRS", "db")
for ext in extensions:
(subdir / f"header.{ext}").touch()
rc, *_ = wrapper.run_make("cellinstall")
cell_path = wrapper.get_env_var("E3_MODULES_INSTALL_LOCATION")
for ext in extensions:
assert (Path(cell_path) / "include" / "subdir" / f"header.{ext}").is_file()
assert not (Path(cell_path) / "include" / f"header.{ext}").is_file()
def test_updated_dependencies(wrappers):
wrapper_dep = wrappers.get()
wrapper_main = wrappers.get()
cell_path = wrapper_main.path / "cellMods"
old_version = "0.0.0+0"
wrapper_main.add_var_to_config_module(
f"{wrapper_dep.name}_DEP_VERSION", old_version, modifier=""
module_version=old_version,
cell_path=cell_path,
rc, *_ = wrapper_main.run_make("cellinstall", module_version=old_version)
assert rc == 0
new_version = "1.0.0+0"
module_version=new_version,
cell_path=cell_path,
wrapper_main.add_var_to_config_module(
f"{wrapper_dep.name}_DEP_VERSION", new_version, modifier=""
rc, *_ = wrapper_main.run_make("cellinstall", module_version=new_version)
wrapper_main.name, new_version, wrapper_main.path / "cellMods"
)
assert rc == 0
assert f"Loaded {wrapper_dep.name} version {new_version}" in outs
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def test_match_versions(wrappers):
"""Test match version scenario.
This test checks if inconsistent versions are correctly verified during
build time. This tests if the dependecies B->A->C and B->C with A and B
both requesting the same version of C will be correctly built.
"""
wrapper_dep = wrappers.get()
wrapper_a = wrappers.get()
wrapper_b = wrappers.get()
cell_path = wrapper_b.path / "cellmods"
dep_version = "1.0.0+0"
a_version = "0.0.0+0"
b_version = "0.0.0+0"
# Wrapper a dependes on dep,1.0.0+0
wrapper_a.add_var_to_config_module(
f"{wrapper_dep.name}_DEP_VERSION", dep_version, modifier=""
)
# Wrapper b depends on dep,1.0.0+0
wrapper_b.add_var_to_config_module(
f"{wrapper_dep.name}_DEP_VERSION", dep_version, modifier=""
)
# Wrapper b also depends on a
wrapper_b.add_var_to_config_module(
f"{wrapper_a.name}_DEP_VERSION", a_version, modifier=""
)
rc, *_ = wrapper_dep.run_make(
"cellinstall", module_version=dep_version, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_a.run_make(
"cellinstall", module_version=a_version, cell_path=cell_path
)
assert rc == 0
# As wrappers a and b both depends on dep,1.0.0+0 this build should finish
# corretly.
rc, *_ = wrapper_b.run_make(
"cellinstall", module_version=b_version, cell_path=cell_path
)
assert rc == 0
def test_unmatching_versions(wrappers):
"""Test unmatching version scenarion.
This test checks if inconsistent versions are correctly verified during
build time. This checks for the scenarion where B->A->C and B->C however
A depends on a version of C different than B.
"""
wrapper_dep = wrappers.get()
wrapper_a = wrappers.get()
wrapper_b = wrappers.get()
cell_path = wrapper_b.path / "cellmods"
dep_version_1 = "1.0.0+0"
dep_version_2 = "2.0.0+0"
a_version = "0.0.0+0"
b_version = "0.0.0+0"
# Wrapper a dependes on dep v1
wrapper_a.add_var_to_config_module(
f"{wrapper_dep.name}_DEP_VERSION", dep_version_1, modifier=""
)
# Wrapper b depends on dep v2
wrapper_b.add_var_to_config_module(
f"{wrapper_dep.name}_DEP_VERSION", dep_version_2, modifier=""
)
# Wrapper b also depends on wrapper_a
wrapper_b.add_var_to_config_module(
f"{wrapper_a.name}_DEP_VERSION", a_version, modifier=""
)
rc, *_ = wrapper_dep.run_make(
"cellinstall", module_version=dep_version_1, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_a.run_make(
"cellinstall", module_version=a_version, cell_path=cell_path
)
assert rc == 0
# Now a second installation of wrapper_dep but with version 2
rc, *_ = wrapper_dep.run_make(
"cellinstall", module_version=dep_version_2, cell_path=cell_path
)
assert rc == 0
# This next installation should fail because B depends on A
# that depends on DEP. However A needs DEP 1.0.0+0 and B
# needs DEP 2.0.0+0
rc, *_ = wrapper_b.run_make(
"cellinstall", module_version=b_version, cell_path=cell_path
)
assert rc != 0
def test_indirect_unmatching_versions(wrappers):
"""Test indirect unmatching version scenarion.
This test checks if inconsistend versions are correctly verified during
build time. This checks for the scenarion where B->A->C and B->D->C
however A depends on a version of C different than D.
"""
wrapper_c = wrappers.get()
wrapper_a = wrappers.get()
wrapper_b = wrappers.get()
wrapper_d = wrappers.get()
cell_path = wrapper_b.path / "cellmods"
c_version_a = "1.0.0+0"
c_version_d = "2.0.0+0"
a_version = "0.0.0+0"
d_version = "0.0.0+0"
b_version = "0.0.0+0"
# Wrapper a dependes on c
wrapper_a.add_var_to_config_module(
f"{wrapper_c.name}_DEP_VERSION", c_version_a, modifier=""
)
# Wrapper d dependes on c
wrapper_d.add_var_to_config_module(
f"{wrapper_c.name}_DEP_VERSION", c_version_d, modifier=""
)
# Wrapper b depends on d
wrapper_b.add_var_to_config_module(
f"{wrapper_d.name}_DEP_VERSION", d_version, modifier=""
)
# Wrapper b also depends on a
wrapper_b.add_var_to_config_module(
f"{wrapper_a.name}_DEP_VERSION", a_version, modifier=""
)
rc, *_ = wrapper_c.run_make(
"cellinstall", module_version=c_version_a, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_a.run_make(
"cellinstall", module_version=a_version, cell_path=cell_path
)
assert rc == 0
# Now a second installation of wrapper_dep but with version 2
rc, *_ = wrapper_c.run_make(
"cellinstall", module_version=c_version_d, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_d.run_make(
"cellinstall", module_version=d_version, cell_path=cell_path
)
assert rc == 0
# This next installation should fail because A depends on C
# with a different version that D depends on C.
rc, *_ = wrapper_b.run_make(
"cellinstall", module_version=b_version, cell_path=cell_path
)
assert rc != 0
def test_automated_dependency(wrappers):
wrapper_a = wrappers.get()
wrapper_b = wrappers.get()
cell_path = wrapper_a.path / "cellMods"
module_version = "0.0.0+0"
wrapper_a.add_var_to_config_module(f"{wrapper_b.name}_DEP_VERSION", module_version)
rc, *_ = wrapper_b.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_a.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
assert rc == 0
for dep_file in (cell_path / wrapper_a.name).rglob("*.dep"):
with open(dep_file, "r") as f:
contents = f.readlines()
assert len(contents) == 2
assert contents[0].strip() == "# Generated file. Do not edit."
assert f"{wrapper_b.name} {module_version}" == contents[1]
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
def test_architecture_dependent_dependency(wrappers):
wrapper_a = wrappers.get()
wrapper_b = wrappers.get()
wrapper_c = wrappers.get()
cell_path = wrapper_a.path / "cellMods"
module_version = "0.0.0+0"
wrapper_a.add_var_to_config_module(
f"{wrapper_b.name}_DEP_VERSION_linux", module_version
)
wrapper_a.add_var_to_config_module(
f"{wrapper_c.name}_DEP_VERSION_not_an_arch", module_version
)
rc, *_ = wrapper_c.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_b.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_a.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
assert rc == 0
rc, outs, _ = run_ioc_get_output(
wrapper_a.name, module_version, wrapper_a.path / "cellMods"
)
assert rc == 0
assert f"Loaded {wrapper_b.name} version {module_version}" in outs
assert f"Loaded {wrapper_c.name} version {module_version}" not in outs
def test_recursive_header_include(wrappers):
wrapper_a = wrappers.get()
wrapper_b = wrappers.get()
wrapper_c = wrappers.get()
cell_path = wrapper_a.path / "cellMods"
module_version = "0.0.0+0"
wrapper_b.add_var_to_config_module(f"{wrapper_c.name}_DEP_VERSION", module_version)
wrapper_a.add_var_to_config_module(f"{wrapper_b.name}_DEP_VERSION", module_version)
wrapper_c.add_var_to_makefile("HEADERS", f"{wrapper_c.name}.h")
(wrapper_c.module_dir / f"{wrapper_c.name}.h").touch()
wrapper_a.add_var_to_makefile("SOURCES", f"{wrapper_a.name}.c")
with open(wrapper_a.module_dir / f"{wrapper_a.name}.c", "w") as f:
f.write(f'#include "{wrapper_c.name}.h"')
rc, *_ = wrapper_c.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
assert rc == 0
rc, *_ = wrapper_b.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
rc, *_ = wrapper_a.run_make(
"cellinstall", module_version=module_version, cell_path=cell_path
)
rc, outs, _ = run_ioc_get_output(
wrapper_a.name, module_version, wrapper_a.path / "cellMods"
)
assert f"Loaded {wrapper_c.name} version {module_version}" in outs
def test_updated_template_files(wrapper):
wrapper.add_var_to_makefile("SUBS", "x.substitutions")
substitution_file = wrapper.module_dir / "x.substitutions"
substitution_file.write_text("file x.template {pattern {x} {y}}")
template_file = wrapper.module_dir / "x.template"
base_version = wrapper.get_env_var("EPICS_VERSION_NUMBER")
db_file = wrapper.module_dir / f"O.{base_version}_Common" / "x.db"
rc, *_ = wrapper.run_make("db_internal")
assert rc == 0
rc, *_ = wrapper.run_make("db_internal")
assert rc == 0
@pytest.mark.parametrize(
"installed_archs, param, expected",
[
("foo bar baz foo-bar", "ARCH_FILTER=foo", ["foo"]),
("foo", "EXCLUDE_ARCHS=foo", []),
("foo-bar foo-baz baz baz-qux", "EXCLUDE_ARCHS=foo", ["baz", "baz-qux"]),
],
)
def test_arch_filter(wrapper, installed_archs, param, expected):
arch_regex = re.compile(r"Pass 3: T_A =\s*([^\s]+)")
wrapper.add_var_to_makefile(
"CROSS_COMPILER_TARGET_ARCHS", installed_archs, modifier=""
)
rc, o, _ = wrapper.run_make("debug", param)
assert rc == 0
host_arch = os.getenv("EPICS_HOST_ARCH")
build_archs = [arch for arch in arch_regex.findall(o) if arch != host_arch]
assert build_archs == expected