Merge pull request #115 from hfmanson/master
[tlspool] / test / errorsizes.c
1 /* Ensure that the current compiler regime is happy with error sizes.
2  * See <tlspool/commands.h> above PIOC_ERROR_V2 for backgrounds.
3  * We move error codes back and forth between pioc_error.tlserrno and
4  * errno, where the former is an integer limited to int32_t values and
5  * the latter has wild implementations but usually holds a small range
6  * but is nonetheless the replacement for an "extern int errno" practice.
7  *
8  * From: Rick van Rein <rick@openfortress.nl>
9  */
10
11
12 #include <stdlib.h>
13 #include <stdint.h>
14 #include <stdio.h>
15
16 #include <errno.h>
17 #include <tlspool/commands.h>
18
19
20 #define NUM_VALS 18
21
22 long req_okay_vals [NUM_VALS] = {
23         (long) (int32_t) 0x80000000,
24         (long) (int32_t) 0x80000001,
25         (long) (int32_t) 0x80100000,
26         (long) (int32_t) 0xc0000000,
27         (long) (int32_t) 0xf0000000,
28         (long) (int32_t) 0xff000000,
29         (long) (int32_t) 0xffffff00,
30         (long) (int32_t) 0xffffffff,
31         (long) (int32_t) 0x00000000,
32         (long) (int32_t) 0x00000001,
33         (long) (int32_t) 0x00000100,
34         (long) (int32_t) 0x10000000,
35         (long) (int32_t) 0x10000001,
36         (long) (int32_t) 0x7f000000,
37         (long) (int32_t) 0x7fffff00,
38         (long) (int32_t) 0x7fffff01,
39         (long) (int32_t) 0x7ffffff0,
40         (long) (int32_t) 0x7fffffff
41 };
42
43
44 int main (int argc, char *argv []) {
45         struct pioc_error pe1, pe2;
46         int i;
47         long out1, out2;
48         int exit_val = 0;
49         for (i=0; i<NUM_VALS; i++) {
50                 //
51                 // in.long -> tlserrno -> errno -> out.long
52                 pe1.tlserrno = req_okay_vals [i];
53                 errno = pe1.tlserrno;
54                 out1 = errno;
55                 if (out1 != req_okay_vals [i]) {
56                         fprintf (stderr, "FAILURE.  in %ld -> tlserrno %d -> errno %d -> out %ld\n",
57                                                 req_okay_vals [i],
58                                                 pe1.tlserrno,
59                                                 errno,
60                                                 out1);
61                         exit_val = 1;
62                 }
63                 //
64                 // in.long -> errno -> tlserrno -> out.long
65                 errno = req_okay_vals [i];
66                 pe2.tlserrno = errno;
67                 out2 = pe2.tlserrno;
68                 if (out2 != req_okay_vals [i]) {
69                         fprintf (stderr, "FAILURE.  in %ld -> errno %d -> tlserrno %d -> out %ld\n",
70                                                 req_okay_vals [i],
71                                                 errno,
72                                                 pe2.tlserrno,
73                                                 out2);
74                         exit_val = 1;
75                 }
76         }
77         exit (exit_val);
78 }