File: test_macrocheck.c

package info (click to toggle)
dwarfutils 1%3A0.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,732 kB
  • sloc: ansic: 119,558; cpp: 6,689; xml: 4,736; sh: 1,674; python: 1,117; makefile: 1,099
file content (117 lines) | stat: -rw-r--r-- 3,965 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
  Copyright 2015-2016 David Anderson. All rights reserved.

  This program is free software; you can redistribute it and/or
  modify it under the terms of version 2 of the GNU General
  Public License as published by the Free Software Foundation.

  This program is distributed in the hope that it would be
  useful, but WITHOUT ANY WARRANTY; without even the implied
  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.

  Further, this software is distributed without any warranty
  that it is free of the rightful claim of any third person
  regarding infringement or the like.  Any license provided
  herein, whether implied or otherwise, applies only to this
  software file.  Patent licenses, if any, provided herein
  do not apply to combinations of this program with other
  software, or any other product whatsoever.

  You should have received a copy of the GNU General Public
  License along with this program; if not, write the Free
  Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  Boston MA 02110-1301, USA.

*/

#include "dd_macrocheck.c"
#include "dd_minimal.h"
#include <stdlib.h> /* for exit() */
void dd_minimal_count_global_error(void) {}

int
main(void)
{
    void * base = 0;
    Dwarf_Unsigned count = 0;
    int basefailcount = 0;
    int isdwarf5=FALSE;

    /* Test 1 */
    add_macro_import(&base,TRUE,200,0,0);
    count = macro_count_recs(&base);
    if (count != 1) {
        printf("FAIL: expect count 1, got %" DW_PR_DUu "\n",count);
        ++failcount;
    }
    print_macrocheck_statistics("test1",&base,isdwarf5,2000);

    /* Test two */
    add_macro_area_len(&base,200,100);
    add_macro_import(&base,FALSE,350,0,0);
    add_macro_area_len(&base,350,100);
    count = macro_count_recs(&base);
    if (count != 2) {
        printf("FAIL: expect count 2, got %" DW_PR_DUu "\n",count);
        ++failcount;
    }
    print_macrocheck_statistics("test 2",&base,isdwarf5,2000);
    clear_macrocheck_statistics(&base);

    /* Test three */
    basefailcount = failcount;
    add_macro_import(&base,TRUE,0,0,0);
    add_macro_area_len(&base,0,1000);
    add_macro_import(&base,FALSE,2000,0,0);
    add_macro_area_len(&base,2000,100);
    mark_macro_offset_printed(&base,2000);
    add_macro_import(&base,FALSE,1000,0,0);
    add_macro_area_len(&base,1000,900);
    add_macro_import(&base,FALSE,1000,0,0);
    add_macro_area_len(&base,1000,900);
    count = macro_count_recs(&base);
    if (count != 3) {
        printf("FAIL: expect count 3, got %" DW_PR_DUu "\n",count);
        ++failcount;
    }
    printf("\n  Expect an ERROR about overlap with "
        "the end of section\n");
    print_macrocheck_statistics("test 3",&base,isdwarf5,2000);
    clear_macrocheck_statistics(&base);
    if ((basefailcount+1) != failcount) {
        printf("FAIL: Found no error in test 3 checking!\n");
        ++failcount;
    } else {
        failcount = basefailcount;
    }

    /* Test Four */
    basefailcount = failcount;
    add_macro_import(&base,TRUE,50,0,0);
    add_macro_import(&base,TRUE,50,0,0);
    add_macro_area_len(&base,50,50);
    add_macro_import(&base,FALSE,200,0,0);
    add_macro_import(&base,FALSE,50,0,0);
    add_macro_import(&base,FALSE,60,0,0);
    add_macro_area_len(&base,60,10);
    printf( "\n  Expect an ERROR about offset 50 having "
        "2 primaries\n");
    printf( "  and Expect an ERROR about offset 50 having 2\n"
        "  primaries"
        " and a secondary\n");
    printf( "  and Expect an ERROR about crazy overlap 60\n\n");
    print_macrocheck_statistics("test 4",&base,isdwarf5,2000);
    clear_macrocheck_statistics(&base);
    if ((basefailcount + 3) != failcount) {
        printf("FAIL: Found wrong errors in test 4 checking!\n");
    } else {
        failcount = basefailcount;
    }
    if (failcount > 0) {
        printf("FAIL macrocheck selftest\n");
        exit(EXIT_FAILURE);
    }
    printf("PASS macrocheck selftest\n");
    return 0;
}