1 /* ``Licensed under the Apache License, Version 2.0 (the "License");
2 * you may not use this file except in compliance with the License.
3 * You may obtain a copy of the License at
4 *
5 * http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
12 *
13 * The Initial Developer of the Original Code is Ericsson Utvecklings AB.
14 * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
15 * AB. All Rights Reserved.''
16 *
17 * $Id$
18 */
19
20 #include "testcase_driver.h"
21 #include "allocator_test.h"
22 #include <stdio.h>
23
24 #define MAX_TEST_SIZE 100000000
25
26 char *
testcase_name(void)27 testcase_name(void)
28 {
29 return "bucket_index";
30 }
31
32 void test_it(TestCaseState_t *tcs, unsigned sbct);
33
34 void
testcase_run(TestCaseState_t * tcs)35 testcase_run(TestCaseState_t *tcs)
36 {
37 testcase_printf(tcs, "No of buckets = %lu:\n\n", NO_OF_BKTS);
38
39 test_it(tcs, 1);
40 test_it(tcs, 0);
41 test_it(tcs, 1024);
42 test_it(tcs, 10240);
43 }
44
45 void
testcase_cleanup(TestCaseState_t * tcs)46 testcase_cleanup(TestCaseState_t *tcs)
47 {
48 if (tcs->extra) {
49 STOP_ALC(tcs->extra);
50 tcs->extra = NULL;
51 }
52 }
53
54 void
test_it(TestCaseState_t * tcs,unsigned sbct)55 test_it(TestCaseState_t *tcs, unsigned sbct)
56 {
57 Ulong max_cont_test_sz;
58 char sbct_buf[21];
59 char *argv[] = {"-tas", "gf", "-tsbct", NULL, NULL};
60 int no_changes;
61 Ulong bi;
62 Ulong min_sz;
63 Ulong prev_bi;
64 Ulong sz;
65 Allctr_t *a;
66
67 no_changes = 0;
68 prev_bi = -1;
69
70 if (sbct) {
71 sprintf(sbct_buf, "%d", sbct);
72 argv[3] = sbct_buf;
73 }
74 else
75 argv[2] = NULL;
76
77 max_cont_test_sz = 2*sbct*1024;
78 if (max_cont_test_sz < 1000000)
79 max_cont_test_sz = 1000000;
80
81 testcase_printf(tcs, "Testing with sbct = %s\n",
82 sbct ? sbct_buf : "default");
83 a = START_ALC("bkt_ix_", 0, argv);
84 tcs->extra = (void *) a;
85 ASSERT(tcs, a);
86
87 sz = MIN_BLK_SZ(a);
88 while(sz < ((((Ulong)1) << 31) - 1)) {
89 bi = BKT_IX(a, sz);
90 if (prev_bi != bi) {
91 ASSERT(tcs, prev_bi + 1 == bi);
92
93 min_sz = BKT_MIN_SZ(a, bi);
94
95 ASSERT(tcs, sz == min_sz);
96
97 testcase_printf(tcs, "sz=%d->ix=%d ", sz, bi);
98 no_changes++;
99 }
100 prev_bi = bi;
101 if (sz < max_cont_test_sz)
102 sz++;
103 else
104 sz += 100000000;
105 }
106 testcase_printf(tcs, "\n\n");
107 ASSERT(tcs, no_changes == NO_OF_BKTS);
108
109 STOP_ALC(a);
110 tcs->extra = NULL;
111
112 testcase_printf(tcs, "Test with sbct=%s succeeded\n",
113 sbct ? sbct_buf : "default");
114 }
115
116 ERL_NIF_INIT(bucket_index, testcase_nif_funcs, testcase_nif_init,
117 NULL, NULL, NULL);
118