Changeset 51878 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Jul 5, 2014 8:23:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTDigest-2.cpp
r51856 r51878 36 36 #include <iprt/err.h> 37 37 #include <iprt/test.h> 38 #include <iprt/thread.h> 38 39 #include <iprt/string.h> 39 40 … … 103 104 * @param cTests The number of tests in the table. 104 105 * @param pszDigestName The name of the digest. 106 * @param enmDigestType The digest enum type value. 105 107 */ 106 static void testGeneric(const char *pszDigestObjId, TESTRTDIGEST const *paTests, size_t cTests, const char *pszDigestName) 108 static void testGeneric(const char *pszDigestObjId, TESTRTDIGEST const *paTests, size_t cTests, const char *pszDigestName, 109 RTDIGESTTYPE enmDigestType) 107 110 { 108 111 /* … … 154 157 */ 155 158 RTTESTI_CHECK_RC_RETV(RTCrDigestCreateByObjIdString(&hDigest, pszDigestObjId), VINF_SUCCESS); 156 uint32_t cChunks = 64; 159 160 /* Warmup. */ 161 uint32_t cChunks = enmDigestType == RTDIGESTTYPE_MD2 ? 12 : 128; 157 162 uint32_t cLeft = cChunks; 158 163 int rc = VINF_SUCCESS; 159 164 RTThreadYield(); 160 165 uint64_t uStartTS = RTTimeNanoTS(); 161 166 while (cLeft-- > 0) 162 167 rc |= RTCrDigestUpdate(hDigest, g_abRandom72KB, sizeof(g_abRandom72KB)); 163 rc |= RTCrDigestFinal(hDigest, NULL, 0); 168 uint64_t cNsPerChunk = (RTTimeNanoTS() - uStartTS) / cChunks; 169 if (!cNsPerChunk) 170 cNsPerChunk = 16000000 / cChunks; /* Time resolution kludge: 16ms. */ 171 RTTESTI_CHECK_RETV(rc == VINF_SUCCESS); 172 173 /* Do it for real for about 2 seconds. */ 174 RTTESTI_CHECK_RC(RTCrDigestReset(hDigest), VINF_SUCCESS); 175 cChunks = _2G32 / cNsPerChunk; 176 cLeft = cChunks; 177 RTThreadYield(); 178 uStartTS = RTTimeNanoTS(); 179 while (cLeft-- > 0) 180 rc |= RTCrDigestUpdate(hDigest, g_abRandom72KB, sizeof(g_abRandom72KB)); 164 181 uint64_t cNsElapsed = RTTimeNanoTS() - uStartTS; 165 182 RTTESTI_CHECK(rc == VINF_SUCCESS); 166 183 167 /* If it was too quick, redo with more chunks. */168 if (rc == VINF_SUCCESS && cNsElapsed < 100000000 /* 100 ms */)169 {170 cChunks = 1024;171 cLeft = cChunks;172 RTTESTI_CHECK_RC(RTCrDigestReset(hDigest), VINF_SUCCESS);173 174 uStartTS = RTTimeNanoTS();175 while (cLeft-- > 0)176 rc |= RTCrDigestUpdate(hDigest, g_abRandom72KB, sizeof(g_abRandom72KB));177 rc |= RTCrDigestFinal(hDigest, NULL, 0);178 cNsElapsed = RTTimeNanoTS() - uStartTS;179 RTTESTI_CHECK(rc == VINF_SUCCESS);180 }181 182 184 RTTestIValueF((uint64_t)cChunks * sizeof(g_abRandom72KB) / _1K / (0.000000001 * cNsElapsed), RTTESTUNIT_KILOBYTES_PER_SEC, 183 185 "%s throughput", pszDigestName); 186 RTTESTI_CHECK_RC(RTCrDigestRelease(hDigest), 0); 184 187 } 185 188 … … 380 383 { &g_abRandom72KB[0x20c9], 9991, "bbba194efa81238e5b613e20e937144e", "MD2 8393 bytes @9991" }, 381 384 }; 382 testGeneric("1.2.840.113549.2.2", s_abTests, RT_ELEMENTS(s_abTests), "MD2" );385 testGeneric("1.2.840.113549.2.2", s_abTests, RT_ELEMENTS(s_abTests), "MD2", RTDIGESTTYPE_MD2); 383 386 } 384 387 … … 579 582 { &g_abRandom72KB[0x20c9], 9991, "6461339c6615d23c704298a313e07cf5", "MD5 8393 bytes @9991" }, 580 583 }; 581 testGeneric("1.2.840.113549.2.5", s_abTests, RT_ELEMENTS(s_abTests), "MD5" );584 testGeneric("1.2.840.113549.2.5", s_abTests, RT_ELEMENTS(s_abTests), "MD5", RTDIGESTTYPE_MD5); 582 585 } 583 586 … … 758 761 { &g_abRandom72KB[0x20c9], 9991, "62001184bacacce3774566d916055d425a85eba5", "SHA-1 8393 bytes @9991" }, 759 762 }; 760 testGeneric("1.3.14.3.2.26", s_abTests, RT_ELEMENTS(s_abTests), "SHA-1" );763 testGeneric("1.3.14.3.2.26", s_abTests, RT_ELEMENTS(s_abTests), "SHA-1", RTDIGESTTYPE_SHA1); 761 764 } 762 765 … … 926 929 { &g_abRandom72KB[0x20c9], 9991, "8bd4c6142e36f15385769ebdeb855dcdf542f72d067315472a52ff626946310e", "SHA-256 8393 bytes @9991" }, 927 930 }; 928 testGeneric("2.16.840.1.101.3.4.2.1", s_abTests, RT_ELEMENTS(s_abTests), "SHA-256" );931 testGeneric("2.16.840.1.101.3.4.2.1", s_abTests, RT_ELEMENTS(s_abTests), "SHA-256", RTDIGESTTYPE_SHA256); 929 932 } 930 933 … … 964 967 "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525", "SHA-224 abcdbc..." }, 965 968 }; 966 testGeneric("2.16.840.1.101.3.4.2.4", s_abTests, RT_ELEMENTS(s_abTests), "SHA-224" );969 testGeneric("2.16.840.1.101.3.4.2.4", s_abTests, RT_ELEMENTS(s_abTests), "SHA-224", RTDIGESTTYPE_SHA224); 967 970 } 968 971 … … 1132 1135 { &g_abRandom72KB[0x20c9], 9991, "d6ac7c68664df2e34dc6be233b33f8dad196348350b70a4c2c5a78eb54d6e297c819771313d798de7552b7a3cb85370aab25087e189f3be8560d49406ebb6280", "SHA-512 8393 bytes @9991" }, 1133 1136 }; 1134 testGeneric("2.16.840.1.101.3.4.2.3", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512" );1137 testGeneric("2.16.840.1.101.3.4.2.3", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512", RTDIGESTTYPE_SHA512); 1135 1138 } 1136 1139 … … 1170 1173 "23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9", "SHA-512/256 abcdef..." }, 1171 1174 }; 1172 testGeneric("2.16.840.1.101.3.4.2.5", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512/224" );1175 testGeneric("2.16.840.1.101.3.4.2.5", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512/224", RTDIGESTTYPE_SHA512T224); 1173 1176 } 1174 1177 #endif /* IPRT_WITHOUT_SHA512T224 */ … … 1208 1211 "3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a", "SHA-512/256 abcdef..." }, 1209 1212 }; 1210 testGeneric("2.16.840.1.101.3.4.2.6", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512/256" );1213 testGeneric("2.16.840.1.101.3.4.2.6", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512/256", RTDIGESTTYPE_SHA512T256); 1211 1214 } 1212 1215 #endif /* !IPRT_WITHOUT_SHA512T256 */ … … 1245 1248 "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039", "SHA-384 abcdef..." }, 1246 1249 }; 1247 testGeneric("2.16.840.1.101.3.4.2.2", s_abTests, RT_ELEMENTS(s_abTests), "SHA-384" );1250 testGeneric("2.16.840.1.101.3.4.2.2", s_abTests, RT_ELEMENTS(s_abTests), "SHA-384", RTDIGESTTYPE_SHA384); 1248 1251 } 1249 1252
Note:
See TracChangeset
for help on using the changeset viewer.