Cache: Specify item count explcitly in tests

This commit is contained in:
Johan Wikman
2016-12-16 14:41:26 +02:00
parent 43c694020c
commit 9998f60493
4 changed files with 14 additions and 27 deletions

View File

@ -143,15 +143,13 @@ TesterStorage::TesterStorage(std::ostream* pOut, StorageFactory* pFactory)
{ {
} }
int TesterStorage::run(size_t n_threads, size_t n_seconds, std::istream& in) int TesterStorage::run(size_t n_threads, size_t n_seconds, size_t n_max_items, std::istream& in)
{ {
int rv = EXIT_FAILURE; int rv = EXIT_FAILURE;
size_t n_items = get_n_items(n_threads, n_seconds);
CacheItems cache_items; CacheItems cache_items;
if (get_cache_items(in, n_items, m_factory, &cache_items)) if (get_cache_items(in, n_max_items, m_factory, &cache_items))
{ {
rv = execute(n_threads, n_seconds, cache_items); rv = execute(n_threads, n_seconds, cache_items);
} }
@ -255,8 +253,3 @@ TesterStorage::storage_action_t TesterStorage::get_random_action()
return action; return action;
} }
size_t TesterStorage::get_n_items(size_t n_threads, size_t n_seconds)
{
return n_threads * n_seconds * 10; // From the sleeve...
}

View File

@ -75,13 +75,15 @@ public:
* *
* Will call back into the virtual @c execute function below. * Will call back into the virtual @c execute function below.
* *
* @param n_threads How many threads to use. * @param n_threads How many threads to use.
* @param n_seconds For how many seconds to run the test. * @param n_seconds For how many seconds to run the test.
* @param in Stream, assumed to refer to a file containing statements. * @param n_max_items How many items to read from the stream at most; 0 means
* no limit.
* @param in Stream, assumed to refer to a file containing statements.
* *
* @return EXIT_SUCCESS or EXIT_FAILURE. * @return EXIT_SUCCESS or EXIT_FAILURE.
*/ */
virtual int run(size_t n_threads, size_t n_seconds, std::istream& in); virtual int run(size_t n_threads, size_t n_seconds, size_t n_max_items, std::istream& in);
/** /**
* Creates cache items with the size varying between the specified minimum * Creates cache items with the size varying between the specified minimum
@ -162,16 +164,6 @@ protected:
*/ */
TesterStorage(std::ostream* pOut, StorageFactory* pFactory); TesterStorage(std::ostream* pOut, StorageFactory* pFactory);
/**
* Return the desired number of cache items to be used in the tests.
*
* @param n_threads How many threads are used.
* @param n_seconds For how many seconds the tests will be run.
*
* @return The desired number of items to use.
*/
virtual size_t get_n_items(size_t n_threads, size_t n_seconds);
protected: protected:
StorageFactory& m_factory; /*< The storage factory that is used. */ StorageFactory& m_factory; /*< The storage factory that is used. */

View File

@ -65,10 +65,11 @@ int main(int argc, char* argv[])
TesterLRUStorage tester(&cout, pFactory); TesterLRUStorage tester(&cout, pFactory);
size_t n_threads = get_processor_count() + 1; size_t n_threads = get_processor_count() + 1;
size_t n_max_items = n_threads * n_seconds * 10;
if (argc == 3) if (argc == 3)
{ {
rv = tester.run(n_threads, n_seconds, cin); rv = tester.run(n_threads, n_seconds, n_max_items, cin);
} }
else else
{ {
@ -76,7 +77,7 @@ int main(int argc, char* argv[])
if (in) if (in)
{ {
rv = tester.run(n_threads, n_seconds, in); rv = tester.run(n_threads, n_seconds, n_max_items, in);
} }
else else
{ {

View File

@ -65,10 +65,11 @@ int main(int argc, char* argv[])
TesterRawStorage tester(&cout, pFactory); TesterRawStorage tester(&cout, pFactory);
size_t n_threads = get_processor_count() + 1; size_t n_threads = get_processor_count() + 1;
size_t n_max_items = n_threads * n_seconds * 10;
if (argc == 3) if (argc == 3)
{ {
rv = tester.run(n_threads, n_seconds, cin); rv = tester.run(n_threads, n_seconds, n_max_items, cin);
} }
else else
{ {
@ -76,7 +77,7 @@ int main(int argc, char* argv[])
if (in) if (in)
{ {
rv = tester.run(n_threads, n_seconds, in); rv = tester.run(n_threads, n_seconds, n_max_items, in);
} }
else else
{ {