-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathtest_qibuild_configure.py
More file actions
381 lines (326 loc) · 15.1 KB
/
test_qibuild_configure.py
File metadata and controls
381 lines (326 loc) · 15.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
## Copyright (c) 2012-2016 Aldebaran Robotics. All rights reserved.
## Use of this source code is governed by a BSD-style license that can be
## found in the COPYING file.
import os
import platform
import subprocess
import time
import qisys.command
import qisys.error
import qibuild.cmake
import qibuild.config
import qibuild.find
import qisrc.git
import qitoolchain
from qibuild.test.conftest import TestBuildWorkTree
from qipy.test.conftest import qipy_action
import mock
import pytest
# This module also serves as a test for the
# qibuild cmake API
def test_simple(qibuild_action):
# Just make sure that the basic stuff works
# (find qibuild-config.cmake)
qibuild_action.add_test_project("world")
qibuild_action("configure", "world")
def test_deps(qibuild_action):
# Running `qibuild configure hello` should work out of the box
qibuild_action.add_test_project("world")
qibuild_action.add_test_project("hello")
qibuild_action("configure", "hello")
# As should `qibuild configure --all`
qibuild_action("configure", "-a")
def test_error_when_using_dash_j(qibuild_action):
qibuild_action.add_test_project("world")
error = qibuild_action("configure", "world", "-j", "2", raises=True)
assert "unrecognized arguments" in error
def test_qi_use_lib(qibuild_action):
use_lib_proj = qibuild_action.add_test_project("uselib")
qibuild_action("configure", "uselib")
# Read cache and check that DEPENDS value are here
cmake_cache = use_lib_proj.cmake_cache
cache = qibuild.cmake.read_cmake_cache(cmake_cache)
assert cache["D_DEPENDS"] == "A;B"
assert cache["E_DEPENDS"] == "D;A;B;CC"
# Make sure it builds
qibuild_action("make", "uselib")
# Make sure it fails when it should
# pylint: disable-msg=E1101
with pytest.raises(qisys.error.Error):
qibuild_action("configure", "uselib", "-DSHOULD_FAIL=ON")
def test_qi_stage_lib_simple(qibuild_action):
qibuild_action.add_test_project("stagelib")
qibuild_action("configure", "stagelib")
def test_qi_stage_lib_but_really_bin(qibuild_action):
qibuild_action.add_test_project("stagelib")
# pylint: disable-msg=E1101
with pytest.raises(qibuild.build.ConfigureFailed):
qibuild_action("configure", "stagelib",
"-DSHOULD_FAIL_STAGE_LIB_BUT_REALLY_BIN=ON")
def test_qi_stage_lib_but_no_such_target(qibuild_action):
qibuild_action.add_test_project("stagelib")
# pylint: disable-msg=E1101
with pytest.raises(qisys.error.Error):
qibuild_action("configure", "stagelib",
"-DSHOULD_FAIL_STAGE_NO_SUCH_TARGET")
def test_preserve_cache(qibuild_action):
foo_proj = qibuild_action.add_test_project("foo")
qibuild_action("configure", "foo")
# Read cache and check that DEPENDS value are here
cache_before = qibuild.cmake.read_cmake_cache(foo_proj.cmake_cache)
assert cache_before["EGGS_DEPENDS"] == "SPAM"
assert cache_before["BAR_DEPENDS"] == "EGGS;SPAM"
# run cmake .. and check the cache did not change
qisys.command.call(["cmake", ".."], cwd=foo_proj.build_directory)
cache_after = qibuild.cmake.read_cmake_cache(foo_proj.cmake_cache)
if os.name == 'nt':
# no way to prevent CMake from storing c:\Users
# in the cache ...
for k in cache_before:
cache_before[k] = cache_before[k].lower()
for k in cache_after:
cache_after[k] = cache_after[k].lower()
assert cache_before == cache_after
def test_config_h_simple(qibuild_action, tmpdir):
proj = qibuild_action.add_test_project("config_h")
qibuild_action("configure", "config_h")
qibuild_action("make", "config_h")
qibuild_action("install", "config_h", tmpdir.strpath)
foo = qibuild.find.find_bin([tmpdir.strpath], "foo")
process = subprocess.Popen([foo])
process.wait()
assert process.returncode == 42
assert tmpdir.join("include", "foo", "config.h").check(file=1)
# pylint: disable-msg=E1101
@pytest.mark.xfail
def test_config_h_extra_install_rule(qibuild_action, tmpdir):
proj = qibuild_action.add_test_project("config_h")
qibuild_action("configure", "config_h", "-DWITH_EXTRA_INSTALL_RULE=ON")
qibuild_action("make", "config_h")
qibuild_action("install", "config_h", tmpdir.strpath)
full_config_h = os.path.join(proj.build_directory,
"include", "foo", "config.h")
full_config_h = os.path.join(tmpdir.strpath, full_config_h)
assert not os.path.exists(full_config_h)
def test_detects_incorrect_cmake(qibuild_action):
proj = qibuild_action.add_test_project("incorrect_cmake")
qibuild_action("configure", "incorrect_cmake", raises=True)
def test_git_version(qibuild_action):
proj = qibuild_action.add_test_project("gitversion")
git = qisrc.git.Git(proj.path)
git.call("init")
git.call("add", ".")
git.call("commit", "--message", "initial commit")
git.call("tag", "v0.1")
qibuild_action("configure", "gitversion")
qibuild_action("make", "gitversion")
testversion = qibuild.find.find_bin([proj.sdk_directory], "testversion")
process = subprocess.Popen(testversion, stdout=subprocess.PIPE)
out, _ = process.communicate()
assert out.strip() == "v0.1"
def test_submodule(qibuild_action):
qibuild_action.add_test_project("submodule")
qibuild_action("configure", "submodule")
qibuild_action("make", "submodule")
def test_pycmd(qibuild_action):
pycmd_proj = qibuild_action.add_test_project("pycmd")
pycmd_proj.configure()
test_txt = os.path.join(pycmd_proj.build_directory, "test.txt")
with open(test_txt, "r") as fp:
assert fp.read() == "Written from Python\n"
qibuild_action("configure", "pycmd", "-DFAIL=TRUE", raises=True)
def test_cmake_option_build_test_on(qibuild_action):
project = qibuild_action.add_test_project("testme")
qibuild_action("configure", "testme", "-DQI_WITH_TESTS=ON")
qibuild_action("make", "testme")
project.build()
test_path = qibuild.find.find([project.sdk_directory], "ok")
assert test_path is not None
assert os.path.exists(test_path)
def test_cmake_option_build_test_off(qibuild_action):
project = qibuild_action.add_test_project("testme")
qibuild_action("configure", "testme", "-DQI_WITH_TESTS=OFF")
qibuild_action("make", "testme")
test_path = qibuild.find.find([project.sdk_directory], "ok", expect_one=False)
assert not test_path
def test_cmake_option_build_perf_test_on(qibuild_action):
project = qibuild_action.add_test_project("perf")
qibuild_action("configure", "perf", "-DQI_WITH_PERF_TESTS=ON")
qibuild_action("make", "perf")
project.build()
test_path = qibuild.find.find([project.sdk_directory], "perf_spam")
assert test_path is not None
assert os.path.exists(test_path)
def test_cmake_option_build_perf_test_off(qibuild_action):
project = qibuild_action.add_test_project("perf")
qibuild_action("configure", "perf", "-DQI_WITH_PERF_TESTS=OFF")
qibuild_action("make", "perf")
test_path = qibuild.find.find([project.sdk_directory], "perf_spam", expect_one=False)
assert not test_path
def read_path_conf(project):
path_conf_path = os.path.join(project.sdk_directory,
"share", "qi", "path.conf")
with open(path_conf_path, "r") as fp:
return fp.read()
def test_using_dash_s_with_path_conf(qibuild_action):
stagepath_proj = qibuild_action.add_test_project("stagepath")
usepath_proj = qibuild_action.add_test_project("usepath")
qibuild_action("configure", "usepath")
path_conf_before = read_path_conf(stagepath_proj)
qibuild_action("configure", "-s", "usepath")
path_conf_after = read_path_conf(stagepath_proj)
assert path_conf_before == path_conf_after
def test_staged_path_first_in_path_conf(qibuild_action, toolchains):
toolchains.create("foo")
qibuild.config.add_build_config("foo", toolchain="foo")
bar_package = toolchains.add_package("foo", "bar")
qibuild_action.add_test_project("stagepath")
qibuild_action("configure", "stagepath", "--config", "foo")
build_worktree = TestBuildWorkTree()
build_worktree.set_active_config("foo")
stagepath_proj = build_worktree.get_build_project("stagepath")
path_conf = read_path_conf(stagepath_proj)
lines = path_conf.splitlines()
# need to resolve symlinks
# (the path to the sources of stagepath_proj is written by CMake, so we
# have to do that by hand)
lines = [os.path.realpath(x) for x in lines]
expected = [
stagepath_proj.path,
stagepath_proj.sdk_directory,
bar_package.path
]
expected = [os.path.realpath(x) for x in expected]
assert lines == expected
def test_path_conf_contains_toolchain_paths(qibuild_action, toolchains):
toolchains.create("foo")
qibuild.config.add_build_config("foo", toolchain="foo")
toolchains.add_package("foo", "bar")
foo_tc = qitoolchain.get_toolchain("foo")
bar_path = foo_tc.get_package("bar").path
qibuild_action.add_test_project("hello")
qibuild_action.add_test_project("world")
build_woktree = TestBuildWorkTree()
build_woktree.build_config.set_active_config("foo")
qibuild_action("configure", "hello", "--config", "foo")
world_proj = build_woktree.get_build_project("world")
hello_proj = build_woktree.get_build_project("hello")
path_conf = os.path.join(hello_proj.sdk_directory, "share", "qi", "path.conf")
with open(path_conf, "r") as fp:
contents = fp.readlines()
sdk_dirs = [x.strip() for x in contents]
assert hello_proj.sdk_directory in sdk_dirs
assert world_proj.sdk_directory in sdk_dirs
assert bar_path in sdk_dirs
def test_adding_a_new_test(qibuild_action):
qibuild_proj = qibuild_action.add_test_project("testme")
qibuild_action("configure", "testme")
qibuild_action("make", "testme")
test_proj1 = qibuild_proj.to_test_project()
num_tests_before = len(test_proj1.tests)
cmake_lists = os.path.join(qibuild_proj.path, "CMakeLists.txt")
with open(cmake_lists, "a") as fp:
fp.write("""
qi_create_test(env2 env.cpp)
""")
qibuild_action("make", "testme")
test_proj2 = qibuild_proj.to_test_project()
num_tests_after = len(test_proj2.tests)
assert num_tests_after == num_tests_before + 1
def test_using_build_prefix_from_command_line(qibuild_action, tmpdir):
qibuild_action.add_test_project("world")
prefix = tmpdir.join("mybuild")
qibuild_action("configure", "world", "--build-prefix", prefix.strpath)
expected = prefix.join("build-sys-%s-%s" % (platform.system().lower(),
platform.machine().lower()),
"world")
assert expected.join("CMakeCache.txt").check(file=True)
def test_using_build_prefix_from_config(qibuild_action, tmpdir):
build_worktree = TestBuildWorkTree()
qibuild_action.add_test_project("world")
qibuild_cfg = qibuild.config.QiBuildConfig()
qibuild_cfg.local.build.prefix = "prefix"
qibuild_cfg.write_local_config(build_worktree.qibuild_xml)
qibuild_action("configure", "world")
prefix = build_worktree.tmpdir.join("prefix")
expected = prefix.join("build-sys-%s-%s" % (platform.system().lower(),
platform.machine().lower()),
"world")
assert expected.join("CMakeCache.txt").check(file=True)
def test_relwithdebinfo(qibuild_action):
world_proj = qibuild_action.add_test_project("world")
qibuild_action("configure", "world", "--build-type", "RelWithDebInfo")
cmake_build_type = qibuild.cmake.get_cached_var(world_proj.build_directory,
"CMAKE_BUILD_TYPE")
assert cmake_build_type == "RelWithDebInfo"
def test_using_fake_ctc(qibuild_action, fake_ctc):
qibuild_action.add_test_project("footool")
qibuild_action("configure", "footool", "--config", "fake-ctc")
qibuild_action("make", "footool", "--config", "fake-ctc")
build_worktree = TestBuildWorkTree()
build_worktree.set_active_config("fake-ctc")
footool_proj = build_worktree.get_build_project("footool")
# assert that bin/footool exists but cannot be run:
footool = qibuild.find.find_bin([footool_proj.sdk_directory], "footool",
expect_one=True)
assert os.path.exists(footool)
# pylint: disable-msg=E1101
with pytest.raises(Exception):
qisys.command.call([footool])
def test_bin_sdk(qibuild_action):
qibuild_action.add_test_project("binsdk")
qibuild_action.add_test_project("binsdkuser")
qibuild_action("configure", "binsdkuser")
def test_gtest(qibuild_action, tmpdir):
qibuild_action.add_test_project("fakegtest")
qibuild_action.add_test_project("gtestuser")
qibuild_action("configure", "gtestuser")
qibuild_action("make", "gtestuser")
qibuild_action("install", "gtestuser", tmpdir.strpath)
assert not tmpdir.join("include", "fakegtest", "gtest.h").check(file=True)
def test_setting_cflags(qibuild_action):
qibuild_action.add_test_project("world")
qibuild_action("configure", "world", "-DCMAKE_CXX_FLAGS=-std=gnu++11")
def test_virtualenv_path(qipy_action, qibuild_action):
py_proj = qibuild_action.add_test_project("py")
qibuild_action("configure", "py")
qibuild_action("make", "py")
qipy_action("bootstrap")
py_test = os.path.join(py_proj.sdk_directory, "bin", "py_test")
output = subprocess.check_output([py_test]).strip()
bin_python = os.path.join(output, "bin", "python")
assert os.path.exists(bin_python)
def test_skips_configure(qibuild_action, record_messages):
world_proj = qibuild_action.add_test_project("world")
qibuild_action.add_test_project("hello")
qibuild_action("configure", "hello")
with mock.patch("qisys.command.call") as mock_call:
qibuild_action("configure", "hello")
# hello should be rebuild because it's a top project,
# but world should be skipped
assert len(mock_call.call_args_list) == 1
world_cmake = os.path.join(world_proj.path, "CMakeLists.txt")
os.utime(world_cmake, None)
record_messages.reset()
with mock.patch("qisys.command.call") as mock_call:
qibuild_action("configure", "hello")
assert record_messages.find("Re-running CMake because CMakeLists.txt has changed")
assert len(mock_call.call_args_list) == 2
def test_re_run_cmake_when_flags_change(qibuild_action, record_messages):
qibuild_action.add_test_project("world")
qibuild_action("configure", "world")
record_messages.reset()
qibuild_action("configure", "world", "-DFOO=BAR")
assert not record_messages.find("up to date")
def test_never_skip_top_projects(qibuild_action, record_messages):
qibuild_action.add_test_project("world")
qibuild_action("configure", "world")
record_messages.reset()
qibuild_action("configure", "world")
assert not record_messages.find("skipping")
def test_running_cmake_for_the_first_time(qibuild_action, record_messages):
qibuild_action.add_test_project("world")
qibuild_action.add_test_project("hello")
record_messages.reset()
qibuild_action("configure", "hello")
assert not record_messages.find("CMake arguments changed")