summaryrefslogtreecommitdiffstats
path: root/src/util/et/t_com_err.c
blob: 2cba3cfdcca1ee83b2629971ffeed5db7053ba3c (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "com_err.h"
#include "et1.h"
#include "et2.h"

int misc_err, known_err;	/* known_err is err in whether or not
                                   table is 'known' to library */
int fail;

static void
try_one (errcode_t code, int known, int table, int msgno)
{
    const char *msg = error_message (code);
    char buffy[1024];

    sprintf (buffy, "error table %d message %d", table, msgno);
    if (0 == strcmp (buffy, msg)) {
	if (!known) {
	    known_err++;
	}
	return;
    }
    sprintf (buffy, "Unknown code et%d %d", table, msgno);
    if (!strcmp (buffy, msg)) {
	if (known)
	    known_err++;
	return;
    }
    printf ("error code %ld got unrecognized message '%s',\n"
	    "should have been table %d message %d\n",
	    (long) code, msg, table, msgno);
    misc_err++;
}

static void
try_table (int table, int known, int lineno,
	   errcode_t c0, errcode_t c1, errcode_t c2)
{
    try_one (c0, known, table, 0);
    try_one (c1, known, table, 1);
    try_one (c2, known, table, 2);
    if (misc_err != 0 || known_err != 0) {
	fail++;
	if (known_err)
	    printf ("table list error from line %d, table %d\n", lineno,
		    table);
	if (misc_err)
	    printf ("misc errors from line %d table %d\n", lineno, table);
	misc_err = known_err = 0;
    }
}

static void
try_em_1 (int t1_known, int t2_known, int lineno)
{
    try_table (1, t1_known, lineno, ET1_M0, ET1_M1, ET1_M2);
    try_table (2, t2_known, lineno, ET2_M0, ET2_M1, ET2_M2);
}
#define try_em(A,B) try_em_1(A,B,__LINE__)

static void *run(/*@unused@*/ void *x)
{
    try_em (0, 0);
    (void) add_error_table (&et_et1_error_table);
    try_em (1, 0);
    (void) add_error_table (&et_et2_error_table);
    try_em (1, 1);
    (void) remove_error_table (&et_et1_error_table);
    try_em (0, 1);
    (void) remove_error_table (&et_et1_error_table);
    try_em (0, 1);
    (void) remove_error_table (&et_et2_error_table);
    try_em (0, 0);

    initialize_et1_error_table ();
    try_em (1, 0);
    (void) add_error_table (&et_et1_error_table);
    try_em (1, 0);
    (void) remove_error_table (&et_et1_error_table);
    try_em (1, 0);
    (void) remove_error_table (&et_et1_error_table);
    try_em (0, 0);

    initialize_et1_error_table ();
    try_em (1, 0);
    (void) add_error_table (&et_et1_error_table);
    try_em (1, 0);
    (void) add_error_table (&et_et2_error_table);
    try_em (1, 1);
    (void) remove_error_table (&et_et1_error_table);
    try_em (1, 1);
    (void) remove_error_table (&et_et1_error_table);
    try_em (0, 1);
    (void) remove_error_table (&et_et2_error_table);
    try_em (0, 0);
    (void) remove_error_table (&et_et2_error_table);
    try_em (0, 0);

    (void) add_error_table (&et_et2_error_table);
    try_em (0, 1);
    initialize_et2_error_table ();
    try_em (0, 1);
    (void) add_error_table (&et_et1_error_table);
    try_em (1, 1);
    (void) remove_error_table (&et_et1_error_table);
    try_em (0, 1);
    (void) remove_error_table (&et_et2_error_table);
    try_em (0, 1);
    (void) remove_error_table (&et_et2_error_table);
    try_em (0, 0);

    return 0;
}

#ifdef TEST_THREADS
#include <pthread.h>
#endif

int main (/*@unused@*/ int argc, /*@unused@*/ char *argv[])
{
#ifdef TEST_THREADS
    pthread_t t;
    int err;
    void *t_retval;

    err = pthread_create(&t, 0, run, 0);
    if (err) {
	fprintf(stderr, "pthread_create error: %s\n", strerror(err));
	exit(1);
    }
    err = pthread_join(t, &t_retval);
    if (err) {
	fprintf(stderr, "pthread_join error: %s\n", strerror(err));
	exit(1);
    }
    return fail;
#else
    run(0);
    return fail;
#endif
}