]>
git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_xref.c
3 * Copyright (C) 2020 David Lamparter for NetDEF, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 * "lib/test_xref.c" (only 1 directory component included)
27 * 0x00000003 (network byte order - LOG_ERR)
28 * 0x00000000 (network byte order - EC / zero here)
30 * note there are no '\0' terminators included for the strings
33 * => 71a65ce6e81517f642c8f55fb2af6f181f7df54357913b5b577aa61a663fdd4c
40 * (for reference: base32ch[] = "0123456789ABCDEFGHJKMNPQRSTVWXYZ")
42 * (bits are consumed starting with the lowest bit, and the first character
43 * only consumes 4 bits and has the 5th bit at 1)
46 static const char *expect_uid
= "H7KJB-67TBH";
47 static bool test_logcall(void)
49 zlog_err("logging call");
54 static void check_xref(const struct xref
*xref
, bool *found
, bool *error
)
56 const char *file
= xref
->file
, *p
;
58 p
= strrchr(file
, '/');
62 if (strcmp(file
, "test_xref.c"))
64 if (xref
->type
!= XREFT_LOGMSG
)
66 if (strcmp(xref
->func
, "test_logcall"))
69 printf("xref: %s:%d %s() type=%d uid=%s\n",
70 xref
->file
, xref
->line
, xref
->func
, xref
->type
,
71 xref
->xrefdata
? xref
->xrefdata
->uid
: "--");
74 printf("duplicate xref!\n");
78 const struct xref_logmsg
*logmsg
;
80 logmsg
= container_of(xref
, struct xref_logmsg
, xref
);
81 if (strcmp(logmsg
->fmtstring
, "logging call")) {
82 printf("log message mismatch!\n");
85 if (logmsg
->priority
!= LOG_ERR
|| logmsg
->ec
!= 0) {
86 printf("metadata mismatch!\n");
92 if (!xref
->xrefdata
) {
93 printf("no unique ID?\n");
98 if (strcmp(xref
->xrefdata
->uid
, expect_uid
)) {
99 printf("unique ID mismatch, expected %s, got %s\n",
100 expect_uid
, xref
->xrefdata
->uid
);
105 static bool test_lookup(void)
107 struct xref_block
*xb
;
108 bool found
= false, error
= false;
110 for (xb
= xref_blocks
; xb
; xb
= xb
->next
) {
111 const struct xref
* const *xrefp
;
113 for (xrefp
= xb
->start
; xrefp
< xb
->stop
; xrefp
++) {
114 const struct xref
*xref
= *xrefp
;
119 check_xref(xref
, &found
, &error
);
122 return found
&& !error
;
125 bool (*tests
[])(void) = {
132 int main(int argc
, char **argv
)
134 zlog_aux_init("NONE: ", ZLOG_DISABLED
);
136 for (unsigned int i
= 0; i
< array_size(tests
); i
++)