From: Rich Salz Date: Tue, 28 Jun 2016 17:05:24 +0000 (-0400) Subject: Platform sanity test X-Git-Tag: OpenSSL_1_1_0-pre6~248 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cc75cbc4ed568dca387ed218274573f5170f88de;p=oweals%2Fopenssl.git Platform sanity test Replace nptest with sanity test. Reviewed-by: Richard Levitte --- diff --git a/test/build.info b/test/build.info index aac86937f2..30f94a2385 100644 --- a/test/build.info +++ b/test/build.info @@ -1,7 +1,7 @@ IF[{- !$disabled{tests} -}] PROGRAMS=\ aborttest \ - nptest bntest \ + sanitytest bntest \ ectest ecdsatest ecdhtest gmdifftest pbelutest ideatest \ md2test md4test md5test \ hmactest wp_test \ @@ -22,9 +22,9 @@ IF[{- !$disabled{tests} -}] INCLUDE[aborttest]=../include DEPEND[aborttest]=../libcrypto - SOURCE[nptest]=nptest.c - INCLUDE[nptest]=../include - DEPEND[nptest]=../libcrypto + SOURCE[sanitytest]=sanitytest.c + INCLUDE[sanitytest]=../include + DEPEND[sanitytest]=../libcrypto SOURCE[bntest]=bntest.c INCLUDE[bntest]=.. ../crypto/include ../include diff --git a/test/nptest.c b/test/nptest.c deleted file mode 100644 index 62dd27135d..0000000000 --- a/test/nptest.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#include -#include - -int main() -{ - char *p = NULL; - char bytes[sizeof(p)]; - - memset(bytes, 0, sizeof bytes); - return memcmp(&p, bytes, sizeof(bytes)) == 0 ? 0 : 1; -} diff --git a/test/recipes/01-test_ordinals.t b/test/recipes/01-test_ordinals.t deleted file mode 100755 index 473d05b014..0000000000 --- a/test/recipes/01-test_ordinals.t +++ /dev/null @@ -1,58 +0,0 @@ -#! /usr/bin/env perl -# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. -# -# Licensed under the OpenSSL license (the "License"). You may not use -# this file except in compliance with the License. You can obtain a copy -# in the file LICENSE in the source distribution or at -# https://www.openssl.org/source/license.html - -use strict; -use OpenSSL::Test qw/:DEFAULT srctop_file/; - -setup("test_ordinals"); - -plan tests => 2; - -ok(testordinals(srctop_file("util", "libcrypto.num")), "Test libcrypto.num"); -ok(testordinals(srctop_file("util", "libssl.num")), "Test libssl.num"); - -sub testordinals -{ - my $filename = shift; - my $cnt = 0; - my $ret = 1; - my $qualifier = ""; - my $newqual; - my $lastfunc = ""; - - open(my $fh, '<', $filename); - while (my $line = <$fh>) { - my @tokens = split(/(?:\s+|\s*:\s*)/, $line); - #Check the line looks sane - if ($#tokens < 5 || $#tokens > 6) { - print STDERR "Invalid line:\n$line\n"; - $ret = 0; - last; - } - if ($tokens[3] eq "NOEXIST") { - #Ignore this line - next; - } - #Some ordinals can be repeated, e.g. if one is VMS and another is !VMS - $newqual = $tokens[4]; - $newqual =~ s/!//g; - if ($cnt > $tokens[1] - || ($cnt == $tokens[1] && ($qualifier ne $newqual - || $qualifier eq ""))) { - print STDERR "Invalid ordinal detected: ".$tokens[1]."\n"; - $ret = 0; - last; - } - $cnt = $tokens[1]; - $qualifier = $newqual; - $lastfunc = $tokens[0]; - } - close($fh); - - return $ret; -} diff --git a/test/recipes/01-test_sanity.t b/test/recipes/01-test_sanity.t new file mode 100644 index 0000000000..f01466d8c9 --- /dev/null +++ b/test/recipes/01-test_sanity.t @@ -0,0 +1,12 @@ +#! /usr/bin/env perl +# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + + +use OpenSSL::Test::Simple; + +simple_test("test_sanity", "sanitytest"); diff --git a/test/recipes/02-test_ordinals.t b/test/recipes/02-test_ordinals.t new file mode 100755 index 0000000000..473d05b014 --- /dev/null +++ b/test/recipes/02-test_ordinals.t @@ -0,0 +1,58 @@ +#! /usr/bin/env perl +# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +use strict; +use OpenSSL::Test qw/:DEFAULT srctop_file/; + +setup("test_ordinals"); + +plan tests => 2; + +ok(testordinals(srctop_file("util", "libcrypto.num")), "Test libcrypto.num"); +ok(testordinals(srctop_file("util", "libssl.num")), "Test libssl.num"); + +sub testordinals +{ + my $filename = shift; + my $cnt = 0; + my $ret = 1; + my $qualifier = ""; + my $newqual; + my $lastfunc = ""; + + open(my $fh, '<', $filename); + while (my $line = <$fh>) { + my @tokens = split(/(?:\s+|\s*:\s*)/, $line); + #Check the line looks sane + if ($#tokens < 5 || $#tokens > 6) { + print STDERR "Invalid line:\n$line\n"; + $ret = 0; + last; + } + if ($tokens[3] eq "NOEXIST") { + #Ignore this line + next; + } + #Some ordinals can be repeated, e.g. if one is VMS and another is !VMS + $newqual = $tokens[4]; + $newqual =~ s/!//g; + if ($cnt > $tokens[1] + || ($cnt == $tokens[1] && ($qualifier ne $newqual + || $qualifier eq ""))) { + print STDERR "Invalid ordinal detected: ".$tokens[1]."\n"; + $ret = 0; + last; + } + $cnt = $tokens[1]; + $qualifier = $newqual; + $lastfunc = $tokens[0]; + } + close($fh); + + return $ret; +} diff --git a/test/recipes/90-test_np.t b/test/recipes/90-test_np.t deleted file mode 100644 index 08bb84b081..0000000000 --- a/test/recipes/90-test_np.t +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env perl -# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. -# -# Licensed under the OpenSSL license (the "License"). You may not use -# this file except in compliance with the License. You can obtain a copy -# in the file LICENSE in the source distribution or at -# https://www.openssl.org/source/license.html - - -use OpenSSL::Test::Simple; - -simple_test("test_np", "nptest"); diff --git a/test/sanitytest.c b/test/sanitytest.c new file mode 100644 index 0000000000..9c968f46d9 --- /dev/null +++ b/test/sanitytest.c @@ -0,0 +1,67 @@ +/* + * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include +#include + + +#define TEST(e) \ + do { \ + if (!(e)) { \ + fprintf(stderr, "Failed " #e "\n"); \ + failures++; \ + } \ + } while (0) + + +enum smallchoices { sa, sb, sc }; +enum medchoices { ma, mb, mc, md, me, mf, mg, mh, mi, mj, mk, ml }; +enum largechoices { + a01, b01, c01, d01, e01, f01, g01, h01, i01, j01, + a02, b02, c02, d02, e02, f02, g02, h02, i02, j02, + a03, b03, c03, d03, e03, f03, g03, h03, i03, j03, + a04, b04, c04, d04, e04, f04, g04, h04, i04, j04, + a05, b05, c05, d05, e05, f05, g05, h05, i05, j05, + a06, b06, c06, d06, e06, f06, g06, h06, i06, j06, + a07, b07, c07, d07, e07, f07, g07, h07, i07, j07, + a08, b08, c08, d08, e08, f08, g08, h08, i08, j08, + a09, b09, c09, d09, e09, f09, g09, h09, i09, j09, + a10, b10, c10, d10, e10, f10, g10, h10, i10, j10, + xxx }; + +int main() +{ + char *p; + char bytes[sizeof(p)]; + int failures = 0; + + /* Is NULL equivalent to all-bytes-zero? */ + p = NULL; + memset(bytes, 0, sizeof bytes); + TEST(memcmp(&p, bytes, sizeof(bytes)) == 0); + + /* Enum size */ + TEST(sizeof(enum smallchoices) == sizeof(int)); + TEST(sizeof(enum medchoices) == sizeof(int)); + TEST(sizeof(enum largechoices) == sizeof(int)); + /* Basic two's complement checks. */ + TEST(~(-1) == 0); + TEST(~(-1L) == 0L); + + /* Check that values with sign bit 1 and value bits 0 are valid */ + TEST(-(INT_MIN + 1) == INT_MAX); + TEST(-(LONG_MIN + 1) == LONG_MAX); + + /* Check that unsigned-to-signed conversions preserve bit patterns */ + TEST((int)((unsigned int)INT_MAX + 1) == INT_MIN); + TEST((long)((unsigned long)LONG_MAX + 1) == LONG_MIN); + + return failures; +}