Commit 1afe4130 authored by Tim Taubert's avatar Tim Taubert

Bug 1318280 - Fix freebl_gtest on macOS r=franziskus

Differential Revision: https://nss-review.dev.mozaws.net/D75
parent 6e9ea2f6
......@@ -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" \
......
......@@ -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,
......@@ -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);
......@@ -57,11 +90,12 @@ 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);
}
......@@ -69,11 +103,12 @@ TEST_F(MPITest, MpiCmpConstTest) {
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);
}
......
......@@ -103,9 +103,6 @@
'dependencies': [
'<(DEPTH)/lib/util/util.gyp:nssutil3',
],
'defines': [
'CT_VERIF',
],
}],
[ 'target_arch=="x64"', {
'sources': [
......@@ -224,6 +221,11 @@
'UNSAFE_FUZZER_MODE',
],
}],
[ 'test_build==1', {
'defines': [
'CT_VERIF',
],
}],
[ 'OS=="mac"', {
'conditions': [
[ 'target_arch=="ia32"', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment