diff options
Diffstat (limited to 'vespamalloc/src/tests/allocfree/creatingmanythreads.cpp')
-rw-r--r-- | vespamalloc/src/tests/allocfree/creatingmanythreads.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vespamalloc/src/tests/allocfree/creatingmanythreads.cpp b/vespamalloc/src/tests/allocfree/creatingmanythreads.cpp new file mode 100644 index 00000000000..53de3f274cc --- /dev/null +++ b/vespamalloc/src/tests/allocfree/creatingmanythreads.cpp @@ -0,0 +1,39 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/log/log.h> +#include <vespa/fastos/fastos.h> +#include <vespa/vespalib/testkit/testapp.h> + +LOG_SETUP("creatingmanythreads_test"); + +TEST_SETUP(Test); + +void * thread_alloc(void * arg) +{ + char * v = new char [*static_cast<int *>(arg)]; + delete [] v; + return NULL; +} + +int Test::Main() { + int numThreads(10000); + int allocSize(256); + if (_argc > 1) { + numThreads = atoi(_argv[1]); + } + if (_argc > 2) { + allocSize = atoi(_argv[2]); + } + TEST_INIT("creatingmanythreads_test"); + + LOG(info, "Will create and run %d threads each allocating a single block of memory of %d size\n", numThreads, allocSize); + for (int i(0); i < numThreads; ) { + for (int j(0); (i < numThreads) && j < 10000; i++, j++) { + pthread_t thread; + ASSERT_EQUAL(0, pthread_create(&thread, NULL, thread_alloc, &allocSize)); + ASSERT_EQUAL(0, pthread_join(thread, NULL)); + } + LOG(info, "Completed %d tests", i); + } + + TEST_DONE(); +} |