Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1318280 - Fix freebl_gtest on macOS r=franziskus
  • Loading branch information
Tim Taubert committed Nov 17, 2016
1 parent 6e9ea2f commit 1afe413
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions automation/taskcluster/scripts/run_clang_format.sh
Expand Up @@ -42,6 +42,7 @@ else
"$top/lib/util" \
"$top/gtests/common" \
"$top/gtests/der_gtest" \
"$top/gtests/freebl_gtest" \
"$top/gtests/pk11_gtest" \
"$top/gtests/ssl_gtest" \
"$top/gtests/util_gtest" \
Expand Down
53 changes: 44 additions & 9 deletions gtests/freebl_gtest/mpi_unittest.cc
Expand Up @@ -12,9 +12,30 @@
#include <string.h>
#include <string>

#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif

#include "mpi.h"
namespace nss_test {

void gettime(struct timespec *tp) {
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;

host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);

tp->tv_sec = mts.tv_sec;
tp->tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_MONOTONIC, tp);
#endif
}

class MPITest : public ::testing::Test {
protected:
void TestCmp(const std::string a_string, const std::string b_string,
Expand Down Expand Up @@ -46,9 +67,21 @@ TEST_F(MPITest, MpiCmpConstTest) {
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_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);
Expand All @@ -57,23 +90,25 @@ TEST_F(MPITest, MpiCmpConstTest) {
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);
gettime(&start);
int r = mp_cmp(&a, &b);
clock_gettime(CLOCK_MONOTONIC, &end);
gettime(&end);
unsigned long long used = end.tv_sec * 1000000000L + end.tv_nsec;
used -= (unsigned long long)start.tv_sec * 1000000000L + start.tv_nsec;
used -= static_cast<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);
gettime(&start);
int r = mp_cmp(&a, &c);
clock_gettime(CLOCK_MONOTONIC, &end);
gettime(&end);
unsigned long long used = end.tv_sec * 1000000000L + end.tv_nsec;
used -= (unsigned long long)start.tv_sec * 1000000000L + start.tv_nsec;
used -= static_cast<unsigned long long>(start.tv_sec * 1000000000L +
start.tv_nsec);
time_c += used;
ASSERT_EQ(1, r);
}
Expand Down
8 changes: 5 additions & 3 deletions lib/freebl/freebl.gyp
Expand Up @@ -103,9 +103,6 @@
'dependencies': [
'<(DEPTH)/lib/util/util.gyp:nssutil3',
],
'defines': [
'CT_VERIF',
],
}],
[ 'target_arch=="x64"', {
'sources': [
Expand Down Expand Up @@ -224,6 +221,11 @@
'UNSAFE_FUZZER_MODE',
],
}],
[ 'test_build==1', {
'defines': [
'CT_VERIF',
],
}],
[ 'OS=="mac"', {
'conditions': [
[ 'target_arch=="ia32"', {
Expand Down

0 comments on commit 1afe413

Please sign in to comment.