35#ifdef SYSTEM_IS_MACINTOSH
46namespace layer1_foundations {
47namespace orbiter_kernel_system {
57 struct tms *buffer = (
struct tms *) malloc(
sizeof(
struct tms));
59 *l = (long) buffer->tms_utime;
63#ifdef SYSTEM_IS_MACINTOSH
74#ifdef SYSTEM_IS_MACINTOSH
76 struct task_basic_info t_info;
77 mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
79 if (KERN_SUCCESS != task_info(mach_task_self(),
80 TASK_BASIC_INFO, (task_info_t)&t_info,
83 cout <<
"os_interface::os_memory_usage error in task_info" << endl;
92 return t_info.resident_size;
99 FILE* file = fopen(
"/proc/self/status",
"r");
101 while (fgets(line, chars, file) != NULL) {
103 if (strncmp(line,
"VmPeak:", 7) == 0) {
107 p[strlen(p)-3] =
'\0';
123 struct tms tms_buffer;
126 if (-1 == (
int) times(&tms_buffer))
128 t = tms_buffer.tms_utime;
133#ifdef SYSTEM_IS_MACINTOSH
146static int f_system_time_set =
FALSE;
147static int system_time0 = 0;
154 if (!f_system_time_set) {
155 f_system_time_set =
TRUE;
165 static int f_tps_computed =
FALSE;
174 clk_tck = sysconf(_SC_CLK_TCK);
176 f_tps_computed =
TRUE;
188 int tps,
int &d,
int &h,
int &m,
int &s)
194 cout <<
"os_ticks_to_dhms ticks = " << ticks << endl;
198 cout <<
"os_ticks_to_dhms l1 = " << l1 << endl;
202 cout <<
"os_ticks_to_dhms s = " << s << endl;
207 cout <<
"os_ticks_to_dhms m = " << m << endl;
212 cout <<
"os_ticks_to_dhms h = " << h << endl;
221 cout <<
"os_ticks_to_dhms d = " << d << endl;
227 int tps, d, h, min, s;
232 if (d == 0 && h == 0 && min == 0 && s == 0) {
233 ost << (double) dt / (
double) tps <<
" of a second, dt=" << dt <<
" tps = " << tps << endl;
236 if ((dt / tps) >= 1) {
248 ost << d <<
"-" << h <<
":" << m <<
":" << s;
251 ost << h <<
":" << m <<
":" << s;
254 ost << m <<
":" << s;
283 srand((
unsigned int) time(0));
288 srand((
unsigned int) seed);
297 cout <<
"random_integer p = 0" << endl;
300 n = (int)(((
double)rand() * (
double)p / RAND_MAX)) % p;
310 fp <<
"#!/bin/bash" << endl;
311 fp <<
"echo $(date +%s)" << endl;
313 system(
"chmod ugo+x b");
319 f1.getline(str,
sizeof(str));
320 sscanf(str,
"%d", &a);
326 int &i,
int verbose_level)
330 if (ST.
stringcmp(argv[i],
"-long_string") == 0) {
334 if (ST.
stringcmp(argv[i],
"-end_string") == 0) {
348static const char *ascii_code =
"abcdefghijklmnop";
350static int f_has_swap_initialized =
FALSE;
351static int f_has_swap = 0;
358 int_4 test = 0x11223344L;
361 ptr = (
char *) &test;
362 if (ptr[0] == 0x44) {
364 cout <<
"we have a swap" << endl;
366 else if (ptr[0] == 0x11) {
368 cout <<
"we don't have a swap" << endl;
371 cout <<
"The test_swap test is inconclusive" << endl;
374 f_has_swap_initialized =
TRUE;
384 char *ptr_end, *ptr_start;
388 if (!f_has_swap_initialized) {
391 if ((f_has_swap) && (size > 1)) {
396 ptr_end = ptr_start + (size - 1);
397 for (i = size / 2; i--; ) {
399 *ptr_start++ = *ptr_end;
438 *p++ = ascii_code[a_high];
439 *p++ = ascii_code[a_low];
444 int a_high = (int)(*p++ -
'a');
445 int a_low = (int)(*p++ -
'a');
449 i = (a_high << 4) | a_low;
464 f1.getline(s,
sizeof(s));
468 str.assign(
"unknown");
474 cout <<
"test_typedefs()" << endl;
475 cout <<
"sizeof(int)=" <<
sizeof(int) << endl;
476 cout <<
"sizeof(long int)=" <<
sizeof(
long int) << endl;
477 if (
sizeof(
int_2) != 2) {
478 cout <<
"warning: sizeof(int_2)=" <<
sizeof(
int_2) << endl;
480 if (
sizeof(
int_4) != 4) {
481 cout <<
"warning: sizeof(int4)=" <<
sizeof(
int_4) << endl;
483 if (
sizeof(
int_8) != 8) {
484 cout <<
"warning: sizeof(int8)=" <<
sizeof(
int_8) << endl;
486 if (
sizeof(
uint_2) != 2) {
487 cout <<
"warning: sizeof(uint_2)=" <<
sizeof(
uint_2) << endl;
489 if (
sizeof(
uint_4) != 4) {
490 cout <<
"warning: sizeof(uint_2)=" <<
sizeof(
uint_4) << endl;
492 if (
sizeof(
uint_8) != 8) {
493 cout <<
"warning: sizeof(uint_2)=" <<
sizeof(
uint_8) << endl;
495 cout <<
"test_typedefs done" << endl;
void decode_uchar(char *&p, uchar &a)
void code_int4(char *&p, int_4 i)
void seed_random_generator(int seed)
int random_integer(int p)
int os_seconds_past_1970()
void get_date(std::string &str)
void get_string_from_command_line(std::string &p, int argc, std::string *argv, int &i, int verbose_level)
int os_ticks_per_second()
void seed_random_generator_with_system_time()
void block_swap_chars(char *ptr, int size, int no)
int_4 decode_int4(char *&p)
void code_uchar(char *&p, uchar a)
void print_elapsed_time(std::ostream &ost, int d, int h, int m, int s)
void os_ticks_to_dhms(int ticks, int tps, int &d, int &h, int &m, int &s)
void time_check(std::ostream &ost, int t0)
void time_check_delta(std::ostream &ost, int dt)
the orbiter library for the classification of combinatorial objects