xref: /aosp_15_r20/external/icing/icing/monkey_test/monkey-test-util.h (revision 8b6cd535a057e39b3b86660c4aa06c99747c2136)
1 // Copyright (C) 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_MONKEY_TEST_MONKEY_TEST_UTIL_H_
16 #define ICING_MONKEY_TEST_MONKEY_TEST_UTIL_H_
17 
18 #include <cstdint>
19 #include <functional>
20 #include <random>
21 #include <utility>
22 #include <vector>
23 
24 namespace icing {
25 namespace lib {
26 
27 using MonkeyTestRandomEngine = std::mt19937;
28 
29 class IcingMonkeyTestRunner;
30 
31 struct IcingMonkeyTestRunnerConfiguration {
IcingMonkeyTestRunnerConfigurationIcingMonkeyTestRunnerConfiguration32   explicit IcingMonkeyTestRunnerConfiguration(uint32_t seed, int num_types,
33                                               int num_namespaces, int num_uris,
34                                               int index_merge_size)
35       : seed(seed),
36         num_types(num_types),
37         num_namespaces(num_namespaces),
38         num_uris(num_uris),
39         index_merge_size(index_merge_size) {}
40 
41   uint32_t seed;
42   int num_types;
43   int num_namespaces;
44   int num_uris;
45   int index_merge_size;
46 
47   // To ensure that the random schema is generated with the best quality, the
48   // number of properties for each type will only be randomly picked from this
49   // list, instead of picking it from a range. For example, a vector of
50   // [1, 2, 3, 4] means each generated types have a 25% chance of getting 1
51   // property, 2 properties, 3 properties and 4 properties.
52   std::vector<int> possible_num_properties;
53 
54   // The possible number of tokens that may appear in a string property of
55   // generated documents, with a noise factor from 0.5 to 1 applied.
56   std::vector<int> possible_num_tokens;
57 
58   // The possible number of embedding vectors that may appear in a repeated
59   // vector property of generated documents.
60   std::vector<int> possible_num_vectors;
61 
62   // The possible dimensions for the randomly generated embedding vectors.
63   std::vector<int> possible_vector_dimensions;
64 
65   // An array of pairs of monkey test APIs with frequencies.
66   // If f_sum is the sum of all the frequencies, an operation with frequency f
67   // means for every f_sum iterations, the operation is expected to run f times.
68   std::vector<std::pair<std::function<void(IcingMonkeyTestRunner*)>, uint32_t>>
69       monkey_api_schedules;
70 };
71 
72 }  // namespace lib
73 }  // namespace icing
74 
75 #endif  // ICING_MONKEY_TEST_MONKEY_TEST_UTIL_H_
76