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>
27 #ifdef HAVE_CONFIG_H // Built using autoconf
28 #include "stressapptest_config.h"
30 using namespace __gnu_cxx;
32 typedef signed long long int64;
33 typedef signed int int32;
34 typedef signed short int int16;
35 typedef signed char int8;
37 typedef unsigned long long uint64;
38 typedef unsigned int uint32;
39 typedef unsigned short uint16;
40 typedef unsigned char uint8;
42 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
43 TypeName(const TypeName&); \
44 void operator=(const TypeName&)
46 inline const char* Timestamp() {
47 return STRESSAPPTEST_TIMESTAMP;
50 inline const char* BuildChangelist() {
51 return "open source release";
54 static const bool kOpenSource = true;
56 static const bool kOpenSource = false;
57 #include "googlesattypes.h"
59 // Workaround to allow 32/64 bit conversion
60 // without running into strict aliasing problems.
70 // File sync'd print to console and log
71 void logprintf(int priority, const char *format, ...);
73 // We print to stderr ourselves first in case we're in such a bad state that the
75 #define sat_assert(x) \
78 fprintf(stderr, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
79 logprintf(0, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
84 #if !defined(CPU_SETSIZE)
85 // Define type and macros for cpu mask operations
86 // Note: this code is hacked together to deal with difference
87 // function signatures across versions of glibc, ie those that take
88 // cpu_set_t versus those that take unsigned long. -johnhuang
89 typedef unsigned long cpu_set_t;
90 #define CPU_SETSIZE 32
91 #define CPU_ISSET(index, cpu_set_ptr) (*(cpu_set_ptr) & 1 << (index))
92 #define CPU_SET(index, cpu_set_ptr) (*(cpu_set_ptr) |= 1 << (index))
93 #define CPU_ZERO(cpu_set_ptr) (*(cpu_set_ptr) = 0)
94 #define CPU_CLR(index, cpu_set_ptr) (*(cpu_set_ptr) &= ~(1 << (index)))
97 // Make using CPUSET non-super-painful.
98 static inline uint32 cpuset_to_uint32(cpu_set_t *cpuset) {
100 for (int index = 0; index < CPU_SETSIZE; index++) {
101 if (CPU_ISSET(index, cpuset)) {
105 logprintf(0, "Process Error: Cpu index (%d) higher than 32\n", index);
113 static inline void cpuset_from_uint32(uint32 mask, cpu_set_t *cpuset) {
115 for (int index = 0; index < 32; index++) {
116 if (mask & (1 << index))
117 CPU_SET(index, cpuset);
121 static const int32 kUSleepOneSecond = 1000000;
123 // This is guaranteed not to use signals.
124 inline bool sat_usleep(int32 microseconds) {
126 req.tv_sec = microseconds / 1000000;
127 // Convert microseconds argument to nano seconds.
128 req.tv_nsec = (microseconds % 1000000) * 1000;
129 return nanosleep(&req, NULL) == 0;
132 // This is guaranteed not to use signals.
133 inline bool sat_sleep(time_t seconds) {
135 req.tv_sec = seconds;
137 return nanosleep(&req, NULL) == 0;
140 // Get an error code description for use in error messages.
143 // error_num: an errno error code
144 inline string ErrorString(int error_num) {
146 return string(strerror_r(error_num, buf, sizeof buf));
149 // Define handy constants here
150 static const int kTicksPerSec = 100;
151 static const int kMegabyte = (1024LL*1024LL);
152 static const int kSatDiskPageMax = 32;
153 static const int kSatDiskPage = 8;
154 static const int kSatPageSize = (1024LL*1024LL);
155 static const int kCacheLineSize = 64;
156 static const uint16_t kNetworkPort = 19996;
158 #endif // STRESSAPPTEST_SATTYPES_H_