Skip to content

Commit

Permalink
Bug 1363213 - more, non-leaking mpi tests; run them on TC, r=ttaubert
Browse files Browse the repository at this point in the history
Differential Revision: https://nss-review.dev.mozaws.net/D284

--HG--
extra : rebase_source : 1b7a656ed77e1a8dd6c695beeba7b5d6bc128921
extra : amend_source : fcbc61ff59341d89bd0c13eb8488df2376a225af
  • Loading branch information
franziskuskiefer committed May 8, 2017
1 parent ffe4ee4 commit ac72e0e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
13 changes: 13 additions & 0 deletions automation/taskcluster/graph/src/extend.js
Expand Up @@ -455,6 +455,19 @@ async function scheduleTestBuilds(base, args = "") {
symbol: "mpi",
kind: "test"
}));
queue.scheduleTask(merge(base, {
parent: task_build,
command: [
"/bin/bash",
"-c",
"bin/checkout.sh && nss/automation/taskcluster/scripts/run_tests.sh"
],
name: "Gtests",
symbol: "Gtest",
tests: "gtests",
cycle: "standard",
kind: "test"
}));

return queue.submit();
}
Expand Down
46 changes: 43 additions & 3 deletions gtests/freebl_gtest/mpi_unittest.cc
Expand Up @@ -40,16 +40,18 @@ 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_int a, b;
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));

mp_clear(&a);
mp_clear(&b);
}
};

Expand All @@ -58,7 +60,41 @@ 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) {
TEST_F(MPITest, MpiCmpUnalignedTest) {
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, "ffffffffffffffff3b4e802b4e1478", 16);
mp_read_radix(&b, "ffffffffffffffff3b4e802b4e1478", 16);
EXPECT_EQ(0, mp_cmp(&a, &b));

// Now change a and b such that they contain the same numbers but are not
// aligned.
// a = ffffffffffffff|ff3b4e802b4e1478
// b = ffffffffffffffff|3b4e802b4e1478
MP_DIGITS(&b)[0] &= 0x00ffffffffffffff;
MP_DIGITS(&b)[1] = 0xffffffffffffffff;
EXPECT_EQ(-1, mp_cmp(&a, &b));

ASSERT_EQ(MP_OKAY, mp_sub(&a, &b, &c));
char c_tmp[40];
ASSERT_EQ(MP_OKAY, mp_toradix(&c, c_tmp, 16));
ASSERT_TRUE(strncmp(c_tmp, "feffffffffffffff100000000000000", 31));

mp_clear(&a);
mp_clear(&b);
mp_clear(&c);
}

// This test is slow. Disable it by default so we can run these tests on CI.
class DISABLED_MPITest : public ::testing::Test {};

TEST_F(DISABLED_MPITest, MpiCmpConstTest) {
mp_int a, b, c;
MP_DIGITS(&a) = 0;
MP_DIGITS(&b) = 0;
Expand Down Expand Up @@ -115,6 +151,10 @@ TEST_F(MPITest, MpiCmpConstTest) {
ASSERT_EQ(1, r);
}
printf("time c: %u\n", time_c / runs);

mp_clear(&a);
mp_clear(&b);
mp_clear(&c);
}

} // nss_test
2 changes: 1 addition & 1 deletion tests/gtests/gtests.sh
Expand Up @@ -83,7 +83,7 @@ gtest_cleanup()
}

################## main #################################################
GTESTS="prng_gtest der_gtest pk11_gtest util_gtest"
GTESTS="prng_gtest der_gtest pk11_gtest util_gtest freebl_gtest"
SOURCE_DIR="$PWD"/../..
gtest_init $0
gtest_start
Expand Down

0 comments on commit ac72e0e

Please sign in to comment.