[openssl-commits] [openssl] master update

Matt Caswell matt at openssl.org
Wed Apr 12 10:12:13 UTC 2017


The branch master has been updated
       via  cbf0cfafd14038a7bc9674aaf9200eced7fcc842 (commit)
      from  deeac6c346f73a1b6106f44160b62e883ee71a40 (commit)


- Log -----------------------------------------------------------------
commit cbf0cfafd14038a7bc9674aaf9200eced7fcc842
Author: Pauli <paul.dale at oracle.com>
Date:   Tue Apr 11 12:47:00 2017 +1000

    Update sanitytest to use the test infrastructure
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3176)

-----------------------------------------------------------------------

Summary of changes:
 test/build.info   |  2 +-
 test/sanitytest.c | 98 +++++++++++++++++++++++++++++++++----------------------
 2 files changed, 60 insertions(+), 40 deletions(-)

diff --git a/test/build.info b/test/build.info
index fce0098..658509f 100644
--- a/test/build.info
+++ b/test/build.info
@@ -35,7 +35,7 @@ IF[{- !$disabled{tests} -}]
   INCLUDE[aborttest]=../include
   DEPEND[aborttest]=../libcrypto
 
-  SOURCE[sanitytest]=sanitytest.c
+  SOURCE[sanitytest]=sanitytest.c testutil.c test_main.c
   INCLUDE[sanitytest]=../include
   DEPEND[sanitytest]=../libcrypto
 
diff --git a/test/sanitytest.c b/test/sanitytest.c
index 9c968f4..3ef0a37 100644
--- a/test/sanitytest.c
+++ b/test/sanitytest.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-2017 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
@@ -7,61 +7,81 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include <stdio.h>
 #include <string.h>
 #include <internal/numbers.h>
 
+#include "test_main.h"
+#include "testutil.h"
 
-#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()
+static int test_sanity_null_zero(void)
 {
     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);
+    return TEST_mem_eq(&p, sizeof(p), bytes, sizeof(bytes));
+}
+
+static int test_sanity_enum_size(void)
+{
+    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 };
 
     /* Enum size */
-    TEST(sizeof(enum smallchoices) == sizeof(int));
-    TEST(sizeof(enum medchoices) == sizeof(int));
-    TEST(sizeof(enum largechoices) == sizeof(int));
+    if (!TEST_size_t_eq(sizeof(enum smallchoices), sizeof(int))
+        || !TEST_size_t_eq(sizeof(enum medchoices), sizeof(int))
+        || !TEST_size_t_eq(sizeof(enum largechoices), sizeof(int)))
+        return 0;
+    return 1;
+}
+
+static int test_sanity_twos_complement(void)
+{
     /* Basic two's complement checks. */
-    TEST(~(-1) == 0);
-    TEST(~(-1L) == 0L);
+    if (!TEST_int_eq(~(-1), 0)
+        || !TEST_long_eq(~(-1L), 0L))
+        return 0;
+    return 1;
+}
 
+static int test_sanity_sign(void)
+{
     /* 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);
+    if (!TEST_int_eq(-(INT_MIN + 1), INT_MAX)
+        || !TEST_long_eq(-(LONG_MIN + 1), LONG_MAX))
+        return 0;
+    return 1;
+}
 
+static int test_sanity_unsigned_convertion(void)
+{
     /* 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);
+    if (!TEST_int_eq((int)((unsigned int)INT_MAX + 1), INT_MIN)
+        || !TEST_long_eq((long)((unsigned long)LONG_MAX + 1), LONG_MIN))
+        return 0;
+    return 1;
+}
 
-    return failures;
+void register_tests(void)
+{
+    ADD_TEST(test_sanity_null_zero);
+    ADD_TEST(test_sanity_enum_size);
+    ADD_TEST(test_sanity_twos_complement);
+    ADD_TEST(test_sanity_sign);
+    ADD_TEST(test_sanity_unsigned_convertion);
 }
+


More information about the openssl-commits mailing list