1 // Copyright 2006 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef STRESSAPPTEST_SATTYPES_H_
16 #define STRESSAPPTEST_SATTYPES_H_
18 #include <arpa/inet.h>
22 #include <sys/types.h>
28 #ifdef HAVE_CONFIG_H // Built using autoconf
29 #include "stressapptest_config.h"
31 using namespace __gnu_cxx;
33 typedef signed long long int64;
34 typedef signed int int32;
35 typedef signed short int int16;
36 typedef signed char int8;
38 typedef unsigned long long uint64;
39 typedef unsigned int uint32;
40 typedef unsigned short uint16;
41 typedef unsigned char uint8;
43 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
44 TypeName(const TypeName&); \
45 void operator=(const TypeName&)
47 inline const char* Timestamp() {
48 return STRESSAPPTEST_TIMESTAMP;
51 inline const char* BuildChangelist() {
52 return "open source release";
55 static const bool kOpenSource = true;
57 static const bool kOpenSource = false;
58 #include "googlesattypes.h"
60 // Workaround to allow 32/64 bit conversion
61 // without running into strict aliasing problems.
71 // File sync'd print to console and log
72 void logprintf(int priority, const char *format, ...);
74 // We print to stderr ourselves first in case we're in such a bad state that the
76 #define sat_assert(x) \
79 fprintf(stderr, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
80 logprintf(0, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
85 #if !defined(CPU_SETSIZE)
86 // Define type and macros for cpu mask operations
87 // Note: this code is hacked together to deal with difference
88 // function signatures across versions of glibc, ie those that take
89 // cpu_set_t versus those that take unsigned long. -johnhuang
90 typedef uint64 cpu_set_t;
91 #define CPU_SETSIZE (sizeof(cpu_set_t) * 8)
92 #define CPU_ISSET(index, cpu_set_ptr) (*(cpu_set_ptr) & 1ull << (index))
93 #define CPU_SET(index, cpu_set_ptr) (*(cpu_set_ptr) |= 1ull << (index))
94 #define CPU_ZERO(cpu_set_ptr) (*(cpu_set_ptr) = 0)
95 #define CPU_CLR(index, cpu_set_ptr) (*(cpu_set_ptr) &= ~(1ull << (index)))
98 static inline bool cpuset_isequal(const cpu_set_t *c1, const cpu_set_t *c2) {
99 for (int i = 0; i < CPU_SETSIZE; ++i)
100 if ((CPU_ISSET(i, c1) != 0) != (CPU_ISSET(i, c2) != 0))
105 static inline bool cpuset_issubset(const cpu_set_t *c1, const cpu_set_t *c2) {
106 for (int i = 0; i < CPU_SETSIZE; ++i)
107 if (CPU_ISSET(i, c1) && !CPU_ISSET(i, c2))
112 static inline int cpuset_count(const cpu_set_t *cpuset) {
114 for (int i = 0; i < CPU_SETSIZE; ++i)
115 if (CPU_ISSET(i, cpuset))
120 static inline void cpuset_set_ab(cpu_set_t *cpuset, int a, int b) {
122 for (int i = a; i < b; ++i)
126 static inline string cpuset_format(const cpu_set_t *cpuset) {
128 int digit = 0, last_non_zero_size = 1;
129 for (int i = 0; i < CPU_SETSIZE; ++i) {
130 if (CPU_ISSET(i, cpuset)) {
131 digit |= 1 << (i & 3);
134 format += char(digit <= 9 ? '0' + digit: 'A' + digit - 10);
136 last_non_zero_size = format.size();
142 format += char(digit <= 9 ? '0' + digit: 'A' + digit - 10);
143 last_non_zero_size = format.size();
145 format.erase(last_non_zero_size);
146 reverse(format.begin(), format.end());
150 static const int32 kUSleepOneSecond = 1000000;
152 // This is guaranteed not to use signals.
153 inline bool sat_usleep(int32 microseconds) {
155 req.tv_sec = microseconds / 1000000;
156 // Convert microseconds argument to nano seconds.
157 req.tv_nsec = (microseconds % 1000000) * 1000;
158 return nanosleep(&req, NULL) == 0;
161 // This is guaranteed not to use signals.
162 inline bool sat_sleep(time_t seconds) {
164 req.tv_sec = seconds;
166 return nanosleep(&req, NULL) == 0;
169 // Get an error code description for use in error messages.
172 // error_num: an errno error code
173 inline string ErrorString(int error_num) {
175 return string(strerror_r(error_num, buf, sizeof buf));
178 // Define handy constants here
179 static const int kTicksPerSec = 100;
180 static const int kMegabyte = (1024LL*1024LL);
181 static const int kSatDiskPageMax = 32;
182 static const int kSatDiskPage = 8;
183 static const int kSatPageSize = (1024LL*1024LL);
184 static const int kCacheLineSize = 64;
185 static const uint16_t kNetworkPort = 19996;
187 #endif // STRESSAPPTEST_SATTYPES_H_