2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: store_test.C /main/7 1996/08/21 15:56:52 drk $ */
26 #include <sys/times.h>
27 #include "utility/pm_random.h"
28 #include "storage/page_storage.h"
30 ////////////////////////////
31 // case: store pages exist
32 ////////////////////////////
33 void real_page_cache_test_1(pm_random& rand_gen, page_storage** st, unsigned int ct, unsigned int no_access)
36 page_storage::access_t l;
38 for ( unsigned int i=0; i< no_access; i++)
41 j = rand_gen.rand() % ct; // pick the store
42 k = rand_gen.rand() % (st[j] -> pages()) + 1; // pick the page
44 // pick the READ/WRITE option
46 l = (rand_gen.rand_01()>0.5) ? page_storage::READ : page_storage::WRITE;
48 cerr << "store=" << st[j] -> my_name() << " ";
49 cerr << "page=" << k << " ";
50 if (l==page_storage::READ)
61 prepare_store(char* path, lru& open_file_policy,
62 pm_random& rand_gen, unsigned int ct, unsigned int low, unsigned int high)
66 page_storage** x = new page_storagePtr[ct];
67 unixf_storage* unix_file = 0;
69 for ( unsigned int i=0; i<ct; i++) {
70 int pages = rand_gen.rand() % (high-low) + low;
79 snprintf(name, sizeof(name), "test.%d", i);
81 if ( exist_file(name) == true )
84 unix_file = new unixf_storage(path, name, &open_file_policy);
85 x[i] = new page_storage(path, name, unix_file, 1024);
86 x[i] -> add_page_frames(pages);
91 void quit_store(page_storage** st, unsigned int ct)
93 for ( unsigned int i=0; i<ct; i++) {
99 int page_cache_test_1(int argc, char** argv)
102 cerr << "usage: page_cache_test1 db_path stores min_pages max_pages no_probes\n";
104 cerr << " db_path: a path where the test dbs will be created;\n";
105 cerr << " stores: number of stores;\n";
106 cerr << " min_pages: min number of pages in these stores;\n";
107 cerr << " max_pages: max number of pages in these stores;\n";
108 cerr << " no_probes: number of probes to check the page cache.\n";
115 if ((seed = (int)times(&tp)) < 0)
121 int seed = ( gettimeofday(&tp, &tzp) == 0 ) ? int(tp.tv_sec) : 19;
126 char* path = argv[2];
128 if ( check_and_create_dir(path) != true )
131 lru open_file_policy(20, 1000, false);
133 unsigned int ct = atoi(argv[3]);
134 unsigned int low = atoi(argv[4]); if ( low == 0 ) low = 1;
136 unsigned int high = atoi(argv[5]);
137 unsigned int no_access= atoi(argv[6]);
140 prepare_store(path, open_file_policy, rand_gen, ct, low, high);
142 real_page_cache_test_1(rand_gen, st, ct, no_access);
149 int store_test(int argc, char** argv)
151 if ( strcmp(argv[1], "page_cache_test_1") == 0 )
152 return page_cache_test_1(argc, argv);