tests: Assert that byte-order is swapped on LE but not BE CPUs
authorSimon McVittie <smcv@collabora.com>
Wed, 3 Jan 2018 08:23:10 +0000 (08:23 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 4 Jan 2018 12:32:47 +0000 (12:32 +0000)
Closes: #1392
Signed-off-by: Simon McVittie <smcv@collabora.com>
Closes: #1393
Approved by: cgwalters

Makefile-tests.am
tests/basic-test.sh
tests/get-byte-order.c [new file with mode: 0644]

index 2b335556141b5854b7d6d4010eabfbc0ccc6fc77..25a8d08b155e8fdc1eaa399c677f35be4410df70 100644 (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)
index 87cb9fa25576783a23dca11afea863b838698cad..c4eb9cadda4f1d2c9bb32c65e0511f3014e300db 100644 (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
diff --git a/tests/get-byte-order.c b/tests/get-byte-order.c
new file mode 100644 (file)
index 0000000..7e7ba31
--- /dev/null
@@ -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;
+}