2 * Copyright (C) 2009 The Android Open Source Project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #ifndef ANDROID_NATIVETEST_SYSTEM_EXTRAS_TESTS_SDCARD_SYSUTIL_H_
30 #define ANDROID_NATIVETEST_SYSTEM_EXTRAS_TESTS_SDCARD_SYSUTIL_H_
35 // Collection of functions to access the system:
36 // .kernelVersion Retrieve the full kernel description.
37 // .pidOutOfMemoryAdj Get and set the OOM adj value.
38 // .setPidOutOfMemoryAdj
39 // .schedFeatures Manipulate the scheduler using debugfs.
41 // .setNewFairSleepers
42 // .disableCpuScaling Set cpu scaling to 'performance'.
43 // .forkOrExit Fork a child or exit.
44 // .syncAnddropCaches Call sync an drop page/dentries/inodes caches.
45 // .fsyncAnddropCaches Call fsync an drop page/dentries/inodes caches.
46 // .resetDirectory Delete (non-recursive) files in a directory.
48 // IPC function to synchonize a processes with their parent.
49 // .writePidAndWaitForReply To instruct the parent the child is ready.
50 // Blocks until the parent signals back.
51 // .waitForChildrenAndSignal Blocks until all the children have called
52 // writePidAndWaitForReply.
53 // Then unblock all the children.
54 // .waitForChildrenOrExit Wait and exit if a child exit with errors.
57 // Minimum size for the buffer to retrieve the kernel version.
58 static const size_t kMinKernelVersionBufferSize = 256;
60 // @param str points to the buffer where the kernel version should be
61 // added. Must be at least kMinKernelVersionBufferSize chars.
62 // @param size of the buffer pointed by str.
63 // @return If successful the number of characters inserted in the
64 // buffer (not including the trailing '\0' byte). -1 otherwise.
65 int kernelVersion(char *str, size_t size);
68 // Return the out of memory adj for this process. /proc/<pid>/oom_adj.
69 // @return the oom_adj of the current process. Typically:
70 // 0: a regular process. Should die on OOM.
71 // -16: system_server level.
72 // -17: disable, this process will never be killed.
74 int pidOutOfMemoryAdj();
75 void setPidOutOfMemoryAdj(int level);
77 // Disable cpu scaling.
78 void disableCpuScaling();
81 // Minimum size for the buffer to retrieve the sched features.
82 static const size_t kMinSchedFeaturesBufferSize = 256;
84 // @param str points to the buffer where the sched features should be
85 // added. Must be at least kMinSchedFeaturesBufferSize chars.
86 // @param size of the buffer pointed by str.
87 // @return If successful the number of characters inserted in the
88 // buffer (not including the trailing '\0' byte). -1 otherwise.
89 int schedFeatures(char *str, size_t size);
91 // @return true if NEW_FAIR_SLEEPERS is set, false if NO_NEW_FAIR_SLEEPERS is set.
92 bool newFairSleepers();
94 // Turns NEW_FAIR_SLEEPERS on or off.
95 void setNewFairSleepers(bool on);
97 // @return true if NORMALIZED_SLEEPERS is set, false if NO_NORMALIZED_SLEEPERS is set.
98 bool normalizedSleepers();
100 // Turns NORMALIZED_SLEEPERS on or off.
101 void setNormalizedSleepers(bool on);
105 // Sync and drop caches. Sync is needed because dirty objects are not
108 // * 1 To free pagecache.
109 // * 2 To free dentries and inodes.
110 // * 3 To free pagecache, dentries and inodes.
111 void syncAndDropCaches(int code = 3);
113 // Fsync the given fd and drop caches. Fsync is needed because dirty
114 // objects are not freable.
116 // * 1 To free pagecache.
117 // * 2 To free dentries and inodes.
118 // * 3 To free pagecache, dentries and inodes.
119 void fsyncAndDropCaches(int fd, int code = 3);
121 // Delete all the files in the given directory. If the directory does
122 // not exist, it is created. Use this at the beginning of a test to
123 // make sure you have a clean existing directory, previous run may
124 // have crashed and left clutter around.
125 void resetDirectory(const char *directory);
129 // Try to fork. exit on failure.
132 // Signal our parent we are alive and ready by sending our pid.
133 // Then do a blocking read for parent's reply.
134 bool writePidAndWaitForReply(int writefd, int readfd);
136 // Wait for all the children to report their pids.
137 // Then unblock them.
138 bool waitForChildrenAndSignal(int mProcessNb, int readfd, int writefd);
140 // Wait for 'num' children to complete.
141 // If a child did not exit cleanly, exit.
142 void waitForChildrenOrExit(int num);
144 } // namespace android
146 #endif // ANDROID_NATIVETEST_SYSTEM_EXTRAS_TESTS_SDCARD_SYSUTIL_H_