secnet.8: Describe capability negotiation in its own section.
[secnet] / msgcode-test.c
CommitLineData
7b2ef224
MW
1/*
2 * msgcode-test.c: check that the new message encoding is correct
3 */
4/*
5 * This file is Free Software. It was originally written for secnet.
6 *
7 * Copyright 2017 Mark Wooding
8 *
9 * You may redistribute secnet as a whole and/or modify it under the
10 * terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 3, or (at your option) any
12 * later version.
13 *
14 * You may redistribute this file and/or modify it under the terms of
15 * the GNU General Public License as published by the Free Software
16 * Foundation; either version 2, or (at your option) any later
17 * version.
18 *
19 * This software is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this software; if not, see
26 * https://www.gnu.org/licenses/gpl.html.
27 */
28
29#include <inttypes.h>
30#include <stdint.h>
31#include <stdio.h>
32#include <stdlib.h>
33
34#include "magic.h"
35
36#define OLD_LABEL_NAK 0x00000000
37#define OLD_LABEL_MSG0 0x00020200
38#define OLD_LABEL_MSG1 0x01010101
39#define OLD_LABEL_MSG2 0x02020202
40#define OLD_LABEL_MSG3 0x03030303
41#define OLD_LABEL_MSG3BIS 0x13030313
42#define OLD_LABEL_MSG4 0x04040404
43#define OLD_LABEL_MSG5 0x05050505
44#define OLD_LABEL_MSG6 0x06060606
45#define OLD_LABEL_MSG7 0x07070707
46#define OLD_LABEL_MSG8 0x08080808
47#define OLD_LABEL_MSG9 0x09090909
48#define OLD_LABEL_PROD 0x0a0a0a0a
49
50static void check_labels(const char *what, uint32_t new, uint32_t old)
51{
52 if (old != new) {
53 printf("mismatch for %s: %08"PRIx32" (new) /= %08"PRIx32" (old)\n",
54 what, new, old);
55 exit(2);
56 }
57}
58
59int main(void)
60{
61 unsigned i, j;
62 uint32_t m, r, s;
63
64#define CHECK(label) check_labels(#label, LABEL_##label, OLD_LABEL_##label)
65 CHECK(NAK);
66 CHECK(MSG0);
67 CHECK(MSG1);
68 CHECK(MSG2);
69 CHECK(MSG3);
70 CHECK(MSG3BIS);
71 CHECK(MSG4);
72 CHECK(MSG5);
73 CHECK(MSG6);
74 CHECK(MSG7);
75 CHECK(MSG8);
76 CHECK(MSG9);
77 CHECK(PROD);
78#undef CHECK
79 for (i = 0; i < 65536; i++) {
80 for (j = 0; j < 65536; j++) {
81 m = MSGCODE(i, j);
82 r = MSGMAJOR(m); s = MSGMINOR(m);
83 if (r != i || s != j) {
84 printf("roundtrip fail: %04x %04x -> %08"PRIx32" "
85 "-> %08"PRIx32" %08"PRIx32"\n",
86 i, j, m, r, s);
87 exit(2);
88 }
89 }
90 }
91
92 return (0);
93}