1 /*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifndef ZCBOR_DEBUG_H__
8 #define ZCBOR_DEBUG_H__
9
10 #include <stdint.h>
11 #include <stdbool.h>
12 #include <stddef.h>
13 #include "zcbor_common.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 __attribute__((used))
zcbor_print_compare_lines(const uint8_t * str1,const uint8_t * str2,uint32_t size)20 static void zcbor_print_compare_lines(const uint8_t *str1, const uint8_t *str2, uint32_t size)
21 {
22 for (uint32_t j = 0; j < size; j++) {
23 printk ("%x ", str1[j]);
24 }
25 printk("\r\n");
26 for (uint32_t j = 0; j < size; j++) {
27 printk ("%x ", str2[j]);
28 }
29 printk("\r\n");
30 for (uint32_t j = 0; j < size; j++) {
31 printk ("%x ", str1[j] != str2[j]);
32 }
33 printk("\r\n");
34 printk("\r\n");
35 }
36
37 __attribute__((used))
zcbor_print_compare_strings(const uint8_t * str1,const uint8_t * str2,uint32_t size)38 static void zcbor_print_compare_strings(const uint8_t *str1, const uint8_t *str2, uint32_t size)
39 {
40 for (uint32_t i = 0; i <= size / 16; i++) {
41 printk("line %d (char %d)\r\n", i, i*16);
42 zcbor_print_compare_lines(&str1[i*16], &str2[i*16],
43 MIN(16, (size - i*16)));
44 }
45 printk("\r\n");
46 }
47
48 __attribute__((used))
zcbor_print_compare_strings_diff(const uint8_t * str1,const uint8_t * str2,uint32_t size)49 static void zcbor_print_compare_strings_diff(const uint8_t *str1, const uint8_t *str2, uint32_t size)
50 {
51 bool printed = false;
52 for (uint32_t i = 0; i <= size / 16; i++) {
53 if (memcmp(&str1[i*16], &str2[i*16], MIN(16, (size - i*16)) != 0)) {
54 printk("line %d (char %d)\r\n", i, i*16);
55 zcbor_print_compare_lines(&str1[i*16], &str2[i*16],
56 MIN(16, (size - i*16)));
57 printed = true;
58 }
59 }
60 if (printed) {
61 printk("\r\n");
62 }
63 }
64
65 #ifdef __cplusplus
66 }
67 #endif
68
69 #endif /* ZCBOR_DEBUG_H__ */
70