|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 | """Tests that check if both the debug and the release builds pass."""
|
4 | 4 |
|
| 5 | +import itertools |
5 | 6 | import os
|
| 7 | +import pytest |
6 | 8 |
|
7 | 9 | import host_tools.cargo_build as host # pylint:disable=import-error
|
8 | 10 |
|
9 |
| - |
10 |
| -CARGO_DEBUG_REL_PATH = os.path.join(host.CARGO_BUILD_REL_PATH, 'debug') |
11 |
| -CARGO_DEBUG_REL_PATH_FEATURES = os.path.join( |
12 |
| - host.CARGO_BUILD_REL_PATH, |
13 |
| - 'debug-features' |
14 |
| -) |
15 |
| -CARGO_RELEASE_REL_PATH_FEATURES = os.path.join( |
16 |
| - host.CARGO_BUILD_REL_PATH, |
17 |
| - 'release-features' |
18 |
| -) |
| 11 | +FEATURES = ["", "vsock"] |
| 12 | +BUILD_TYPES = ["debug", "release"] |
19 | 13 |
|
20 | 14 |
|
21 |
| -def test_build_debug(test_session_root_path): |
22 |
| - """Test if a debug-mode build works.""" |
23 |
| - build_path = os.path.join( |
24 |
| - test_session_root_path, |
25 |
| - CARGO_DEBUG_REL_PATH |
26 |
| - ) |
27 |
| - host.cargo_build(build_path) |
28 |
| - |
29 |
| - |
30 |
| -def test_build_debug_with_features(test_session_root_path): |
31 |
| - """Test if a debug-mode build works for supported features.""" |
32 |
| - build_path = os.path.join( |
33 |
| - test_session_root_path, |
34 |
| - CARGO_DEBUG_REL_PATH_FEATURES |
| 15 | +@pytest.mark.parametrize( |
| 16 | + "features, build_type", |
| 17 | + itertools.product(FEATURES, BUILD_TYPES) |
| 18 | +) |
| 19 | +def test_build(test_session_root_path, features, build_type): |
| 20 | + """ |
| 21 | + Test build using a cartesian product of possible features and build |
| 22 | + types. |
| 23 | + """ |
| 24 | + extra_args = "" |
| 25 | + |
| 26 | + if build_type == "release": |
| 27 | + extra_args += "--release " |
| 28 | + |
| 29 | + # The relative path of the binaries is computed using the build_type |
| 30 | + # (either release or debug) and if any features are provided also using |
| 31 | + # the features names. |
| 32 | + # For example, a default release build with no features will end up in |
| 33 | + # the relative directory "release", but for a vsock release build the |
| 34 | + # relative directory will be "release-vsock". |
| 35 | + rel_path = os.path.join( |
| 36 | + host.CARGO_BUILD_REL_PATH, |
| 37 | + build_type |
35 | 38 | )
|
36 |
| - # Building with multiple features is as simple as: |
37 |
| - # cargo build --features "feature1 feature2". We are currently |
38 |
| - # supporting only one features: vsock. |
39 |
| - host.cargo_build(build_path, '--features "{}"'.format('vsock')) |
| 39 | + if features: |
| 40 | + rel_path += "-{}".format(features) |
| 41 | + extra_args = "--features {} ".format(features) |
40 | 42 |
|
41 |
| - |
42 |
| -def test_build_release(test_session_root_path): |
43 |
| - """Test if a release-mode build works.""" |
44 | 43 | build_path = os.path.join(
|
45 | 44 | test_session_root_path,
|
46 |
| - host.CARGO_RELEASE_REL_PATH |
| 45 | + rel_path |
47 | 46 | )
|
48 |
| - host.cargo_build(build_path, '--release') |
49 |
| - |
50 | 47 |
|
51 |
| -def test_build_release_with_features(test_session_root_path): |
52 |
| - """Test if a release-mode build works for supported features.""" |
53 |
| - build_path = os.path.join( |
54 |
| - test_session_root_path, |
55 |
| - CARGO_RELEASE_REL_PATH_FEATURES |
56 |
| - ) |
57 |
| - host.cargo_build( |
58 |
| - build_path, |
59 |
| - '--features "{}"'.format('vsock'), |
60 |
| - '--release' |
61 |
| - ) |
| 48 | + host.cargo_build(build_path, extra_args=extra_args) |
0 commit comments