xref: /libbtbb/tests/test_syndromes.c (revision e25b118a40ed6b5c2ea76bae29e388cfbc2f6e92)
1 /* -*- c -*- */
2 /*
3  * Copyright 2007 - 2011 Dominic Spill, Michael Ossmann
4  *
5  * This file is part of libbtbb
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with libbtbb; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include "../bluetooth_packet.h"
28 #include <stdio.h>
29 
30 int test_syndromes() {
31     int ret, i;
32     uint64_t syndrome, syncword;
33     ret = 0;
34 
35     printf("Testing syndromes\n");
36     printf("-----------------\n");
37 
38     uint64_t syndrome_input[2] = {
39         /* No errors */
40         0xcc7b7268ff614e1b,
41         /* Errors */
42         0xcc7d7268ff614e1b
43     };
44 
45     uint64_t syndrome_output[2] = {
46         /* No errors */
47         0,
48         /* Errors */
49         0x0000000299c6f9b5
50     };
51 
52     for(i = 0; i < 2; i++) {
53         syndrome = gen_syndrome(syndrome_input[i]);
54         if (syndrome == syndrome_output[i]) {
55             printf(".");
56         } else {
57             printf("F");
58             ret++;
59         }
60     }
61 
62     uint64_t syncword_input[2] = {
63         /* No errors */
64         0xcc7b7268ff614e1b,
65         /* Errors */
66         0xcc7b7268ff514e1b
67     };
68 
69     uint64_t syncword_output[2] = {
70         /* No errors */
71         0x4ffffffe44ad1ae7,
72         /* Errors */
73         0x4ffffffe44ad1ae7
74     };
75 
76     gen_syndrome_map();
77     for(i = 0; i < 2; i++) {
78         syncword = decode_syncword(syncword_input[i] ^ pn);
79         if (syncword == syncword_output[i]) {
80             printf(".");
81         } else {
82             printf("F");
83             ret++;
84         }
85     }
86 
87 	if (ret > 0)
88 		printf("%d errors\n", ret);
89     printf("\n-----------------\n");
90     printf("Done testing syndrome generation\n");
91     return ret;
92 }
93 
94 int main(int argc, char** argv) {
95     int ret = 0;
96 
97     ret += test_syndromes();
98 
99     exit(ret);
100 }
101