Files
loongoffice/unotest/source/cpp/officeconnection.cxx
Stephan Bergmann e854abe076 Avoid external processes picking up instdir/program/libnspr4.so
...which is a problem in ASan builds, as seen with a failing
CppunitTest_sd_import_tests (among lots of other similarly failing tests):

> Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-11-openjdk-11.0.11.0.9-5.fc34.x86_64/lib/libsystemconf.so: ~/lo/core/instdir/program/libnspr4.so: undefined symbol: __asan_option_detect_stack_use_after_return
> 	at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
> 	at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442)
> 	at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498)
> 	at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
> 	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2648)
> 	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
> 	at java.base/java.lang.System.loadLibrary(System.java:1873)
> 	at java.base/java.security.SystemConfigurator$1.run(SystemConfigurator.java:67)
> 	at java.base/java.security.SystemConfigurator$1.run(SystemConfigurator.java:65)
> 	at java.base/java.security.AccessController.doPrivileged(Native Method)
> 	at java.base/java.security.SystemConfigurator.<clinit>(SystemConfigurator.java:65)
> 	at java.base/java.security.Security.initialize(Security.java:208)
> 	at java.base/java.security.Security$2.run(Security.java:93)
> 	at java.base/java.security.Security$2.run(Security.java:91)
> 	at java.base/java.security.AccessController.doPrivileged(Native Method)
> 	at java.base/java.security.Security.<clinit>(Security.java:91)
> 	at java.base/sun.security.jca.ProviderList.<init>(ProviderList.java:176)
> 	at java.base/sun.security.jca.ProviderList$2.run(ProviderList.java:94)
> 	at java.base/sun.security.jca.ProviderList$2.run(ProviderList.java:92)
> 	at java.base/java.security.AccessController.doPrivileged(Native Method)
> 	at java.base/sun.security.jca.ProviderList.fromSecurityProperties(ProviderList.java:91)
> 	at java.base/sun.security.jca.Providers.<clinit>(Providers.java:54)
> 	at java.base/java.security.SecureRandom.getDefaultPRNG(SecureRandom.java:264)
> 	at java.base/java.security.SecureRandom.<init>(SecureRandom.java:219)
> 	at java.base/java.util.UUID$Holder.<clinit>(UUID.java:101)
> 	at java.base/java.util.UUID.randomUUID(UUID.java:147)
> 	at org.probatron.officeotron.sessionstorage.Store.putZippedResource(Unknown Source)
> 	at org.probatron.officeotron.CommandLineSubmission.<init>(Unknown Source)
> 	at org.probatron.officeotron.Driver.main(Unknown Source)
> warn:svl.items:1258842:1258842:svl/source/items/itempool.cxx:358: old secondary pool: EditEngineItemPool of pool: XOutdevItemPool must be empty.
> ~/lo/core/test/source/bootstrapfixture.cxx:232:SdImportTest::testDocumentLayout
> equality assertion failed
> - Expected: 0
> - Actual  : 256
> - failed to execute: sh ~/lo/core/bin/officeotron.sh ~/lo/tmp/SdImportTest__testDocumentLayout_16w8dw.tmp > ~/lo/tmp/SdImportTest__testDocumentLayout_16w8dy.tmp

The solution reuses the arg-env bootstrap variable already used by
test::OfficeConnection::setUp (unotest/source/cpp/officeconnection.cxx) and for
that makes test::getArgumnet available outside Library_unotest.  (For
simplicity, it adds the relevant gb_CppunitTest_add_arguments calls
unconditionally to the various *.mk files, even though the data is only used
conditionally for non-_WIN32 in test::BootstrapFixture::validate in
test/source/bootstrapfixture.cxx, at least for now.)

Not sure what exactly started to cause this issue now for my ASan builds on
Fedora 34.

Change-Id: I7a4d6c0e36b94935442c6c91d5ee967fcad61763
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119317
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-07-21 15:27:02 +02:00

