Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1280846 - tests: adjust gtests to compile under modular builds, r…
…=franziskus

--HG--
extra : histedit_source : fb4abd45b84a6ecbde7a5de16131b033066f8c11
  • Loading branch information
ueno committed Jun 1, 2017
1 parent 02a9a2f commit c049dad
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 40 deletions.
25 changes: 10 additions & 15 deletions cmd/platlibs.mk
Expand Up @@ -32,6 +32,12 @@ else
DBMLIB = $(DIST)/lib/$(LIB_PREFIX)dbm.$(LIB_SUFFIX)
endif

ifeq ($(NSS_BUILD_UTIL_ONLY),1)
SECTOOL_LIB = $(NULL)
else
SECTOOL_LIB = $(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX)
endif

ifdef USE_STATIC_LIBS

DEFINES += -DNSS_USE_STATIC_LIBS
Expand Down Expand Up @@ -70,20 +76,10 @@ endif
endif

NSS_LIBS_1=
SECTOOL_LIB=
NSS_LIBS_2=
NSS_LIBS_3=
NSS_LIBS_4=

ifneq ($(NSS_BUILD_UTIL_ONLY),1)
SECTOOL_LIB = \
$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
$(NULL)
else
SECTOOL_LIB = \
$(NULL)
endif

ifneq ($(NSS_BUILD_SOFTOKEN_ONLY),1)
ifeq ($(OS_ARCH), WINNT)
# breakdown for windows
Expand Down Expand Up @@ -121,9 +117,6 @@ NSS_LIBS_1 = \
$(DIST)/lib/$(LIB_PREFIX)ssl.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)nss.$(LIB_SUFFIX) \
$(NULL)
SECTOOL_LIB = \
$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
$(NULL)
NSS_LIBS_2 = \
$(DIST)/lib/$(LIB_PREFIX)pkcs12.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)pkcs7.$(LIB_SUFFIX) \
Expand Down Expand Up @@ -201,7 +194,7 @@ ifeq ($(OS_ARCH), WINNT)

# $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
EXTRA_LIBS += \
$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
$(SECTOOL_LIB) \
$(NSSUTIL_LIB_DIR)/$(IMPORT_LIB_PREFIX)nssutil3$(IMPORT_LIB_SUFFIX) \
$(DIST)/lib/$(IMPORT_LIB_PREFIX)smime3$(IMPORT_LIB_SUFFIX) \
$(DIST)/lib/$(IMPORT_LIB_PREFIX)ssl3$(IMPORT_LIB_SUFFIX) \
Expand All @@ -220,7 +213,7 @@ else

# $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
EXTRA_LIBS += \
$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
$(SECTOOL_LIB) \
$(NULL)

ifeq ($(OS_ARCH), AIX)
Expand All @@ -238,13 +231,15 @@ EXTRA_SHARED_LIBS += \
-lplds4 \
-lnspr4 \
$(NULL)
ifndef NSS_BUILD_UTIL_ONLY
ifndef NSS_BUILD_SOFTOKEN_ONLY
EXTRA_SHARED_LIBS += \
-lssl3 \
-lsmime3 \
-lnss3
endif
endif
endif

ifdef SOFTOKEN_LIB_DIR
ifdef NSS_USE_SYSTEM_FREEBL
Expand Down
39 changes: 39 additions & 0 deletions cpputil/scoped_ptrs_util.h
@@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */

#ifndef scoped_ptrs_util_h__
#define scoped_ptrs_util_h__

#include <memory>
#include "pkcs11uri.h"
#include "secoid.h"

struct ScopedDelete {
void operator()(SECAlgorithmID* id) { SECOID_DestroyAlgorithmID(id, true); }
void operator()(SECItem* item) { SECITEM_FreeItem(item, true); }
void operator()(PK11URI* uri) { PK11URI_DestroyURI(uri); }
void operator()(PLArenaPool* arena) { PORT_FreeArena(arena, PR_FALSE); }
};

template <class T>
struct ScopedMaybeDelete {
void operator()(T* ptr) {
if (ptr) {
ScopedDelete del;
del(ptr);
}
}
};

#define SCOPED(x) typedef std::unique_ptr<x, ScopedMaybeDelete<x> > Scoped##x

SCOPED(SECAlgorithmID);
SCOPED(SECItem);
SCOPED(PK11URI);

#undef SCOPED

#endif // scoped_ptrs_util_h__
4 changes: 2 additions & 2 deletions gtests/certhigh_gtest/manifest.mn
Expand Up @@ -14,9 +14,9 @@ INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
-I$(CORE_DEPTH)/gtests/common \
-I$(CORE_DEPTH)/cpputil

REQUIRES = nspr nss libdbm gtest
REQUIRES = nspr gtest

PROGRAM = certhigh_gtest

EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) $(EXTRA_OBJS) \
../common/$(OBJDIR)/gtests$(OBJ_SUFFIX)
$(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX)
26 changes: 26 additions & 0 deletions gtests/common/gtests-util.cc
@@ -0,0 +1,26 @@
/* 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 "nspr.h"
#include "secoid.h"

#include <cstdlib>

#define GTEST_HAS_RTTI 0
#include "gtest/gtest.h"

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);

if (SECOID_Init() != SECSuccess) {
return 1;
}
int rv = RUN_ALL_TESTS();

if (SECOID_Shutdown() != SECSuccess) {
return 1;
}

return rv;
}
13 changes: 7 additions & 6 deletions gtests/common/manifest.mn
Expand Up @@ -6,9 +6,13 @@ CORE_DEPTH = ../..
DEPTH = ../..
MODULE = nss

CPPSRCS = \
gtests.cc \
$(NULL)
LIBRARY_NAME = gtestutil

ifeq ($(NSS_BUILD_UTIL_ONLY),1)
CPPSRCS = gtests-util.cc
else
CPPSRCS = gtests.cc
endif

INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
-I$(CORE_DEPTH)/gtests/common \
Expand All @@ -17,6 +21,3 @@ INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
REQUIRES = gtest

EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX)

# NOTE: this is not actually used but required to build gtests.o
PROGRAM = gtests
7 changes: 3 additions & 4 deletions gtests/der_gtest/der_getint_unittest.cc
Expand Up @@ -4,14 +4,13 @@
* 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 "secder.h"
#include "secerr.h"

#include <climits>
#include <memory>
#include "nss.h"
#include "pk11pub.h"
#include "secutil.h"

#include "gtest/gtest.h"
#include "scoped_ptrs.h"

namespace nss_test {

Expand Down
1 change: 0 additions & 1 deletion gtests/der_gtest/der_gtest.gyp
Expand Up @@ -12,7 +12,6 @@
'type': 'executable',
'sources': [
'der_getint_unittest.cc',
'der_private_key_import_unittest.cc',
'der_quickder_unittest.cc',
'<(DEPTH)/gtests/common/gtests.cc'
],
Expand Down
3 changes: 2 additions & 1 deletion gtests/der_gtest/der_quickder_unittest.cc
Expand Up @@ -7,11 +7,12 @@
#include <stdint.h>

#include "gtest/gtest.h"
#include "scoped_ptrs.h"
#include "scoped_ptrs_util.h"

#include "nss.h"
#include "prerror.h"
#include "secasn1.h"
#include "secder.h"
#include "secerr.h"
#include "secitem.h"

Expand Down
5 changes: 2 additions & 3 deletions gtests/der_gtest/manifest.mn
Expand Up @@ -8,17 +8,16 @@ MODULE = nss

CPPSRCS = \
der_getint_unittest.cc \
der_private_key_import_unittest.cc \
der_quickder_unittest.cc \
$(NULL)

INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
-I$(CORE_DEPTH)/gtests/common \
-I$(CORE_DEPTH)/cpputil

REQUIRES = nspr nss libdbm gtest
REQUIRES = nspr gtest

PROGRAM = der_gtest

EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) $(EXTRA_OBJS) \
../common/$(OBJDIR)/gtests$(OBJ_SUFFIX)
$(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX)
24 changes: 21 additions & 3 deletions gtests/manifest.mn
Expand Up @@ -5,14 +5,32 @@
CORE_DEPTH = ..
DEPTH = ..

DIRS = \
LIB_SRCDIRS = \
google_test \
common \
$(NULL)

ifneq ($(NSS_BUILD_WITHOUT_UTIL),1)
UTIL_SRCDIRS = \
util_gtest \
der_gtest \
$(NULL)
endif

ifneq ($(NSS_BUILD_SOFTOKEN_ONLY),1)
ifneq ($(NSS_BUILD_UTIL_ONLY),1)
NSS_SRCDIRS = \
certdb_gtest \
certhigh_gtest \
der_gtest \
util_gtest \
pk11_gtest \
ssl_gtest \
nss_bogo_shim \
$(NULL)
endif
endif

DIRS = \
$(LIB_SRCDIRS) \
$(UTIL_SRCDIRS) \
$(NSS_SRCDIRS) \
$(NULL)
3 changes: 2 additions & 1 deletion gtests/pk11_gtest/manifest.mn
Expand Up @@ -16,6 +16,7 @@ CPPSRCS = \
pk11_prf_unittest.cc \
pk11_prng_unittest.cc \
pk11_rsapss_unittest.cc \
pk11_der_private_key_import_unittest.cc \
$(NULL)

INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
Expand All @@ -27,5 +28,5 @@ REQUIRES = nspr nss libdbm gtest
PROGRAM = pk11_gtest

EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) $(EXTRA_OBJS) \
../common/$(OBJDIR)/gtests$(OBJ_SUFFIX)
$(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX)

0 comments on commit c049dad

Please sign in to comment.