[openssl-commits] [openssl] master update

paul.dale at oracle.com paul.dale at oracle.com
Mon Nov 27 22:57:31 UTC 2017


The branch master has been updated
       via  b7af3f1433cc0d8d5f88c0b8dcd55c0c2261281a (commit)
       via  92738d7d7321ab8b7e6b467dded9bd2d587b980c (commit)
      from  378db52bb0177ae03cac3c3ba194bb6dec34a2d7 (commit)


- Log -----------------------------------------------------------------
commit b7af3f1433cc0d8d5f88c0b8dcd55c0c2261281a
Author: Pauli <paul.dale at oracle.com>
Date:   Mon Nov 27 13:27:35 2017 +1000

    Test support for time_t comparisons.
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4797)

commit 92738d7d7321ab8b7e6b467dded9bd2d587b980c
Author: Pauli <paul.dale at oracle.com>
Date:   Mon Nov 27 13:19:27 2017 +1000

    use size_t tests instead of int ones
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4797)

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

Summary of changes:
 test/test_test.c      | 52 +++++++++++++++++++++++++++++++++++++--------------
 test/testutil.h       |  8 ++++++++
 test/testutil/tests.c | 30 +++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 14 deletions(-)

diff --git a/test/test_test.c b/test/test_test.c
index 2ec2b51..c45bf8d 100644
--- a/test/test_test.c
+++ b/test/test_test.c
@@ -170,20 +170,43 @@ err:
 
 static int test_size_t(void)
 {
-    if (!TEST(1, TEST_int_eq((size_t)10, (size_t)10))
-        | !TEST(0, TEST_int_eq((size_t)10, (size_t)12))
-        | !TEST(1, TEST_int_ne((size_t)10, (size_t)12))
-        | !TEST(0, TEST_int_ne((size_t)24, (size_t)24))
-        | !TEST(1, TEST_int_lt((size_t)30, (size_t)88))
-        | !TEST(0, TEST_int_lt((size_t)88, (size_t)30))
-        | !TEST(1, TEST_int_le((size_t)30, (size_t)88))
-        | !TEST(1, TEST_int_le((size_t)33, (size_t)33))
-        | !TEST(0, TEST_int_le((size_t)88, (size_t)30))
-        | !TEST(1, TEST_int_gt((size_t)52, (size_t)33))
-        | !TEST(0, TEST_int_gt((size_t)33, (size_t)52))
-        | !TEST(1, TEST_int_ge((size_t)52, (size_t)33))
-        | !TEST(1, TEST_int_ge((size_t)38, (size_t)38))
-        | !TEST(0, TEST_int_ge((size_t)33, (size_t)52)))
+    if (!TEST(1, TEST_size_t_eq((size_t)10, (size_t)10))
+        | !TEST(0, TEST_size_t_eq((size_t)10, (size_t)12))
+        | !TEST(1, TEST_size_t_ne((size_t)10, (size_t)12))
+        | !TEST(0, TEST_size_t_ne((size_t)24, (size_t)24))
+        | !TEST(1, TEST_size_t_lt((size_t)30, (size_t)88))
+        | !TEST(0, TEST_size_t_lt((size_t)88, (size_t)30))
+        | !TEST(1, TEST_size_t_le((size_t)30, (size_t)88))
+        | !TEST(1, TEST_size_t_le((size_t)33, (size_t)33))
+        | !TEST(0, TEST_size_t_le((size_t)88, (size_t)30))
+        | !TEST(1, TEST_size_t_gt((size_t)52, (size_t)33))
+        | !TEST(0, TEST_size_t_gt((size_t)33, (size_t)52))
+        | !TEST(1, TEST_size_t_ge((size_t)52, (size_t)33))
+        | !TEST(1, TEST_size_t_ge((size_t)38, (size_t)38))
+        | !TEST(0, TEST_size_t_ge((size_t)33, (size_t)52)))
+        goto err;
+    return 1;
+
+err:
+    return 0;
+}
+
+static int test_time_t(void)
+{
+    if (!TEST(1, TEST_time_t_eq((time_t)10, (time_t)10))
+        | !TEST(0, TEST_time_t_eq((time_t)10, (time_t)12))
+        | !TEST(1, TEST_time_t_ne((time_t)10, (time_t)12))
+        | !TEST(0, TEST_time_t_ne((time_t)24, (time_t)24))
+        | !TEST(1, TEST_time_t_lt((time_t)30, (time_t)88))
+        | !TEST(0, TEST_time_t_lt((time_t)88, (time_t)30))
+        | !TEST(1, TEST_time_t_le((time_t)30, (time_t)88))
+        | !TEST(1, TEST_time_t_le((time_t)33, (time_t)33))
+        | !TEST(0, TEST_time_t_le((time_t)88, (time_t)30))
+        | !TEST(1, TEST_time_t_gt((time_t)52, (time_t)33))
+        | !TEST(0, TEST_time_t_gt((time_t)33, (time_t)52))
+        | !TEST(1, TEST_time_t_ge((time_t)52, (time_t)33))
+        | !TEST(1, TEST_time_t_ge((time_t)38, (time_t)38))
+        | !TEST(0, TEST_time_t_ge((time_t)33, (time_t)52)))
         goto err;
     return 1;
 
@@ -518,6 +541,7 @@ int setup_tests(void)
     ADD_TEST(test_long);
     ADD_TEST(test_ulong);
     ADD_TEST(test_size_t);
+    ADD_TEST(test_time_t);
     ADD_TEST(test_pointer);
     ADD_TEST(test_bool);
     ADD_TEST(test_string);
diff --git a/test/testutil.h b/test/testutil.h
index 2356786..6391905 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -186,6 +186,7 @@ DECLARE_COMPARISONS(char, char)
 DECLARE_COMPARISONS(unsigned char, uchar)
 DECLARE_COMPARISONS(long, long)
 DECLARE_COMPARISONS(unsigned long, ulong)
+DECLARE_COMPARISONS(time_t, time_t)
 /*
  * Because this comparison uses a printf format specifier that's not
  * universally known (yet), we provide an option to not have it declared.
@@ -336,6 +337,13 @@ void test_perror(const char *s);
 # define TEST_size_t_gt(a, b) test_size_t_gt(__FILE__, __LINE__, #a, #b, a, b)
 # define TEST_size_t_ge(a, b) test_size_t_ge(__FILE__, __LINE__, #a, #b, a, b)
 
+# define TEST_time_t_eq(a, b) test_time_t_eq(__FILE__, __LINE__, #a, #b, a, b)
+# define TEST_time_t_ne(a, b) test_time_t_ne(__FILE__, __LINE__, #a, #b, a, b)
+# define TEST_time_t_lt(a, b) test_time_t_lt(__FILE__, __LINE__, #a, #b, a, b)
+# define TEST_time_t_le(a, b) test_time_t_le(__FILE__, __LINE__, #a, #b, a, b)
+# define TEST_time_t_gt(a, b) test_time_t_gt(__FILE__, __LINE__, #a, #b, a, b)
+# define TEST_time_t_ge(a, b) test_time_t_ge(__FILE__, __LINE__, #a, #b, a, b)
+
 # define TEST_ptr_eq(a, b)    test_ptr_eq(__FILE__, __LINE__, #a, #b, a, b)
 # define TEST_ptr_ne(a, b)    test_ptr_ne(__FILE__, __LINE__, #a, #b, a, b)
 # define TEST_ptr(a)          test_ptr(__FILE__, __LINE__, #a, a)
diff --git a/test/testutil/tests.c b/test/testutil/tests.c
index eb0a393..a60af07 100644
--- a/test/testutil/tests.c
+++ b/test/testutil/tests.c
@@ -15,6 +15,7 @@
 #include <string.h>
 #include <ctype.h>
 #include "internal/nelem.h"
+#include <openssl/asn1.h>
 
 /*
  * Output a failed test first line.
@@ -416,3 +417,32 @@ int test_BN_abs_eq_word(const char *file, int line, const char *bns,
     BN_free(aa);
     return 0;
 }
+
+static const char *print_time(const ASN1_TIME *t)
+{
+    return t == NULL ? "<null>" : (char *)ASN1_STRING_get0_data(t);
+}
+
+#define DEFINE_TIME_T_COMPARISON(opname, op)                            \
+    int test_time_t_ ## opname(const char *file, int line,              \
+                               const char *s1, const char *s2,          \
+                               const time_t t1, const time_t t2)        \
+    {                                                                   \
+        ASN1_TIME *at1 = ASN1_TIME_set(NULL, t1);                       \
+        ASN1_TIME *at2 = ASN1_TIME_set(NULL, t2);                       \
+        int r = at1 != NULL && at2 != NULL                              \
+                && ASN1_TIME_compare(at1, at2) op 0;                    \
+        if (!r)                                                         \
+            test_fail_message(NULL, file, line, "time_t", s1, s2, #op,  \
+                              "[%s] compared to [%s]",                  \
+                              print_time(at1), print_time(at2));        \
+        ASN1_STRING_free(at1);                                          \
+        ASN1_STRING_free(at2);                                          \
+        return r;                                                       \
+    }
+DEFINE_TIME_T_COMPARISON(eq, ==)
+DEFINE_TIME_T_COMPARISON(ne, !=)
+DEFINE_TIME_T_COMPARISON(gt, >)
+DEFINE_TIME_T_COMPARISON(ge, >=)
+DEFINE_TIME_T_COMPARISON(lt, <)
+DEFINE_TIME_T_COMPARISON(le, <=)


More information about the openssl-commits mailing list