Browse Source

test with -DCI. Don't run performance test on CI. Remove CommonCrypto tests.

Marcin Krzyżanowski 8 years ago
parent
commit
d295e1db1f

+ 2 - 8
CryptoSwift.xcodeproj/project.pbxproj

@@ -57,7 +57,6 @@
 		757BC9C01C1CA5790093AAA9 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC93B1C1CA5790093AAA9 /* Utils.swift */; };
 		757DA2531A4ED0A4002BA3EF /* PaddingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2521A4ED0A4002BA3EF /* PaddingTests.swift */; };
 		757DA2551A4ED408002BA3EF /* AESTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2541A4ED408002BA3EF /* AESTests.swift */; };
-		757DA2571A4ED47B002BA3EF /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2561A4ED47B002BA3EF /* Helpers.swift */; };
 		757DA2591A4ED4D7002BA3EF /* ChaCha20Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757DA2581A4ED4D7002BA3EF /* ChaCha20Tests.swift */; };
 		757F44091CC172B6002B1F85 /* BlockCipher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757F44081CC172B6002B1F85 /* BlockCipher.swift */; };
 		757F440E1CC1822B002B1F85 /* SecureBytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757F440D1CC1822A002B1F85 /* SecureBytes.swift */; };
@@ -82,7 +81,6 @@
 		75DB81A81CDC06B100ED181A /* Updatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75DB81A71CDC06B100ED181A /* Updatable.swift */; };
 		75F818231D9527CE00A78C92 /* SHA3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F818221D9527CE00A78C92 /* SHA3.swift */; };
 		80545D131CA9FECD00474A99 /* Bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80545D121CA9FECD00474A99 /* Bit.swift */; };
-		E3FD2D501D6B7E1100A9F35F /* CommonCryptoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3FD2D4E1D6B734A00A9F35F /* CommonCryptoTests.swift */; };
 		E3FD2D531D6B81CE00A9F35F /* Error+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3FD2D511D6B813C00A9F35F /* Error+Extension.swift */; };
 /* End PBXBuildFile section */
 
