summaryrefslogtreecommitdiff
path: root/test/debug.h
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2018-12-04 11:30:57 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2018-12-04 11:30:57 +0100
commit52c0e83053a4a7326da6436f9ef29b7dcc64db41 (patch)
tree6a25782a0470828e7609139c844cae38238b6cd2 /test/debug.h
parentfd17b298ed968f5719e11e8f517f4d7886c06c73 (diff)
downloadlilliput-ae-implem-52c0e83053a4a7326da6436f9ef29b7dcc64db41.tar.xz
Déplacement des entêtes de test/debug hors de src/
Diffstat (limited to 'test/debug.h')
-rw-r--r--test/debug.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/debug.h b/test/debug.h
new file mode 100644
index 0000000..24b7787
--- /dev/null
+++ b/test/debug.h
@@ -0,0 +1,71 @@
+#ifndef DEBUG_H
+#define DEBUG_H
+
+#include <inttypes.h>
+#include <stdio.h>
+
+
+extern FILE *DUMP; /* Define this variable somewhere (eg with DUMP = stderr). */
+
+
+static inline void debug_dump_lanes(const char *header, size_t len, const uint8_t buf[len], int indent)
+{
+ fprintf(DUMP, "%s\n", header);
+
+ for (size_t line=0; line<len/8; line++)
+ {
+ fprintf(DUMP, "%*s", indent, "");
+ for (size_t b=0; b<8; b++)
+ {
+ /* start with MSB */
+ size_t byte_index = len-(1+line*8+b);
+ fprintf(DUMP, "%*s%02x", 5, "", buf[byte_index]);
+ }
+ fprintf(DUMP, "\n");
+ }
+ fprintf(DUMP, "\n");
+}
+
+static inline void debug_dump_buffer(const char *header, size_t len, const uint8_t buf[len], int indent)
+{
+ fprintf(DUMP, "%*s%s\n", indent, "", header);
+
+ if (len%8 != 0)
+ {
+ fprintf(DUMP, "%*s", (int)(3*(8-len%8))+indent, "");
+ for (size_t b=0; b<len%8; b++)
+ {
+ size_t byte_index = len-1-b;
+ fprintf(DUMP, "%02x ", buf[byte_index]);
+ }
+ fprintf(DUMP, "\n");
+ }
+
+ for (size_t line=0; line<len/8; line++)
+ {
+ fprintf(DUMP, "%*s", indent, "");
+ for (size_t b=0; b<8; b++)
+ {
+ /* start with MSB */
+ size_t byte_index = 8*(len/8 - 1 - line) + 7-b;
+ /* fprintf(DUMP, "[%zu / %zu => %zu]", line, b, byte_index); */
+ fprintf(DUMP, "%02x ", buf[byte_index]);
+ }
+ fprintf(DUMP, "\n");
+ }
+
+ fprintf(DUMP, "\n");
+}
+
+static inline void debug_open_dump(const char *folder, const char *suite, const char *vector_name)
+{
+ size_t namelen = snprintf(
+ NULL, 0, "%s/traces-%s-%s.txt", folder, suite, vector_name
+ );
+ char name[namelen+1];
+ snprintf(name, sizeof(name), "%s/traces-%s-%s.txt", folder, suite, vector_name);
+ DUMP = fopen(name, "w");
+}
+
+
+#endif /* DEBUG_H */