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