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";
55 #include "googlesattypes.h"
57 // Workaround to allow 32/64 bit conversion
58 // without running into strict aliasing problems.
68 // File sync'd print to console and log
69 void logprintf(int priority, const char *format, ...);
71 // We print to stderr ourselves first in case we're in such a bad state that the
73 #define sat_assert(x) \
76 fprintf(stderr, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
77 logprintf(0, "Assertion failed at %s:%d\n", __FILE__, __LINE__);\
82 #if !defined(CPU_SETSIZE)
83 // Define type and macros for cpu mask operations
84 // Note: this code is hacked together to deal with difference
85 // function signatures across versions of glibc, ie those that take
86 // cpu_set_t versus those that take unsigned long. -johnhuang
87 typedef unsigned long cpu_set_t;
88 #define CPU_SETSIZE 32
89 #define CPU_ISSET(index, cpu_set_ptr) (*(cpu_set_ptr) & 1 << (index))
90 #define CPU_SET(index, cpu_set_ptr) (*(cpu_set_ptr) |= 1 << (index))
91 #define CPU_ZERO(cpu_set_ptr) (*(cpu_set_ptr) = 0)
92 #define CPU_CLR(index, cpu_set_ptr) (*(cpu_set_ptr) &= ~(1 << (index)))
95 // Make using CPUSET non-super-painful.
96 static inline uint32 cpuset_to_uint32(cpu_set_t *cpuset) {
98 for (int index = 0; index < CPU_SETSIZE; index++) {
99 if (CPU_ISSET(index, cpuset)) {
103 logprintf(0, "Process Error: Cpu index (%d) higher than 32\n", index);
111 static inline void cpuset_from_uint32(uint32 mask, cpu_set_t *cpuset) {
113 for (int index = 0; index < 32; index++) {
114 if (mask & (1 << index))
115 CPU_SET(index, cpuset);
119 static const int32 kUSleepOneSecond = 1000000;
121 // This is guaranteed not to use signals.
122 inline bool sat_usleep(int32 microseconds) {
124 req.tv_sec = microseconds / 1000000;
125 // Convert microseconds argument to nano seconds.
126 req.tv_nsec = (microseconds % 1000000) * 1000;
127 return nanosleep(&req, NULL) == 0;
130 // This is guaranteed not to use signals.
131 inline bool sat_sleep(time_t seconds) {
133 req.tv_sec = seconds;
135 return nanosleep(&req, NULL) == 0;
138 // Get an error code description for use in error messages.
141 // error_num: an errno error code
142 inline string ErrorString(int error_num) {
144 return string(strerror_r(error_num, buf, sizeof buf));
147 // Define handy constants here
148 static const int kTicksPerSec = 100;
149 static const int kMegabyte = (1024LL*1024LL);
150 static const int kSatDiskPageMax = 32;
151 static const int kSatDiskPage = 8;
152 static const int kSatPageSize = (1024LL*1024LL);
153 static const int kCacheLineSize = 64;
154 static const uint16_t kNetworkPort = 19996;
156 #endif // STRESSAPPTEST_SATTYPES_H_