aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2022-03-31 11:44:10 +0000
committerHåvard Pettersen <havardpe@oath.com>2022-04-01 10:24:32 +0000
commitd71f76a73fe54558f613e75a3a8cfd70fc46a7e8 (patch)
tree7d170e5b792dbf5fed06ff7c7b2db398b6cb64c7 /searchlib/src/tests
parent1bb3dd192f4bcb91e710fe19ca54b2b8935ffb83 (diff)
use getopt/getopt_long directly
Diffstat (limited to 'searchlib/src/tests')
-rw-r--r--searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp43
-rw-r--r--searchlib/src/tests/bitvector/bitvectorbenchmark.cpp11
-rw-r--r--searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp12
-rw-r--r--searchlib/src/tests/features/featurebenchmark.cpp11
-rw-r--r--searchlib/src/tests/postinglistbm/postinglistbm.cpp38
-rw-r--r--searchlib/src/tests/transactionlogstress/translogstress.cpp29
6 files changed, 68 insertions, 76 deletions
diff --git a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp
index 7d168407328..4a690a28cc8 100644
--- a/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp
+++ b/searchlib/src/tests/attribute/benchmark/attributebenchmark.cpp
@@ -11,6 +11,7 @@
#include "attributesearcher.h"
#include "attributeupdater.h"
#include <sys/resource.h>
+#include <unistd.h>
#include <vespa/log/log.h>
LOG_SETUP("attributebenchmark");
@@ -485,62 +486,60 @@ AttributeBenchmark::Main()
dc._prefixLength = 2;
dc._prefixSearch = false;
- int idx = 1;
int opt;
- const char * arg;
bool optError = false;
- while ((opt = GetOpt("n:u:v:s:q:p:r:c:l:h:i:a:e:S:E:D:L:bRPtw", arg, idx)) != -1) {
+ while ((opt = getopt(_argc, _argv, "n:u:v:s:q:p:r:c:l:h:i:a:e:S:E:D:L:bRPtw")) != -1) {
switch (opt) {
case 'n':
- dc._numDocs = atoi(arg);
+ dc._numDocs = atoi(optarg);
break;
case 'u':
- dc._numUpdates = atoi(arg);
+ dc._numUpdates = atoi(optarg);
break;
case 'v':
- dc._numValues = atoi(arg);
+ dc._numValues = atoi(optarg);
break;
case 's':
- dc._numSearchers = atoi(arg);
+ dc._numSearchers = atoi(optarg);
break;
case 'q':
- dc._numQueries = atoi(arg);
+ dc._numQueries = atoi(optarg);
break;
case 'p':
- dc._populateRuns = atoi(arg);
+ dc._populateRuns = atoi(optarg);
break;
case 'r':
- dc._updateRuns = atoi(arg);
+ dc._updateRuns = atoi(optarg);
break;
case 'c':
- dc._commitFreq = atoi(arg);
+ dc._commitFreq = atoi(optarg);
break;
case 'l':
- dc._minValueCount = atoi(arg);
+ dc._minValueCount = atoi(optarg);
break;
case 'h':
- dc._maxValueCount = atoi(arg);
+ dc._maxValueCount = atoi(optarg);
break;
case 'i':
- dc._minStringLen = atoi(arg);
+ dc._minStringLen = atoi(optarg);
break;
case 'a':
- dc._maxStringLen = atoi(arg);
+ dc._maxStringLen = atoi(optarg);
break;
case 'e':
- dc._seed = atoi(arg);
+ dc._seed = atoi(optarg);
break;
case 'S':
- dc._rangeStart = strtoll(arg, NULL, 10);
+ dc._rangeStart = strtoll(optarg, NULL, 10);
break;
case 'E':
- dc._rangeEnd = strtoll(arg, NULL, 10);
+ dc._rangeEnd = strtoll(optarg, NULL, 10);
break;
case 'D':
- dc._rangeDelta = strtoll(arg, NULL, 10);
+ dc._rangeDelta = strtoll(optarg, NULL, 10);
break;
case 'L':
- dc._prefixLength = atoi(arg);
+ dc._prefixLength = atoi(optarg);
break;
case 'b':
dc._searchersOnly = false;
@@ -563,12 +562,12 @@ AttributeBenchmark::Main()
}
}
- if (_argc != (idx + 1) || optError) {
+ if (_argc != (optind + 1) || optError) {
usage();
return -1;
}
- dc._attribute = vespalib::string(_argv[idx]);
+ dc._attribute = vespalib::string(_argv[optind]);
_threadPool = new FastOS_ThreadPool(256000);
diff --git a/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp b/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp
index 52888d0c659..e140814a5ad 100644
--- a/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp
+++ b/searchlib/src/tests/bitvector/bitvectorbenchmark.cpp
@@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include <cassert>
+#include <unistd.h>
LOG_SETUP("bitvectorbenchmark");
@@ -165,19 +166,17 @@ void BitVectorBenchmark::testOrSpeed2()
int BitVectorBenchmark::Main()
{
- int idx = 1;
std::string operation;
size_t numBits(8*1000000);
int opt;
- const char * arg;
bool optError = false;
- while ((opt = GetOpt("n:t:", arg, idx)) != -1) {
+ while ((opt = getopt(_argc, _argv, "n:t:")) != -1) {
switch (opt) {
case 'n':
- numBits = strtoll(arg, NULL, 10);
+ numBits = strtoll(optarg, NULL, 10);
break;
case 't':
- operation = arg;
+ operation = optarg;
break;
default:
optError = true;
@@ -185,7 +184,7 @@ int BitVectorBenchmark::Main()
}
}
- if ((_argc != idx ) || optError) {
+ if ((_argc != optind ) || optError) {
usage();
return -1;
}
diff --git a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp
index 35b42223cfc..aa5f9a13e7d 100644
--- a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp
+++ b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp
@@ -21,6 +21,7 @@
#include <openssl/evp.h>
#include <vespa/fastos/file.h>
#include <vespa/fastos/app.h>
+#include <unistd.h>
#include <vespa/log/log.h>
LOG_SETUP("fieldwriter_test");
@@ -665,30 +666,27 @@ testFieldWriterVariantsWithHighLids(FakeWordSet &wordSet, uint32_t docIdLimit,
int
FieldWriterTest::Main()
{
- int argi;
int c;
- const char *optArg;
if (_argc > 0) {
DummyFileHeaderContext::setCreator(_argv[0]);
}
- argi = 1;
- while ((c = GetOpt("c:d:vw:", optArg, argi)) != -1) {
+ while ((c = getopt(_argc, _argv, "c:d:vw:")) != -1) {
switch(c) {
case 'c':
- _commonDocFreq = atoi(optArg);
+ _commonDocFreq = atoi(optarg);
if (_commonDocFreq == 0)
_commonDocFreq = 1;
break;
case 'd':
- _numDocs = atoi(optArg);
+ _numDocs = atoi(optarg);
break;
case 'v':
_verbose = true;
break;
case 'w':
- _numWordsPerClass = atoi(optArg);
+ _numWordsPerClass = atoi(optarg);
break;
default:
Usage();
diff --git a/searchlib/src/tests/features/featurebenchmark.cpp b/searchlib/src/tests/features/featurebenchmark.cpp
index f4fc830335d..5a70f1752fc 100644
--- a/searchlib/src/tests/features/featurebenchmark.cpp
+++ b/searchlib/src/tests/features/featurebenchmark.cpp
@@ -17,6 +17,7 @@
#include <iomanip>
#include <iostream>
#include <string>
+#include <unistd.h>
using namespace search::features;
using namespace search::fef;
@@ -596,19 +597,17 @@ Benchmark::Main()
setup_fef_test_plugin(_factory);
setup_search_features(_factory);
- int idx = 1;
int opt;
- const char * arg;
bool optError = false;
vespalib::string file;
vespalib::string feature;
- while ((opt = GetOpt("c:f:", arg, idx)) != -1) {
+ while ((opt = getopt(_argc, _argv, "c:f:")) != -1) {
switch (opt) {
case 'c':
- file.assign(arg);
+ file.assign(optarg);
break;
case 'f':
- feature.assign(arg);
+ feature.assign(optarg);
break;
default:
optError = true;
@@ -616,7 +615,7 @@ Benchmark::Main()
}
}
- if (_argc != idx || optError) {
+ if (_argc != optind || optError) {
//usage();
return -1;
}
diff --git a/searchlib/src/tests/postinglistbm/postinglistbm.cpp b/searchlib/src/tests/postinglistbm/postinglistbm.cpp
index 198ff57435a..d0552958611 100644
--- a/searchlib/src/tests/postinglistbm/postinglistbm.cpp
+++ b/searchlib/src/tests/postinglistbm/postinglistbm.cpp
@@ -12,6 +12,7 @@
#include <vespa/searchlib/test/fakedata/fpfactory.h>
#include <vespa/vespalib/util/rand48.h>
#include <vespa/vespalib/util/size_literals.h>
+#include <unistd.h>
#include <vespa/log/log.h>
@@ -109,52 +110,49 @@ PostingListBM::~PostingListBM() = default;
int
PostingListBM::Main()
{
- int argi;
int c;
- const char *optArg;
- argi = 1;
bool hasElements = false;
bool hasElementWeights = false;
- while ((c = GetOpt("C:c:m:r:d:l:s:t:o:uw:T:q", optArg, argi)) != -1) {
+ while ((c = getopt(_argc, _argv, "C:c:m:r:d:l:s:t:o:uw:T:q")) != -1) {
switch(c) {
case 'C':
- _skipCommonPairsRate = atoi(optArg);
+ _skipCommonPairsRate = atoi(optarg);
break;
case 'T':
- if (strcmp(optArg, "single") == 0) {
+ if (strcmp(optarg, "single") == 0) {
hasElements = false;
hasElementWeights = false;
- } else if (strcmp(optArg, "array") == 0) {
+ } else if (strcmp(optarg, "array") == 0) {
hasElements = true;
hasElementWeights = false;
- } else if (strcmp(optArg, "weightedSet") == 0) {
+ } else if (strcmp(optarg, "weightedSet") == 0) {
hasElements = true;
hasElementWeights = true;
} else {
- printf("Bad collection type: '%s'\n", optArg);
+ printf("Bad collection type: '%s'\n", optarg);
printf("Supported types: single, array, weightedSet\n");
return 1;
}
break;
case 'c':
- _commonDocFreq = atoi(optArg);
+ _commonDocFreq = atoi(optarg);
break;
case 'm':
- _mediumDocFreq = atoi(optArg);
+ _mediumDocFreq = atoi(optarg);
break;
case 'r':
- _rareDocFreq = atoi(optArg);
+ _rareDocFreq = atoi(optarg);
break;
case 'd':
- _numDocs = atoi(optArg);
+ _numDocs = atoi(optarg);
break;
case 'l':
- _loops = atoi(optArg);
+ _loops = atoi(optarg);
break;
case 's':
- _stride = atoi(optArg);
+ _stride = atoi(optarg);
break;
case 't':
do {
@@ -163,17 +161,17 @@ PostingListBM::Main()
DataType::STRING,
CollectionType::SINGLE);
schema.addIndexField(indexField);
- std::unique_ptr<FPFactory> ff(getFPFactory(optArg, schema));
+ std::unique_ptr<FPFactory> ff(getFPFactory(optarg, schema));
if (ff.get() == nullptr) {
- badPostingType(optArg);
+ badPostingType(optarg);
return 1;
}
} while (0);
- _postingTypes.push_back(optArg);
+ _postingTypes.push_back(optarg);
break;
case 'o':
{
- vespalib::string operatorType(optArg);
+ vespalib::string operatorType(optarg);
if (operatorType == "direct") {
_operatorType = StressRunner::OperatorType::Direct;
} else if (operatorType == "and") {
@@ -191,7 +189,7 @@ PostingListBM::Main()
_unpack = true;
break;
case 'w':
- _numWordsPerClass = atoi(optArg);
+ _numWordsPerClass = atoi(optarg);
break;
default:
usage();
diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp
index de0e1b60ca0..cfd2138f2e8 100644
--- a/searchlib/src/tests/transactionlogstress/translogstress.cpp
+++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp
@@ -12,6 +12,7 @@
#include <iostream>
#include <sstream>
#include <thread>
+#include <unistd.h>
#include <vespa/log/log.h>
#include <vespa/vespalib/util/time.h>
@@ -642,44 +643,42 @@ TransLogStress::Main()
vespalib::duration sleepTime = 4s;
- int idx = 1;
int opt;
- const char * arg;
bool optError = false;
- while ((opt = GetOpt("d:p:t:f:s:v:c:e:g:i:a:b:h", arg, idx)) != -1) {
+ while ((opt = getopt(_argc, _argv, "d:p:t:f:s:v:c:e:g:i:a:b:h")) != -1) {
switch (opt) {
case 'd':
- _cfg.domainPartSize = atol(arg);
+ _cfg.domainPartSize = atol(optarg);
break;
case 'p':
- _cfg.packetSize = atol(arg);
+ _cfg.packetSize = atol(optarg);
break;
case 't':
- _cfg.stressTime = std::chrono::milliseconds(1000 * atol(arg));
+ _cfg.stressTime = std::chrono::milliseconds(1000 * atol(optarg));
break;
case 'f':
- _cfg.feedRate = atoi(arg);
+ _cfg.feedRate = atoi(optarg);
break;
case 'v':
- _cfg.numVisitors = atoi(arg);
+ _cfg.numVisitors = atoi(optarg);
break;
case 'c':
- _cfg.visitorInterval = std::chrono::milliseconds(atol(arg));
+ _cfg.visitorInterval = std::chrono::milliseconds(atol(optarg));
break;
case 'e':
- _cfg.pruneInterval = vespalib::from_s(atol(arg));
+ _cfg.pruneInterval = vespalib::from_s(atol(optarg));
break;
case 'g':
- _cfg.numPreGeneratedBuffers = atoi(arg);
+ _cfg.numPreGeneratedBuffers = atoi(optarg);
break;
case 'i':
- _cfg.minStrLen = atoi(arg);
+ _cfg.minStrLen = atoi(optarg);
break;
case 'a':
- _cfg.maxStrLen = atoi(arg);
+ _cfg.maxStrLen = atoi(optarg);
break;
case 'b':
- _cfg.baseSeed = atol(arg);
+ _cfg.baseSeed = atol(optarg);
break;
case 'h':
usage();
@@ -693,7 +692,7 @@ TransLogStress::Main()
printConfig();
std::this_thread::sleep_for(sleepTime);
- if (_argc != idx || optError) {
+ if (_argc != optind || optError) {
usage();
return -1;
}