1b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross/*
2b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * Copyright (C) 2012 The Android Open Source Project
3b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross *
4b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * Licensed under the Apache License, Version 2.0 (the "License");
5b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * you may not use this file except in compliance with the License.
6b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * You may obtain a copy of the License at
7b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross *
8b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross *      http://www.apache.org/licenses/LICENSE-2.0
9b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross *
10b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * Unless required by applicable law or agreed to in writing, software
11b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * distributed under the License is distributed on an "AS IS" BASIS,
12b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * See the License for the specific language governing permissions and
14b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross * limitations under the License.
15b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross */
16b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
17b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#include "benchmark.h"
188b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris#include <errno.h>
198b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris#include <stdio.h>
208b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris#include <stdlib.h>
21cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann#include <unistd.h>
22b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
23b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
24b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#include <sys/_system_properties.h>
25b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
26b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#include <vector>
27cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann#include <string>
28b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
291540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmannextern void *__system_property_area__;
30b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
31b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris// Do not exceed 512, that is about the largest number of properties
32b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris// that can be created with the current property area size.
33b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross#define TEST_NUM_PROPS \
34b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris    Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)
35b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
36b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossstruct LocalPropertyTestState {
37cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann    LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
38b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris        static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
39cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
408b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris        const char* android_data = getenv("ANDROID_DATA");
418b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris        if (android_data == NULL) {
428b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris          printf("ANDROID_DATA environment variable not set\n");
438b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris          return;
448b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris        }
458b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris        char dir_template[PATH_MAX];
468b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris        snprintf(dir_template, sizeof(dir_template), "%s/local/tmp/prop-XXXXXX", android_data);
47cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        char *dirname = mkdtemp(dir_template);
48cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        if (!dirname) {
498b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris            printf("making temp file for test state failed (is %s/local/tmp writable?): %s\n",
508b1ade5c0bdb5b3186c73c3081cc3013540190d9Christopher Ferris                   android_data, strerror(errno));
51cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann            return;
52cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        }
53cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
541540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann        old_pa = __system_property_area__;
551540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann        __system_property_area__ = NULL;
56cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
57cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        pa_dirname = dirname;
58cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        pa_filename = pa_dirname + "/__properties__";
59cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
60cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        __system_property_set_filename(pa_filename.c_str());
61cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        __system_property_area_init();
62b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
63b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        names = new char* [nprops];
64b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        name_lens = new int[nprops];
65b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        values = new char* [nprops];
66b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        value_lens = new int[nprops];
67b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
68b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        srandom(nprops);
69b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
70b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        for (int i = 0; i < nprops; i++) {
71b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            // Make sure the name has at least 10 characters to make
72b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            // it very unlikely to generate the same random name.
73b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            name_lens[i] = (random() % (PROP_NAME_MAX - 10)) + 10;
74b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            names[i] = new char[PROP_NAME_MAX + 1];
75b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            size_t prop_name_len = sizeof(prop_name_chars) - 1;
76b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            for (int j = 0; j < name_lens[i]; j++) {
77b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                if (j == 0 || names[i][j-1] == '.' || j == name_lens[i] - 1) {
78b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    // Certain values are not allowed:
79b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    // - Don't start name with '.'
80b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    // - Don't allow '.' to appear twice in a row
81b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    // - Don't allow the name to end with '.'
82b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    // This assumes that '.' is the last character in the
83b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    // array so that decrementing the length by one removes
84b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    // the value from the possible values.
85b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                    prop_name_len--;
86b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                }
87b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                names[i][j] = prop_name_chars[random() % prop_name_len];
88b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            }
89b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            names[i][name_lens[i]] = 0;
90b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris
91b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            // Make sure the value contains at least 1 character.
92b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            value_lens[i] = (random() % (PROP_VALUE_MAX - 1)) + 1;
93b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            values[i] = new char[PROP_VALUE_MAX];
94b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            for (int j = 0; j < value_lens[i]; j++) {
95b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross                values[i][j] = prop_name_chars[random() % (sizeof(prop_name_chars) - 1)];
96b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            }
97b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris
98b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            if (__system_property_add(names[i], name_lens[i], values[i], value_lens[i]) < 0) {
99b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                printf("Failed to add a property, terminating...\n");
100b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                printf("%s = %.*s\n", names[i], value_lens[i], values[i]);
101b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris                exit(1);
102b0815aeacb86e20cbbd4fa27dd90ad43b9c200feChristopher Ferris            }
103b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        }
104cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
105cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        valid = true;
106b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    }
107b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
108b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    ~LocalPropertyTestState() {
109cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        if (!valid)
110cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann            return;
111cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
1121540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann        __system_property_area__ = old_pa;
113cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
114cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        __system_property_set_filename(PROP_FILENAME);
115cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        unlink(pa_filename.c_str());
116cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        rmdir(pa_dirname.c_str());
117cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
118b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        for (int i = 0; i < nprops; i++) {
119b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            delete names[i];
120b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross            delete values[i];
121b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross        }
1227d06813d93b3b3745d438c000f596a38cb0efeb4Colin Cross        delete[] names;
1237d06813d93b3b3745d438c000f596a38cb0efeb4Colin Cross        delete[] name_lens;
1247d06813d93b3b3745d438c000f596a38cb0efeb4Colin Cross        delete[] values;
1257d06813d93b3b3745d438c000f596a38cb0efeb4Colin Cross        delete[] value_lens;
126b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    }
127b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crosspublic:
128b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    const int nprops;
129b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    char **names;
130b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    int *name_lens;
131b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    char **values;
132b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    int *value_lens;
133cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann    bool valid;
134b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
135b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossprivate:
136cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann    std::string pa_dirname;
137cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann    std::string pa_filename;
1381540f601be32bdd4af8e8c13bdf2bc06bdaa76f1Greg Hackmann    void *old_pa;
139b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross};
140b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
141b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossstatic void BM_property_get(int iters, int nprops)
142b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross{
143b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    StopBenchmarkTiming();
144b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
145b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    LocalPropertyTestState pa(nprops);
146b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    char value[PROP_VALUE_MAX];
147b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
148cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann    if (!pa.valid)
149cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        return;
150cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
1517d90cfa6b5b49abb2123b069b81e0b9f4eba6432Colin Cross    srandom(iters * nprops);
1527d90cfa6b5b49abb2123b069b81e0b9f4eba6432Colin Cross
153b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    StartBenchmarkTiming();
154b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
155b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    for (int i = 0; i < iters; i++) {
1567d90cfa6b5b49abb2123b069b81e0b9f4eba6432Colin Cross        __system_property_get(pa.names[random() % nprops], value);
157b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    }
158b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    StopBenchmarkTiming();
159b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross}
160b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossBENCHMARK(BM_property_get)->TEST_NUM_PROPS;
161b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
162b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Crossstatic void BM_property_find(int iters, int nprops)
163b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross{
164b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    StopBenchmarkTiming();
165b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
166b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    LocalPropertyTestState pa(nprops);
167b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
168cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann    if (!pa.valid)
169cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann        return;
170cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7Greg Hackmann
1717d90cfa6b5b49abb2123b069b81e0b9f4eba6432Colin Cross    srandom(iters * nprops);
1727d90cfa6b5b49abb2123b069b81e0b9f4eba6432Colin Cross
173b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    StartBenchmarkTiming();
174b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross
175b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    for (int i = 0; i < iters; i++) {
1767d90cfa6b5b49abb2123b069b81e0b9f4eba6432Colin Cross        __system_property_find(pa.names[random() % nprops]);
177b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    }
178b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross    StopBenchmarkTiming();
179b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin Cross}
180b27e200ad6170ba3163f5ae6ba581bdaabb2e696Colin CrossBENCHMARK(BM_property_find)->TEST_NUM_PROPS;
181a304476145810d62f76b23a188b1680287716cfdBrigid Smith
182a304476145810d62f76b23a188b1680287716cfdBrigid Smithstatic void BM_property_read(int iters, int nprops)
183a304476145810d62f76b23a188b1680287716cfdBrigid Smith{
184a304476145810d62f76b23a188b1680287716cfdBrigid Smith    StopBenchmarkTiming();
185a304476145810d62f76b23a188b1680287716cfdBrigid Smith
186a304476145810d62f76b23a188b1680287716cfdBrigid Smith    LocalPropertyTestState pa(nprops);
187a304476145810d62f76b23a188b1680287716cfdBrigid Smith
188a304476145810d62f76b23a188b1680287716cfdBrigid Smith    if (!pa.valid)
189a304476145810d62f76b23a188b1680287716cfdBrigid Smith        return;
190a304476145810d62f76b23a188b1680287716cfdBrigid Smith
191a304476145810d62f76b23a188b1680287716cfdBrigid Smith    srandom(iters * nprops);
192a304476145810d62f76b23a188b1680287716cfdBrigid Smith    const prop_info** pinfo = new const prop_info*[iters];
193a304476145810d62f76b23a188b1680287716cfdBrigid Smith    char propvalue[PROP_VALUE_MAX];
194a304476145810d62f76b23a188b1680287716cfdBrigid Smith
195a304476145810d62f76b23a188b1680287716cfdBrigid Smith    for (int i = 0; i < iters; i++) {
196a304476145810d62f76b23a188b1680287716cfdBrigid Smith        pinfo[i] = __system_property_find(pa.names[random() % nprops]);
197a304476145810d62f76b23a188b1680287716cfdBrigid Smith    }
198a304476145810d62f76b23a188b1680287716cfdBrigid Smith
199a304476145810d62f76b23a188b1680287716cfdBrigid Smith    StartBenchmarkTiming();
200a304476145810d62f76b23a188b1680287716cfdBrigid Smith    for (int i = 0; i < iters; i++) {
201a304476145810d62f76b23a188b1680287716cfdBrigid Smith        __system_property_read(pinfo[i], 0, propvalue);
202a304476145810d62f76b23a188b1680287716cfdBrigid Smith    }
203a304476145810d62f76b23a188b1680287716cfdBrigid Smith    StopBenchmarkTiming();
204a304476145810d62f76b23a188b1680287716cfdBrigid Smith
205a304476145810d62f76b23a188b1680287716cfdBrigid Smith    delete[] pinfo;
206a304476145810d62f76b23a188b1680287716cfdBrigid Smith}
207a304476145810d62f76b23a188b1680287716cfdBrigid SmithBENCHMARK(BM_property_read)->TEST_NUM_PROPS;
20828417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith
20928417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smithstatic void BM_property_serial(int iters, int nprops)
21028417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith{
21128417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    StopBenchmarkTiming();
21228417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith
21328417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    LocalPropertyTestState pa(nprops);
21428417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith
21528417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    if (!pa.valid)
21628417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith        return;
21728417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith
21828417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    srandom(iters * nprops);
21928417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    const prop_info** pinfo = new const prop_info*[iters];
22028417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith
22128417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    for (int i = 0; i < iters; i++) {
22228417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith        pinfo[i] = __system_property_find(pa.names[random() % nprops]);
22328417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    }
22428417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith
22528417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    StartBenchmarkTiming();
22628417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    for (int i = 0; i < iters; i++) {
22728417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith        __system_property_serial(pinfo[i]);
22828417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    }
22928417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    StopBenchmarkTiming();
23028417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith
23128417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith    delete[] pinfo;
23228417e6314768d057ab7ad7a0208f1af7597b4d6Brigid Smith}
23328417e6314768d057ab7ad7a0208f1af7597b4d6Brigid SmithBENCHMARK(BM_property_serial)->TEST_NUM_PROPS;
234