| 1 |
#include <unistd.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <stdio.h> |
| 4 |
#include <time.h> |
| 5 |
#include <string.h> |
| 6 |
|
| 7 |
#ifdef LOOP |
| 8 |
static struct timespec req = {0, 200000000}; |
| 9 |
#endif |
| 10 |
|
| 11 |
void sem_display (); |
| 12 |
void bar (int i); |
| 13 |
void baz (int i, char* s); |
| 14 |
void buz (int parm); |
| 15 |
|
| 16 |
#ifndef ONLY_MAIN |
| 17 |
#include "sdt_misc_.h" |
| 18 |
|
| 19 |
void |
| 20 |
sem_display () |
| 21 |
{ |
| 22 |
printf("%s epilogue %s=%ld\n", (SDT_MISC_TEST_PROBE_0_ENABLED() ? "FAIL" : "PASS"), "test_probe_0_semaphore", SDT_MISC_TEST_PROBE_0_ENABLED()); |
| 23 |
printf("%s epilogue %s=%ld\n", (SDT_MISC_TEST_PROBE_2_ENABLED() ? "FAIL" : "PASS"), "test_probe_2_semaphore", SDT_MISC_TEST_PROBE_2_ENABLED()); |
| 24 |
printf("%s epilogue %s=%ld\n", (SDT_MISC_TEST_PROBE_3_ENABLED() ? "FAIL" : "PASS"), "test_probe_3_semaphore", SDT_MISC_TEST_PROBE_3_ENABLED()); |
| 25 |
printf("%s epilogue %s=%ld\n", (SDT_MISC_TEST_PROBE_4_ENABLED() ? "FAIL" : "PASS"), "test_probe_4_semaphore", SDT_MISC_TEST_PROBE_4_ENABLED()); |
| 26 |
} |
| 27 |
|
| 28 |
#ifdef LOOP |
| 29 |
int |
| 30 |
loop_check() |
| 31 |
{ |
| 32 |
return SDT_MISC_TEST_PROBE_0_ENABLED(); |
| 33 |
} |
| 34 |
#endif |
| 35 |
|
| 36 |
void |
| 37 |
bar (int i) |
| 38 |
{ |
| 39 |
#ifdef LOOP |
| 40 |
while (!loop_check()) |
| 41 |
{ |
| 42 |
nanosleep(&req, NULL); |
| 43 |
} |
| 44 |
#endif |
| 45 |
#ifndef NO_SLEEP |
| 46 |
sleep (3); |
| 47 |
#endif |
| 48 |
|
| 49 |
SDT_MISC_TEST_PROBE_2(i); |
| 50 |
if (i == 0) |
| 51 |
i = 1000; |
| 52 |
if (SDT_MISC_TEST_PROBE_2_ENABLED()) |
| 53 |
STAP_PROBE1(sdt_misc,test_probe_2,i); |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
baz (int i, char* s) |
| 58 |
{ |
| 59 |
static char ss [32]; |
| 60 |
strcpy(ss, s); |
| 61 |
if (SDT_MISC_TEST_PROBE_0_ENABLED()) |
| 62 |
STAP_PROBE1(sdt_misc,test_probe_0,i); |
| 63 |
if (i == 0) |
| 64 |
i = 1000; |
| 65 |
if (SDT_MISC_TEST_PROBE_3_ENABLED()) |
| 66 |
SDT_MISC_TEST_PROBE_3(i,s); |
| 67 |
} |
| 68 |
|
| 69 |
void |
| 70 |
buz (int parm) |
| 71 |
{ |
| 72 |
struct astruct |
| 73 |
{ |
| 74 |
int a; |
| 75 |
int b; |
| 76 |
int *c; |
| 77 |
}; |
| 78 |
struct astruct bstruct = {parm, parm + 1}; |
| 79 |
struct astruct *cstruct = &bstruct; |
| 80 |
if (parm == 0) |
| 81 |
parm = 1000; |
| 82 |
if (SDT_MISC_TEST_PROBE_4_ENABLED()) |
| 83 |
DTRACE_PROBE1(sdt_misc,test_probe_4,&bstruct); |
| 84 |
SDT_MISC_TEST_PROBE_1(cstruct->c != ((void*)0)); |
| 85 |
} |
| 86 |
#endif |
| 87 |
|
| 88 |
#ifndef NO_MAIN |
| 89 |
void int_handler(int sig) |
| 90 |
{ |
| 91 |
sem_display(); |
| 92 |
exit(1); |
| 93 |
} |
| 94 |
|
| 95 |
void alrm_handler(int sig) |
| 96 |
{ |
| 97 |
exit (1); |
| 98 |
} |
| 99 |
|
| 100 |
#ifdef LOOP |
| 101 |
#include <signal.h> |
| 102 |
#endif |
| 103 |
|
| 104 |
int |
| 105 |
main () |
| 106 |
{ |
| 107 |
#ifdef LOOP |
| 108 |
signal (SIGINT, &int_handler); |
| 109 |
// signal (SIGALRM, &alrm_handler); |
| 110 |
// alarm (300); |
| 111 |
#endif |
| 112 |
bar(2); |
| 113 |
baz(3,(char*)"abc"); |
| 114 |
buz(4); |
| 115 |
#ifdef LOOP |
| 116 |
while (1) {nanosleep(&req, NULL);} |
| 117 |
#endif |
| 118 |
return 0; |
| 119 |
} |
| 120 |
#endif |