diff options
author | Franziskus Kiefer <franziskuskiefer@gmail.com> | 2017-05-09 13:21:55 -0700 |
---|---|---|
committer | Franziskus Kiefer <franziskuskiefer@gmail.com> | 2017-05-09 13:21:55 -0700 |
commit | 2076ef5e8bc031ad64fd14b8830cec109480d1ab (patch) | |
tree | 1b80c509130d84cfe4543b9f342ce2dc4481a430 /gtests/freebl_gtest | |
parent | 8652b3b9402d5149fa435ba70712561b0d948b02 (diff) | |
download | nss-hg-2076ef5e8bc031ad64fd14b8830cec109480d1ab.tar.gz |
Bug 1362392 - fix s_mpi_div on 32-bit; fix 32-bit test builds
Differential Revision: https://nss-review.dev.mozaws.net/D320
Diffstat (limited to 'gtests/freebl_gtest')
-rw-r--r-- | gtests/freebl_gtest/freebl_gtest.gyp | 25 | ||||
-rw-r--r-- | gtests/freebl_gtest/mpi_unittest.cc | 27 |
2 files changed, 44 insertions, 8 deletions
diff --git a/gtests/freebl_gtest/freebl_gtest.gyp b/gtests/freebl_gtest/freebl_gtest.gyp index 546e69aa9..d74a39b4f 100644 --- a/gtests/freebl_gtest/freebl_gtest.gyp +++ b/gtests/freebl_gtest/freebl_gtest.gyp @@ -29,13 +29,6 @@ '<(DEPTH)/lib/pki/pki.gyp:nsspki', '<(DEPTH)/lib/ssl/ssl.gyp:ssl', ], - 'conditions': [ - [ 'ct_verif==1', { - 'defines': [ - 'CT_VERIF', - ], - }], - ], }, { 'target_name': 'prng_gtest', @@ -62,7 +55,23 @@ 'target_defaults': { 'include_dirs': [ '<(DEPTH)/lib/freebl/mpi', - ] + ], + # For test builds we have to set MPI defines. + 'conditions': [ + [ 'ct_verif==1', { + 'defines': [ + 'CT_VERIF', + ], + }], + [ 'target_arch=="ia32"', { + 'defines': [ + 'MP_USE_UINT_DIGIT', + 'MP_ASSEMBLY_MULTIPLY', + 'MP_ASSEMBLY_SQUARE', + 'MP_ASSEMBLY_DIV_2DX1D', + ], + }], + ], }, 'variables': { 'module': 'nss' diff --git a/gtests/freebl_gtest/mpi_unittest.cc b/gtests/freebl_gtest/mpi_unittest.cc index 1f769c014..059183fb6 100644 --- a/gtests/freebl_gtest/mpi_unittest.cc +++ b/gtests/freebl_gtest/mpi_unittest.cc @@ -53,13 +53,39 @@ class MPITest : public ::testing::Test { mp_clear(&a); mp_clear(&b); } + + void TestDiv(const std::string a_string, const std::string b_string, + const std::string 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)); + ASSERT_EQ(MP_OKAY, mp_init(&c)); + + mp_read_radix(&a, a_string.c_str(), 16); + mp_read_radix(&b, b_string.c_str(), 16); + mp_read_radix(&c, result.c_str(), 16); + EXPECT_EQ(MP_OKAY, mp_div(&a, &b, &a, &b)); + EXPECT_EQ(0, mp_cmp(&a, &c)); + + mp_clear(&a); + mp_clear(&b); + mp_clear(&c); + } }; 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, MpiDiv32ErrorTest) { + TestDiv("FFFF00FFFFFFFF000000000000", "FFFF00FFFFFFFFFF", "FFFFFFFFFF"); +} +#ifdef NSS_X64 +// This tests assumes 64-bit mp_digits. TEST_F(MPITest, MpiCmpUnalignedTest) { mp_int a, b, c; MP_DIGITS(&a) = 0; @@ -90,6 +116,7 @@ TEST_F(MPITest, MpiCmpUnalignedTest) { mp_clear(&b); mp_clear(&c); } +#endif // This test is slow. Disable it by default so we can run these tests on CI. class DISABLED_MPITest : public ::testing::Test {}; |