]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/sanitytest.c
Platform sanity test
[thirdparty/openssl.git] / test / sanitytest.c
1 /*
2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <internal/numbers.h>
13
14
15 #define TEST(e) \
16 do { \
17 if (!(e)) { \
18 fprintf(stderr, "Failed " #e "\n"); \
19 failures++; \
20 } \
21 } while (0)
22
23
24 enum smallchoices { sa, sb, sc };
25 enum medchoices { ma, mb, mc, md, me, mf, mg, mh, mi, mj, mk, ml };
26 enum largechoices {
27 a01, b01, c01, d01, e01, f01, g01, h01, i01, j01,
28 a02, b02, c02, d02, e02, f02, g02, h02, i02, j02,
29 a03, b03, c03, d03, e03, f03, g03, h03, i03, j03,
30 a04, b04, c04, d04, e04, f04, g04, h04, i04, j04,
31 a05, b05, c05, d05, e05, f05, g05, h05, i05, j05,
32 a06, b06, c06, d06, e06, f06, g06, h06, i06, j06,
33 a07, b07, c07, d07, e07, f07, g07, h07, i07, j07,
34 a08, b08, c08, d08, e08, f08, g08, h08, i08, j08,
35 a09, b09, c09, d09, e09, f09, g09, h09, i09, j09,
36 a10, b10, c10, d10, e10, f10, g10, h10, i10, j10,
37 xxx };
38
39 int main()
40 {
41 char *p;
42 char bytes[sizeof(p)];
43 int failures = 0;
44
45 /* Is NULL equivalent to all-bytes-zero? */
46 p = NULL;
47 memset(bytes, 0, sizeof bytes);
48 TEST(memcmp(&p, bytes, sizeof(bytes)) == 0);
49
50 /* Enum size */
51 TEST(sizeof(enum smallchoices) == sizeof(int));
52 TEST(sizeof(enum medchoices) == sizeof(int));
53 TEST(sizeof(enum largechoices) == sizeof(int));
54 /* Basic two's complement checks. */
55 TEST(~(-1) == 0);
56 TEST(~(-1L) == 0L);
57
58 /* Check that values with sign bit 1 and value bits 0 are valid */
59 TEST(-(INT_MIN + 1) == INT_MAX);
60 TEST(-(LONG_MIN + 1) == LONG_MAX);
61
62 /* Check that unsigned-to-signed conversions preserve bit patterns */
63 TEST((int)((unsigned int)INT_MAX + 1) == INT_MIN);
64 TEST((long)((unsigned long)LONG_MAX + 1) == LONG_MIN);
65
66 return failures;
67 }