aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2024-06-20 09:06:20 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2024-06-20 09:09:19 +0000
commitdf84441bbfb66161bf823f9235532083ce58b1bc (patch)
tree5d6219190f9d5935cc50ac6f9544ee2257e745bc
parentd0369ddd0bea5c559883115429302eb95a97d586 (diff)
stop using TEST_APPHOOK in vespamalloc
just use TEST_MAIN directly, since we want argc/argv
-rw-r--r--vespamalloc/src/tests/doubledelete/expectsignal.cpp25
-rw-r--r--vespamalloc/src/tests/overwrite/expectsignal.cpp26
-rw-r--r--vespamalloc/src/tests/overwrite/overwrite.cpp45
-rw-r--r--vespamalloc/src/tests/thread/racemanythreads.cpp29
-rw-r--r--vespamalloc/src/tests/thread/thread.cpp26
5 files changed, 33 insertions, 118 deletions
diff --git a/vespamalloc/src/tests/doubledelete/expectsignal.cpp b/vespamalloc/src/tests/doubledelete/expectsignal.cpp
index d26c0dae6ae..e3ed1079522 100644
--- a/vespamalloc/src/tests/doubledelete/expectsignal.cpp
+++ b/vespamalloc/src/tests/doubledelete/expectsignal.cpp
@@ -1,28 +1,19 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/process/process.h>
#include <sys/wait.h>
using namespace vespalib;
-class Test : public TestApp
-{
-public:
- int Main() override;
-};
+TEST_MAIN() {
-int Test::Main()
-{
- TEST_INIT("expectsignal_test");
+ ASSERT_EQUAL(argc, 3);
- EXPECT_EQUAL(_argc, 3);
- ASSERT_TRUE(_argc == 3);
+ int retval = strtol(argv[1], NULL, 0);
- int retval = strtol(_argv[1], NULL, 0);
+ fprintf(stderr, "argc=%d : Running '%s' expecting signal %d\n", argc, argv[2], retval);
- fprintf(stderr, "argc=%d : Running '%s' expecting signal %d\n", _argc, _argv[2], retval);
-
- Process cmd(_argv[2]);
+ Process cmd(argv[2]);
for (vespalib::string line = cmd.read_line(); !(line.empty() && cmd.eof()); line = cmd.read_line()) {
fprintf(stdout, "%s\n", line.c_str());
}
@@ -42,8 +33,4 @@ int Test::Main()
}
EXPECT_EQUAL(exitCode & 0x7f, retval);
-
- TEST_DONE();
}
-
-TEST_APPHOOK(Test)
diff --git a/vespamalloc/src/tests/overwrite/expectsignal.cpp b/vespamalloc/src/tests/overwrite/expectsignal.cpp
index d26c0dae6ae..2c725ac0784 100644
--- a/vespamalloc/src/tests/overwrite/expectsignal.cpp
+++ b/vespamalloc/src/tests/overwrite/expectsignal.cpp
@@ -1,28 +1,18 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/process/process.h>
#include <sys/wait.h>
using namespace vespalib;
-class Test : public TestApp
-{
-public:
- int Main() override;
-};
+TEST_MAIN() {
+ ASSERT_EQUAL(argc, 3);
-int Test::Main()
-{
- TEST_INIT("expectsignal_test");
+ int retval = strtol(argv[1], NULL, 0);
- EXPECT_EQUAL(_argc, 3);
- ASSERT_TRUE(_argc == 3);
+ fprintf(stderr, "argc=%d : Running '%s' expecting signal %d\n", argc, argv[2], retval);
- int retval = strtol(_argv[1], NULL, 0);
-
- fprintf(stderr, "argc=%d : Running '%s' expecting signal %d\n", _argc, _argv[2], retval);
-
- Process cmd(_argv[2]);
+ Process cmd(argv[2]);
for (vespalib::string line = cmd.read_line(); !(line.empty() && cmd.eof()); line = cmd.read_line()) {
fprintf(stdout, "%s\n", line.c_str());
}
@@ -42,8 +32,4 @@ int Test::Main()
}
EXPECT_EQUAL(exitCode & 0x7f, retval);
-
- TEST_DONE();
}
-
-TEST_APPHOOK(Test)
diff --git a/vespamalloc/src/tests/overwrite/overwrite.cpp b/vespamalloc/src/tests/overwrite/overwrite.cpp
index c09824c2dad..a7d60fa0de8 100644
--- a/vespamalloc/src/tests/overwrite/overwrite.cpp
+++ b/vespamalloc/src/tests/overwrite/overwrite.cpp
@@ -1,5 +1,5 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
using namespace vespalib;
@@ -31,21 +31,7 @@ void delete_vec_real(char *ptr)
void (*delete_vec)(char *ptr) = delete_vec_real;
-class Test : public TestApp
-{
-public:
- int Main() override;
- ~Test();
-private:
- void testFillValue(char *a);
- void verifyPreWriteDetection(); // Should abort
- void verifyPostWriteDetection(); // Should abort
- void verifyWriteAfterFreeDetection(); // Should abort
-};
-
-Test::~Test() = default;
-
-void Test::testFillValue(char *a)
+void testFillValue(char *a)
{
// Verify fillvalue
EXPECT_EQUAL((int)a[0], 0x66);
@@ -79,21 +65,21 @@ void Test::testFillValue(char *a)
}
}
-void Test::verifyPreWriteDetection()
+void verifyPreWriteDetection()
{
char * a = new_vec(8);
overwrite_memory(a, -1);
delete_vec(a);
}
-void Test::verifyPostWriteDetection()
+void verifyPostWriteDetection()
{
char * a = new_vec(8);
overwrite_memory(a, 8);
delete_vec(a);
}
-void Test::verifyWriteAfterFreeDetection()
+void verifyWriteAfterFreeDetection()
{
// Make sure that enough blocks of memory is allocated and freed.
char * a = new_vec(256);
@@ -120,10 +106,7 @@ void Test::verifyWriteAfterFreeDetection()
}
}
-int Test::Main()
-{
- TEST_INIT("overwrite_test");
-
+TEST_MAIN() {
char * a = new_vec(256);
memset(a, 0x77, 256);
a[0] = 0;
@@ -136,17 +119,14 @@ int Test::Main()
delete_vec(a);
EXPECT_EQUAL(a, b);
- if (_argc > 1) {
+ if (argc > 1) {
testFillValue(a);
- if (strcmp(_argv[1], "prewrite") == 0) {
+ if (strcmp(argv[1], "prewrite") == 0) {
verifyPreWriteDetection();
- return 0;
- } else if (strcmp(_argv[1], "postwrite") == 0) {
+ } else if (strcmp(argv[1], "postwrite") == 0) {
verifyPostWriteDetection();
- return 0;
- } else if (strcmp(_argv[1], "writeafterfree") == 0) {
+ } else if (strcmp(argv[1], "writeafterfree") == 0) {
verifyWriteAfterFreeDetection();
- return 0;
}
} else {
@@ -155,9 +135,4 @@ int Test::Main()
EXPECT_EQUAL((int)a[1], 0x77);
EXPECT_EQUAL((int)a[255], 0x77);
}
-
- TEST_DONE();
- return 42;
}
-
-TEST_APPHOOK(Test)
diff --git a/vespamalloc/src/tests/thread/racemanythreads.cpp b/vespamalloc/src/tests/thread/racemanythreads.cpp
index bcceb96a24e..3f153825844 100644
--- a/vespamalloc/src/tests/thread/racemanythreads.cpp
+++ b/vespamalloc/src/tests/thread/racemanythreads.cpp
@@ -1,21 +1,10 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
#include <unistd.h>
using namespace vespalib;
-class Test : public TestApp
-{
-public:
- ~Test();
- int Main() override;
-};
-
-Test::~Test()
-{
-}
-
void * hammer(void * arg)
{
usleep(4000000);
@@ -42,15 +31,13 @@ void * hammer(void * arg)
return arg;
}
-int Test::Main()
-{
- TEST_INIT("racemanythreads_test");
+TEST_MAIN() {
size_t threadCount(1024);
long seconds(10);
- if (_argc >= 2) {
- threadCount = strtoul(_argv[1], NULL, 0);
- if (_argc >= 3) {
- seconds = strtoul(_argv[2], NULL, 0);
+ if (argc >= 2) {
+ threadCount = strtoul(argv[1], NULL, 0);
+ if (argc >= 3) {
+ seconds = strtoul(argv[2], NULL, 0);
}
}
@@ -65,8 +52,4 @@ int Test::Main()
void *retval;
EXPECT_EQUAL(pthread_join(threads[i], &retval), 0);
}
-
- TEST_DONE();
}
-
-TEST_APPHOOK(Test);
diff --git a/vespamalloc/src/tests/thread/thread.cpp b/vespamalloc/src/tests/thread/thread.cpp
index b0d89f852d0..0498f828cc4 100644
--- a/vespamalloc/src/tests/thread/thread.cpp
+++ b/vespamalloc/src/tests/thread/thread.cpp
@@ -1,22 +1,11 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
#include <atomic>
#include <unistd.h>
using namespace vespalib;
-class Test : public TestApp
-{
-public:
- ~Test();
- int Main() override;
-};
-
-Test::~Test()
-{
-}
-
void * just_return(void * arg)
{
return arg;
@@ -61,15 +50,13 @@ void * just_wait(void * arg)
return arg;
}
-int Test::Main()
-{
- TEST_INIT("thread_test");
+TEST_MAIN() {
size_t threadCount(102400);
- if (_argc >= 3) {
- threadCount = strtoul(_argv[2], NULL, 0);
+ if (argc >= 3) {
+ threadCount = strtoul(argv[2], NULL, 0);
}
- const char * testType = _argv[1];
+ const char * testType = argv[1];
for (size_t i(0); i < threadCount; i++) {
pthread_t th;
@@ -114,7 +101,4 @@ int Test::Main()
}
EXPECT_EQUAL(pthread_attr_destroy(&attr), 0);
EXPECT_EQUAL(info._count, 0ul);
- TEST_DONE();
}
-
-TEST_APPHOOK(Test);