Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1317924 - resurrect mpi tests, r=ttaubert
Differential Revision: https://nss-review.dev.mozaws.net/D68 --HG-- rename : lib/freebl/mpi/mpi-test.c => cmd/mpitests/mpi-test.c rename : gtests/util_gtest/util_gtest.gyp => cmd/mpitests/mpitests.gyp rename : lib/freebl/mpi/test-info.c => cmd/mpitests/test-info.c rename : gtests/util_gtest/util_gtest.gyp => gtests/freebl_gtest/freebl_gtest.gyp extra : rebase_source : 163b288b5fac99b04e7de8376628a5a6b0e3f1da extra : amend_source : 5850535f6d2114601a4bed890315b130245f28c5
- Loading branch information
1 parent
d1a94bd
commit 4c3da8d
Showing
10 changed files
with
195 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
{ | ||
'includes': [ | ||
'../../coreconf/config.gypi', | ||
'../../cmd/platlibs.gypi' | ||
], | ||
'targets': [ | ||
{ | ||
'target_name': 'mpi_tests', | ||
'type': 'executable', | ||
'sources': [ | ||
'mpi-test.c', | ||
], | ||
'dependencies': [ | ||
'<(DEPTH)/lib/freebl/freebl.gyp:<(freebl_name)', | ||
] | ||
} | ||
], | ||
'target_defaults': { | ||
'include_dirs': [ | ||
'<(DEPTH)/lib/freebl/mpi', | ||
'<(DEPTH)/lib/util', | ||
] | ||
}, | ||
'variables': { | ||
'module': 'nss' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
{ | ||
'includes': [ | ||
'../../coreconf/config.gypi', | ||
'../common/gtest.gypi', | ||
], | ||
'targets': [ | ||
{ | ||
'target_name': 'freebl_gtest', | ||
'type': 'executable', | ||
'sources': [ | ||
'mpi_unittest.cc', | ||
'<(DEPTH)/gtests/common/gtests.cc' | ||
], | ||
'dependencies': [ | ||
'<(DEPTH)/exports.gyp:nss_exports', | ||
'<(DEPTH)/lib/freebl/freebl.gyp:<(freebl_name)', | ||
'<(DEPTH)/gtests/google_test/google_test.gyp:gtest', | ||
], | ||
'defines': [ | ||
'CT_VERIF', | ||
], | ||
} | ||
], | ||
'target_defaults': { | ||
'include_dirs': [ | ||
'<(DEPTH)/gtests/google_test/gtest/include', | ||
'<(DEPTH)/gtests/common', | ||
'<(DEPTH)/lib/freebl/mpi', | ||
] | ||
}, | ||
'variables': { | ||
'module': 'nss' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "secdert.h" | ||
#include "secitem.h" | ||
#include "secport.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include <stdint.h> | ||
#include <string.h> | ||
#include <string> | ||
|
||
#include "mpi.h" | ||
namespace nss_test { | ||
|
||
class MPITest : public ::testing::Test { | ||
protected: | ||
void TestCmp(const std::string a_string, const std::string b_string, | ||
int result) { | ||
mp_int a, b, c; | ||
MP_DIGITS(&a) = 0; | ||
MP_DIGITS(&b) = 0; | ||
MP_DIGITS(&c) = 0; | ||
ASSERT_EQ(MP_OKAY, mp_init(&a)); | ||
ASSERT_EQ(MP_OKAY, mp_init(&b)); | ||
|
||
mp_read_radix(&a, a_string.c_str(), 16); | ||
mp_read_radix(&b, b_string.c_str(), 16); | ||
EXPECT_EQ(result, mp_cmp(&a, &b)); | ||
} | ||
}; | ||
|
||
TEST_F(MPITest, MpiCmp01Test) { TestCmp("0", "1", -1); } | ||
TEST_F(MPITest, MpiCmp10Test) { TestCmp("1", "0", 1); } | ||
TEST_F(MPITest, MpiCmp00Test) { TestCmp("0", "0", 0); } | ||
TEST_F(MPITest, MpiCmp11Test) { TestCmp("1", "1", 0); } | ||
|
||
TEST_F(MPITest, MpiCmpConstTest) { | ||
mp_int a, b, c; | ||
MP_DIGITS(&a) = 0; | ||
MP_DIGITS(&b) = 0; | ||
MP_DIGITS(&c) = 0; | ||
ASSERT_EQ(MP_OKAY, mp_init(&a)); | ||
ASSERT_EQ(MP_OKAY, mp_init(&b)); | ||
ASSERT_EQ(MP_OKAY, mp_init(&c)); | ||
|
||
mp_read_radix(&a, const_cast<char *>("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"), 16); | ||
mp_read_radix(&b, const_cast<char *>("FF0FFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551"), 16); | ||
mp_read_radix(&c, const_cast<char *>("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632550"), 16); | ||
|
||
mp_taint(&b); | ||
mp_taint(&c); | ||
|
||
uint32_t runs = 5000000; | ||
uint32_t time_b = 0, time_c = 0; | ||
for (uint32_t i = 0; i < runs; ++i) { | ||
struct timespec start, end; | ||
clock_gettime(CLOCK_MONOTONIC, &start); | ||
int r = mp_cmp(&a, &b); | ||
clock_gettime(CLOCK_MONOTONIC, &end); | ||
unsigned long long used = end.tv_sec * 1000000000L + end.tv_nsec; | ||
used -= (unsigned long long)start.tv_sec * 1000000000L + start.tv_nsec; | ||
time_b += used; | ||
ASSERT_EQ(1, r); | ||
} | ||
printf("time b: %u\n", time_b / runs); | ||
|
||
for (uint32_t i = 0; i < runs; ++i) { | ||
struct timespec start, end; | ||
clock_gettime(CLOCK_MONOTONIC, &start); | ||
int r = mp_cmp(&a, &c); | ||
clock_gettime(CLOCK_MONOTONIC, &end); | ||
unsigned long long used = end.tv_sec * 1000000000L + end.tv_nsec; | ||
used -= (unsigned long long)start.tv_sec * 1000000000L + start.tv_nsec; | ||
time_c += used; | ||
ASSERT_EQ(1, r); | ||
} | ||
printf("time c: %u\n", time_c / runs); | ||
} | ||
|
||
} // nss_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters