tests: Assert that byte-order is swapped on LE but not BE CPUs

Closes: #1392
Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #1393
Approved by: cgwalters
This commit is contained in:
Simon McVittie 2018-01-03 08:23:10 +00:00 committed by Atomic Bot
parent 95f9b392a4
commit 994cd66744
3 changed files with 32 additions and 2 deletions

View File

@ -130,7 +130,13 @@ experimental_test_scripts = \
tests/test-summary-collections.sh \
tests/test-pull-collections.sh \
$(NULL)
test_extra_programs = $(NULL)
test_extra_programs = \
tests/get-byte-order \
$(NULL)
tests_get_byte_order_SOURCES = tests/get-byte-order.c
tests_get_byte_order_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
tests_get_byte_order_LDADD = $(GLIB_LIBS)
tests_repo_finder_mount_SOURCES = tests/repo-finder-mount.c
tests_repo_finder_mount_CFLAGS = $(common_tests_cflags)

View File

@ -759,8 +759,20 @@ $OSTREE show --print-metadata-key=FOO test2 > test2-meta
assert_file_has_content test2-meta "BAR"
$OSTREE show --print-metadata-key=KITTENS test2 > test2-meta
assert_file_has_content test2-meta "CUTE"
$OSTREE show --print-metadata-key=SOMENUM test2 > test2-meta
assert_file_has_content test2-meta "uint64 3026418949592973312"
case "$("${test_builddir}/get-byte-order")" in
(4321)
assert_file_has_content test2-meta "uint64 42"
;;
(1234)
assert_file_has_content test2-meta "uint64 3026418949592973312"
;;
(*)
fatal "neither little-endian nor big-endian?"
;;
esac
$OSTREE show -B --print-metadata-key=SOMENUM test2 > test2-meta
assert_file_has_content test2-meta "uint64 42"
$OSTREE show --print-detached-metadata-key=SIGNATURE test2 > test2-meta

12
tests/get-byte-order.c Normal file
View File

@ -0,0 +1,12 @@
/* Helper for OSTree tests: return host byte order */
#include "config.h"
#include <glib.h>
int
main (void)
{
g_print ("%d\n", G_BYTE_ORDER);
return 0;
}