153 lines
5.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/bridge/UnoUrlResolver.hpp>
#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
#include <com/sun/star/connection/NoConnectException.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <cppuhelper/bootstrap.hxx>
#include <cppunit/TestAssert.h>
#include <osl/process.h>
#include <osl/test/uniquepipename.hxx>
#include <osl/time.h>
#include <sal/macros.h>
#include <unotest/getargument.hxx>
#include <unotest/officeconnection.hxx>
#include <unotest/toabsolutefileurl.hxx>
namespace test {
OfficeConnection::OfficeConnection(): process_(nullptr) {}
OfficeConnection::~OfficeConnection() {}
void OfficeConnection::setUp() {
css::uno::Reference< css::bridge::XUnoUrlResolver > resolver(
css::bridge::UnoUrlResolver::create(
cppu::defaultBootstrap_InitialComponentContext()));
OUString desc;
OUString argSoffice;
CPPUNIT_ASSERT(
getArgument(
u"soffice",
&argSoffice));
if (argSoffice.match("path:")) {
desc = "pipe,name=" + osl::test::uniquePipeName("oootest");
OUString noquickArg("--quickstart=no");
OUString norestoreArg("--norestore");
OUString nologoArg("--nologo");
// disable use of the unix standalone splash screen app for the
// tests (probably not needed in combination with --headless?)
OUString headlessArg("--headless");
OUString acceptArg("--accept=" + desc + ";urp");
OUString argUser;
CPPUNIT_ASSERT(
getArgument(u"user", &argUser));
OUString userArg("-env:UserInstallation=" + toAbsoluteFileUrl(argUser));
OUString jreArg(
"-env:UNO_JAVA_JFW_ENV_JREHOME=true");
rtl_uString * args[] = {
noquickArg.pData, norestoreArg.pData,
nologoArg.pData, headlessArg.pData, acceptArg.pData, userArg.pData,
jreArg.pData };
rtl_uString ** envs = nullptr;
OUString argEnv;
if (getArgument(u"env", &argEnv))
{
envs = &argEnv.pData;
}
// coverity[callee_ptr_arith] - arith is fine
CPPUNIT_ASSERT_EQUAL(
osl_Process_E_None,
osl_executeProcess(
toAbsoluteFileUrl(
argSoffice.copy(RTL_CONSTASCII_LENGTH("path:"))).pData,
args, SAL_N_ELEMENTS(args), 0, nullptr, nullptr, envs, envs == nullptr ? 0 : 1,
&process_));
} else if (argSoffice.match("connect:")) {
desc = argSoffice.copy(RTL_CONSTASCII_LENGTH("connect:"));
} else {
CPPUNIT_FAIL(
"\"soffice\" argument starts with neither \"path:\" nor"
" \"connect:\"");
}
for (;;) {
try {
context_ =
css::uno::Reference< css::uno::XComponentContext >(
resolver->resolve(
"uno:" + desc + ";urp;StarOffice.ComponentContext"),
css::uno::UNO_QUERY_THROW);
break;
} catch (css::connection::NoConnectException &) {}
if (process_ != nullptr) {
TimeValue delay = { 1, 0 }; // 1 sec
CPPUNIT_ASSERT_EQUAL(
osl_Process_E_TimedOut,
osl_joinProcessWithTimeout(process_, &delay));
}
}
}
void OfficeConnection::tearDown() {
if (process_ == nullptr)
return;
if (context_.is()) {
css::uno::Reference< css::frame::XDesktop2 > desktop = css::frame::Desktop::create( context_ );
context_.clear();
try {
CPPUNIT_ASSERT(desktop->terminate());
desktop.clear();
} catch (css::lang::DisposedException &) {}
// it appears that DisposedExceptions can already happen while
// receiving the response of the terminate call
}
CPPUNIT_ASSERT_EQUAL(osl_Process_E_None, osl_joinProcess(process_));
oslProcessInfo info;
info.Size = sizeof info;
CPPUNIT_ASSERT_EQUAL(
osl_Process_E_None,
osl_getProcessInfo(process_, osl_Process_EXITCODE, &info));
CPPUNIT_ASSERT_EQUAL(oslProcessExitCode(0), info.Code);
osl_freeProcessHandle(process_);
process_ = nullptr; // guard against subsequent calls to isStillAlive
}
bool OfficeConnection::isStillAlive() const {
if (process_ == nullptr) {
// In case "soffice" argument starts with "connect:" we have no direct
// control over the liveness of the soffice.bin process (would need to
// directly monitor the bridge) so can only assume the best here:
return true;
}
TimeValue delay = { 0, 0 }; // 0 sec
oslProcessError e = osl_joinProcessWithTimeout(process_, &delay);
CPPUNIT_ASSERT(e == osl_Process_E_None || e == osl_Process_E_TimedOut);
return e == osl_Process_E_TimedOut;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */