1 # The MIT License (MIT)
3 # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
4 # Copyright (c) 2023 Erica Bugden <ebugden@efficios.com>
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 # Tests that the tracer generated by barectf will not build when the
32 # configured native byte order (big endian in this case) does not match
33 # the system's native byte order (little endian in this case).
35 # NOTE: This test does not validate that it runs on a little-endian
36 # system, but we can assume that that is the case since it is what the
37 # barectf tests currently require.
38 def test_byte_order_check(request
, tmpdir
):
39 yaml_path
= os
.path
.join(os
.path
.dirname(request
.fspath
), 'configs',
40 'pass', 'type', 'byte-order-yes.yaml')
42 # Create barectf configuration
43 with
open(yaml_path
) as f
:
44 cfg
= barectf
.configuration_from_file(f
)
46 # Generate and write C code files
47 cg
= barectf
.CodeGenerator(cfg
)
49 for file in cg
.generate_c_headers() + cg
.generate_c_sources():
50 with
open(os
.path
.join(tmpdir
, file.name
), 'w') as f
:
51 f
.write(file.contents
)
53 # Verify that building the C code fails because of the byte order
55 cc
= os
.environ
.get('CC', 'cc')
58 expected_output
= ("barectf: The native byte order of the target architecture (little "
59 "endian) doesn't match the configured native byte order (big "
60 "endian): the generated tracer could produce invalid or corrupted "
61 "CTF packets. Please make sure that the native byte order in the "
62 "barectf configuration's trace type object is little endian.")
64 with pytest
.raises(subprocess
.CalledProcessError
) as excinfo
:
65 subprocess
.check_output([cc
, '-c', '-o', o_file
, 'barectf.c'], cwd
=tmpdir
,
66 text
=True, stderr
=subprocess
.STDOUT
)
68 assert(expected_output
in excinfo
.value
.output
)
This page took 0.030796 seconds and 4 git commands to generate.