diff options
author | Arnstein Ressem <aressem@gmail.com> | 2016-08-23 15:10:36 +0200 |
---|---|---|
committer | Vegard Sjonfjell <vegardsjo@gmail.com> | 2016-08-23 15:10:36 +0200 |
commit | 55e5a91901109161186e05d3a6e959e06958bbba (patch) | |
tree | f312bab2c60207ee305dbcfa047fcc4fa8fd2dc1 | |
parent | d337a29392fb752dc725e4aea5efa0cc0df5f17a (diff) |
Aressem/cmake more out of source tests (#441)
* vespalib tests run out of source.
* staging_vespalib run tests out of source.
* fastos tests run out of source.
* Fixed storage tests out of source.
* Fixed some of the config tests.
* config* tests run out of source.
* document_* tests run out of source.
* documentapi_ tests run out of source.
* Fixed fsa out of source tests.
* Fix jrt_test out of source.
* More tests run out of source.
* Fix some slobrok and messagebus tests.
* More fixes for out of source tests.
* Done with first pass of regular tests out of source.
* Only use SOURCE_DIRECTORY in a limited set of places.
* Fix some remaining tests.
* Some cleanups.
* No need for extra slash.
122 files changed, 513 insertions, 301 deletions
diff --git a/config/src/tests/configgen/configgen.cpp b/config/src/tests/configgen/configgen.cpp index 786268e7287..a1e891e19fa 100644 --- a/config/src/tests/configgen/configgen.cpp +++ b/config/src/tests/configgen/configgen.cpp @@ -3,13 +3,15 @@ #include <vespa/log/log.h> LOG_SETUP("configgen"); #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/config/config.h> #include "config-motd.h" using namespace config; TEST("require that config type can be compiled") { - std::unique_ptr<MotdConfig> cfg = ConfigGetter<MotdConfig>::getConfig("motd", FileSpec("motd.cfg")); + std::unique_ptr<MotdConfig> cfg = ConfigGetter<MotdConfig>::getConfig("motd", + FileSpec(vespalib::TestApp::GetSourceDirectory() + "motd.cfg")); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/config/src/tests/file_subscription/file_subscription.cpp b/config/src/tests/file_subscription/file_subscription.cpp index 4b2c84281e9..19aa43297a6 100644 --- a/config/src/tests/file_subscription/file_subscription.cpp +++ b/config/src/tests/file_subscription/file_subscription.cpp @@ -5,6 +5,7 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/file/filesource.h> #include <vespa/vespalib/util/sync.h> +#include <vespa/vespalib/testkit/testapp.h> #include <fstream> #include <config-my.h> #include <config-foo.h> @@ -27,6 +28,7 @@ namespace { } } + TEST("requireThatFileSpecGivesCorrectKey") { std::string str("/home/my/config.cfg"); FileSpec spec(str); @@ -129,7 +131,7 @@ TEST("requireThatMultipleSubscribersCanSubscribeToSameFile") { } TEST("requireThatCanSubscribeToDirectory") { - DirSpec spec("cfgdir"); + DirSpec spec(vespalib::TestApp::GetSourceDirectory() + "cfgdir"); ConfigSubscriber s(spec); ConfigHandle<FooConfig>::UP fooHandle = s.subscribe<FooConfig>(""); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); @@ -145,7 +147,7 @@ TEST("requireThatCanSubscribeToDirectory") { } TEST("requireThatCanSubscribeToDirectoryWithEmptyCfgFile") { - DirSpec spec("cfgemptyfile"); + DirSpec spec(vespalib::TestApp::GetSourceDirectory() + "cfgemptyfile"); ConfigSubscriber s(spec); ConfigHandle<FoodefaultConfig>::UP fooHandle = s.subscribe<FoodefaultConfig>(""); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); @@ -161,7 +163,7 @@ TEST("requireThatCanSubscribeToDirectoryWithEmptyCfgFile") { } TEST("requireThatCanSubscribeToDirectoryWithNonExistingCfgFile") { - DirSpec spec("cfgnonexistingfile"); + DirSpec spec(vespalib::TestApp::GetSourceDirectory() + "cfgnonexistingfile"); ConfigSubscriber s(spec); ConfigHandle<FoodefaultConfig>::UP fooHandle = s.subscribe<FoodefaultConfig>(""); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); @@ -176,7 +178,8 @@ TEST("requireThatCanSubscribeToDirectoryWithNonExistingCfgFile") { ASSERT_EQUAL("barbar", barCfg->barValue); } -TEST_F("requireThatDirSpecDoesNotMixNames", DirSpec("cfgdir2")) { +TEST_F("requireThatDirSpecDoesNotMixNames", + DirSpec(vespalib::TestApp::GetSourceDirectory() + "cfgdir2")) { ConfigSubscriber s(f); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>(""); ConfigHandle<FoobarConfig>::UP foobarHandle = s.subscribe<FoobarConfig>(""); @@ -189,7 +192,8 @@ TEST_F("requireThatDirSpecDoesNotMixNames", DirSpec("cfgdir2")) { ASSERT_EQUAL("foobarlol", foobar->fooBarValue); } -TEST_F("require that can subscribe multiple config ids of same config", DirSpec("cfgdir3")) { +TEST_F("require that can subscribe multiple config ids of same config", + DirSpec(vespalib::TestApp::GetSourceDirectory() + "cfgdir3")) { ConfigSubscriber s(f1); ConfigHandle<BarConfig>::UP fooHandle = s.subscribe<BarConfig>("foo"); ConfigHandle<BarConfig>::UP barHandle = s.subscribe<BarConfig>("bar"); diff --git a/config/src/tests/functiontest/functiontest.cpp b/config/src/tests/functiontest/functiontest.cpp index 6541e76e06a..444ba776f27 100644 --- a/config/src/tests/functiontest/functiontest.cpp +++ b/config/src/tests/functiontest/functiontest.cpp @@ -95,7 +95,7 @@ struct LazyTestFixture std::unique_ptr<FunctionTestConfig> _config; LazyTestFixture(const std::string & dirName) - : _spec(dirName), + : _spec(vespalib::TestApp::GetSourceDirectory() + dirName), _subscriber(_spec), _handle(_subscriber.subscribe<FunctionTestConfig>("")) { @@ -130,7 +130,7 @@ struct ErrorFixture }; void attemptLacking(const std::string& param, bool isArray) { - std::ifstream in("defaultvalues/function-test.cfg", std::ios_base::in); + std::ifstream in(vespalib::TestApp::GetSourceDirectory() + "defaultvalues/function-test.cfg", std::ios_base::in); std::ostringstream config; std::string s; while (std::getline(in, s)) { @@ -172,7 +172,7 @@ TEST_F("testVariableAccess", TestFixture("variableaccess")) { TEST("test variable access from slime") { vespalib::Slime slime; - std::string json(readFile("slime-payload.json")); + std::string json(readFile(vespalib::TestApp::GetSourceDirectory() + "slime-payload.json")); vespalib::slime::JsonFormat::decode(json, slime); FunctionTestConfig config(config::ConfigPayload(slime.get())); checkVariableAccess(config); diff --git a/config/src/tests/getconfig/getconfig.cpp b/config/src/tests/getconfig/getconfig.cpp index ec350e3140b..27f4fcf7505 100644 --- a/config/src/tests/getconfig/getconfig.cpp +++ b/config/src/tests/getconfig/getconfig.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/config/config.h> #include <vespa/config/raw/rawsource.h> #include "config-my.h" @@ -34,7 +35,7 @@ TEST("requireThatGetConfigReturnsCorrectConfig") TEST("requireThatGetConfigReturnsCorrectConfig") { - FileSpec spec("my.cfg"); + FileSpec spec(vespalib::TestApp::GetSourceDirectory() + "my.cfg"); std::unique_ptr<MyConfig> cfg = ConfigGetter<MyConfig>::getConfig("", spec); ASSERT_TRUE(cfg.get() != NULL); ASSERT_EQUAL("my", cfg->defName()); diff --git a/config/src/tests/legacysubscriber/legacysubscriber.cpp b/config/src/tests/legacysubscriber/legacysubscriber.cpp index 966e12a0b82..031f3f76f00 100644 --- a/config/src/tests/legacysubscriber/legacysubscriber.cpp +++ b/config/src/tests/legacysubscriber/legacysubscriber.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/config/helper/legacysubscriber.h> #include <fstream> #include <config-my.h> @@ -23,10 +24,19 @@ public: bool _configured; }; +struct ConfigIdGenerator +{ + static std::string id(const std::string &type, const std::string &name) + { + return std::string(type + ":" + + vespalib::TestApp::GetSourceDirectory() + name); + } +}; + TEST("requireThatFileLegacyWorks") { LegacySubscriber s; MyCallback<MyConfig> cb; - s.subscribe<MyConfig>("file:test1.cfg", &cb); + s.subscribe<MyConfig>(ConfigIdGenerator::id("file", "test1.cfg"), &cb); ASSERT_TRUE(cb._configured); ASSERT_TRUE(cb._config.get() != NULL); ASSERT_EQUAL("bar", cb._config->myField); @@ -35,7 +45,7 @@ TEST("requireThatFileLegacyWorks") { TEST("requireThatDirLegacyWorks") { LegacySubscriber s; MyCallback<MyConfig> cb; - s.subscribe<MyConfig>("dir:testdir", &cb); + s.subscribe<MyConfig>(ConfigIdGenerator::id("dir","testdir"), &cb); ASSERT_TRUE(cb._configured); ASSERT_TRUE(cb._config.get() != NULL); ASSERT_EQUAL("bar", cb._config->myField); @@ -47,8 +57,8 @@ TEST("requireThatDirMultiFileLegacyWorks") { MyCallback<BarConfig> cb2; LegacySubscriber s1, s2; - s1.subscribe<FooConfig>("dir:testdir/foobar", &cb1); - s2.subscribe<BarConfig>("dir:testdir/foobar", &cb2); + s1.subscribe<FooConfig>(ConfigIdGenerator::id("dir", "testdir/foobar"), &cb1); + s2.subscribe<BarConfig>(ConfigIdGenerator::id("dir", "testdir/foobar"), &cb2); ASSERT_TRUE(cb1._configured); ASSERT_TRUE(cb1._config.get() != NULL); @@ -62,13 +72,13 @@ TEST("requireThatDirMultiFileLegacyWorks") { TEST("requireThatFileLegacyWorksMultipleTimes") { LegacySubscriber s; MyCallback<MyConfig> cb; - s.subscribe<MyConfig>("file:test1.cfg", &cb); + s.subscribe<MyConfig>(ConfigIdGenerator::id("file", "test1.cfg"), &cb); ASSERT_TRUE(cb._configured); ASSERT_TRUE(cb._config.get() != NULL); ASSERT_EQUAL("bar", cb._config->myField); cb._configured = false; LegacySubscriber s2; - s2.subscribe<MyConfig>("file:test1.cfg", &cb); + s2.subscribe<MyConfig>(ConfigIdGenerator::id("file", "test1.cfg"), &cb); ASSERT_TRUE(cb._configured); ASSERT_TRUE(cb._config.get() != NULL); ASSERT_EQUAL("bar", cb._config->myField); diff --git a/config/src/tests/print/print.cpp b/config/src/tests/print/print.cpp index 7faae087e74..f0f0570f2a9 100644 --- a/config/src/tests/print/print.cpp +++ b/config/src/tests/print/print.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/config/config.h> #include <vespa/config/print.h> #include <vespa/config/print/fileconfigreader.h> @@ -82,10 +83,12 @@ TEST_F("requireThatCanLoadWrittenWithConfigFormat", RawFixture<MyConfig>) { } TEST("requireThatAllFieldsArePrintedCorrectly") { - std::unique_ptr<MotdConfig> cfg = ConfigGetter<MotdConfig>::getConfig("motd", FileSpec("motd.cfg")); + std::unique_ptr<MotdConfig> cfg = ConfigGetter<MotdConfig>::getConfig( + "motd", FileSpec(vespalib::TestApp::GetSourceDirectory() + "motd.cfg")); FileConfigWriter writer("motd2.cfg"); ASSERT_TRUE(writer.write(*cfg, FileConfigFormatter())); - std::unique_ptr<MotdConfig> cfg2 = ConfigGetter<MotdConfig>::getConfig("motd2", FileSpec("motd2.cfg")); + std::unique_ptr<MotdConfig> cfg2 = ConfigGetter<MotdConfig>::getConfig( + "motd2", FileSpec("motd2.cfg")); ASSERT_TRUE(*cfg2 == *cfg); } diff --git a/configutil/src/tests/model_inspect/model_inspect_test.cpp b/configutil/src/tests/model_inspect/model_inspect_test.cpp index 283d1f0c4f2..a2d07fcaedf 100644 --- a/configutil/src/tests/model_inspect/model_inspect_test.cpp +++ b/configutil/src/tests/model_inspect/model_inspect_test.cpp @@ -11,12 +11,12 @@ public: std::stringstream stream; ModelInspect model; - Model() : uri("file:model.cfg"), flags(), stream(), + Model() : uri(configUri("file", "model.cfg")), flags(), stream(), model(flags, uri, stream) { }; Model(ModelInspect::Flags _flags) - : uri("file:model.cfg"), flags(_flags), stream(), + : uri(configUri("file", "model.cfg")), flags(_flags), stream(), model(flags, uri, stream) { }; @@ -30,6 +30,12 @@ public: ~Model() { }; + + static config::ConfigUri configUri(const std::string &type, const std::string &name) + { + return config::ConfigUri(type + ":" + + vespalib::TestApp::GetSourceDirectory() + "/" + name); + } }; class MakeUriFlags : public ModelInspect::Flags { @@ -63,7 +69,7 @@ public: _getIndexOf; ModelDummy(std::stringstream &stream) : ModelInspect(ModelInspect::Flags(), - config::ConfigUri("file:model.cfg"), + config::ConfigUri(Model::configUri("file", "model.cfg")), stream) { _yamlDump = _listHosts = diff --git a/document/src/tests/documentidtest.cpp b/document/src/tests/documentidtest.cpp index fd60c6c436b..b3da80ba958 100644 --- a/document/src/tests/documentidtest.cpp +++ b/document/src/tests/documentidtest.cpp @@ -5,6 +5,7 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/document/serialization/vespadocumentserializer.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/vespalib/testkit/testapp.h> #include <sstream> #include <string> #include <vespa/document/bucket/bucketidfactory.h> @@ -81,7 +82,7 @@ void DocumentIdTest::generateJavaComplianceFile() writeGlobalIdBucketId(ost, "id:np:type:g=agroup:another"); writeGlobalIdBucketId(ost, "id:ns:type:g=another:specific"); FastOS_File file; - CPPUNIT_ASSERT(file.OpenWriteOnlyTruncate("cpp-globalidbucketids.txt")); + CPPUNIT_ASSERT(file.OpenWriteOnlyTruncate((vespalib::TestApp::GetSourceDirectory() + "cpp-globalidbucketids.txt").c_str())); std::string content(ost.str()); CPPUNIT_ASSERT(file.CheckedWrite(content.c_str(), content.size())); CPPUNIT_ASSERT(file.Close()); diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 9f8ab454bd2..fbef378e745 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -16,6 +16,7 @@ #include <vespa/document/serialization/vespadocumentserializer.h> #include <vespa/vespalib/objects/nbostream.h> #include <fstream> +#include <vespa/vespalib/testkit/testapp.h> using vespalib::nbostream; @@ -589,10 +590,10 @@ void verifyJavaDocument(Document& doc) void DocumentTest::testReadSerializedFile() { // Reads a file serialized from java - const char file_name[] = "data/crossplatform-java-cpp-doctypes.cfg"; + const std::string file_name = vespalib::TestApp::GetSourceDirectory() + "data/crossplatform-java-cpp-doctypes.cfg"; DocumentTypeRepo repo(readDocumenttypesConfig(file_name)); - int fd = open("data/serializejava.dat", O_RDONLY); + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serializejava.dat").c_str(), O_RDONLY); size_t len = lseek(fd,0,SEEK_END); ByteBuffer buf(len); @@ -623,10 +624,11 @@ void DocumentTest::testReadSerializedFile() void DocumentTest::testReadSerializedFileCompressed() { // Reads a file serialized from java - const char file_name[] = "data/crossplatform-java-cpp-doctypes.cfg"; + const std::string file_name = vespalib::TestApp::GetSourceDirectory() + + "data/crossplatform-java-cpp-doctypes.cfg"; DocumentTypeRepo repo(readDocumenttypesConfig(file_name)); - int fd = open("data/serializejava-compressed.dat", O_RDONLY); + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serializejava-compressed.dat").c_str(), O_RDONLY); int len = lseek(fd,0,SEEK_END); ByteBuffer buf(len); @@ -743,7 +745,7 @@ void DocumentTest::testReadSerializedAllVersions() //doc.setCompression(CompressionConfig(CompressionConfig::NONE, 0, 0)); std::unique_ptr<ByteBuffer> buf = doc.serialize(); CPPUNIT_ASSERT_EQUAL(buf->getLength(), buf->getPos()); - int fd = open("data/document-cpp-currentversion-uncompressed.dat", + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/document-cpp-currentversion-uncompressed.dat").c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644); CPPUNIT_ASSERT(fd > 0); size_t len = write(fd, buf->getBuffer(), buf->getPos()); @@ -756,7 +758,7 @@ void DocumentTest::testReadSerializedAllVersions() const_cast<StructDataType &>(doc.getType().getFieldsType()).setCompressionConfig(newCfg); std::unique_ptr<ByteBuffer> buf = doc.serialize(); CPPUNIT_ASSERT(buf->getPos() <= buf->getLength()); - int fd = open("data/document-cpp-currentversion-lz4-9.dat", + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/document-cpp-currentversion-lz4-9.dat").c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644); CPPUNIT_ASSERT(fd > 0); size_t len = write(fd, buf->getBuffer(), buf->getPos()); @@ -766,12 +768,12 @@ void DocumentTest::testReadSerializedAllVersions() } } - std::string jpath = "../test/serializeddocuments/"; + std::string jpath = vespalib::TestApp::GetSourceDirectory() + "../test/serializeddocuments/"; std::vector<TestDoc> tests; - tests.push_back(TestDoc("data/document-cpp-v8-uncompressed.dat", 8)); - tests.push_back(TestDoc("data/document-cpp-v7-uncompressed.dat", 7)); - tests.push_back(TestDoc("data/serializev6.dat", 6)); + tests.push_back(TestDoc(vespalib::TestApp::GetSourceDirectory() + "data/document-cpp-v8-uncompressed.dat", 8)); + tests.push_back(TestDoc(vespalib::TestApp::GetSourceDirectory() + "data/document-cpp-v7-uncompressed.dat", 7)); + tests.push_back(TestDoc(vespalib::TestApp::GetSourceDirectory() + "data/serializev6.dat", 6)); tests.push_back(TestDoc(jpath + "document-java-v8-uncompressed.dat", 8)); for (uint32_t i=0; i<tests.size(); ++i) { int version = tests[i]._createdVersion; @@ -867,7 +869,7 @@ size_t getSerializedSizeBody(const Document &doc) { void DocumentTest::testGenerateSerializedFile() { - const char file_name[] = "data/crossplatform-java-cpp-doctypes.cfg"; + const std::string file_name = vespalib::TestApp::GetSourceDirectory() + "data/crossplatform-java-cpp-doctypes.cfg"; DocumentTypeRepo repo(readDocumenttypesConfig(file_name)); Document doc(*repo.getDocumentType("serializetest"), DocumentId(DocIdString("serializetest", @@ -906,8 +908,8 @@ void DocumentTest::testGenerateSerializedFile() std::unique_ptr<ByteBuffer> buf = doc.serialize(); -#define SERIALIZED_DIR "../test/document/" - int fd = open(SERIALIZED_DIR "/serializecpp.dat", + const std::string serializedDir = vespalib::TestApp::GetSourceDirectory() + "../test/document/"; + int fd = open((serializedDir + "/serializecpp.dat").c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644); if (write(fd, buf->getBuffer(), buf->getPos()) != (ssize_t)buf->getPos()) { throw vespalib::Exception("write failed"); @@ -916,7 +918,7 @@ void DocumentTest::testGenerateSerializedFile() ByteBuffer hBuf(getSerializedSizeHeader(doc)); doc.serializeHeader(hBuf); - fd = open(SERIALIZED_DIR "/serializecppsplit_header.dat", + fd = open((serializedDir + "/serializecppsplit_header.dat").c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644); if (write(fd, hBuf.getBuffer(), hBuf.getPos()) != (ssize_t)hBuf.getPos()) { throw vespalib::Exception("write failed"); @@ -925,14 +927,13 @@ void DocumentTest::testGenerateSerializedFile() ByteBuffer bBuf(getSerializedSizeBody(doc)); doc.serializeBody(bBuf); - fd = open(SERIALIZED_DIR "/serializecppsplit_body.dat", + fd = open((vespalib::TestApp::GetSourceDirectory() + "/serializecppsplit_body.dat").c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644); if (write(fd, bBuf.getBuffer(), bBuf.getPos()) != (ssize_t)bBuf.getPos()) { throw vespalib::Exception("write failed"); } close(fd); - CompressionConfig newCfg(CompressionConfig::LZ4, 9, 95); const_cast<StructDataType &>(doc.getType().getFieldsType()).setCompressionConfig(newCfg); @@ -941,7 +942,7 @@ void DocumentTest::testGenerateSerializedFile() doc.serialize(lz4buf); lz4buf.flip(); - fd = open(SERIALIZED_DIR "/serializecpp-lz4-level9.dat", + fd = open((vespalib::TestApp::GetSourceDirectory() + "/serializecpp-lz4-level9.dat").c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644); if (write(fd, lz4buf.getBufferAtPos(), lz4buf.getRemaining()) != (ssize_t)lz4buf.getRemaining()) { throw vespalib::Exception("write failed"); @@ -1308,7 +1309,7 @@ DocumentTest::testUnknownEntries() // Copy paste of above test to read an old version document and // deserialize it with some fields lacking to see that it doesn't // report failure. (Had a bug on this earlier) - int fd = open("data/serializev6.dat", O_RDONLY); + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serializev6.dat").c_str(), O_RDONLY); int len = lseek(fd,0,SEEK_END); ByteBuffer buf(len); lseek(fd,0,SEEK_SET); @@ -1357,7 +1358,7 @@ void DocumentTest::testAnnotationDeserialization() .annotationType(1730712959, "apple", 0); DocumentTypeRepo repo(builder.config()); - int fd = open("data/serializejavawithannotations.dat", O_RDONLY); + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serializejavawithannotations.dat").c_str(), O_RDONLY); int len = lseek(fd,0,SEEK_END); ByteBuffer buf(len); lseek(fd,0,SEEK_SET); diff --git a/document/src/tests/documenttypetestcase.cpp b/document/src/tests/documenttypetestcase.cpp index e946844e867..da6d61b507d 100644 --- a/document/src/tests/documenttypetestcase.cpp +++ b/document/src/tests/documenttypetestcase.cpp @@ -7,6 +7,8 @@ #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/testkit/testapp.h> + #include <sstream> #include <string> @@ -39,7 +41,6 @@ struct DocumentTypeTest : public CppUnit::TestFixture { CPPUNIT_TEST(testOutputOperator); CPPUNIT_TEST(testHeaderContent); CPPUNIT_TEST_SUITE_END(); - }; CPPUNIT_TEST_SUITE_REGISTRATION(DocumentTypeTest); @@ -93,8 +94,8 @@ void DocumentTypeTest::testInheritanceConfig() { DocumentTypeRepo - repo(readDocumenttypesConfig("data/inheritancetest.cfg")); - + repo(readDocumenttypesConfig(vespalib::TestApp::GetSourceDirectory() + + "data/inheritancetest.cfg")); { const DocumentType* type(repo.getDocumentType("music")); CPPUNIT_ASSERT(type != NULL); @@ -110,7 +111,8 @@ void DocumentTypeTest::testHeaderContent() { DocumentTypeRepo - repo(readDocumenttypesConfig("data/doctypesconfigtest.cfg")); + repo(readDocumenttypesConfig(vespalib::TestApp::GetSourceDirectory() + + "data/doctypesconfigtest.cfg")); const DocumentType* type(repo.getDocumentType("derived")); diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index 971b8c4e88e..f3604493f01 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -23,6 +23,7 @@ #include <vespa/vespalib/tensor/types.h> #include <vespa/vespalib/tensor/default_tensor.h> #include <vespa/vespalib/tensor/tensor_factory.h> +#include <vespa/vespalib/testkit/testapp.h> using namespace document::config_builder; using vespalib::tensor::Tensor; @@ -572,10 +573,10 @@ DocumentUpdateTest::testIncrementWithZeroResultWeightIsRemoved() void DocumentUpdateTest::testReadSerializedFile() { // Reads a file serialized from java - const char file_name[] = "data/crossplatform-java-cpp-doctypes.cfg"; + const std::string file_name = vespalib::TestApp::GetSourceDirectory() + "data/crossplatform-java-cpp-doctypes.cfg"; DocumentTypeRepo repo(readDocumenttypesConfig(file_name)); - int fd = open("data/serializeupdatejava.dat", O_RDONLY); + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serializeupdatejava.dat").c_str(), O_RDONLY); int len = lseek(fd,0,SEEK_END); ByteBuffer buf(len); @@ -649,7 +650,7 @@ void DocumentUpdateTest::testReadSerializedFile() void DocumentUpdateTest::testGenerateSerializedFile() { // Tests nothing, only generates a file for java test - const char file_name[] = "data/crossplatform-java-cpp-doctypes.cfg"; + const std::string file_name = vespalib::TestApp::GetSourceDirectory() + "data/crossplatform-java-cpp-doctypes.cfg"; DocumentTypeRepo repo(readDocumenttypesConfig(file_name)); const DocumentType *type(repo.getDocumentType("serializetest")); @@ -671,7 +672,7 @@ void DocumentUpdateTest::testGenerateSerializedFile() ArithmeticValueUpdate(ArithmeticValueUpdate::Mul, 2)))); ByteBuffer::UP buf(serialize42(upd)); - int fd = open("data/serializeupdatecpp.dat", + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serializeupdatecpp.dat").c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644); if (write(fd, buf->getBuffer(), buf->getPos()) != (ssize_t)buf->getPos()) { throw vespalib::Exception("read failed"); diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp index b79ff8873e5..ca1c8338f90 100644 --- a/document/src/tests/fieldpathupdatetestcase.cpp +++ b/document/src/tests/fieldpathupdatetestcase.cpp @@ -10,6 +10,7 @@ #include <vespa/document/repo/configbuilder.h> #include <vespa/vespalib/objects/identifiable.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/document/serialization/vespadocumentserializer.h> #include <fstream> #include <sstream> @@ -1270,10 +1271,10 @@ void FieldPathUpdateTestCase::testReadSerializedFile() { // Reads a file serialized from java - const char cfg_file_name[] = "data/crossplatform-java-cpp-doctypes.cfg"; + const std::string cfg_file_name = vespalib::TestApp::GetSourceDirectory() + "data/crossplatform-java-cpp-doctypes.cfg"; DocumentTypeRepo repo(readDocumenttypesConfig(cfg_file_name)); - int fd = open("data/serialize-fieldpathupdate-java.dat", O_RDONLY); + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serialize-fieldpathupdate-java.dat").c_str(), O_RDONLY); int len = lseek(fd,0,SEEK_END); ByteBuffer buf(len); @@ -1294,7 +1295,7 @@ FieldPathUpdateTestCase::testReadSerializedFile() void FieldPathUpdateTestCase::testGenerateSerializedFile() { - const char cfg_file_name[] = "data/crossplatform-java-cpp-doctypes.cfg"; + const std::string cfg_file_name = vespalib::TestApp::GetSourceDirectory()+ "data/crossplatform-java-cpp-doctypes.cfg"; DocumentTypeRepo repo(readDocumenttypesConfig(cfg_file_name)); // Tests nothing, only generates a file for java test DocumentUpdate::UP upd( @@ -1302,7 +1303,7 @@ FieldPathUpdateTestCase::testGenerateSerializedFile() ByteBuffer::UP buf(serializeHEAD(*upd)); - int fd = open("data/serialize-fieldpathupdate-cpp.dat", + int fd = open((vespalib::TestApp::GetSourceDirectory() + "data/serialize-fieldpathupdate-cpp.dat").c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644); if (write(fd, buf->getBuffer(), buf->getPos()) != (ssize_t)buf->getPos()) { throw vespalib::Exception("write failed"); diff --git a/document/src/tests/repo/documenttyperepo_test.cpp b/document/src/tests/repo/documenttyperepo_test.cpp index 003bd1698af..c53661cc170 100644 --- a/document/src/tests/repo/documenttyperepo_test.cpp +++ b/document/src/tests/repo/documenttyperepo_test.cpp @@ -441,7 +441,7 @@ TEST("requireThatDocumentLookupChecksName") { } TEST("requireThatBuildFromConfigWorks") { - DocumentTypeRepo repo(readDocumenttypesConfig("documenttypes.cfg")); + DocumentTypeRepo repo(readDocumenttypesConfig(vespalib::TestApp::GetSourceDirectory() + "documenttypes.cfg")); ASSERT_TRUE(repo.getDocumentType("document")); ASSERT_TRUE(repo.getDocumentType("types")); ASSERT_TRUE(repo.getDocumentType("types_search")); diff --git a/document/src/tests/serialization/annotationserializer_test.cpp b/document/src/tests/serialization/annotationserializer_test.cpp index 1cc3fc19373..e4321953620 100644 --- a/document/src/tests/serialization/annotationserializer_test.cpp +++ b/document/src/tests/serialization/annotationserializer_test.cpp @@ -80,9 +80,11 @@ Test::readSpanTree(const string &file_name, const FixedTypeRepo &repo) { } void Test::requireThatSimpleSpanTreeIsDeserialized() { - DocumentTypeRepo type_repo(readDocumenttypesConfig("annotation.serialize.test.repo.cfg")); + DocumentTypeRepo type_repo(readDocumenttypesConfig( + vespalib::TestApp::GetSourceDirectory() + "annotation.serialize.test.repo.cfg")); FixedTypeRepo repo(type_repo); - SpanTree::UP span_tree = std::move(readSpanTree("test_data_serialized_simple", repo).front()); + SpanTree::UP span_tree = std::move(readSpanTree( + vespalib::TestApp::GetSourceDirectory() + "test_data_serialized_simple", repo).front()); EXPECT_EQUAL("html", span_tree->getName()); const SimpleSpanList *root = dynamic_cast<const SimpleSpanList *>(&span_tree->getRoot()); @@ -126,9 +128,10 @@ struct AnnotationComparator { void Test::requireThatAdvancedSpanTreeIsDeserialized() { DocumentTypeRepo type_repo( - readDocumenttypesConfig("annotation.serialize.test.repo.cfg")); + readDocumenttypesConfig(vespalib::TestApp::GetSourceDirectory() + "annotation.serialize.test.repo.cfg")); FixedTypeRepo repo(type_repo, "my_document"); - SpanTree::UP span_tree = std::move(readSpanTree("test_data_serialized_advanced", repo).front()); + SpanTree::UP span_tree = std::move(readSpanTree( + vespalib::TestApp::GetSourceDirectory() + "test_data_serialized_advanced", repo).front()); EXPECT_EQUAL("html", span_tree->getName()); const SpanList *root = dynamic_cast<const SpanList *>(&span_tree->getRoot()); @@ -220,9 +223,9 @@ void Test::requireThatAdvancedSpanTreeIsDeserialized() { void Test::requireThatSpanTreeCanBeSerialized() { DocumentTypeRepo type_repo( - readDocumenttypesConfig("annotation.serialize.test.repo.cfg")); + readDocumenttypesConfig(vespalib::TestApp::GetSourceDirectory() + "annotation.serialize.test.repo.cfg")); FixedTypeRepo repo(type_repo, "my_document"); - string file_name = "test_data_serialized_advanced"; + string file_name = vespalib::TestApp::GetSourceDirectory() + "test_data_serialized_advanced"; FastOS_File file(file_name.c_str()); ASSERT_TRUE(file.OpenReadOnlyExisting()); diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index 0043548a906..7a238cd3b87 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -682,7 +682,7 @@ void deserializeAndCheck(const string &file_name, PredicateFieldValue &value) { } void checkDeserialization(const string &name, std::unique_ptr<Slime> slime) { - const string data_dir = "../../test/resources/predicates/"; + const string data_dir = vespalib::TestApp::GetSourceDirectory() + "../../test/resources/predicates/"; PredicateFieldValue value(std::move(slime)); serializeToFile(value, data_dir + name + "__cpp"); @@ -801,7 +801,7 @@ void deserializeAndCheck(const string &file_name, TensorFieldValue &value) { } void checkDeserialization(const string &name, std::unique_ptr<Tensor> tensor) { - const string data_dir = "../../test/resources/tensor/"; + const string data_dir = vespalib::TestApp::GetSourceDirectory() + "../../test/resources/tensor/"; TensorFieldValue value; if (tensor) { diff --git a/document/src/tests/struct_anno/struct_anno_test.cpp b/document/src/tests/struct_anno/struct_anno_test.cpp index 85b3b8f2d0b..2c1b7fb9fe6 100644 --- a/document/src/tests/struct_anno/struct_anno_test.cpp +++ b/document/src/tests/struct_anno/struct_anno_test.cpp @@ -47,9 +47,10 @@ int Test::Main() { template <typename T, int N> int arraysize(const T (&)[N]) { return N; } void Test::requireThatStructFieldsCanContainAnnotations() { - DocumentTypeRepo repo(readDocumenttypesConfig("documenttypes.cfg")); + DocumentTypeRepo repo(readDocumenttypesConfig(vespalib::TestApp::GetSourceDirectory() + + "documenttypes.cfg")); - FastOS_File file("document.dat"); + FastOS_File file((vespalib::TestApp::GetSourceDirectory() + "document.dat").c_str()); ASSERT_TRUE(file.OpenReadOnlyExisting()); char buffer[1024]; ssize_t size = file.Read(buffer, arraysize(buffer)); diff --git a/document/src/tests/testxml.cpp b/document/src/tests/testxml.cpp index 7729c748b3f..90849060598 100644 --- a/document/src/tests/testxml.cpp +++ b/document/src/tests/testxml.cpp @@ -16,6 +16,7 @@ #include <vespa/document/update/removevalueupdate.h> #include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/vespalib/text/stringtokenizer.h> +#include <vespa/vespalib/testkit/testapp.h> using vespalib::StringTokenizer; @@ -97,7 +98,8 @@ createTestDocumentUpdate(const DocumentTypeRepo& repo) void TestXml::testSimpleUsage() { - DocumentTypeRepo repo(readDocumenttypesConfig("data/defaultdoctypes.cfg")); + DocumentTypeRepo repo(readDocumenttypesConfig( + vespalib::TestApp::GetSourceDirectory() + "data/defaultdoctypes.cfg")); Document::UP doc1(createTestDocument(repo)); doc1->setValue(doc1->getField("stringattr"), StringFieldValue("tjohei���")); @@ -126,7 +128,8 @@ void TestXml::testSimpleUsage() void TestXml::testDocumentUpdate() { - DocumentTypeRepo repo(readDocumenttypesConfig("data/defaultdoctypes.cfg")); + DocumentTypeRepo repo(readDocumenttypesConfig( + vespalib::TestApp::GetSourceDirectory() + "data/defaultdoctypes.cfg")); DocumentUpdate::UP up1(createTestDocumentUpdate(repo)); std::string expected = diff --git a/document/src/vespa/document/repo/documenttyperepo.cpp b/document/src/vespa/document/repo/documenttyperepo.cpp index fd0feb35064..4b05261ab4b 100644 --- a/document/src/vespa/document/repo/documenttyperepo.cpp +++ b/document/src/vespa/document/repo/documenttyperepo.cpp @@ -586,4 +586,8 @@ DocumenttypesConfig readDocumenttypesConfig(const char *file_name) { return DocumenttypesConfig(*reader.read()); } +DocumenttypesConfig readDocumenttypesConfig(const std::string &file_name ) { + return readDocumenttypesConfig(file_name.c_str()); +} + } // namespace document diff --git a/document/src/vespa/document/repo/documenttyperepo.h b/document/src/vespa/document/repo/documenttyperepo.h index f3542d3cae2..199d35c0351 100644 --- a/document/src/vespa/document/repo/documenttyperepo.h +++ b/document/src/vespa/document/repo/documenttyperepo.h @@ -46,6 +46,7 @@ private: }; DocumenttypesConfig readDocumenttypesConfig(const char *file_name); +DocumenttypesConfig readDocumenttypesConfig(const std::string& file_name); } // namespace document diff --git a/documentapi/src/tests/messagebus/messagebus_test.cpp b/documentapi/src/tests/messagebus/messagebus_test.cpp index b55d35825fe..924325d117a 100644 --- a/documentapi/src/tests/messagebus/messagebus_test.cpp +++ b/documentapi/src/tests/messagebus/messagebus_test.cpp @@ -36,7 +36,8 @@ int Test::Main() { TEST_INIT(_argv[0]); - _repo.reset(new DocumentTypeRepo(readDocumenttypesConfig("../../../test/cfg/testdoctypes.cfg"))); + _repo.reset(new DocumentTypeRepo(readDocumenttypesConfig( + GetSourceDirectory() + "../../../test/cfg/testdoctypes.cfg"))); testMessage(); TEST_FLUSH(); testProtocol(); TEST_FLUSH(); diff --git a/documentapi/src/tests/messages/error_codes_test.cpp b/documentapi/src/tests/messages/error_codes_test.cpp index 1714fb70a04..e9ad68f441e 100644 --- a/documentapi/src/tests/messages/error_codes_test.cpp +++ b/documentapi/src/tests/messages/error_codes_test.cpp @@ -16,6 +16,7 @@ class ErrorCodesTest : public vespalib::TestApp { int Main() override; void error_codes_match_java_definitions(); NamedErrorCodes all_document_protocol_error_codes(); + std::string path_prefixed(const std::string& file_name) const; }; TEST_APPHOOK(ErrorCodesTest); @@ -94,12 +95,13 @@ std::string to_sorted_key_value_string(const NamedErrorCodes& codes) { return os.str(); } -std::string path_prefixed(const std::string& file_name) { - return "../../../test/crosslanguagefiles/" + file_name; -} - } // anon ns +std::string +ErrorCodesTest::path_prefixed(const std::string& file_name) const { + return GetSourceDirectory() + "../../../test/crosslanguagefiles/" + file_name; +} + void ErrorCodesTest::error_codes_match_java_definitions() { diff --git a/documentapi/src/tests/messages/testbase.cpp b/documentapi/src/tests/messages/testbase.cpp index 2edbd2d0b9c..7ccf681c825 100644 --- a/documentapi/src/tests/messages/testbase.cpp +++ b/documentapi/src/tests/messages/testbase.cpp @@ -11,8 +11,9 @@ using document::DocumentTypeRepo; using document::readDocumenttypesConfig; TestBase::TestBase() : - _repo(new DocumentTypeRepo(readDocumenttypesConfig("../../../test/cfg/testdoctypes.cfg"))), - _dataPath("../../../test/crosslanguagefiles"), + _repo(new DocumentTypeRepo(readDocumenttypesConfig( + GetSourceDirectory() + "../../../test/cfg/testdoctypes.cfg"))), + _dataPath(GetSourceDirectory() + "../../../test/crosslanguagefiles"), _loadTypes(), _protocol(_loadTypes, _repo), _tests() diff --git a/documentapi/src/tests/policies/policies_test.cpp b/documentapi/src/tests/policies/policies_test.cpp index 1cab15a325f..6ee1625954d 100644 --- a/documentapi/src/tests/policies/policies_test.cpp +++ b/documentapi/src/tests/policies/policies_test.cpp @@ -97,7 +97,7 @@ Test::Main() { TEST_INIT(_argv[0]); _repo.reset(new DocumentTypeRepo(readDocumenttypesConfig( - "../../../test/cfg/testdoctypes.cfg"))); + GetSourceDirectory() + "../../../test/cfg/testdoctypes.cfg"))); _docType = _repo->getDocumentType("testdoc"); testProtocol(); TEST_FLUSH(); diff --git a/documentapi/src/tests/priority/priority.cpp b/documentapi/src/tests/priority/priority.cpp index 3ad0e2041cf..a9fcd011a5e 100644 --- a/documentapi/src/tests/priority/priority.cpp +++ b/documentapi/src/tests/priority/priority.cpp @@ -35,7 +35,7 @@ Test::Main() expected.push_back(Priority::PRI_LOWEST); std::ifstream in; - in.open("../../../test/crosslanguagefiles/5.1-Priority.txt"); + in.open((GetSourceDirectory() + "../../../test/crosslanguagefiles/5.1-Priority.txt").c_str()); ASSERT_TRUE(in.good()); while (in) { std::string str; diff --git a/fastlib/src/vespa/fastlib/testsuite/test.h b/fastlib/src/vespa/fastlib/testsuite/test.h index ed9690a08ff..40b99c6ed66 100644 --- a/fastlib/src/vespa/fastlib/testsuite/test.h +++ b/fastlib/src/vespa/fastlib/testsuite/test.h @@ -89,6 +89,7 @@ public: virtual void Run() = 0; const char *get_name() const; + static const std::string& GetSourceDirectory(); long GetNumPassed() const; long GetNumFailed() const; const std::ostream* GetStream() const; @@ -144,15 +145,8 @@ Test::Test(std::ostream* osptr, const char*name) : inline Test::Test(const char*name) : - m_osptr(NULL), - name_(name), - m_nPass(0), - m_nFail(0), - m_index(0), - m_description() + Test(nullptr, name) { - m_pchar[0]= '|'; - m_pchar[1]= '-'; } inline @@ -161,6 +155,23 @@ const char *Test::get_name() const { } inline +const std::string& Test::GetSourceDirectory() +{ + static const std::string srcDir = [] () { + std::string dir("."); + const char* env = getenv("SOURCE_DIRECTORY"); + if (env) { + dir = env; + } + if (*dir.rbegin() != '/') { + dir += "/"; + } + return dir; + } (); + return srcDir; +} + +inline long Test::GetNumPassed() const { return m_nPass; diff --git a/fastos/src/tests/filetest.cpp b/fastos/src/tests/filetest.cpp index ca53c359605..ca7a3b235e1 100644 --- a/fastos/src/tests/filetest.cpp +++ b/fastos/src/tests/filetest.cpp @@ -41,9 +41,10 @@ class FileTest : public BaseTest private: virtual bool useProcessStarter() const { return true; } public: - static const char * roFilename; - static const char * woFilename; - static const char * rwFilename; + const std::string srcDir = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; + const std::string roFilename = srcDir + "/hello.txt"; + const std::string woFilename = "generated/writeonlytest.txt"; + const std::string rwFilename = "generated/readwritetest.txt"; void DirectoryTest() { @@ -435,7 +436,7 @@ public: { TestHeader("Read-Only Test"); - FastOS_File *myFile = new FastOS_File(roFilename); + FastOS_File *myFile = new FastOS_File(roFilename.c_str()); if (myFile->OpenReadOnly()) { int64_t filesize; @@ -472,7 +473,7 @@ public: } } } else { - Progress(false, "Unable to open file '%s'.", roFilename); + Progress(false, "Unable to open file '%s'.", roFilename.c_str()); } delete(myFile); PrintSeparator(); @@ -483,7 +484,7 @@ public: TestHeader("Write-Only Test"); FastOS_File::MakeDirectory("generated"); - FastOS_File *myFile = new FastOS_File(woFilename); + FastOS_File *myFile = new FastOS_File(woFilename.c_str()); if (myFile->OpenWriteOnly()) { int64_t filesize; @@ -531,12 +532,12 @@ public: bool closeResult = myFile->Close(); Progress(closeResult, "Close file."); } else { - Progress(false, "Unable to open file '%s'.", woFilename); + Progress(false, "Unable to open file '%s'.", woFilename.c_str()); } bool deleteResult = myFile->Delete(); - Progress(deleteResult, "Delete file '%s'.", woFilename); + Progress(deleteResult, "Delete file '%s'.", woFilename.c_str()); delete(myFile); FastOS_File::EmptyAndRemoveDirectory("generated"); @@ -548,13 +549,13 @@ public: TestHeader("Read/Write Test"); FastOS_File::MakeDirectory("generated"); - FastOS_File *myFile = new FastOS_File(rwFilename); + FastOS_File *myFile = new FastOS_File(rwFilename.c_str()); if (myFile->OpenExisting()) { - Progress(false, "OpenExisting() should not work when '%s' does not exist.", rwFilename); + Progress(false, "OpenExisting() should not work when '%s' does not exist.", rwFilename.c_str()); myFile->Close(); } else { - Progress(true, "OpenExisting() should fail when '%s' does not exist, and it did.", rwFilename); + Progress(true, "OpenExisting() should fail when '%s' does not exist, and it did.", rwFilename.c_str()); } if (myFile->OpenReadWrite()) { @@ -628,10 +629,10 @@ public: bool closeResult = myFile->Close(); Progress(closeResult, "Close file."); } else { - Progress(false, "Unable to open file '%s'.", rwFilename); + Progress(false, "Unable to open file '%s'.", rwFilename.c_str()); } bool deleteResult = myFile->Delete(); - Progress(deleteResult, "Delete file '%s'.", rwFilename); + Progress(deleteResult, "Delete file '%s'.", rwFilename.c_str()); delete(myFile); FastOS_File::EmptyAndRemoveDirectory("generated"); @@ -661,7 +662,7 @@ public: { TestHeader("ReadBuf Test"); - FastOS_File file(roFilename); + FastOS_File file(roFilename.c_str()); char buffer[20]; @@ -691,7 +692,7 @@ public: { TestHeader("DiskFreeSpace Test"); - int64_t freeSpace = FastOS_File::GetFreeDiskSpace(roFilename); + int64_t freeSpace = FastOS_File::GetFreeDiskSpace(roFilename.c_str()); ProgressI64(freeSpace != -1, "DiskFreeSpace using file ('hello.txt'): %ld MB.", freeSpace == -1 ? -1 : freeSpace/(1024*1024)); freeSpace = FastOS_File::GetFreeDiskSpace("."); ProgressI64(freeSpace != -1, "DiskFreeSpace using dir (.): %ld MB.", freeSpace == -1 ? -1 : freeSpace/(1024*1024)); @@ -817,11 +818,6 @@ public: } }; -const char *FileTest::roFilename = "hello.txt"; -const char *FileTest::woFilename = "generated/writeonlytest.txt"; -const char *FileTest::rwFilename = "generated/readwritetest.txt"; - - int main (int argc, char **argv) { FileTest app; diff --git a/fsa/src/alltest/CMakeLists.txt b/fsa/src/alltest/CMakeLists.txt index a2d99497499..f9cd36d1fe7 100644 --- a/fsa/src/alltest/CMakeLists.txt +++ b/fsa/src/alltest/CMakeLists.txt @@ -67,4 +67,4 @@ vespa_add_executable(fsa_vectorizer_perf_test_app TEST DEPENDS fsa ) -vespa_add_test(NAME fsa_vectorizer_perf_test_app NO_VALGRIND COMMAND sh alltest.sh) +vespa_add_test(NAME fsa_vectorizer_perf_test_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/alltest.sh) diff --git a/fsa/src/alltest/alltest.sh b/fsa/src/alltest/alltest.sh index 9225a9dafec..19f7b0f8681 100755 --- a/fsa/src/alltest/alltest.sh +++ b/fsa/src/alltest/alltest.sh @@ -1,18 +1,22 @@ #!/bin/bash set -e +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + # first create the FSA ./fsa_fsa_create_test_app # simple tests -./lookup_test.sh -./fsa_test.sh -./detector_test.sh +$SOURCE_DIRECTORY/lookup_test.sh +$SOURCE_DIRECTORY/fsa_test.sh +$SOURCE_DIRECTORY/detector_test.sh # advanced tests -./ngram_test.sh -./segmenter_test.sh -./vectorizer_test.sh +$SOURCE_DIRECTORY/ngram_test.sh +$SOURCE_DIRECTORY/segmenter_test.sh +$SOURCE_DIRECTORY/vectorizer_test.sh # manager test ./fsa_fsamanager_test_app . __testfsa__.__fsa__ diff --git a/fsa/src/alltest/detector_test.sh b/fsa/src/alltest/detector_test.sh index 73748a3382e..a712e313b0f 100755 --- a/fsa/src/alltest/detector_test.sh +++ b/fsa/src/alltest/detector_test.sh @@ -1,4 +1,9 @@ #!/bin/bash set -e -./fsa_detector_test_app < testinput.txt > detector_test.output -diff detector_test.output detector_test.out + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + +./fsa_detector_test_app < $SOURCE_DIRECTORY/testinput.txt > detector_test.output +diff detector_test.output $SOURCE_DIRECTORY/detector_test.out diff --git a/fsa/src/alltest/fsa_test.sh b/fsa/src/alltest/fsa_test.sh index 09470044430..7969df745e8 100755 --- a/fsa/src/alltest/fsa_test.sh +++ b/fsa/src/alltest/fsa_test.sh @@ -1,4 +1,9 @@ #!/bin/bash set -e + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + ./fsa_fsa_test_app > fsa_test.output -diff fsa_test.output fsa_test.out +diff fsa_test.output $SOURCE_DIRECTORY/fsa_test.out diff --git a/fsa/src/alltest/lookup_test.sh b/fsa/src/alltest/lookup_test.sh index 1732e21de65..2f633ea9c74 100755 --- a/fsa/src/alltest/lookup_test.sh +++ b/fsa/src/alltest/lookup_test.sh @@ -1,4 +1,9 @@ #!/bin/bash set -e -./fsa_lookup_test_app __testfsa__.__fsa__ < testinput.txt > lookup_test.output -diff lookup_test.output lookup_test.out + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + +./fsa_lookup_test_app __testfsa__.__fsa__ < $SOURCE_DIRECTORY/testinput.txt > lookup_test.output +diff lookup_test.output $SOURCE_DIRECTORY/lookup_test.out diff --git a/fsa/src/alltest/ngram_test.sh b/fsa/src/alltest/ngram_test.sh index 6116737c5fa..cc3ccb83b0f 100755 --- a/fsa/src/alltest/ngram_test.sh +++ b/fsa/src/alltest/ngram_test.sh @@ -1,4 +1,9 @@ #!/bin/bash set -e + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + ./fsa_ngram_test_app > ngram_test.output -diff ngram_test.output ngram_test.out +diff ngram_test.output $SOURCE_DIRECTORY/ngram_test.out diff --git a/fsa/src/alltest/segmenter_test.sh b/fsa/src/alltest/segmenter_test.sh index d5c84f6af34..5b8f73b30f8 100755 --- a/fsa/src/alltest/segmenter_test.sh +++ b/fsa/src/alltest/segmenter_test.sh @@ -1,4 +1,9 @@ #!/bin/bash set -e -./fsa_segmenter_test_app < testinput.txt > segmenter_test.output -diff segmenter_test.output segmenter_test.out + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + +./fsa_segmenter_test_app < $SOURCE_DIRECTORY/testinput.txt > segmenter_test.output +diff segmenter_test.output $SOURCE_DIRECTORY/segmenter_test.out diff --git a/fsa/src/alltest/vectorizer_test.sh b/fsa/src/alltest/vectorizer_test.sh index f1d70397472..5e482935da1 100755 --- a/fsa/src/alltest/vectorizer_test.sh +++ b/fsa/src/alltest/vectorizer_test.sh @@ -1,4 +1,9 @@ #!/bin/bash set -e -./fsa_vectorizer_test_app < testinput.txt > vectorizer_test.output -diff vectorizer_test.output vectorizer_test.out + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + +./fsa_vectorizer_test_app < $SOURCE_DIRECTORY/testinput.txt > vectorizer_test.output +diff vectorizer_test.output $SOURCE_DIRECTORY/vectorizer_test.out diff --git a/jrt_test/src/binref/CMakeLists.txt b/jrt_test/src/binref/CMakeLists.txt index 20594f98d02..3abbdee7aed 100644 --- a/jrt_test/src/binref/CMakeLists.txt +++ b/jrt_test/src/binref/CMakeLists.txt @@ -3,3 +3,7 @@ configure_file(compilejava.in compilejava @ONLY) configure_file(runjava.in runjava @ONLY) configure_file(env.sh.in env.sh @ONLY) + +if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + file(COPY sbcmd simpleserver slobrok DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() diff --git a/jrt_test/src/binref/runjava.in b/jrt_test/src/binref/runjava.in index 5cbc6ba4988..5f3a5addd7e 100755 --- a/jrt_test/src/binref/runjava.in +++ b/jrt_test/src/binref/runjava.in @@ -1,7 +1,7 @@ #!/bin/sh unset VESPA_LOG_TARGET -CLASSPATH=@PROJECT_BINARY_DIR@/jrt/target/jrt.jar -CLASSPATH=$CLASSPATH:@PROJECT_BINARY_DIR@/vespajlib/target/vespajlib.jar +CLASSPATH=@PROJECT_SOURCE_DIR@/jrt/target/jrt.jar +CLASSPATH=$CLASSPATH:@PROJECT_SOURCE_DIR@/vespajlib/target/vespajlib.jar CLASSPATH=$CLASSPATH:@CMAKE_CURRENT_SOURCE_DIR@/../java/classes CLASSPATH=$CLASSPATH:. if [ $# -lt 1 ]; then diff --git a/jrt_test/src/tests/echo/CMakeLists.txt b/jrt_test/src/tests/echo/CMakeLists.txt index bab581e1606..8de1ea6f842 100644 --- a/jrt_test/src/tests/echo/CMakeLists.txt +++ b/jrt_test/src/tests/echo/CMakeLists.txt @@ -4,4 +4,4 @@ vespa_add_executable(jrt_test_echo-client_app TEST echo-client.cpp DEPENDS ) -vespa_add_test(NAME jrt_test_echo-client_app NO_VALGRIND COMMAND sh echo_test.sh) +vespa_add_test(NAME jrt_test_echo-client_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/echo_test.sh) diff --git a/jrt_test/src/tests/echo/dotest.sh b/jrt_test/src/tests/echo/dotest.sh index 91b26c7f425..bf54fba26ca 100644 --- a/jrt_test/src/tests/echo/dotest.sh +++ b/jrt_test/src/tests/echo/dotest.sh @@ -1,16 +1,18 @@ #!/bin/bash # Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi fail=0 . ../../binref/env.sh export PORT_2 -$BINREF/progctl.sh progdefs.sh start javaserver 1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh start javaserver 1 $BINREF/runjava PollRPCServer tcp/localhost:$PORT_2 || fail=1 $VALGRIND ./jrt_test_echo-client_app tcp/localhost:$PORT_2 > out.txt || fail=1 -$BINREF/progctl.sh progdefs.sh stop javaserver 1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop javaserver 1 -if diff -u out.txt ref.txt; then +if diff -u out.txt $SOURCE_DIRECTORY/ref.txt; then exit $fail else exit 1 diff --git a/jrt_test/src/tests/echo/echo_test.sh b/jrt_test/src/tests/echo/echo_test.sh index 997d8d42996..aabe3a10a25 100755 --- a/jrt_test/src/tests/echo/echo_test.sh +++ b/jrt_test/src/tests/echo/echo_test.sh @@ -1,6 +1,11 @@ #!/bin/bash + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + fail=0 . ../../binref/env.sh -bash ./dotest.sh || fail=1 -$BINREF/progctl.sh progdefs.sh stop all +bash $SOURCE_DIRECTORY/dotest.sh || fail=1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop all exit $fail diff --git a/jrt_test/src/tests/mandatory-methods/CMakeLists.txt b/jrt_test/src/tests/mandatory-methods/CMakeLists.txt index 561f19e5912..9f7665ec4b0 100644 --- a/jrt_test/src/tests/mandatory-methods/CMakeLists.txt +++ b/jrt_test/src/tests/mandatory-methods/CMakeLists.txt @@ -4,4 +4,4 @@ vespa_add_executable(jrt_test_extract-reflection_app TEST extract-reflection.cpp DEPENDS ) -vespa_add_test(NAME jrt_test_extract-reflection_app NO_VALGRIND COMMAND sh mandatory-methods_test.sh) +vespa_add_test(NAME jrt_test_extract-reflection_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mandatory-methods_test.sh) diff --git a/jrt_test/src/tests/mandatory-methods/dotest.sh b/jrt_test/src/tests/mandatory-methods/dotest.sh index 8cbd99c6988..e6773456475 100644 --- a/jrt_test/src/tests/mandatory-methods/dotest.sh +++ b/jrt_test/src/tests/mandatory-methods/dotest.sh @@ -1,15 +1,19 @@ #!/bin/bash # Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + fail=0 -$BINREF/progctl.sh progdefs.sh start javaserver 1 || fail=1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh start javaserver 1 || fail=1 ./jrt_test_extract-reflection_app tcp/localhost:$PORT_1 verbose > out.txt || fail=1 -$BINREF/progctl.sh progdefs.sh stop javaserver 1 || fail=1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop javaserver 1 || fail=1 -if diff -u out.txt ref.txt; then +if diff -u out.txt $SOURCE_DIRECTORY/ref.txt; then exit $fail else exit 1 diff --git a/jrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh b/jrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh index c6ffbe4d3a1..ba0bc04997f 100755 --- a/jrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh +++ b/jrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh @@ -1,14 +1,18 @@ #!/bin/bash +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + fail=0 . ../../binref/env.sh export PORT_1 -$BINREF/compilejava RPCServer.java || fail=1 +$BINREF/compilejava -d . $SOURCE_DIRECTORY/RPCServer.java || fail=1 -bash ./dotest.sh || fail=1 +bash $SOURCE_DIRECTORY/dotest.sh || fail=1 -$BINREF/progctl.sh progdefs.sh stop all +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop all exit $fail diff --git a/jrt_test/src/tests/mockup-invoke/CMakeLists.txt b/jrt_test/src/tests/mockup-invoke/CMakeLists.txt index 049b42a7e16..c5e484ea43c 100644 --- a/jrt_test/src/tests/mockup-invoke/CMakeLists.txt +++ b/jrt_test/src/tests/mockup-invoke/CMakeLists.txt @@ -4,4 +4,4 @@ vespa_add_executable(jrt_test_mockup-server_app TEST mockup-server.cpp DEPENDS ) -vespa_add_test(NAME jrt_test_mockup-server_app NO_VALGRIND COMMAND sh mockup-invoke_test.sh) +vespa_add_test(NAME jrt_test_mockup-server_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mockup-invoke_test.sh) diff --git a/jrt_test/src/tests/mockup-invoke/dotest.sh b/jrt_test/src/tests/mockup-invoke/dotest.sh index f7fcf007c56..65796f535d4 100644 --- a/jrt_test/src/tests/mockup-invoke/dotest.sh +++ b/jrt_test/src/tests/mockup-invoke/dotest.sh @@ -1,9 +1,13 @@ #!/bin/bash # Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + fail=0 -$BINREF/progctl.sh progdefs.sh start server 1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh start server 1 $BINREF/runjava PollRPCServer tcp/localhost:$PORT_0 || fail=1 $BINREF/runjava MockupInvoke tcp/localhost:$PORT_0 aaa bbb > out.txt || fail=1 @@ -12,8 +16,8 @@ $BINREF/runjava MockupInvoke tcp/localhost:$PORT_0 ccc ddd >> out.txt || fail=1 $BINREF/runjava MockupInvoke tcp/localhost:$PORT_0 ddd eee >> out.txt || fail=1 $BINREF/runjava MockupInvoke tcp/localhost:$PORT_0 eee fff >> out.txt || fail=1 -$BINREF/progctl.sh progdefs.sh stop server 1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop server 1 -diff -u out.txt ref.txt || fail=1 +diff -u out.txt $SOURCE_DIRECTORY/ref.txt || fail=1 exit $fail diff --git a/jrt_test/src/tests/mockup-invoke/mockup-invoke_test.sh b/jrt_test/src/tests/mockup-invoke/mockup-invoke_test.sh index 516b6abef63..dcb0666fdac 100755 --- a/jrt_test/src/tests/mockup-invoke/mockup-invoke_test.sh +++ b/jrt_test/src/tests/mockup-invoke/mockup-invoke_test.sh @@ -1,15 +1,19 @@ #!/bin/bash +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + fail=0 . ../../binref/env.sh export PORT_0 -$BINREF/compilejava MockupInvoke.java || fail=1 +$BINREF/compilejava -d . $SOURCE_DIRECTORY/MockupInvoke.java || fail=1 -bash ./dotest.sh || fail=1 +bash $SOURCE_DIRECTORY/dotest.sh || fail=1 -$BINREF/progctl.sh progdefs.sh stop all +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop all exit $fail diff --git a/jrt_test/src/tests/rpc-error/CMakeLists.txt b/jrt_test/src/tests/rpc-error/CMakeLists.txt index f4756f3dffa..fbe9720d55e 100644 --- a/jrt_test/src/tests/rpc-error/CMakeLists.txt +++ b/jrt_test/src/tests/rpc-error/CMakeLists.txt @@ -4,4 +4,4 @@ vespa_add_executable(jrt_test_test-errors_app TEST test-errors.cpp DEPENDS ) -vespa_add_test(NAME jrt_test_test-errors_app NO_VALGRIND COMMAND sh rpc-error_test.sh) +vespa_add_test(NAME jrt_test_test-errors_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/rpc-error_test.sh) diff --git a/jrt_test/src/tests/rpc-error/dotest.sh b/jrt_test/src/tests/rpc-error/dotest.sh index df9cb4ac62a..5c68309f462 100644 --- a/jrt_test/src/tests/rpc-error/dotest.sh +++ b/jrt_test/src/tests/rpc-error/dotest.sh @@ -1,6 +1,10 @@ #!/bin/bash # Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + fail=0 . ../../binref/env.sh @@ -12,7 +16,7 @@ CPP_PORT=$PORT_4 export JAVA_PORT export CPP_PORT -$BINREF/progctl.sh progdefs.sh start cppserver 1 || fail=1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh start cppserver 1 || fail=1 $BINREF/runjava PollRPCServer tcp/localhost:$CPP_PORT || fail=1 echo "CPP CLIENT <-> CPP SERVER" @@ -21,8 +25,8 @@ echo "CPP CLIENT <-> CPP SERVER" echo "JAVA CLIENT <-> CPP SERVER" $BINREF/runjava TestErrors tcp/localhost:$CPP_PORT || fail=1 -$BINREF/progctl.sh progdefs.sh stop cppserver 1 -$BINREF/progctl.sh progdefs.sh start javaserver 1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop cppserver 1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh start javaserver 1 $BINREF/runjava PollRPCServer tcp/localhost:$JAVA_PORT || fail=1 echo "CPP CLIENT <-> JAVA SERVER" @@ -31,7 +35,7 @@ echo "CPP CLIENT <-> JAVA SERVER" echo "JAVA CLIENT <-> JAVA SERVER" $BINREF/runjava TestErrors tcp/localhost:$JAVA_PORT || fail=1 -$BINREF/progctl.sh progdefs.sh stop javaserver 1 +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop javaserver 1 if [ $fail = "0" ]; then echo "OK" diff --git a/jrt_test/src/tests/rpc-error/rpc-error_test.sh b/jrt_test/src/tests/rpc-error/rpc-error_test.sh index bee324273b1..c30dae9dc82 100755 --- a/jrt_test/src/tests/rpc-error/rpc-error_test.sh +++ b/jrt_test/src/tests/rpc-error/rpc-error_test.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + fail=0 . ../../binref/env.sh @@ -11,10 +15,10 @@ CPP_PORT=$PORT_4 export JAVA_PORT export CPP_PORT -$BINREF/compilejava TestErrors.java || fail=1 +$BINREF/compilejava -d . $SOURCE_DIRECTORY/TestErrors.java || fail=1 -bash ./dotest.sh || fail=1 +bash $SOURCE_DIRECTORY/dotest.sh || fail=1 -$BINREF/progctl.sh progdefs.sh stop all +$SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/progdefs.sh stop all exit $fail diff --git a/juniper/src/test/CMakeLists.txt b/juniper/src/test/CMakeLists.txt index d574c068c38..2edabb70c2b 100644 --- a/juniper/src/test/CMakeLists.txt +++ b/juniper/src/test/CMakeLists.txt @@ -6,6 +6,7 @@ vespa_add_executable(juniper_mcandTest_app TEST testenv.cpp DEPENDS juniper + vespalib ) vespa_add_test(NAME juniper_mcandTest_app COMMAND juniper_mcandTest_app) vespa_add_executable(juniper_queryparserTest_app TEST @@ -16,6 +17,7 @@ vespa_add_executable(juniper_queryparserTest_app TEST testenv.cpp DEPENDS juniper + vespalib ) vespa_add_test(NAME juniper_queryparserTest_app COMMAND juniper_queryparserTest_app) vespa_add_executable(juniper_matchobjectTest_app TEST @@ -26,6 +28,7 @@ vespa_add_executable(juniper_matchobjectTest_app TEST fakerewriter.cpp DEPENDS juniper + vespalib ) vespa_add_test(NAME juniper_matchobjectTest_app COMMAND juniper_matchobjectTest_app) vespa_add_executable(juniper_appender_test_app TEST @@ -33,6 +36,7 @@ vespa_add_executable(juniper_appender_test_app TEST appender_test.cpp DEPENDS juniper + vespalib ) vespa_add_test(NAME juniper_appender_test_app COMMAND juniper_appender_test_app) vespa_add_executable(juniper_queryvisitor_test_app TEST @@ -40,6 +44,7 @@ vespa_add_executable(juniper_queryvisitor_test_app TEST queryvisitor_test.cpp DEPENDS juniper + vespalib ) vespa_add_test(NAME juniper_queryvisitor_test_app COMMAND juniper_queryvisitor_test_app) vespa_add_executable(juniper_auxTest_app TEST @@ -49,6 +54,7 @@ vespa_add_executable(juniper_auxTest_app TEST testenv.cpp DEPENDS juniper + vespalib ) vespa_add_test(NAME juniper_auxTest_app COMMAND juniper_auxTest_app) vespa_add_executable(juniper_SrcTestSuite_app TEST @@ -62,5 +68,6 @@ vespa_add_executable(juniper_SrcTestSuite_app TEST testenv.cpp DEPENDS juniper + vespalib ) vespa_add_test(NAME juniper_SrcTestSuite_app COMMAND juniper_SrcTestSuite_app) diff --git a/juniper/src/test/SrcTestSuite.cpp b/juniper/src/test/SrcTestSuite.cpp index d725278a009..42dbe6e4a5e 100644 --- a/juniper/src/test/SrcTestSuite.cpp +++ b/juniper/src/test/SrcTestSuite.cpp @@ -17,6 +17,7 @@ ****************************************************************************/ #include <vespa/fastos/fastos.h> #include <vespa/log/log.h> +#include <vespa/vespalib/testkit/testapp.h> LOG_SETUP("SrcTestSuite"); #include <vespa/fastlib/testsuite/suite.h> #include "testenv.h" @@ -52,13 +53,13 @@ SrcTestSuite::SrcTestSuite() : * * @author Knut Omang */ -class SrcTestSuiteApp : public FastOS_Application { +class SrcTestSuiteApp : public vespalib::TestApp { public: virtual int Main(); }; int SrcTestSuiteApp::Main() { - juniper::TestEnv te(this, "../rpclient/testclient.rc"); + juniper::TestEnv te(this, (GetSourceDirectory() + "../rpclient/testclient.rc").c_str()); SrcTestSuite suite; suite.Run(); long failures = suite.Report(); diff --git a/juniper/src/test/auxTest.cpp b/juniper/src/test/auxTest.cpp index 7c53b2a7999..99ccd24af35 100644 --- a/juniper/src/test/auxTest.cpp +++ b/juniper/src/test/auxTest.cpp @@ -154,7 +154,7 @@ AuxTest::TestPartialUTF8() { const int inputSize = 5769; // NB: update this if input is changed char input[inputSize]; - FastOS_File file("partialutf8.input.utf8"); + FastOS_File file((GetSourceDirectory() + "partialutf8.input.utf8").c_str()); _test(file.OpenReadOnly()); _test(file.GetSize() == inputSize); _test(file.Read(input, inputSize)); @@ -191,7 +191,7 @@ void AuxTest::TestLargeBlockChinese() { const int inputSize = 10410; // NB: update this if input is changed char input[inputSize]; - FastOS_File file("largeblockchinese.input.utf8"); + FastOS_File file((GetSourceDirectory() + "largeblockchinese.input.utf8").c_str()); _test(file.OpenReadOnly()); _test(file.GetSize() == inputSize); _test(file.Read(input, inputSize)); diff --git a/juniper/src/test/auxTestApp.cpp b/juniper/src/test/auxTestApp.cpp index 7b37cc909bb..50b367f99ec 100644 --- a/juniper/src/test/auxTestApp.cpp +++ b/juniper/src/test/auxTestApp.cpp @@ -1,10 +1,11 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/log/log.h> +#include <vespa/vespalib/testkit/testapp.h> LOG_SETUP("auxTest"); #include "auxTest.h" -class AuxTestApp : public FastOS_Application +class AuxTestApp : public vespalib::TestApp { public: virtual int Main(); @@ -20,7 +21,7 @@ void Usage(char* s) int AuxTestApp::Main() { - juniper::TestEnv te(this, "../rpclient/testclient.rc"); + juniper::TestEnv te(this, (GetSourceDirectory() + "../rpclient/testclient.rc").c_str()); AuxTest pta; pta.SetStream(&std::cout); pta.Run(_argc, _argv); diff --git a/juniper/src/test/matchobjectTestApp.cpp b/juniper/src/test/matchobjectTestApp.cpp index ada38fa1747..9c9786969be 100644 --- a/juniper/src/test/matchobjectTestApp.cpp +++ b/juniper/src/test/matchobjectTestApp.cpp @@ -18,6 +18,7 @@ ****************************************************************************/ #include <vespa/fastos/fastos.h> #include <vespa/log/log.h> +#include <vespa/vespalib/testkit/testapp.h> LOG_SETUP("matchobjectTest"); #include "matchobjectTest.h" #include "testenv.h" @@ -28,10 +29,10 @@ LOG_SETUP("matchobjectTest"); * * @sa MatchObject @author Knut Omang */ -class MatchObjectTestApp : public FastOS_Application { +class MatchObjectTestApp : public vespalib::TestApp { public: virtual int Main() { - juniper::TestEnv te(this, "../rpclient/testclient.rc"); + juniper::TestEnv te(this, (GetSourceDirectory() + "../rpclient/testclient.rc").c_str()); MatchObjectTest test; test.SetStream(&std::cout); test.Run(_argc, _argv); diff --git a/juniper/src/test/mcandTestApp.cpp b/juniper/src/test/mcandTestApp.cpp index 7bbc9681d21..fb331ac2b2a 100644 --- a/juniper/src/test/mcandTestApp.cpp +++ b/juniper/src/test/mcandTestApp.cpp @@ -18,6 +18,7 @@ ****************************************************************************/ #include <vespa/fastos/fastos.h> #include <vespa/log/log.h> +#include <vespa/vespalib/testkit/testapp.h> LOG_SETUP("mcandTest"); #include "mcandTest.h" #include "testenv.h" @@ -28,10 +29,10 @@ LOG_SETUP("mcandTest"); * * @sa MatchCandidate @author Knut Omang */ -class MatchCandidateTestApp : public FastOS_Application { +class MatchCandidateTestApp : public vespalib::TestApp { public: virtual int Main() { - juniper::TestEnv te(this, "../rpclient/testclient.rc"); + juniper::TestEnv te(this, (GetSourceDirectory() + "../rpclient/testclient.rc").c_str()); MatchCandidateTest test; test.SetStream(&std::cout); test.Run(_argc, _argv); diff --git a/juniper/src/test/queryparserTestApp.cpp b/juniper/src/test/queryparserTestApp.cpp index f7c8bce4afa..6391885599a 100644 --- a/juniper/src/test/queryparserTestApp.cpp +++ b/juniper/src/test/queryparserTestApp.cpp @@ -18,6 +18,7 @@ ****************************************************************************/ #include <vespa/fastos/fastos.h> #include <vespa/log/log.h> +#include <vespa/vespalib/testkit/testapp.h> LOG_SETUP("queryparserTest"); #include "queryparserTest.h" #include "testenv.h" @@ -28,10 +29,10 @@ LOG_SETUP("queryparserTest"); * * @sa QueryParser @author Knut Omang */ -class QueryParserTestApp : public FastOS_Application { +class QueryParserTestApp : public vespalib::TestApp { public: virtual int Main() { - juniper::TestEnv te(this, "../rpclient/testclient.rc"); + juniper::TestEnv te(this, (GetSourceDirectory() + "../rpclient/testclient.rc").c_str()); QueryParserTest test; test.SetStream(&std::cout); test.Run(_argc, _argv); diff --git a/lowercasing_test/src/tests/lowercasing/CMakeLists.txt b/lowercasing_test/src/tests/lowercasing/CMakeLists.txt index cfcc932a35a..fcef0151729 100644 --- a/lowercasing_test/src/tests/lowercasing/CMakeLists.txt +++ b/lowercasing_test/src/tests/lowercasing/CMakeLists.txt @@ -4,7 +4,7 @@ vespa_add_executable(lowercasing_test_casingvariants_fastlib_app TEST casingvariants_fastlib.cpp DEPENDS ) -vespa_add_test(NAME lowercasing_test_lowrcasing NO_VALGRIND COMMAND sh lowercasing_test.sh) +vespa_add_test(NAME lowercasing_test_lowrcasing NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lowercasing_test.sh) vespa_add_executable(lowercasing_test_casingvariants_vespalib_app TEST SOURCES casingvariants_vespalib.cpp diff --git a/lowercasing_test/src/tests/lowercasing/CasingVariants.java b/lowercasing_test/src/tests/lowercasing/CasingVariants.java index aa1bf8fcf4d..7c8fd314ce9 100644 --- a/lowercasing_test/src/tests/lowercasing/CasingVariants.java +++ b/lowercasing_test/src/tests/lowercasing/CasingVariants.java @@ -17,7 +17,11 @@ public class CasingVariants { int read = 0; char[] buffer = new char[5000]; String raw; - File f = new File("./letters"); + String srcDir = System.getenv("SOURCE_DIRECTORY"); + if (srcDir == null) { + srcDir = "."; + } + File f = new File(srcDir + "/letters"); StringBuilder s = new StringBuilder(); InputStream in = new FileInputStream(f); diff --git a/lowercasing_test/src/tests/lowercasing/dotest.sh b/lowercasing_test/src/tests/lowercasing/dotest.sh index 943f35cee67..189bf939ff6 100755 --- a/lowercasing_test/src/tests/lowercasing/dotest.sh +++ b/lowercasing_test/src/tests/lowercasing/dotest.sh @@ -2,25 +2,29 @@ # Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. set -e +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + . ../../binref/env.sh ver="java8u20" $BINREF/runjava CasingVariants > out.txt -./lowercasing_test_casingvariants_fastlib_app ./letters ref.txt.$ver > out.fastlib.txt -./lowercasing_test_casingvariants_vespalib_app ./letters ref.txt.$ver > out.vespalib.txt +./lowercasing_test_casingvariants_fastlib_app $SOURCE_DIRECTORY/letters $SOURCE_DIRECTORY/ref.txt.$ver > out.fastlib.txt +./lowercasing_test_casingvariants_vespalib_app $SOURCE_DIRECTORY/letters $SOURCE_DIRECTORY/ref.txt.$ver > out.vespalib.txt echo "Verify Java" -if ! diff -u out.txt ref.txt.$ver; then +if ! diff -u out.txt $SOURCE_DIRECTORY/ref.txt.$ver; then exit 1 fi echo "Verify fastlib" -if ! diff -u out.fastlib.txt ref.fastlib.txt.$ver; then +if ! diff -u out.fastlib.txt $SOURCE_DIRECTORY/ref.fastlib.txt.$ver; then exit 1 fi echo "Verify vespalib" -if ! diff -u out.vespalib.txt ref.vespalib.txt.$ver; then +if ! diff -u out.vespalib.txt $SOURCE_DIRECTORY/ref.vespalib.txt.$ver; then exit 1 fi diff --git a/lowercasing_test/src/tests/lowercasing/lowercasing_test.sh b/lowercasing_test/src/tests/lowercasing/lowercasing_test.sh index 4985f6f86f7..d14b867f3db 100755 --- a/lowercasing_test/src/tests/lowercasing/lowercasing_test.sh +++ b/lowercasing_test/src/tests/lowercasing/lowercasing_test.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e + +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + . ../../binref/env.sh -$BINREF/compilejava CasingVariants.java -bash -e dotest.sh +$BINREF/compilejava -d . $SOURCE_DIRECTORY/CasingVariants.java +bash -e $SOURCE_DIRECTORY/dotest.sh diff --git a/memfilepersistence/src/tests/device/partitionmonitortest.cpp b/memfilepersistence/src/tests/device/partitionmonitortest.cpp index 1a016edcc83..45eed305507 100644 --- a/memfilepersistence/src/tests/device/partitionmonitortest.cpp +++ b/memfilepersistence/src/tests/device/partitionmonitortest.cpp @@ -2,6 +2,7 @@ #include <vespa/fastos/fastos.h> #include <vespa/memfilepersistence/device/partitionmonitor.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vdstestlib/cppunit/macros.h> namespace storage { @@ -62,15 +63,16 @@ struct FakeStatter : public PartitionMonitor::Statter { void PartitionMonitorTest::testNormalUsage() { - PartitionMonitor monitor("testrunner.cpp"); + const std::string file_name = vespalib::TestApp::GetSourceDirectory() + "testrunner.cpp"; + PartitionMonitor monitor(file_name); FakeStatter* statter = new FakeStatter(); monitor.setStatter(std::unique_ptr<PartitionMonitor::Statter>(statter)); std::string expected( - "PartitionMonitor(testrunner.cpp, STAT_PERIOD(100), " + "PartitionMonitor(" + file_name + ", STAT_PERIOD(100), " "2048000/3686400 used - 55.5556 % full)"); CPPUNIT_ASSERT_EQUAL(expected, monitor.toString(false)); expected = - "PartitionMonitor(testrunner.cpp) {\n" + "PartitionMonitor(" + file_name + ") {\n" " Fill rate: 55.5556 %\n" " Inode fill rate: 51.6129 %\n" " Detected block size: 4096\n" @@ -88,16 +90,17 @@ void PartitionMonitorTest::testNormalUsage() void PartitionMonitorTest::testHighInodeFillrate() { - PartitionMonitor monitor("testrunner.cpp"); + const std::string file_name = vespalib::TestApp::GetSourceDirectory() + "testrunner.cpp"; + PartitionMonitor monitor(file_name); FakeStatter* statter = new FakeStatter(); statter->_info.f_favail = 2; monitor.setStatter(std::unique_ptr<PartitionMonitor::Statter>(statter)); std::string expected( - "PartitionMonitor(testrunner.cpp, STAT_PERIOD(100), " + "PartitionMonitor(" + file_name + ", STAT_PERIOD(100), " "2048000/3686400 used - 94.1176 % full (inodes))"); CPPUNIT_ASSERT_EQUAL(expected, monitor.toString(false)); expected = - "PartitionMonitor(testrunner.cpp) {\n" + "PartitionMonitor(" + file_name + ") {\n" " Fill rate: 55.5556 %\n" " Inode fill rate: 94.1176 %\n" " Detected block size: 4096\n" @@ -115,7 +118,7 @@ void PartitionMonitorTest::testHighInodeFillrate() void PartitionMonitorTest::testAlwaysStatPolicy() { - PartitionMonitor monitor("testrunner.cpp"); + PartitionMonitor monitor(vespalib::TestApp::GetSourceDirectory() + "testrunner.cpp"); FakeStatter* statter = new FakeStatter(); monitor.setStatter(std::unique_ptr<PartitionMonitor::Statter>(statter)); monitor.setAlwaysStatPolicy(); @@ -127,7 +130,7 @@ void PartitionMonitorTest::testAlwaysStatPolicy() void PartitionMonitorTest::testPeriodPolicy() { - PartitionMonitor monitor("testrunner.cpp"); + PartitionMonitor monitor(vespalib::TestApp::GetSourceDirectory() + "testrunner.cpp"); FakeStatter* statter = new FakeStatter(); monitor.setStatter(std::unique_ptr<PartitionMonitor::Statter>(statter)); monitor.setStatPeriodPolicy(4); @@ -139,7 +142,7 @@ void PartitionMonitorTest::testPeriodPolicy() void PartitionMonitorTest::testStatOncePolicy() { - PartitionMonitor monitor("testrunner.cpp"); + PartitionMonitor monitor(vespalib::TestApp::GetSourceDirectory() + "testrunner.cpp"); FakeStatter* statter = new FakeStatter(); monitor.setStatter(std::unique_ptr<PartitionMonitor::Statter>(statter)); monitor.setStatOncePolicy(); @@ -151,7 +154,7 @@ void PartitionMonitorTest::testStatOncePolicy() void PartitionMonitorTest::testDynamicPolicy() { - PartitionMonitor monitor("testrunner.cpp"); + PartitionMonitor monitor(vespalib::TestApp::GetSourceDirectory() + "testrunner.cpp"); FakeStatter* statter = new FakeStatter(); monitor.setStatter(std::unique_ptr<PartitionMonitor::Statter>(statter)); monitor.setStatDynamicPolicy(2); @@ -177,7 +180,7 @@ void PartitionMonitorTest::testDynamicPolicy() void PartitionMonitorTest::testIsFull() { - PartitionMonitor monitor("testrunner.cpp"); + PartitionMonitor monitor(vespalib::TestApp::GetSourceDirectory() + "testrunner.cpp"); monitor.setMaxFillness(0.85); FakeStatter* statter = new FakeStatter(); monitor.setStatOncePolicy(); diff --git a/memfilepersistence/src/tests/testhelper.cpp b/memfilepersistence/src/tests/testhelper.cpp index 40a3512e400..39bd1d0968b 100644 --- a/memfilepersistence/src/tests/testhelper.cpp +++ b/memfilepersistence/src/tests/testhelper.cpp @@ -4,7 +4,7 @@ #include <vespa/log/log.h> #include <vespa/vespalib/io/fileutil.h> - +#include <vespa/vespalib/testkit/testapp.h> LOG_SETUP(".testhelper"); namespace storage { @@ -86,7 +86,8 @@ vdstestlib::DirConfig getStandardConfig(bool storagenode) { config->set("maxconcurrentvisitors_fixed", "4"); config->set("maxconcurrentvisitors_variable", "0"); config = &dc.addConfig("stor-visitordispatcher"); - addFileConfig(dc, "documenttypes", "config-doctypes.cfg"); + addFileConfig(dc, "documenttypes", + vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg"); addStorageDistributionConfig(dc); return dc; } diff --git a/messagebus/src/tests/configagent/configagent.cpp b/messagebus/src/tests/configagent/configagent.cpp index c08fdd25be0..c04cd48fff1 100644 --- a/messagebus/src/tests/configagent/configagent.cpp +++ b/messagebus/src/tests/configagent/configagent.cpp @@ -109,13 +109,13 @@ Test::Main() ConfigAgent agent(*this); EXPECT_TRUE(!checkHalf()); EXPECT_TRUE(!checkFull()); - agent.configure(FileConfigReader<MessagebusConfig>("full.cfg").read()); + agent.configure(FileConfigReader<MessagebusConfig>(GetSourceDirectory() + "full.cfg").read()); EXPECT_TRUE(!checkHalf()); EXPECT_TRUE(checkFull()); - agent.configure(FileConfigReader<MessagebusConfig>("half.cfg").read()); + agent.configure(FileConfigReader<MessagebusConfig>(GetSourceDirectory() + "half.cfg").read()); EXPECT_TRUE(checkHalf()); EXPECT_TRUE(!checkFull()); - agent.configure(FileConfigReader<MessagebusConfig>("full.cfg").read()); + agent.configure(FileConfigReader<MessagebusConfig>(GetSourceDirectory() + "full.cfg").read()); EXPECT_TRUE(checkFull()); EXPECT_TRUE(!checkHalf()); TEST_DONE(); diff --git a/persistence/src/tests/proxy/CMakeLists.txt b/persistence/src/tests/proxy/CMakeLists.txt index 4f873f25e50..8a8a56fa935 100644 --- a/persistence/src/tests/proxy/CMakeLists.txt +++ b/persistence/src/tests/proxy/CMakeLists.txt @@ -27,4 +27,4 @@ vespa_add_executable(persistence_external_providerproxy_conformancetest_app persistence persistence_persistence_conformancetest ) -vespa_add_test(NAME persistence_providerproxy_conformance_test_app COMMAND sh proxy_test.sh) +vespa_add_test(NAME persistence_providerproxy_conformance_test_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/proxy_test.sh) diff --git a/persistence/src/tests/proxy/proxy_test.sh b/persistence/src/tests/proxy/proxy_test.sh index d21a23ec507..d21a23ec507 100644..100755 --- a/persistence/src/tests/proxy/proxy_test.sh +++ b/persistence/src/tests/proxy/proxy_test.sh diff --git a/searchcommon/src/tests/schema/schema_test.cpp b/searchcommon/src/tests/schema/schema_test.cpp index 56154c7a7d4..0bac074b43a 100644 --- a/searchcommon/src/tests/schema/schema_test.cpp +++ b/searchcommon/src/tests/schema/schema_test.cpp @@ -161,7 +161,7 @@ TEST("testLoadAndSave") { { // load from config -> save to file -> load from file Schema s; - SchemaConfigurer configurer(s, "dir:."); + SchemaConfigurer configurer(s, "dir:" + vespalib::TestApp::GetSourceDirectory()); EXPECT_EQUAL(3u, s.getNumIndexFields()); assertIndexField(SIF("a", SDT::STRING), s.getIndexField(0)); assertIndexField(SIF("b", SDT::INT64), s.getIndexField(1)); diff --git a/searchcore/src/tests/applyattrupdates/applyattrupdates.cpp b/searchcore/src/tests/applyattrupdates/applyattrupdates.cpp index 9454b51b6ac..8cb671f585e 100644 --- a/searchcore/src/tests/applyattrupdates/applyattrupdates.cpp +++ b/searchcore/src/tests/applyattrupdates/applyattrupdates.cpp @@ -134,7 +134,6 @@ private: void requireThatArrayAttributesAreUpdated(); void requireThatWeightedSetAttributesAreUpdated(); - std::string _srcdir; DocumentTypeRepo _repo; const DocumentType* _docType; @@ -318,8 +317,7 @@ Test::requireThatWeightedSetAttributesAreUpdated() } Test::Test() - : _srcdir(getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."), - _repo(readDocumenttypesConfig((_srcdir + "/doctypes.cfg").c_str())), + : _repo(readDocumenttypesConfig(vespalib::TestApp::GetSourceDirectory() + "doctypes.cfg")), _docType(_repo.getDocumentType("testdoc")) { } diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index 5aaded3c848..b472c612281 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -155,7 +155,7 @@ public: _queryLimiter(), _clock(), _dummy(), - _spec(getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."), + _spec(vespalib::TestApp::GetSourceDirectory()), _configMgr(_spec, getDocTypeName()), _documenttypesConfig(new DocumenttypesConfig()), _repo(repo), @@ -1246,13 +1246,13 @@ Test::Test() _resultCfg(), _markupFields() { - auto envSrcDir = getenv("SOURCE_DIRECTORY"); - std::string srcDir = envSrcDir ? envSrcDir : "."; std::string cfgId("summary"); - _summaryCfg = config::ConfigGetter<vespa::config::search::SummaryConfig>::getConfig(cfgId, config::FileSpec(srcDir + "/summary.cfg")); + _summaryCfg = config::ConfigGetter<vespa::config::search::SummaryConfig>::getConfig( + cfgId, config::FileSpec(vespalib::TestApp::GetSourceDirectory() + "summary.cfg")); _resultCfg.ReadConfig(*_summaryCfg, cfgId.c_str()); std::string mapCfgId("summarymap"); - std::unique_ptr<vespa::config::search::SummarymapConfig> mapCfg = config::ConfigGetter<vespa::config::search::SummarymapConfig>::getConfig(mapCfgId, config::FileSpec(srcDir + "/summarymap.cfg")); + std::unique_ptr<vespa::config::search::SummarymapConfig> mapCfg = config::ConfigGetter<vespa::config::search::SummarymapConfig>::getConfig( + mapCfgId, config::FileSpec(vespalib::TestApp::GetSourceDirectory() + "summarymap.cfg")); for (size_t i = 0; i < mapCfg->override.size(); ++i) { const vespa::config::search::SummarymapConfig::Override & o = mapCfg->override[i]; if (o.command == "dynamicteaser") { diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index b2150db91dc..5c6a7db1876 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -54,13 +54,12 @@ typedef std::vector<AttributeGuard> AttributeGuardList; const std::string DOCTYPE_NAME = "searchdocument"; const std::string SUB_NAME = "subdb"; const std::string BASE_DIR = "basedir"; -const std::string SOURCE_DIR = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; const SerialNum CFG_SERIAL = 5; -struct ConfigDir1 { static vespalib::string dir() { return SOURCE_DIR + "/cfg1"; } }; -struct ConfigDir2 { static vespalib::string dir() { return SOURCE_DIR + "/cfg2"; } }; -struct ConfigDir3 { static vespalib::string dir() { return SOURCE_DIR + "/cfg3"; } }; -struct ConfigDir4 { static vespalib::string dir() { return SOURCE_DIR + "/cfg4"; } }; +struct ConfigDir1 { static vespalib::string dir() { return vespalib::TestApp::GetSourceDirectory() + "cfg1"; } }; +struct ConfigDir2 { static vespalib::string dir() { return vespalib::TestApp::GetSourceDirectory() + "cfg2"; } }; +struct ConfigDir3 { static vespalib::string dir() { return vespalib::TestApp::GetSourceDirectory() + "cfg3"; } }; +struct ConfigDir4 { static vespalib::string dir() { return vespalib::TestApp::GetSourceDirectory() + "cfg4"; } }; struct MySubDBOwner : public IDocumentSubDB::IOwner { diff --git a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp index dec1dc08471..605a8fc5530 100644 --- a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp @@ -72,8 +72,7 @@ Fixture::Fixture() DocumentType docType("typea", 0); DocumentTypeRepo::SP repo(new DocumentTypeRepo(docType)); TuneFileDocumentDB::SP tuneFileDocumentDB(new TuneFileDocumentDB); - std::string srcDir = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; - config::DirSpec spec(srcDir + "/cfg"); + config::DirSpec spec(vespalib::TestApp::GetSourceDirectory() + "cfg"); DocumentDBConfigHelper mgr(spec, "typea"); BootstrapConfig::SP b(new BootstrapConfig(1, diff --git a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp index 75cf6601f5a..499f8a11aaf 100644 --- a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp +++ b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp @@ -86,8 +86,7 @@ getSchema(int step) DocumentDBConfig::SP makeBaseConfigSnapshot() { - std::string srcDir = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; - config::DirSpec spec(srcDir + "/cfg"); + config::DirSpec spec(vespalib::TestApp::GetSourceDirectory() + "cfg"); ConfigKeySet extraKeySet; extraKeySet.add<MycfgConfig>(""); DBCM dbcm(spec, "test", extraKeySet); diff --git a/searchlib/src/tests/datastore/logdatastore_test.cpp b/searchlib/src/tests/datastore/logdatastore_test.cpp index 666b725d8de..762bdeb4618 100644 --- a/searchlib/src/tests/datastore/logdatastore_test.cpp +++ b/searchlib/src/tests/datastore/logdatastore_test.cpp @@ -271,14 +271,14 @@ void fetchAndTest(IDataStore & datastore, uint32_t lid, const void *a, size_t sz } TEST("testTruncatedIdxFile"){ - std::string srcDir = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; LogDataStore::Config config; DummyFileHeaderContext fileHeaderContext; vespalib::ThreadStackExecutor executor(config.getNumThreads(), 128*1024); MyTlSyncer tlSyncer; { // Files comes from the 'growing test'. - LogDataStore datastore(executor, srcDir + "/bug-7257706", config, + LogDataStore datastore(executor, + vespalib::TestApp::GetSourceDirectory() + "bug-7257706", config, GrowStrategy(), TuneFileSummary(), fileHeaderContext, tlSyncer, NULL); EXPECT_EQUAL(354ul, datastore.lastSyncToken()); diff --git a/searchlib/src/tests/datastore/logdatastore_test.sh b/searchlib/src/tests/datastore/logdatastore_test.sh index 662c7a767aa..2674f3831d6 100755 --- a/searchlib/src/tests/datastore/logdatastore_test.sh +++ b/searchlib/src/tests/datastore/logdatastore_test.sh @@ -6,11 +6,11 @@ if [ -z "$SOURCE_DIRECTORY" ]; then fi cp -r $SOURCE_DIRECTORY/bug-7257706 bug-7257706-truncated -mkdir dangling-test -cp $SOURCE_DIRECTORY/bug-7257706/*.dat dangling-test/ -cp $SOURCE_DIRECTORY/bug-7257706/*.idx dangling-test/ -cp $SOURCE_DIRECTORY/dangling/*.dat dangling-test/ -cp $SOURCE_DIRECTORY/dangling/*.idx dangling-test/ +mkdir -p dangling-test +cp -a $SOURCE_DIRECTORY/bug-7257706/*.dat dangling-test/ +cp -a $SOURCE_DIRECTORY/bug-7257706/*.idx dangling-test/ +cp -a $SOURCE_DIRECTORY/dangling/*.dat dangling-test/ +cp -a $SOURCE_DIRECTORY/dangling/*.idx dangling-test/ truncate --size 3830 bug-7257706-truncated/1422358701368384000.idx VESPA_LOG_TARGET=file:vlog2.txt $VALGRIND ./searchlib_logdatastore_test_app rm -rf bug-7257706-truncated dangling-test diff --git a/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp b/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp index 1314bee5b15..5b4e3c96da5 100644 --- a/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp +++ b/searchlib/src/tests/fef/featurenameparser/featurenameparser_test.cpp @@ -144,8 +144,7 @@ Test::Main() EXPECT_TRUE(testParse("foo( , , )", true, "foo", ParamList().add("").add("").add(""), "")); EXPECT_TRUE(testParse("foo( \t , \n , \r , \f )", true, "foo", ParamList().add("").add("").add("").add(""), "")); - const std::string srcDir = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; - testFile(srcDir + "/parsetest.txt"); + testFile(vespalib::TestApp::GetSourceDirectory() + "parsetest.txt"); TEST_DONE(); } diff --git a/searchlib/src/tests/fef/table/table_test.cpp b/searchlib/src/tests/fef/table/table_test.cpp index 74fb37ab672..6835b6df5b0 100644 --- a/searchlib/src/tests/fef/table/table_test.cpp +++ b/searchlib/src/tests/fef/table/table_test.cpp @@ -25,7 +25,6 @@ private: void testFunctionTableFactory(); void testTableManager(); - const std::string _srcDir; const std::string _tables1Dir; const std::string _tables2Dir; public: @@ -35,9 +34,8 @@ public: TableTest::TableTest() : vespalib::TestApp(), - _srcDir(getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."), - _tables1Dir(_srcDir + "/tables1"), - _tables2Dir(_srcDir + "/tables2") + _tables1Dir(vespalib::TestApp::GetSourceDirectory() + "tables1"), + _tables2Dir(vespalib::TestApp::GetSourceDirectory() + "tables2") { } diff --git a/searchlib/src/tests/grouping/grouping_serialization_test.cpp b/searchlib/src/tests/grouping/grouping_serialization_test.cpp index efc559a5bab..a194ed7232b 100644 --- a/searchlib/src/tests/grouping/grouping_serialization_test.cpp +++ b/searchlib/src/tests/grouping/grouping_serialization_test.cpp @@ -43,8 +43,7 @@ document::GlobalId getGlobalId(uint32_t docId) { struct Fixture { // Set WRITE_FILES to true to generate new expected serialization files. const bool WRITE_FILES = false; - const std::string src_dir = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; - const std::string file_path = src_dir + "/../../test/files/"; + const std::string file_path = vespalib::TestApp::GetSourceDirectory() + "../../test/files/"; std::string file_name; std::ifstream file_stream; diff --git a/searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp b/searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp index 4bd40863fc2..522f748c423 100644 --- a/searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp +++ b/searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp @@ -4,6 +4,7 @@ LOG_SETUP("indexmetainfo_test"); #include <vespa/vespalib/testkit/testapp.h> #include <vespa/searchlib/common/indexmetainfo.h> +#include "../../../../vespalib/src/vespa/vespalib/testkit/testapp.h" using search::IndexMetaInfo; @@ -14,11 +15,9 @@ TEST_SETUP(Test) int Test::Main() { - const std::string srcDir = getenv("SOURCE_DIRECTORY") ? getenv("SOURCE_DIRECTORY") : "."; - TEST_INIT("indexmetainfo_test"); { // load pregenerated file - IndexMetaInfo info(srcDir); + IndexMetaInfo info(vespalib::TestApp::GetSourceDirectory()); EXPECT_TRUE(info.load()); ASSERT_TRUE(info.snapshots().size() == 4); EXPECT_TRUE(info.snapshots()[0].valid); @@ -90,7 +89,7 @@ Test::Main() EXPECT_TRUE(!info.load("file-not-present.txt")); } { // load files with errors should fail - IndexMetaInfo info(srcDir); + IndexMetaInfo info(vespalib::TestApp::GetSourceDirectory()); EXPECT_TRUE(!info.load("bogus1.txt")); EXPECT_TRUE(!info.load("bogus2.txt")); EXPECT_TRUE(!info.load("bogus3.txt")); diff --git a/searchlib/src/tests/queryeval/weak_and/CMakeLists.txt b/searchlib/src/tests/queryeval/weak_and/CMakeLists.txt index c621219227d..b9f537fd895 100644 --- a/searchlib/src/tests/queryeval/weak_and/CMakeLists.txt +++ b/searchlib/src/tests/queryeval/weak_and/CMakeLists.txt @@ -20,11 +20,11 @@ vespa_add_executable(searchlib_weak_and_bench_app DEPENDS searchlib ) -vespa_add_test(NAME searchlib_weak_and_test_expensive_app COMMAND searchlib_weak_and_bench_app BENCHMARK) +vespa_add_test(NAME searchlib_weak_and_bench_app COMMAND searchlib_weak_and_bench_app BENCHMARK) vespa_add_executable(searchlib_parallel_weak_and_bench_app SOURCES parallel_weak_and_bench.cpp DEPENDS searchlib ) -vespa_add_test(NAME searchlib_weak_and_test_expensive_app COMMAND searchlib_parallel_weak_and_bench_app BENCHMARK) +vespa_add_test(NAME searchlib_parallel_weak_and_bench_app COMMAND searchlib_parallel_weak_and_bench_app BENCHMARK) diff --git a/searchlib/src/vespa/searchlib/features/CMakeLists.txt b/searchlib/src/vespa/searchlib/features/CMakeLists.txt index 2ce9fc6886c..c69486505a0 100644 --- a/searchlib/src/vespa/searchlib/features/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/features/CMakeLists.txt @@ -55,7 +55,7 @@ vespa_add_library(searchlib_features OBJECT termfeature.cpp terminfofeature.cpp text_similarity_feature.cpp - utils.cpp + documenttestutils.cpp valuefeature.cpp weighted_set_parser.cpp DEPENDS diff --git a/searchlib/src/vespa/searchlib/features/utils.cpp b/searchlib/src/vespa/searchlib/features/documenttestutils.cpp index 4f33a6e6e2a..4f33a6e6e2a 100644 --- a/searchlib/src/vespa/searchlib/features/utils.cpp +++ b/searchlib/src/vespa/searchlib/features/documenttestutils.cpp diff --git a/searchsummary/src/tests/extractkeywords/CMakeLists.txt b/searchsummary/src/tests/extractkeywords/CMakeLists.txt index 48fe0aa9785..b571793a015 100644 --- a/searchsummary/src/tests/extractkeywords/CMakeLists.txt +++ b/searchsummary/src/tests/extractkeywords/CMakeLists.txt @@ -5,4 +5,4 @@ vespa_add_executable(searchsummary_extractkeywordstest_app TEST DEPENDS searchsummary ) -vespa_add_test(NAME searchsummary_extractkeywordstest_app COMMAND sh runtests.sh) +vespa_add_test(NAME searchsummary_extractkeywordstest_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/runtests.sh) diff --git a/slobrok/src/tests/startsome/CMakeLists.txt b/slobrok/src/tests/startsome/CMakeLists.txt index 55b82e6100b..c4e64135d36 100644 --- a/slobrok/src/tests/startsome/CMakeLists.txt +++ b/slobrok/src/tests/startsome/CMakeLists.txt @@ -4,7 +4,7 @@ vespa_add_executable(slobrok_tstdst_app TEST tstdst.cpp DEPENDS ) -vespa_add_test(NAME slobrok_tstdst_app NO_VALGRIND COMMAND sh startsome.sh) +vespa_add_test(NAME slobrok_tstdst_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/startsome.sh) vespa_add_executable(slobrok_rpc_info_app SOURCES rpc_info.cpp diff --git a/staging_vespalib/src/tests/fileheader/fileheader_test.cpp b/staging_vespalib/src/tests/fileheader/fileheader_test.cpp index 2aaeeea58a8..cd3dc5271ed 100644 --- a/staging_vespalib/src/tests/fileheader/fileheader_test.cpp +++ b/staging_vespalib/src/tests/fileheader/fileheader_test.cpp @@ -593,7 +593,8 @@ void Test::testLayout() { FastOS_File file; - ASSERT_TRUE(file.OpenReadOnly("fileheader.dat")); + const std::string fileName = vespalib::TestApp::GetSourceDirectory() + "fileheader.dat"; + ASSERT_TRUE(file.OpenReadOnly(fileName.c_str())); FileHeader header; uint32_t len = header.readFile(file); diff --git a/staging_vespalib/src/tests/util/process_memory_stats/CMakeLists.txt b/staging_vespalib/src/tests/util/process_memory_stats/CMakeLists.txt index bc5bb9194ff..aa1e2e0e2b6 100644 --- a/staging_vespalib/src/tests/util/process_memory_stats/CMakeLists.txt +++ b/staging_vespalib/src/tests/util/process_memory_stats/CMakeLists.txt @@ -5,4 +5,4 @@ vespa_add_executable(staging_vespalib_process_memory_stats_test_app TEST DEPENDS staging_vespalib ) -vespa_add_test(NAME staging_vespalib_process_memory_stats_test_app COMMAND sh process_memory_stats_test.sh) +vespa_add_test(NAME staging_vespalib_process_memory_stats_test_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/process_memory_stats_test.sh) diff --git a/storage/src/tests/bucketdb/bucketmanagertest.cpp b/storage/src/tests/bucketdb/bucketmanagertest.cpp index ee2e3f6ef7f..7e34c14a495 100644 --- a/storage/src/tests/bucketdb/bucketmanagertest.cpp +++ b/storage/src/tests/bucketdb/bucketmanagertest.cpp @@ -24,6 +24,7 @@ LOG_SETUP(".test.bucketdb.bucketmanager"); #include <vespa/vdslib/state/random.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/storageapi/message/bucket.h> #include <thread> #include <future> @@ -158,6 +159,7 @@ public: static constexpr uint32_t DIR_SPREAD = 3; static constexpr uint32_t MESSAGE_WAIT_TIME = 60*2; + void setUp() { _emptyBuckets = 0; } @@ -192,8 +194,8 @@ void BucketManagerTest::setupTestEnvironment(bool fakePersistenceLayer, vdstestlib::DirConfig config(getStandardConfig(true)); DocumentTypeRepo::SP repo(new DocumentTypeRepo( - *ConfigGetter<DocumenttypesConfig>::getConfig("config-doctypes", - FileSpec("config-doctypes.cfg")))); + *ConfigGetter<DocumenttypesConfig>::getConfig( + "config-doctypes", FileSpec(vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg")))); _top.reset(new DummyStorageLink); _node.reset(new TestServiceLayerApp( DiskCount(2), NodeIndex(0), config.getConfigId())); diff --git a/storage/src/tests/common/testhelper.cpp b/storage/src/tests/common/testhelper.cpp index b8b42124d39..a530b918b77 100644 --- a/storage/src/tests/common/testhelper.cpp +++ b/storage/src/tests/common/testhelper.cpp @@ -4,6 +4,7 @@ #include <vespa/log/log.h> #include <vespa/vespalib/io/fileutil.h> +#include <vespa/vespalib/testkit/testapp.h> LOG_SETUP(".testhelper"); @@ -159,7 +160,7 @@ vdstestlib::DirConfig getStandardConfig(bool storagenode) { config->set("maxconcurrentvisitors_fixed", "4"); config->set("maxconcurrentvisitors_variable", "0"); config = &dc.addConfig("stor-visitordispatcher"); - addFileConfig(dc, "documenttypes", "config-doctypes.cfg"); + addFileConfig(dc, "documenttypes", vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg"); addStorageDistributionConfig(dc); return dc; } diff --git a/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp b/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp index 65ccc65bdcf..8cbe2045fd2 100644 --- a/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp +++ b/storage/src/tests/distributor/distributor_host_info_reporter_test.cpp @@ -7,6 +7,7 @@ #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/jsonstream.h> +#include <vespa/vespalib/testkit/testapp.h> #include <tests/common/hostreporter/util.h> namespace storage { @@ -186,7 +187,7 @@ DistributorHostInfoReporterTest::generateExampleJson() std::string jsonString = json.str(); - std::string path = "../../../protocols/getnodestate/distributor.json"; + std::string path = vespalib::TestApp::GetSourceDirectory() + "../../../protocols/getnodestate/distributor.json"; std::string goldenString = File::readAll(path); vespalib::slime::Memory goldenMemory(goldenString); diff --git a/storage/src/tests/distributor/getoperationtest.cpp b/storage/src/tests/distributor/getoperationtest.cpp index 12853be2e42..169fdc1c213 100644 --- a/storage/src/tests/distributor/getoperationtest.cpp +++ b/storage/src/tests/distributor/getoperationtest.cpp @@ -10,6 +10,7 @@ #include <tests/distributor/distributortestutil.h> #include <tests/common/dummystoragelink.h> #include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/testkit/testapp.h> #include <iomanip> #include <iostream> #include <memory> @@ -54,7 +55,8 @@ public: void setUp() { _repo.reset( new document::DocumentTypeRepo(*ConfigGetter<DocumenttypesConfig>:: - getConfig("config-doctypes", FileSpec("config-doctypes.cfg")))); + getConfig("config-doctypes", + FileSpec(vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg")))); createLinks(); docId = document::DocumentId(document::DocIdString("test", "uri")); diff --git a/storage/src/tests/distributor/operationtargetresolvertest.cpp b/storage/src/tests/distributor/operationtargetresolvertest.cpp index 5b23d3a7a9e..27f1cb722b0 100644 --- a/storage/src/tests/distributor/operationtargetresolvertest.cpp +++ b/storage/src/tests/distributor/operationtargetresolvertest.cpp @@ -14,6 +14,7 @@ #include <tests/common/dummystoragelink.h> #include <vespa/vdslib/distribution/idealnodecalculatorimpl.h> #include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/storage/distributor/operationtargetresolverimpl.h> using document::BucketId; @@ -49,7 +50,8 @@ struct OperationTargetResolverTest : public CppUnit::TestFixture, void setUp() { _repo.reset(new document::DocumentTypeRepo( *config::ConfigGetter<document::DocumenttypesConfig>::getConfig( - "config-doctypes", config::FileSpec("config-doctypes.cfg")))); + "config-doctypes", + config::FileSpec(vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg")))); _html_type = _repo->getDocumentType("text/html"); createLinks(); }; diff --git a/storage/src/tests/distributor/putoperationtest.cpp b/storage/src/tests/distributor/putoperationtest.cpp index 011b34cd1e3..d2dc7583229 100644 --- a/storage/src/tests/distributor/putoperationtest.cpp +++ b/storage/src/tests/distributor/putoperationtest.cpp @@ -12,6 +12,7 @@ #include <tests/common/dummystoragelink.h> #include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/text/stringtokenizer.h> +#include <vespa/vespalib/testkit/testapp.h> #include <iomanip> #include <iostream> #include <memory> @@ -93,7 +94,8 @@ public: void setUp() { _repo.reset( new DocumentTypeRepo(*ConfigGetter<DocumenttypesConfig> - ::getConfig("config-doctypes", FileSpec("config-doctypes.cfg")))); + ::getConfig("config-doctypes", + FileSpec(vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg")))); _html_type = _repo->getDocumentType("text/html"); createLinks(); }; diff --git a/storage/src/tests/distributor/twophaseupdateoperationtest.cpp b/storage/src/tests/distributor/twophaseupdateoperationtest.cpp index f6346c9755f..60f836e3ea7 100644 --- a/storage/src/tests/distributor/twophaseupdateoperationtest.cpp +++ b/storage/src/tests/distributor/twophaseupdateoperationtest.cpp @@ -25,7 +25,6 @@ namespace distributor { using std::shared_ptr; using config::ConfigGetter; using document::DocumenttypesConfig; -using config::FileSpec; using namespace document; using namespace storage; using namespace storage::distributor; diff --git a/storage/src/tests/distributor/updateoperationtest.cpp b/storage/src/tests/distributor/updateoperationtest.cpp index 912d0235e42..9a2b529eb77 100644 --- a/storage/src/tests/distributor/updateoperationtest.cpp +++ b/storage/src/tests/distributor/updateoperationtest.cpp @@ -13,6 +13,7 @@ #include <vespa/document/config/config-documenttypes.h> #include <tests/distributor/messagesenderstub.h> #include <vespa/storage/distributor/operations/external/updateoperation.h> +#include <vespa/vespalib/testkit/testapp.h> using std::shared_ptr; using namespace document; @@ -48,7 +49,8 @@ public: void setUp() { _repo.reset( new DocumentTypeRepo(*ConfigGetter<DocumenttypesConfig>:: - getConfig("config-doctypes", FileSpec("config-doctypes.cfg")))); + getConfig("config-doctypes", + FileSpec(vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg")))); _html_type = _repo->getDocumentType("text/html"); createLinks(); } diff --git a/storage/src/tests/storageserver/documentapiconvertertest.cpp b/storage/src/tests/storageserver/documentapiconvertertest.cpp index 69083352c4a..604e849ebe8 100644 --- a/storage/src/tests/storageserver/documentapiconvertertest.cpp +++ b/storage/src/tests/storageserver/documentapiconvertertest.cpp @@ -15,6 +15,7 @@ #include <vespa/storageapi/message/persistence.h> #include <vespa/storageapi/message/visitor.h> #include <vespa/vdslib/container/writabledocumentlist.h> +#include <vespa/vespalib/testkit/testapp.h> using document::DataType; using document::DocIdString; @@ -33,7 +34,7 @@ struct DocumentApiConverterTest : public CppUnit::TestFixture DocumentApiConverterTest() : _repo(new DocumentTypeRepo(readDocumenttypesConfig( - "config-doctypes.cfg"))), + vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg"))), _html_type(*_repo->getDocumentType("text/html")) { } diff --git a/storage/src/tests/testhelper.cpp b/storage/src/tests/testhelper.cpp index c4074aa1ac6..55690b2382b 100644 --- a/storage/src/tests/testhelper.cpp +++ b/storage/src/tests/testhelper.cpp @@ -125,7 +125,8 @@ vdstestlib::DirConfig getStandardConfig(bool storagenode) { config->set("maxconcurrentvisitors_fixed", "4"); config->set("maxconcurrentvisitors_variable", "0"); config = &dc.addConfig("stor-visitordispatcher"); - addFileConfig(dc, "documenttypes", "config-doctypes.cfg"); + addFileConfig(dc, "documenttypes", + vespalib::TestApp::GetSourceDirectory() + "config-doctypes.cfg"); addStorageDistributionConfig(dc); return dc; } diff --git a/streamingvisitors/src/tests/searchvisitor/searchvisitor.cpp b/streamingvisitors/src/tests/searchvisitor/searchvisitor.cpp index 77df70ad256..7442e695227 100644 --- a/streamingvisitors/src/tests/searchvisitor/searchvisitor.cpp +++ b/streamingvisitors/src/tests/searchvisitor/searchvisitor.cpp @@ -35,11 +35,11 @@ public: SearchVisitorTest::SearchVisitorTest() : vespalib::TestApp(), _componentRegister(), - _env("dir:cfg") + _env("dir:" + GetSourceDirectory() + "cfg") { _componentRegister.setNodeInfo("mycluster", lib::NodeType::STORAGE, 1); _componentRegister.setClock(_clock); - StorageComponent::DocumentTypeRepoSP repo(new DocumentTypeRepo(readDocumenttypesConfig("cfg/documenttypes.cfg"))); + StorageComponent::DocumentTypeRepoSP repo(new DocumentTypeRepo(readDocumenttypesConfig(GetSourceDirectory() + "cfg/documenttypes.cfg"))); _componentRegister.setDocumentTypeRepo(repo); _component.reset(new StorageComponent(_componentRegister, "storage")); }; @@ -92,13 +92,13 @@ SearchVisitorTest::testSearchVisitor() vespalib::string stackDump = StackDumpCreator::create(*node); params.set("query", stackDump); - testCreateSearchVisitor("dir:cfg", params); + testCreateSearchVisitor("dir:" + GetSourceDirectory() + "cfg", params); } void SearchVisitorTest::testOnlyRequireWeakReadConsistency() { - SearchVisitorFactory factory("dir:cfg"); + SearchVisitorFactory factory("dir:" + GetSourceDirectory() + "cfg"); VisitorFactory& factoryBase(factory); vdslib::Parameters params; std::unique_ptr<Visitor> sv( diff --git a/vbench/src/tests/app_vbench/CMakeLists.txt b/vbench/src/tests/app_vbench/CMakeLists.txt index c8970393a60..c5e57a8505e 100644 --- a/vbench/src/tests/app_vbench/CMakeLists.txt +++ b/vbench/src/tests/app_vbench/CMakeLists.txt @@ -7,3 +7,4 @@ vespa_add_executable(vbench_app_vbench_test_app TEST vbench ) vespa_add_test(NAME vbench_app_vbench_test_app NO_VALGRIND COMMAND vbench_app_vbench_test_app) +configure_file(vbench.cfg.template vbench.cfg @ONLY)
\ No newline at end of file diff --git a/vbench/src/tests/app_vbench/app_vbench_test.cpp b/vbench/src/tests/app_vbench/app_vbench_test.cpp index 87461702075..37b613210a0 100644 --- a/vbench/src/tests/app_vbench/app_vbench_test.cpp +++ b/vbench/src/tests/app_vbench/app_vbench_test.cpp @@ -48,7 +48,6 @@ TEST_MT_F("run vbench", 2, ServerSocket()) { } } else { std::string out; - EXPECT_TRUE(SlaveProc::run("cp vbench.cfg.template vbench.cfg")); EXPECT_TRUE(SlaveProc::run(strfmt("sed -i 's/_LOCAL_PORT_/%d/' vbench.cfg", f1.port()).c_str())); EXPECT_TRUE(SlaveProc::run("../../apps/vbench/vbench_app run vbench.cfg 2> vbench.out", out)); fprintf(stderr, "%s\n", out.c_str()); diff --git a/vbench/src/tests/app_vbench/vbench.cfg.template b/vbench/src/tests/app_vbench/vbench.cfg.template index de8e30a7fbe..950d5151780 100644 --- a/vbench/src/tests/app_vbench/vbench.cfg.template +++ b/vbench/src/tests/app_vbench/vbench.cfg.template @@ -2,14 +2,14 @@ http_threads: 32, inputs: [ { - source: { type: 'RequestGenerator', file: 'input.txt' }, + source: { type: 'RequestGenerator', file: '@CMAKE_CURRENT_SOURCE_DIR@/input.txt' }, prepare: [ { type: 'ServerTagger', host: 'localhost', port:_LOCAL_PORT_ }, { type: 'QpsTagger', qps: 10 } ] }, { - source: { type: 'RequestGenerator', file: 'input.txt' }, + source: { type: 'RequestGenerator', file: '@CMAKE_CURRENT_SOURCE_DIR@/input.txt' }, prepare: [ { type: 'ServerTagger', host: 'localhost', port:_LOCAL_PORT_ }, { type: 'QpsTagger', qps: 10 } diff --git a/vbench/src/tests/input_file_reader/input_file_reader_test.cpp b/vbench/src/tests/input_file_reader/input_file_reader_test.cpp index 2cf59dff1ec..bb39dcceafd 100644 --- a/vbench/src/tests/input_file_reader/input_file_reader_test.cpp +++ b/vbench/src/tests/input_file_reader/input_file_reader_test.cpp @@ -10,7 +10,7 @@ TEST("input file reader") { EXPECT_TRUE(reader.tainted()); } { - InputFileReader reader("simple_test_input.txt"); + InputFileReader reader(vespalib::TestApp::GetSourceDirectory() + "simple_test_input.txt"); EXPECT_TRUE(!reader.tainted()); string line; EXPECT_TRUE(reader.readLine(line)); @@ -23,7 +23,7 @@ TEST("input file reader") { TEST_FLUSH(); } { - InputFileReader reader("hard_test_input.txt"); + InputFileReader reader(vespalib::TestApp::GetSourceDirectory() + "hard_test_input.txt"); EXPECT_TRUE(!reader.tainted()); string line; EXPECT_TRUE(reader.readLine(line)); diff --git a/vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp b/vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp index 5044f5401e1..facd70b20ce 100644 --- a/vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp +++ b/vbench/src/tests/mapped_file_input/mapped_file_input_test.cpp @@ -10,7 +10,7 @@ TEST("mapped file input") { EXPECT_TRUE(file.tainted()); } { - MappedFileInput file("file.txt"); + MappedFileInput file(vespalib::TestApp::GetSourceDirectory() + "file.txt"); EXPECT_TRUE(!file.tainted()); LineReader reader(file, 3); string line; diff --git a/vbench/src/tests/request_generator/request_generator_test.cpp b/vbench/src/tests/request_generator/request_generator_test.cpp index 52aca22954c..bdaf3fee75e 100644 --- a/vbench/src/tests/request_generator/request_generator_test.cpp +++ b/vbench/src/tests/request_generator/request_generator_test.cpp @@ -4,7 +4,7 @@ using namespace vbench; -TEST_FF("generate request", RequestReceptor(), RequestGenerator("input.txt", f1)) { +TEST_FF("generate request", RequestReceptor(), RequestGenerator(vespalib::TestApp::GetSourceDirectory() + "input.txt", f1)) { f2.run(); ASSERT_TRUE(f1.request.get() != 0); EXPECT_EQUAL("/this/is/url", f1.request->url()); @@ -17,7 +17,7 @@ TEST_FF("input not found", RequestReceptor(), RequestGenerator("no_such_input.tx EXPECT_TRUE(f2.tainted()); } -TEST_FF("abort request generation", RequestReceptor(), RequestGenerator("input.txt", f1)) { +TEST_FF("abort request generation", RequestReceptor(), RequestGenerator(vespalib::TestApp::GetSourceDirectory() + "input.txt", f1)) { f2.abort(); f2.run(); EXPECT_TRUE(f1.request.get() == 0); diff --git a/vdslib/src/tests/container/documentlisttest.cpp b/vdslib/src/tests/container/documentlisttest.cpp index 60d01a63c1b..5804c2c1646 100644 --- a/vdslib/src/tests/container/documentlisttest.cpp +++ b/vdslib/src/tests/container/documentlisttest.cpp @@ -12,6 +12,7 @@ #include <vespa/document/update/documentupdate.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/random.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/vstringfmt.h> #include <iostream> @@ -307,10 +308,10 @@ void WritableDocumentListTest::testSizeOf() void WritableDocumentListTest::testReadJavaFile() { DocumentTypeRepo::SP repo(new DocumentTypeRepo(readDocumenttypesConfig( - "../test/files/documenttypes.cfg"))); + vespalib::TestApp::GetSourceDirectory() + "../test/files/documenttypes.cfg"))); //read file - int file = open("../test/files/documentlist-java.dat", O_RDONLY); + int file = open((vespalib::TestApp::GetSourceDirectory() + "../test/files/documentlist-java.dat").c_str(), O_RDONLY); if (file == -1) { CPPUNIT_ASSERT(0); } @@ -407,10 +408,10 @@ void WritableDocumentListTest::testGetSerializedSize() { void WritableDocumentListTest::testCopyEntry() { DocumentTypeRepo::SP repo(new DocumentTypeRepo(readDocumenttypesConfig( - "../test/files/documenttypes.cfg"))); + vespalib::TestApp::GetSourceDirectory() + "../test/files/documenttypes.cfg"))); //read file - int file = open("../test/files/documentlist-java.dat", O_RDONLY); + int file = open((vespalib::TestApp::GetSourceDirectory() + "../test/files/documentlist-java.dat").c_str(), O_RDONLY); if (file == -1) { CPPUNIT_ASSERT(0); } diff --git a/vdslib/src/tests/distribution/distributiontest.cpp b/vdslib/src/tests/distribution/distributiontest.cpp index 698b5f8da09..664c50a3fc9 100644 --- a/vdslib/src/tests/distribution/distributiontest.cpp +++ b/vdslib/src/tests/distribution/distributiontest.cpp @@ -12,6 +12,7 @@ #include <stdlib.h> #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/io/fileutil.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/text/stringtokenizer.h> #include <vespa/vespalib/util/regexp.h> #include <vespa/vespalib/stllike/lexical_cast.h> @@ -117,16 +118,17 @@ DistributionTest::testVerifyJavaDistributions() ClusterState state; { std::ifstream in( - ("distribution/testdata/java_" + test + ".state").c_str()); + (vespalib::TestApp::GetSourceDirectory() + + "distribution/testdata/java_" + test + ".state").c_str()); std::string mystate; in >> mystate; in.close(); state = ClusterState(mystate); } Distribution distr(readConfig<vespa::config::content::StorDistributionConfig>( - "file:distribution/testdata/java_" + test + ".cfg")); - std::ofstream of( - ("distribution/testdata/cpp_" + test + ".distribution").c_str()); + "file:" + vespalib::TestApp::GetSourceDirectory() + "distribution/testdata/java_" + test + ".cfg")); + std::ofstream of((vespalib::TestApp::GetSourceDirectory() + + "distribution/testdata/cpp_" + test + ".distribution").c_str()); long maxBucket = 1; long mask = 0; @@ -157,8 +159,8 @@ DistributionTest::testVerifyJavaDistributions() } of.close(); std::ostringstream cmd; - cmd << "diff -u distribution/testdata/cpp_" << test << ".distribution " - << "distribution/testdata/java_" << test << ".distribution"; + cmd << "diff -u " << vespalib::TestApp::GetSourceDirectory() << "distribution/testdata/cpp_" << test << ".distribution " + << vespalib::TestApp::GetSourceDirectory() << "distribution/testdata/java_" << test << ".distribution"; int result = system(cmd.str().c_str()); CPPUNIT_ASSERT_EQUAL_MSG("Failed distribution sync test: " + test, 0, result); @@ -233,7 +235,7 @@ void DistributionTest::testVerifyJavaDistributions2() { vespalib::DirectoryList files( - vespalib::listDirectory("distribution/testdata")); + vespalib::listDirectory(vespalib::TestApp::GetSourceDirectory() + "distribution/testdata")); for (uint32_t i=0, n=files.size(); i<n; ++i) { size_t pos = files[i].find(".java.results"); if (pos == vespalib::string::npos || pos + 13 != files[i].size()) { @@ -245,14 +247,14 @@ DistributionTest::testVerifyJavaDistributions2() using namespace vespalib::slime; vespalib::Slime slime; - auto buf = readFile("distribution/testdata/" + files[i]); + auto buf = readFile(vespalib::TestApp::GetSourceDirectory() + "distribution/testdata/" + files[i]); auto size = JsonFormat::decode({&buf[0], buf.size()}, slime); if (size == 0) { std::cerr << "\n\nSize of " << files[i] << " is 0. Maybe is not generated yet? Taking a 5 second nap!"; std::this_thread::sleep_for(std::chrono::seconds(5)); - buf = readFile("distribution/testdata/" + files[i]); + buf = readFile(vespalib::TestApp::GetSourceDirectory() + "distribution/testdata/" + files[i]); size = JsonFormat::decode({&buf[0], buf.size()}, slime); if (size == 0) { @@ -298,7 +300,7 @@ DistributionTest::testUnchangedDistribution() ClusterState state("distributor:10 storage:10"); Distribution distr(Distribution::getDefaultDistributionConfig(3, 10)); - std::ifstream in("distribution/testdata/41-distributordistribution"); + std::ifstream in(vespalib::TestApp::GetSourceDirectory() + "distribution/testdata/41-distributordistribution"); for (unsigned i = 0; i < 65536; i++) { uint16_t node = distr.getIdealDistributorNode( diff --git a/vespalib/src/tests/guard/guard_test.cpp b/vespalib/src/tests/guard/guard_test.cpp index a663edc4eec..83de03e3f20 100644 --- a/vespalib/src/tests/guard/guard_test.cpp +++ b/vespalib/src/tests/guard/guard_test.cpp @@ -132,7 +132,7 @@ Test::testDirPointer() EXPECT_TRUE(!dir.valid()); } { - DirPointer dir(opendir(".")); + DirPointer dir(opendir(vespalib::TestApp::GetSourceDirectory().c_str())); EXPECT_TRUE(dir.valid()); dirent *de; diff --git a/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp b/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp index 3c2b9455fe8..5718592203a 100644 --- a/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp +++ b/vespalib/src/tests/make_fixture_macros/make_fixture_macros_test.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/slaveproc.h> using namespace vespalib; @@ -15,7 +16,11 @@ bool runPrint(const char *cmd) { TEST("make fixture macros") { EXPECT_FALSE(runPrint("../../apps/make_fixture_macros/vespalib_make_fixture_macros_app")); EXPECT_TRUE(runPrint("../../apps/make_fixture_macros/vespalib_make_fixture_macros_app 9 > macros.tmp")); - EXPECT_TRUE(runPrint("diff -u ../../vespa/vespalib/testkit/generated_fixture_macros.h macros.tmp")); + + std::string diffCmd("diff -u "); + diffCmd += vespalib::TestApp::GetSourceDirectory(); + diffCmd += "../../vespa/vespalib/testkit/generated_fixture_macros.h macros.tmp"; + EXPECT_TRUE(runPrint(diffCmd.c_str())); } TEST_MAIN_WITH_PROCESS_PROXY() { TEST_RUN_ALL(); } diff --git a/vespalib/src/tests/slime/slime_json_format_test.cpp b/vespalib/src/tests/slime/slime_json_format_test.cpp index e04bc8aa325..7995584f60b 100644 --- a/vespalib/src/tests/slime/slime_json_format_test.cpp +++ b/vespalib/src/tests/slime/slime_json_format_test.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/data/slime/slime.h> #include <iostream> #include <fstream> @@ -351,7 +352,7 @@ TEST("decode simplified form") { } TEST_F("decode bytes not null-terminated", Slime) { - std::ifstream file("large_json.txt"); + std::ifstream file(vespalib::TestApp::GetSourceDirectory() + "large_json.txt"); ASSERT_TRUE(file.is_open()); std::stringstream buf; buf << file.rdbuf(); diff --git a/vespalib/src/tests/stllike/asciistream_test.cpp b/vespalib/src/tests/stllike/asciistream_test.cpp index bca3d431405..1dcfda2b53f 100644 --- a/vespalib/src/tests/stllike/asciistream_test.cpp +++ b/vespalib/src/tests/stllike/asciistream_test.cpp @@ -342,7 +342,7 @@ AsciistreamTest::testCreateFromFile() asciistream is(asciistream::createFromFile("non-existing.txt")); EXPECT_TRUE(is.eof()); - is = asciistream::createFromFile("test.txt"); + is = asciistream::createFromFile(vespalib::TestApp::GetSourceDirectory() + "test.txt"); EXPECT_FALSE(is.eof()); EXPECT_EQUAL(12u, is.size()); string s; diff --git a/vespalib/src/tests/testapp-debug/testapp-debug.cpp b/vespalib/src/tests/testapp-debug/testapp-debug.cpp index 7b332220f1d..cbe032f19f8 100644 --- a/vespalib/src/tests/testapp-debug/testapp-debug.cpp +++ b/vespalib/src/tests/testapp-debug/testapp-debug.cpp @@ -1,11 +1,16 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> using namespace vespalib; TEST_MAIN() { system("./vespalib_debug_test_app"); system("diff lhs.out rhs.out > diff.out"); - EXPECT_EQUAL(system("diff diff.out diff.ref"), 0); + + + std::string diff_cmd("diff diff.out "); + diff_cmd += vespalib::TestApp::GetSourceDirectory() + "diff.ref"; + EXPECT_EQUAL(system(diff_cmd.c_str()), 0); } diff --git a/vespalib/src/tests/testapp-state/testapp-state.cpp b/vespalib/src/tests/testapp-state/testapp-state.cpp index 016ad90dd50..df126f8dcfc 100644 --- a/vespalib/src/tests/testapp-state/testapp-state.cpp +++ b/vespalib/src/tests/testapp-state/testapp-state.cpp @@ -1,11 +1,15 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> using namespace vespalib; TEST_MAIN() { system("./vespalib_state_test_app > out.txt 2>&1 out.txt"); system("cat out.txt | grep STATE | sed 's/([^)].*\\//(/' > actual.txt"); - EXPECT_EQUAL(system("diff -u expect.txt actual.txt"), 0); + + std::string diff_cmd("diff -u actual.txt "); + diff_cmd += vespalib::TestApp::GetSourceDirectory() + "expect.txt"; + EXPECT_EQUAL(system(diff_cmd.c_str()), 0); } diff --git a/vespalib/src/tests/testkit-subset/CMakeLists.txt b/vespalib/src/tests/testkit-subset/CMakeLists.txt index cde1a0c5cc1..d6d278a6628 100644 --- a/vespalib/src/tests/testkit-subset/CMakeLists.txt +++ b/vespalib/src/tests/testkit-subset/CMakeLists.txt @@ -6,4 +6,4 @@ vespa_add_executable(vespalib_testkit-subset_test_app TEST DEPENDS vespalib ) -vespa_add_test(NAME vespalib_testkit-subset_test_app COMMAND sh testkit-subset_test.sh) +vespa_add_test(NAME vespalib_testkit-subset_test_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/testkit-subset_test.sh) diff --git a/vespalib/src/tests/testkit-subset/testkit-subset_test.sh b/vespalib/src/tests/testkit-subset/testkit-subset_test.sh index 44c4f5251b4..12f5a9e63fc 100755 --- a/vespalib/src/tests/testkit-subset/testkit-subset_test.sh +++ b/vespalib/src/tests/testkit-subset/testkit-subset_test.sh @@ -1,9 +1,12 @@ #!/bin/bash - set -e +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + TEST_SUBSET=pass $VALGRIND ./vespalib_testkit-subset_test_app 2> out.txt TEST_SUBSET="extra\.cpp:.*pass.*" $VALGRIND ./vespalib_testkit-subset_test_app 2>> out.txt cat out.txt | grep "\.cpp: " > out.relpath.txt -cmp -s out.relpath.txt out.ref.2.txt && exit 0 -diff -u out.relpath.txt out.ref.txt +cmp -s out.relpath.txt $SOURCE_DIRECTORY/out.ref.2.txt && exit 0 +diff -u out.relpath.txt $SOURCE_DIRECTORY/out.ref.txt diff --git a/vespalib/src/tests/text/lowercase/lowercase_test.cpp b/vespalib/src/tests/text/lowercase/lowercase_test.cpp index b226690790d..39ae5c0aea0 100644 --- a/vespalib/src/tests/text/lowercase/lowercase_test.cpp +++ b/vespalib/src/tests/text/lowercase/lowercase_test.cpp @@ -20,7 +20,7 @@ Test::Main() EXPECT_EQUAL((int8_t)'a', LowerCase::convert((int8_t)'A')); EXPECT_EQUAL((uint8_t)'a', LowerCase::convert((uint8_t)'A')); - std::ifstream yellData("yell-want.dat"); + std::ifstream yellData(vespalib::TestApp::GetSourceDirectory() + "yell-want.dat"); EXPECT_TRUE(yellData.good()); diff --git a/vespalib/src/tests/text/utf8/utf8_test.cpp b/vespalib/src/tests/text/utf8/utf8_test.cpp index 99a926f8088..e88fe756e40 100644 --- a/vespalib/src/tests/text/utf8/utf8_test.cpp +++ b/vespalib/src/tests/text/utf8/utf8_test.cpp @@ -54,7 +54,7 @@ Test::Main() { // read data produced from Java program - int fd = ::open("regular-utf8.dat", O_RDONLY); + int fd = ::open((vespalib::TestApp::GetSourceDirectory() + "regular-utf8.dat").c_str(), O_RDONLY); ASSERT_TRUE(fd > 0); vespalib::string data; data.clear(); diff --git a/vespalib/src/tests/tutorial/CMakeLists.txt b/vespalib/src/tests/tutorial/CMakeLists.txt index 120c848b2ae..9ca6951525c 100644 --- a/vespalib/src/tests/tutorial/CMakeLists.txt +++ b/vespalib/src/tests/tutorial/CMakeLists.txt @@ -5,7 +5,7 @@ vespa_add_executable(vespalib_make_tutorial_app TEST DEPENDS vespalib ) -vespa_add_test(NAME vespalib_make_tutorial_app COMMAND sh ./compare-tutorials.sh) +vespa_add_test(NAME vespalib_make_tutorial_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compare-tutorials.sh) vespa_add_executable(vespalib_xml_escape_app SOURCES xml_escape.cpp diff --git a/vespalib/src/tests/tutorial/compare-tutorials.sh b/vespalib/src/tests/tutorial/compare-tutorials.sh index 4e328bb9742..01f22295395 100755 --- a/vespalib/src/tests/tutorial/compare-tutorials.sh +++ b/vespalib/src/tests/tutorial/compare-tutorials.sh @@ -1,6 +1,10 @@ #!/bin/bash set -e +if [ -z "$SOURCE_DIRECTORY" ]; then + SOURCE_DIRECTORY="." +fi + ./vespalib_make_tutorial_app > tutorial_out.html -diff -u tutorial.html tutorial_out.html || true +diff -u $SOURCE_DIRECTORY/tutorial.html tutorial_out.html || true echo "IGNORED: vespalib_make_tutorial_app" diff --git a/vespalib/src/tests/tutorial/make_tutorial.cpp b/vespalib/src/tests/tutorial/make_tutorial.cpp index 3f83caef67c..a18c33afeeb 100644 --- a/vespalib/src/tests/tutorial/make_tutorial.cpp +++ b/vespalib/src/tests/tutorial/make_tutorial.cpp @@ -1,5 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/slaveproc.h> #include <vespa/vespalib/util/stringfmt.h> #include <sys/mman.h> @@ -29,20 +30,20 @@ std::string runCommand(const std::string &cmd) { return out; } -void insertExample(const std::string &name) { - std::string str = runCommand(make_string("./make_example.sh %s", +void insertExample(const std::string &name, const std::string &src_dir) { + std::string str = runCommand(make_string("%s/make_example.sh %s", src_dir.c_str(), name.c_str())); fprintf(stdout, "%s", str.c_str()); } -void insertSource(const std::string &name) { - std::string str = runCommand(make_string("./make_source.sh %s", +void insertSource(const std::string &name, const std::string &src_dir) { + std::string str = runCommand(make_string("%s/make_source.sh %s", src_dir.c_str(), name.c_str())); fprintf(stdout, "%s", str.c_str()); } -void insertFile(const std::string &name) { - std::string str = readFile(name); +void insertFile(const std::string &name, const std::string &src_dir) { + std::string str = readFile(src_dir + "/" + name); fprintf(stdout, "%s", str.c_str()); } @@ -56,7 +57,7 @@ TEST_MAIN_WITH_PROCESS_PROXY() { size_t pos = 0; size_t end = 0; size_t cursor = 0; - std::string input = readFile("tutorial_source.html"); + std::string input = readFile(vespalib::TestApp::GetSourceDirectory() + "tutorial_source.html"); while ((pos = input.find(pre, cursor)) < input.size() && (end = input.find(post, pos)) < input.size()) { @@ -64,13 +65,16 @@ TEST_MAIN_WITH_PROCESS_PROXY() { pos += pre.size(); if (input.find(example, pos) == pos) { pos += example.size(); - insertExample(std::string((input.data() + pos), (end - pos))); + insertExample(std::string((input.data() + pos), (end - pos)), + vespalib::TestApp::GetSourceDirectory()); } else if (input.find(source, pos) == pos) { pos += source.size(); - insertSource(std::string((input.data() + pos), (end - pos))); + insertSource(std::string((input.data() + pos), (end - pos)), + vespalib::TestApp::GetSourceDirectory()); } else if (input.find(file, pos) == pos) { pos += file.size(); - insertFile(std::string((input.data() + pos), (end - pos))); + insertFile(std::string((input.data() + pos), (end - pos)), + vespalib::TestApp::GetSourceDirectory()); } else { std::string str((input.data() + pos), (end - pos)); TEST_FATAL(make_string("invalid directive >%s<", str.c_str()).c_str()); diff --git a/vespalib/src/vespa/vespalib/testkit/testapp.cpp b/vespalib/src/vespa/vespalib/testkit/testapp.cpp index a4bb01e525c..ee5a76a0500 100644 --- a/vespalib/src/vespa/vespalib/testkit/testapp.cpp +++ b/vespalib/src/vespa/vespalib/testkit/testapp.cpp @@ -17,6 +17,23 @@ TestApp::~TestApp() { } +const std::string& +TestApp::GetSourceDirectory() +{ + static const std::string srcDir = [] () { + std::string dir("."); + const char* env = getenv("SOURCE_DIRECTORY"); + if (env) { + dir = env; + } + if (*dir.rbegin() != '/') { + dir += "/"; + } + return dir; + } (); + return srcDir; +} + void TestApp::ReportInit(const char *name) { diff --git a/vespalib/src/vespa/vespalib/testkit/testapp.h b/vespalib/src/vespa/vespalib/testkit/testapp.h index 644c85e4be7..25e4c060822 100644 --- a/vespalib/src/vespa/vespalib/testkit/testapp.h +++ b/vespalib/src/vespa/vespalib/testkit/testapp.h @@ -179,6 +179,13 @@ public: const char *GetName() { return _name.c_str(); } /** + * @brief Obtain the source directory for the current test + * + * @return Path to source directory with trailing / + */ + static const std::string& GetSourceDirectory(); + + /** * @brief Report test initialization * * @param name the name of this test diff --git a/vespalog/src/test/CMakeLists.txt b/vespalog/src/test/CMakeLists.txt index b50d9d60cb1..e07dc1769d1 100644 --- a/vespalog/src/test/CMakeLists.txt +++ b/vespalog/src/test/CMakeLists.txt @@ -7,14 +7,14 @@ vespa_add_executable(vespalog_bufferedlogtest_app TEST DEPENDS vespalog ) -vespa_add_test(NAME vespalog_bufferedlogtest_app NO_VALGRIND COMMAND sh bufferedlogtest_test.sh) +vespa_add_test(NAME vespalog_bufferedlogtest_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bufferedlogtest_test.sh) vespa_add_executable(vespalog_bufferedlogskiptest_app TEST SOURCES bufferedlogskiptest.cpp DEPENDS vespalog ) -vespa_add_test(NAME vespalog_bufferedlogskiptest_app NO_VALGRIND COMMAND sh bufferedlogskiptest_test.sh) +vespa_add_test(NAME vespalog_bufferedlogskiptest_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bufferedlogskiptest_test.sh) vespa_add_executable(vespalog_rejectfiltertest_app TEST SOURCES rejectfiltertest.cpp @@ -22,3 +22,4 @@ vespa_add_executable(vespalog_rejectfiltertest_app TEST vespalog ) vespa_add_test(NAME vespalog_rejectfiltertest_app NO_VALGRIND COMMAND vespalog_rejectfiltertest_app) +file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/" DESTINATION ${CMAKE_CURRENT_BINARY_DIR} FILES_MATCHING PATTERN "*.log") diff --git a/vespamalloc/src/tests/doubledelete/CMakeLists.txt b/vespamalloc/src/tests/doubledelete/CMakeLists.txt index c687b7ab098..6d78198af24 100644 --- a/vespamalloc/src/tests/doubledelete/CMakeLists.txt +++ b/vespamalloc/src/tests/doubledelete/CMakeLists.txt @@ -4,7 +4,7 @@ vespa_add_executable(vespamalloc_doubledelete_test_app TEST doubledelete.cpp DEPENDS ) -vespa_add_test(NAME vespamalloc_doubledelete_test_app NO_VALGRIND COMMAND sh doubledelete_test.sh) +vespa_add_test(NAME vespamalloc_doubledelete_test_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/doubledelete_test.sh) vespa_add_executable(vespamalloc_expectsignal_app SOURCES expectsignal.cpp diff --git a/vespamalloc/src/tests/overwrite/CMakeLists.txt b/vespamalloc/src/tests/overwrite/CMakeLists.txt index 7777c930669..fe82fe0a01b 100644 --- a/vespamalloc/src/tests/overwrite/CMakeLists.txt +++ b/vespamalloc/src/tests/overwrite/CMakeLists.txt @@ -4,7 +4,8 @@ vespa_add_executable(vespamalloc_overwrite_test_app TEST overwrite.cpp DEPENDS ) -vespa_add_test(NAME vespamalloc_overwrite_test_app NO_VALGRIND COMMAND sh overwrite_test.sh) +vespa_add_test(NAME vespamalloc_overwrite_test_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/overwrite_test.sh) +file(COPY vespamalloc.conf DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) vespa_add_executable(vespamalloc_expectsignal-overwrite_app SOURCES expectsignal.cpp diff --git a/vespamalloc/src/tests/thread/CMakeLists.txt b/vespamalloc/src/tests/thread/CMakeLists.txt index e9bf1489347..61a60dfec04 100644 --- a/vespamalloc/src/tests/thread/CMakeLists.txt +++ b/vespamalloc/src/tests/thread/CMakeLists.txt @@ -3,7 +3,7 @@ vespa_add_executable(vespamalloc_thread_test_app TEST SOURCES thread.cpp ) -vespa_add_test(NAME vespamalloc_thread_test_app NO_VALGRIND COMMAND sh thread_test.sh) +vespa_add_test(NAME vespamalloc_thread_test_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/thread_test.sh) vespa_add_executable(vespamalloc_racemanythreads_test_app SOURCES racemanythreads.cpp diff --git a/vespamalloc/src/tests/thread/thread_test.sh b/vespamalloc/src/tests/thread/thread_test.sh index 3af29ad052e..c3b14834626 100755 --- a/vespamalloc/src/tests/thread/thread_test.sh +++ b/vespamalloc/src/tests/thread/thread_test.sh @@ -3,8 +3,8 @@ set -e echo "Trying to find limit for processes:" if ulimit -u; then - echo "Fixing limit to 31215" - ulimit -u 31215 + echo "Fixing limit to 31100" + ulimit -u 31100 elif [ "$RETRYEXEC" ]; then echo "Already tried to re-exec script, giving up." exit 1 |