@@ -207,7 +205,6 @@
 		757BC93B1C1CA5790093AAA9 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Utils.swift; path = Sources/CryptoSwift/Utils.swift; sourceTree = SOURCE_ROOT; };
 		757DA2521A4ED0A4002BA3EF /* PaddingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaddingTests.swift; sourceTree = "<group>"; };
 		757DA2541A4ED408002BA3EF /* AESTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AESTests.swift; sourceTree = "<group>"; };
-		757DA2561A4ED47B002BA3EF /* Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
 		757DA2581A4ED4D7002BA3EF /* ChaCha20Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChaCha20Tests.swift; sourceTree = "<group>"; };
 		757F44081CC172B6002B1F85 /* BlockCipher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BlockCipher.swift; path = Sources/CryptoSwift/BlockCipher.swift; sourceTree = SOURCE_ROOT; };
 		757F440D1CC1822A002B1F85 /* SecureBytes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SecureBytes.swift; path = Sources/CryptoSwift/SecureBytes.swift; sourceTree = SOURCE_ROOT; };
@@ -228,9 +225,9 @@
 		75D1F1F31D06B98B005A87A2 /* PBKDF1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PBKDF1.swift; path = Sources/CryptoSwift/PKCS5/PBKDF1.swift; sourceTree = SOURCE_ROOT; };
 		75DB81A21CDBFDC700ED181A /* BlockModeWorker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BlockModeWorker.swift; path = Sources/CryptoSwift/BlockMode/BlockModeWorker.swift; sourceTree = SOURCE_ROOT; };
 		75DB81A71CDC06B100ED181A /* Updatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Updatable.swift; path = Sources/CryptoSwift/Updatable.swift; sourceTree = SOURCE_ROOT; };
+		75EDCB811DAC4CA400D270E0 /* LinuxMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LinuxMain.swift; path = Tests/LinuxMain.swift; sourceTree = SOURCE_ROOT; };
 		75F818221D9527CE00A78C92 /* SHA3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SHA3.swift; path = Sources/CryptoSwift/SHA3.swift; sourceTree = SOURCE_ROOT; };
 		80545D121CA9FECD00474A99 /* Bit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Bit.swift; path = Sources/CryptoSwift/Bit.swift; sourceTree = SOURCE_ROOT; };
-		E3FD2D4E1D6B734A00A9F35F /* CommonCryptoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommonCryptoTests.swift; sourceTree = "<group>"; };
 		E3FD2D511D6B813C00A9F35F /* Error+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Error+Extension.swift"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -343,7 +340,6 @@
 		754BE46419693E190098E6F3 /* Tests */ = {
 			isa = PBXGroup;
 			children = (
-				757DA2561A4ED47B002BA3EF /* Helpers.swift */,
 				754BE46719693E190098E6F3 /* DigestTests.swift */,
 				75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */,
 				758A94271A65C59200E46135 /* HMACTests.swift */,
@@ -357,7 +353,6 @@
 				75C2E76C1D55F097003D2BCA /* Access.swift */,
 				756BFDCA1A82B87300B9D9A4 /* Bridging.h */,
 				754BE46519693E190098E6F3 /* Supporting Files */,
-				E3FD2D4E1D6B734A00A9F35F /* CommonCryptoTests.swift */,
 				E3FD2D511D6B813C00A9F35F /* Error+Extension.swift */,
 			);
 			name = Tests;
@@ -367,6 +362,7 @@
 		754BE46519693E190098E6F3 /* Supporting Files */ = {
 			isa = PBXGroup;
 			children = (
+				75EDCB811DAC4CA400D270E0 /* LinuxMain.swift */,
 				754BE46619693E190098E6F3 /* Info.plist */,
 			);
 			name = "Supporting Files";
@@ -620,7 +616,6 @@
 				75482EA41CB310B7001F66A5 /* PBKDF.swift in Sources */,
 				758A94291A65C67400E46135 /* HMACTests.swift in Sources */,
 				75100F8F19B0BC890005C5F5 /* Poly1305Tests.swift in Sources */,
-				757DA2571A4ED47B002BA3EF /* Helpers.swift in Sources */,
 				753B33011DAB84D600D06422 /* RandomBytesSequenceTests.swift in Sources */,
 				754BE46819693E190098E6F3 /* DigestTests.swift in Sources */,
 				E3FD2D531D6B81CE00A9F35F /* Error+Extension.swift in Sources */,
@@ -629,7 +624,6 @@
 				674A736F1BF5D85B00866C5B /* RabbitTests.swift in Sources */,
 				757DA2531A4ED0A4002BA3EF /* PaddingTests.swift in Sources */,
 				757DA2551A4ED408002BA3EF /* AESTests.swift in Sources */,
-				E3FD2D501D6B7E1100A9F35F /* CommonCryptoTests.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 23 - 19
Tests/CryptoSwiftTests/AESTests.swift

@@ -294,25 +294,29 @@ final class AESTests: XCTestCase {
         }
     }
 
-//    func testAES_encrypt_performance() {
-//        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
-//        let iv:Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
-//        let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
-//        let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
-//        measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
-//            _ = try! aes.encrypt(message)
-//        })
-//    }
-//
-//    func testAES_decrypt_performance() {
-//        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
-//        let iv:Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
-//        let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
-//        let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
-//        measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
-//            _ = try! aes.decrypt(message)
-//        })
-//    }
+    func testAES_encrypt_performance() {
+        #if !CI
+        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
+        let iv:Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
+        let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
+        let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
+        measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
+            _ = try! aes.encrypt(message)
+        })
+        #endif
+    }
+
+    func testAES_decrypt_performance() {
+        #if !CI
+        let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
+        let iv:Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
+        let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
+        let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7())
+        measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: true, for: { () -> Void in
+            _ = try! aes.decrypt(message)
+        })
+        #endif
+    }
 
     func testAESWithWrongKey() {
         let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];

+ 2 - 0
Tests/CryptoSwiftTests/ChaCha20Tests.swift

@@ -95,6 +95,7 @@ final class ChaCha20Tests: XCTestCase {
     }
 
     func testChaCha20Performance() {
+        #if !CI
         let key:Array<UInt8> = [0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c];
         let iv:Array<UInt8> = [0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F]
         let message = Array<UInt8>(repeating: 7, count: (1024 * 1024) * 1)
@@ -106,6 +107,7 @@ final class ChaCha20Tests: XCTestCase {
             }
             self.stopMeasuring()
         })
+        #endif
     }
     
     static let allTests =  [

+ 0 - 26
Tests/CryptoSwiftTests/CommonCryptoTests.swift

@@ -1,26 +0,0 @@
-//
-//  CommonCryptoTests.swift
-//  CryptoSwift
-//
-//  Created by Michael Ledin on 22.08.16.
-//  Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
-//
-
-import XCTest
-@testable import CryptoSwift
-
-final class CryptoSwiftTests: XCTestCase {
-    func testMD5PerformanceCommonCrypto() {
-        self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, for: { () -> Void in
-            let buf: UnsafeMutableRawPointer = calloc(1024 * 1024, MemoryLayout<UInt8>.size)
-            let data = NSData(bytes: buf, length: 1024 * 1024)
-            let md = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
-            self.startMeasuring()
-            CC_MD5(data.bytes, CC_LONG(data.length), md)
-            self.stopMeasuring()
-            md.deallocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
-            md.deinitialize()
-            buf.deallocate(bytes: 1024 * 1024, alignedTo: MemoryLayout<UInt8>.alignment)
-        })
-    }
-}

+ 14 - 11
Tests/CryptoSwiftTests/DigestTests.swift

@@ -43,30 +43,33 @@ final class DigestTests: XCTestCase {
     }
 
     func testMD5PerformanceSwift() {
+        #if !CI
         self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, for: { () -> Void in
             let arr = Array<UInt8>(repeating: 200, count: 1024 * 1024)
             self.startMeasuring()
             _ = Digest.md5(arr)
             self.stopMeasuring()
         })
-    }
-    
-    func testSHA1() {
-        let data:Data = Data(bytes: UnsafePointer<UInt8>([0x31, 0x32, 0x33] as Array<UInt8>), count: 3)
-        XCTAssertEqual(data.sha1().toHexString(), "40bd001563085fc35165329ea1ff5c5ecbdbbeef", "SHA1 calculation failed");
-
-        XCTAssertEqual("abc".sha1(), "a9993e364706816aba3e25717850c26c9cd0d89d", "SHA1 calculation failed")
-        XCTAssertEqual("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".sha1(), "84983e441c3bd26ebaae4aa1f95129e5e54670f1", "SHA1 calculation failed")
-        XCTAssertEqual("".sha1(), "da39a3ee5e6b4b0d3255bfef95601890afd80709", "SHA1 calculation failed")
+        #endif
     }
 
     func testSHA1Performance() {
-//        let _ = "".sha1()
+        #if !CI
         self.measure {
             for _ in 0..<10_000 {
                 let _ = "".sha1()
             }
         }
+        #endif
+    }
+
+    func testSHA1() {
+        let data:Data = Data(bytes: UnsafePointer<UInt8>([0x31, 0x32, 0x33] as Array<UInt8>), count: 3)
+        XCTAssertEqual(data.sha1().toHexString(), "40bd001563085fc35165329ea1ff5c5ecbdbbeef", "SHA1 calculation failed");
+
+        XCTAssertEqual("abc".sha1(), "a9993e364706816aba3e25717850c26c9cd0d89d", "SHA1 calculation failed")
+        XCTAssertEqual("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq".sha1(), "84983e441c3bd26ebaae4aa1f95129e5e54670f1", "SHA1 calculation failed")
+        XCTAssertEqual("".sha1(), "da39a3ee5e6b4b0d3255bfef95601890afd80709", "SHA1 calculation failed")
     }
 
     func testSHA224() {
@@ -157,8 +160,8 @@ final class DigestTests: XCTestCase {
         ("testMD5String", testMD5String),
         ("testMD5Updates", testMD5Updates),
         ("testMD5PerformanceSwift", testMD5PerformanceSwift),
-        ("testSHA1", testSHA1),
         ("testSHA1Performance", testSHA1Performance),
+        ("testSHA1", testSHA1),
         ("testSHA224", testSHA224),
         ("testSHA256", testSHA256),
         ("testSHA384", testSHA384),

+ 2 - 0
Tests/CryptoSwiftTests/ExtensionsTest.swift

@@ -12,12 +12,14 @@ import Foundation
 final class ExtensionsTest: XCTestCase {
 
     func testArrayChunksPerformance() {
+        #if !CI
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, for: { () -> Void in
             let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
             self.startMeasuring()
             _ = message.chunks(size: AES.blockSize)
             self.stopMeasuring()
         })
+        #endif
     }
     
     func testBytes() {

+ 0 - 19
Tests/CryptoSwiftTests/Helpers.swift

@@ -1,19 +0,0 @@
-//
-//  Helpers.swift
-//  CryptoSwift
-//
-//  Created by Marcin Krzyzanowski on 27/12/14.
-//  Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
-//
-
-func compareMatrix(_ a:Array<Array<UInt8>>, b:Array<Array<UInt8>>) -> Bool {
-    for (i,arr) in a.enumerated() {
-        for (j,val) in arr.enumerated() {
-            if (val != b[i][j]) {
-                print("Not equal: \(val) vs \(b[i][j])") //FIXME: remove verbose
-                return false
-            }
-        }
-    }
-    return true
-}

+ 2 - 0
Tests/CryptoSwiftTests/RabbitTests.swift

@@ -110,6 +110,7 @@ class RabbitTests: XCTestCase {
     }
     
     func testRabbitPerformance() {
+        #if !CI
         let key: Array<UInt8> = Array<UInt8>(repeating: 0, count: Rabbit.keySize)
         let iv: Array<UInt8> = Array<UInt8>(repeating: 0, count: Rabbit.ivSize)
         let message = Array<UInt8>(repeating: 7, count: (1024 * 1024) * 1)
@@ -118,6 +119,7 @@ class RabbitTests: XCTestCase {
             self.stopMeasuring()
             XCTAssert(!encrypted.isEmpty, "not encrypted")
         })
+        #endif
     }
     
     static let allTests =  [

+ 1 - 1
scripts/CI.sh

@@ -38,5 +38,5 @@ if [ -e "Tools/testprep.sh" ]; then
 fi
 
 if [ -d "Tests" ]; then
-	swift test
+	swift test -Xswiftc -DCI
 fi