Debian Codegraph @

tests/elements/autotools.py

raw
1 #
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 #
14
15 # Pylint doesn't play well with fixtures and dependency injection from pytest
16 # pylint: disable=redefined-outer-name
17
18 import os
19 import pytest
20
21 from buildstream._testing.integration import integration_cache # pylint: disable=unused-import
22 from buildstream._testing import cli_integration as cli # pylint: disable=unused-import
23 from buildstream._testing.integration import assert_contains
24 from buildstream._testing._utils.site import HAVE_SANDBOX
25
26
27 pytestmark = pytest.mark.integration
28
29
30 DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "autotools")
31
32
33 # Test that an autotools build 'works' - we use the autotools sample
34 # amhello project for this.
35 @pytest.mark.datafiles(DATA_DIR)
36 @pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
37 def test_autotools_build(cli, datafiles):
38 project = str(datafiles)
39 checkout = os.path.join(cli.directory, "checkout")
40 element_name = "amhello.bst"
41
42 result = cli.run(project=project, args=["build", element_name])
43 assert result.exit_code == 0
44
45 result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkout])
46 assert result.exit_code == 0
47
48 assert_contains(
49 checkout,
50 [
51 "/usr",
52 "/usr/lib",
53 "/usr/bin",
54 "/usr/share",
55 "/usr/bin/hello",
56 "/usr/share/doc",
57 "/usr/share/doc/amhello",
58 "/usr/share/doc/amhello/README",
59 ],
60 )
61
62 # Check the log
63 result = cli.run(project=project, args=["artifact", "log", element_name])
64 assert result.exit_code == 0
65 log = result.output
66
67 # Verify we get expected output exactly once
68 assert log.count("Making all in src") == 1
69
70
71 # Test that an autotools build 'works' - we use the autotools sample
72 # amhello project for this.
73 @pytest.mark.datafiles(DATA_DIR)
74 @pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
75 def test_autotools_confroot_build(cli, datafiles):
76 project = str(datafiles)
77 checkout = os.path.join(cli.directory, "checkout")
78 element_name = "amhelloconfroot.bst"
79
80 result = cli.run(project=project, args=["build", element_name])
81 assert result.exit_code == 0
82
83 result = cli.run(project=project, args=["artifact", "checkout", element_name, "--directory", checkout])
84 assert result.exit_code == 0
85
86 assert_contains(
87 checkout,
88 [
89 "/usr",
90 "/usr/lib",
91 "/usr/bin",
92 "/usr/share",
93 "/usr/bin/hello",
94 "/usr/share/doc",
95 "/usr/share/doc/amhello",
96 "/usr/share/doc/amhello/README",
97 ],
98 )
99
100
101 # Test running an executable built with autotools
102 @pytest.mark.datafiles(DATA_DIR)
103 @pytest.mark.skipif(not HAVE_SANDBOX, reason="Only available with a functioning sandbox")
104 def test_autotools_run(cli, datafiles):
105 project = str(datafiles)
106 element_name = "amhello.bst"
107
108 result = cli.run(project=project, args=["build", element_name])
109 assert result.exit_code == 0
110
111 result = cli.run(project=project, args=["shell", element_name, "/usr/bin/hello"])
112 assert result.exit_code == 0
113 assert result.output == "Hello World!\nThis is amhello 1.0.\n"