postcopy: Incoming initialisation
[qemu/ar7.git] / tests / libqtest.c
blobf6f3d7a950fea3eae8d938fb7238660e75a60997
1 /*
2 * QTest
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
6 * Copyright SUSE LINUX Products GmbH 2013
8 * Authors:
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Paolo Bonzini <pbonzini@redhat.com>
11 * Andreas Färber <afaerber@suse.de>
13 * This work is licensed under the terms of the GNU GPL, version 2 or later.
14 * See the COPYING file in the top-level directory.
17 #include "libqtest.h"
19 #include <glib.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <sys/wait.h>
23 #include <sys/un.h>
24 #include <inttypes.h>
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
31 #include "qemu/compiler.h"
32 #include "qemu/osdep.h"
33 #include "qapi/qmp/json-parser.h"
34 #include "qapi/qmp/json-streamer.h"
35 #include "qapi/qmp/qjson.h"
37 #define MAX_IRQ 256
38 #define SOCKET_TIMEOUT 5
40 QTestState *global_qtest;
42 struct QTestState
44 int fd;
45 int qmp_fd;
46 bool irq_level[MAX_IRQ];
47 GString *rx;
48 pid_t qemu_pid; /* our child QEMU process */
51 static GHookList abrt_hooks;
52 static GList *qtest_instances;
53 static struct sigaction sigact_old;
55 #define g_assert_no_errno(ret) do { \
56 g_assert_cmpint(ret, !=, -1); \
57 } while (0)
59 static int init_socket(const char *socket_path)
61 struct sockaddr_un addr;
62 int sock;
63 int ret;
65 sock = socket(PF_UNIX, SOCK_STREAM, 0);
66 g_assert_no_errno(sock);
68 addr.sun_family = AF_UNIX;
69 snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socket_path);
70 qemu_set_cloexec(sock);
72 do {
73 ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
74 } while (ret == -1 && errno == EINTR);
75 g_assert_no_errno(ret);
76 ret = listen(sock, 1);
77 g_assert_no_errno(ret);
79 return sock;
82 static int socket_accept(int sock)
84 struct sockaddr_un addr;
85 socklen_t addrlen;
86 int ret;
87 struct timeval timeout = { .tv_sec = SOCKET_TIMEOUT,
88 .tv_usec = 0 };
90 setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout,
91 sizeof(timeout));
93 do {
94 addrlen = sizeof(addr);
95 ret = accept(sock, (struct sockaddr *)&addr, &addrlen);
96 } while (ret == -1 && errno == EINTR);
97 if (ret == -1) {
98 fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
100 close(sock);
102 return ret;
105 static void kill_qemu(QTestState *s)
107 if (s->qemu_pid != -1) {
108 kill(s->qemu_pid, SIGTERM);
109 waitpid(s->qemu_pid, NULL, 0);
113 static void sigabrt_handler(int signo)
115 g_hook_list_invoke(&abrt_hooks, FALSE);
118 static void setup_sigabrt_handler(void)
120 struct sigaction sigact;
122 /* Catch SIGABRT to clean up on g_assert() failure */
123 sigact = (struct sigaction){
124 .sa_handler = sigabrt_handler,
125 .sa_flags = SA_RESETHAND,
127 sigemptyset(&sigact.sa_mask);
128 sigaction(SIGABRT, &sigact, &sigact_old);
131 static void cleanup_sigabrt_handler(void)
133 sigaction(SIGABRT, &sigact_old, NULL);
136 void qtest_add_abrt_handler(void (*fn), const void *data)
138 GHook *hook;
140 /* Only install SIGABRT handler once */
141 if (!abrt_hooks.is_setup) {
142 g_hook_list_init(&abrt_hooks, sizeof(GHook));
143 setup_sigabrt_handler();
146 hook = g_hook_alloc(&abrt_hooks);
147 hook->func = fn;
148 hook->data = (void *)data;
150 g_hook_prepend(&abrt_hooks, hook);
153 QTestState *qtest_init(const char *extra_args)
155 QTestState *s;
156 int sock, qmpsock, i;
157 gchar *socket_path;
158 gchar *qmp_socket_path;
159 gchar *command;
160 const char *qemu_binary;
162 qemu_binary = getenv("QTEST_QEMU_BINARY");
163 g_assert(qemu_binary != NULL);
165 s = g_malloc(sizeof(*s));
167 socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
168 qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
170 sock = init_socket(socket_path);
171 qmpsock = init_socket(qmp_socket_path);
173 qtest_add_abrt_handler(kill_qemu, s);
175 s->qemu_pid = fork();
176 if (s->qemu_pid == 0) {
177 setenv("QEMU_AUDIO_DRV", "none", true);
178 command = g_strdup_printf("exec %s "
179 "-qtest unix:%s,nowait "
180 "-qtest-log %s "
181 "-qmp unix:%s,nowait "
182 "-machine accel=qtest "
183 "-display none "
184 "%s", qemu_binary, socket_path,
185 getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null",
186 qmp_socket_path,
187 extra_args ?: "");
188 execlp("/bin/sh", "sh", "-c", command, NULL);
189 exit(1);
192 s->fd = socket_accept(sock);
193 if (s->fd >= 0) {
194 s->qmp_fd = socket_accept(qmpsock);
196 unlink(socket_path);
197 unlink(qmp_socket_path);
198 g_free(socket_path);
199 g_free(qmp_socket_path);
201 g_assert(s->fd >= 0 && s->qmp_fd >= 0);
203 s->rx = g_string_new("");
204 for (i = 0; i < MAX_IRQ; i++) {
205 s->irq_level[i] = false;
208 /* Read the QMP greeting and then do the handshake */
209 qtest_qmp_discard_response(s, "");
210 qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }");
212 if (getenv("QTEST_STOP")) {
213 kill(s->qemu_pid, SIGSTOP);
216 return s;
219 void qtest_quit(QTestState *s)
221 qtest_instances = g_list_remove(qtest_instances, s);
222 g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s));
224 /* Uninstall SIGABRT handler on last instance */
225 if (!qtest_instances) {
226 cleanup_sigabrt_handler();
229 kill_qemu(s);
230 close(s->fd);
231 close(s->qmp_fd);
232 g_string_free(s->rx, true);
233 g_free(s);
236 static void socket_send(int fd, const char *buf, size_t size)
238 size_t offset;
240 offset = 0;
241 while (offset < size) {
242 ssize_t len;
244 len = write(fd, buf + offset, size - offset);
245 if (len == -1 && errno == EINTR) {
246 continue;
249 g_assert_no_errno(len);
250 g_assert_cmpint(len, >, 0);
252 offset += len;
256 static void socket_sendf(int fd, const char *fmt, va_list ap)
258 gchar *str = g_strdup_vprintf(fmt, ap);
259 size_t size = strlen(str);
261 socket_send(fd, str, size);
262 g_free(str);
265 static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
267 va_list ap;
269 va_start(ap, fmt);
270 socket_sendf(s->fd, fmt, ap);
271 va_end(ap);
274 static GString *qtest_recv_line(QTestState *s)
276 GString *line;
277 size_t offset;
278 char *eol;
280 while ((eol = strchr(s->rx->str, '\n')) == NULL) {
281 ssize_t len;
282 char buffer[1024];
284 len = read(s->fd, buffer, sizeof(buffer));
285 if (len == -1 && errno == EINTR) {
286 continue;
289 if (len == -1 || len == 0) {
290 fprintf(stderr, "Broken pipe\n");
291 exit(1);
294 g_string_append_len(s->rx, buffer, len);
297 offset = eol - s->rx->str;
298 line = g_string_new_len(s->rx->str, offset);
299 g_string_erase(s->rx, 0, offset + 1);
301 return line;
304 static gchar **qtest_rsp(QTestState *s, int expected_args)
306 GString *line;
307 gchar **words;
308 int i;
310 redo:
311 line = qtest_recv_line(s);
312 words = g_strsplit(line->str, " ", 0);
313 g_string_free(line, TRUE);
315 if (strcmp(words[0], "IRQ") == 0) {
316 int irq;
318 g_assert(words[1] != NULL);
319 g_assert(words[2] != NULL);
321 irq = strtoul(words[2], NULL, 0);
322 g_assert_cmpint(irq, >=, 0);
323 g_assert_cmpint(irq, <, MAX_IRQ);
325 if (strcmp(words[1], "raise") == 0) {
326 s->irq_level[irq] = true;
327 } else {
328 s->irq_level[irq] = false;
331 g_strfreev(words);
332 goto redo;
335 g_assert(words[0] != NULL);
336 g_assert_cmpstr(words[0], ==, "OK");
338 if (expected_args) {
339 for (i = 0; i < expected_args; i++) {
340 g_assert(words[i] != NULL);
342 } else {
343 g_strfreev(words);
346 return words;
349 typedef struct {
350 JSONMessageParser parser;
351 QDict *response;
352 } QMPResponseParser;
354 static void qmp_response(JSONMessageParser *parser, QList *tokens)
356 QMPResponseParser *qmp = container_of(parser, QMPResponseParser, parser);
357 QObject *obj;
359 obj = json_parser_parse(tokens, NULL);
360 if (!obj) {
361 fprintf(stderr, "QMP JSON response parsing failed\n");
362 exit(1);
365 g_assert(qobject_type(obj) == QTYPE_QDICT);
366 g_assert(!qmp->response);
367 qmp->response = (QDict *)obj;
370 QDict *qmp_fd_receive(int fd)
372 QMPResponseParser qmp;
373 bool log = getenv("QTEST_LOG") != NULL;
375 qmp.response = NULL;
376 json_message_parser_init(&qmp.parser, qmp_response);
377 while (!qmp.response) {
378 ssize_t len;
379 char c;
381 len = read(fd, &c, 1);
382 if (len == -1 && errno == EINTR) {
383 continue;
386 if (len == -1 || len == 0) {
387 fprintf(stderr, "Broken pipe\n");
388 exit(1);
391 if (log) {
392 len = write(2, &c, 1);
394 json_message_parser_feed(&qmp.parser, &c, 1);
396 json_message_parser_destroy(&qmp.parser);
398 return qmp.response;
401 QDict *qtest_qmp_receive(QTestState *s)
403 return qmp_fd_receive(s->qmp_fd);
407 * Allow users to send a message without waiting for the reply,
408 * in the case that they choose to discard all replies up until
409 * a particular EVENT is received.
411 void qmp_fd_sendv(int fd, const char *fmt, va_list ap)
413 va_list ap_copy;
414 QObject *qobj;
416 /* Going through qobject ensures we escape strings properly.
417 * This seemingly unnecessary copy is required in case va_list
418 * is an array type.
420 va_copy(ap_copy, ap);
421 qobj = qobject_from_jsonv(fmt, &ap_copy);
422 va_end(ap_copy);
424 /* No need to send anything for an empty QObject. */
425 if (qobj) {
426 int log = getenv("QTEST_LOG") != NULL;
427 QString *qstr = qobject_to_json(qobj);
428 const char *str = qstring_get_str(qstr);
429 size_t size = qstring_get_length(qstr);
431 if (log) {
432 fprintf(stderr, "%s", str);
434 /* Send QMP request */
435 socket_send(fd, str, size);
437 QDECREF(qstr);
438 qobject_decref(qobj);
442 void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap)
444 qmp_fd_sendv(s->qmp_fd, fmt, ap);
447 QDict *qmp_fdv(int fd, const char *fmt, va_list ap)
449 qmp_fd_sendv(fd, fmt, ap);
451 return qmp_fd_receive(fd);
454 QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
456 qtest_async_qmpv(s, fmt, ap);
458 /* Receive reply */
459 return qtest_qmp_receive(s);
462 QDict *qmp_fd(int fd, const char *fmt, ...)
464 va_list ap;
465 QDict *response;
467 va_start(ap, fmt);
468 response = qmp_fdv(fd, fmt, ap);
469 va_end(ap);
470 return response;
473 void qmp_fd_send(int fd, const char *fmt, ...)
475 va_list ap;
477 va_start(ap, fmt);
478 qmp_fd_sendv(fd, fmt, ap);
479 va_end(ap);
482 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
484 va_list ap;
485 QDict *response;
487 va_start(ap, fmt);
488 response = qtest_qmpv(s, fmt, ap);
489 va_end(ap);
490 return response;
493 void qtest_async_qmp(QTestState *s, const char *fmt, ...)
495 va_list ap;
497 va_start(ap, fmt);
498 qtest_async_qmpv(s, fmt, ap);
499 va_end(ap);
502 void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap)
504 QDict *response = qtest_qmpv(s, fmt, ap);
505 QDECREF(response);
508 void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...)
510 va_list ap;
511 QDict *response;
513 va_start(ap, fmt);
514 response = qtest_qmpv(s, fmt, ap);
515 va_end(ap);
516 QDECREF(response);
519 void qtest_qmp_eventwait(QTestState *s, const char *event)
521 QDict *response;
523 for (;;) {
524 response = qtest_qmp_receive(s);
525 if ((qdict_haskey(response, "event")) &&
526 (strcmp(qdict_get_str(response, "event"), event) == 0)) {
527 QDECREF(response);
528 break;
530 QDECREF(response);
534 char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap)
536 char *cmd;
537 QDict *resp;
538 char *ret;
540 cmd = g_strdup_vprintf(fmt, ap);
541 resp = qtest_qmp(s, "{'execute': 'human-monitor-command',"
542 " 'arguments': {'command-line': %s}}",
543 cmd);
544 ret = g_strdup(qdict_get_try_str(resp, "return"));
545 g_assert(ret);
546 QDECREF(resp);
547 g_free(cmd);
548 return ret;
551 char *qtest_hmp(QTestState *s, const char *fmt, ...)
553 va_list ap;
554 char *ret;
556 va_start(ap, fmt);
557 ret = qtest_hmpv(s, fmt, ap);
558 va_end(ap);
559 return ret;
562 const char *qtest_get_arch(void)
564 const char *qemu = getenv("QTEST_QEMU_BINARY");
565 g_assert(qemu != NULL);
566 const char *end = strrchr(qemu, '/');
568 return end + strlen("/qemu-system-");
571 bool qtest_get_irq(QTestState *s, int num)
573 /* dummy operation in order to make sure irq is up to date */
574 qtest_inb(s, 0);
576 return s->irq_level[num];
579 static int64_t qtest_clock_rsp(QTestState *s)
581 gchar **words;
582 int64_t clock;
583 words = qtest_rsp(s, 2);
584 clock = g_ascii_strtoll(words[1], NULL, 0);
585 g_strfreev(words);
586 return clock;
589 int64_t qtest_clock_step_next(QTestState *s)
591 qtest_sendf(s, "clock_step\n");
592 return qtest_clock_rsp(s);
595 int64_t qtest_clock_step(QTestState *s, int64_t step)
597 qtest_sendf(s, "clock_step %"PRIi64"\n", step);
598 return qtest_clock_rsp(s);
601 int64_t qtest_clock_set(QTestState *s, int64_t val)
603 qtest_sendf(s, "clock_set %"PRIi64"\n", val);
604 return qtest_clock_rsp(s);
607 void qtest_irq_intercept_out(QTestState *s, const char *qom_path)
609 qtest_sendf(s, "irq_intercept_out %s\n", qom_path);
610 qtest_rsp(s, 0);
613 void qtest_irq_intercept_in(QTestState *s, const char *qom_path)
615 qtest_sendf(s, "irq_intercept_in %s\n", qom_path);
616 qtest_rsp(s, 0);
619 static void qtest_out(QTestState *s, const char *cmd, uint16_t addr, uint32_t value)
621 qtest_sendf(s, "%s 0x%x 0x%x\n", cmd, addr, value);
622 qtest_rsp(s, 0);
625 void qtest_outb(QTestState *s, uint16_t addr, uint8_t value)
627 qtest_out(s, "outb", addr, value);
630 void qtest_outw(QTestState *s, uint16_t addr, uint16_t value)
632 qtest_out(s, "outw", addr, value);
635 void qtest_outl(QTestState *s, uint16_t addr, uint32_t value)
637 qtest_out(s, "outl", addr, value);
640 static uint32_t qtest_in(QTestState *s, const char *cmd, uint16_t addr)
642 gchar **args;
643 uint32_t value;
645 qtest_sendf(s, "%s 0x%x\n", cmd, addr);
646 args = qtest_rsp(s, 2);
647 value = strtoul(args[1], NULL, 0);
648 g_strfreev(args);
650 return value;
653 uint8_t qtest_inb(QTestState *s, uint16_t addr)
655 return qtest_in(s, "inb", addr);
658 uint16_t qtest_inw(QTestState *s, uint16_t addr)
660 return qtest_in(s, "inw", addr);
663 uint32_t qtest_inl(QTestState *s, uint16_t addr)
665 return qtest_in(s, "inl", addr);
668 static void qtest_write(QTestState *s, const char *cmd, uint64_t addr,
669 uint64_t value)
671 qtest_sendf(s, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value);
672 qtest_rsp(s, 0);
675 void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
677 qtest_write(s, "writeb", addr, value);
680 void qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
682 qtest_write(s, "writew", addr, value);
685 void qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
687 qtest_write(s, "writel", addr, value);
690 void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
692 qtest_write(s, "writeq", addr, value);
695 static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr)
697 gchar **args;
698 uint64_t value;
700 qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr);
701 args = qtest_rsp(s, 2);
702 value = strtoull(args[1], NULL, 0);
703 g_strfreev(args);
705 return value;
708 uint8_t qtest_readb(QTestState *s, uint64_t addr)
710 return qtest_read(s, "readb", addr);
713 uint16_t qtest_readw(QTestState *s, uint64_t addr)
715 return qtest_read(s, "readw", addr);
718 uint32_t qtest_readl(QTestState *s, uint64_t addr)
720 return qtest_read(s, "readl", addr);
723 uint64_t qtest_readq(QTestState *s, uint64_t addr)
725 return qtest_read(s, "readq", addr);
728 static int hex2nib(char ch)
730 if (ch >= '0' && ch <= '9') {
731 return ch - '0';
732 } else if (ch >= 'a' && ch <= 'f') {
733 return 10 + (ch - 'a');
734 } else if (ch >= 'A' && ch <= 'F') {
735 return 10 + (ch - 'a');
736 } else {
737 return -1;
741 void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size)
743 uint8_t *ptr = data;
744 gchar **args;
745 size_t i;
747 qtest_sendf(s, "read 0x%" PRIx64 " 0x%zx\n", addr, size);
748 args = qtest_rsp(s, 2);
750 for (i = 0; i < size; i++) {
751 ptr[i] = hex2nib(args[1][2 + (i * 2)]) << 4;
752 ptr[i] |= hex2nib(args[1][2 + (i * 2) + 1]);
755 g_strfreev(args);
758 void qtest_add_func(const char *str, void (*fn))
760 gchar *path = g_strdup_printf("/%s/%s", qtest_get_arch(), str);
761 g_test_add_func(path, fn);
762 g_free(path);
765 void qtest_add_data_func(const char *str, const void *data, void (*fn))
767 gchar *path = g_strdup_printf("/%s/%s", qtest_get_arch(), str);
768 g_test_add_data_func(path, data, fn);
769 g_free(path);
772 void qtest_bufwrite(QTestState *s, uint64_t addr, const void *data, size_t size)
774 gchar *bdata;
776 bdata = g_base64_encode(data, size);
777 qtest_sendf(s, "b64write 0x%" PRIx64 " 0x%zx ", addr, size);
778 socket_send(s->fd, bdata, strlen(bdata));
779 socket_send(s->fd, "\n", 1);
780 qtest_rsp(s, 0);
781 g_free(bdata);
784 void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size)
786 gchar **args;
787 size_t len;
789 qtest_sendf(s, "b64read 0x%" PRIx64 " 0x%zx\n", addr, size);
790 args = qtest_rsp(s, 2);
792 g_base64_decode_inplace(args[1], &len);
793 if (size != len) {
794 fprintf(stderr, "bufread: asked for %zu bytes but decoded %zu\n",
795 size, len);
796 len = MIN(len, size);
799 memcpy(data, args[1], len);
800 g_strfreev(args);
803 void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size)
805 const uint8_t *ptr = data;
806 size_t i;
807 char *enc = g_malloc(2 * size + 1);
809 for (i = 0; i < size; i++) {
810 sprintf(&enc[i * 2], "%02x", ptr[i]);
813 qtest_sendf(s, "write 0x%" PRIx64 " 0x%zx 0x%s\n", addr, size, enc);
814 qtest_rsp(s, 0);
815 g_free(enc);
818 void qtest_memset(QTestState *s, uint64_t addr, uint8_t pattern, size_t size)
820 qtest_sendf(s, "memset 0x%" PRIx64 " 0x%zx 0x%02x\n", addr, size, pattern);
821 qtest_rsp(s, 0);
824 QDict *qmp(const char *fmt, ...)
826 va_list ap;
827 QDict *response;
829 va_start(ap, fmt);
830 response = qtest_qmpv(global_qtest, fmt, ap);
831 va_end(ap);
832 return response;
835 void qmp_async(const char *fmt, ...)
837 va_list ap;
839 va_start(ap, fmt);
840 qtest_async_qmpv(global_qtest, fmt, ap);
841 va_end(ap);
844 void qmp_discard_response(const char *fmt, ...)
846 va_list ap;
848 va_start(ap, fmt);
849 qtest_qmpv_discard_response(global_qtest, fmt, ap);
850 va_end(ap);
852 char *hmp(const char *fmt, ...)
854 va_list ap;
855 char *ret;
857 va_start(ap, fmt);
858 ret = qtest_hmpv(global_qtest, fmt, ap);
859 va_end(ap);
860 return ret;
863 bool qtest_big_endian(void)
865 const char *arch = qtest_get_arch();
866 int i;
868 static const struct {
869 const char *arch;
870 bool big_endian;
871 } endianness[] = {
872 { "aarch64", false },
873 { "alpha", false },
874 { "arm", false },
875 { "cris", false },
876 { "i386", false },
877 { "lm32", true },
878 { "m68k", true },
879 { "microblaze", true },
880 { "microblazeel", false },
881 { "mips", true },
882 { "mips64", true },
883 { "mips64el", false },
884 { "mipsel", false },
885 { "moxie", true },
886 { "or32", true },
887 { "ppc", true },
888 { "ppc64", true },
889 { "ppcemb", true },
890 { "s390x", true },
891 { "sh4", false },
892 { "sh4eb", true },
893 { "sparc", true },
894 { "sparc64", true },
895 { "unicore32", false },
896 { "x86_64", false },
897 { "xtensa", false },
898 { "xtensaeb", true },
902 for (i = 0; endianness[i].arch; i++) {
903 if (strcmp(endianness[i].arch, arch) == 0) {
904 return endianness[i].big_endian;
908 return false;