]> git.saurik.com Git - apple/dyld.git/blob - testing/include/test_support.h
dyld-851.27.tar.gz
[apple/dyld.git] / testing / include / test_support.h
1 #ifndef __DYLD_TEST_SUPPORT_H__
2 #define __DYLD_TEST_SUPPORT_H__ 1
3
4 #if __cplusplus
5 extern "C" {
6 #endif /* __cplusplus */
7
8 #include <unistd.h>
9 #include <mach/mach.h>
10 #include <mach/machine.h>
11 #include <dispatch/dispatch.h>
12
13 #if __cplusplus
14 };
15
16 // Only allow this interface for Objective-C++ due to typename and ARC issues in the default constructor
17
18 typedef void (^_dyld_test_reader_t)(int fd);
19 typedef void (^_dyld_test_exit_handler_t)(pid_t pid);
20 typedef void (^_dyld_test_crash_handler_t)(task_t task);
21
22 struct _process {
23 _process();
24 ~_process();
25 void set_executable_path(const char* EP);
26 void set_args(const char** A);
27 void set_env(const char** E);
28 void set_stdout_handler(_dyld_test_reader_t SOH);
29 void set_stderr_handler(_dyld_test_reader_t SEH);
30 void set_exit_handler(_dyld_test_exit_handler_t EH);
31 void set_crash_handler(_dyld_test_crash_handler_t CH);
32 void set_launch_suspended(bool S);
33 void set_launch_arch(cpu_type_t A);
34 pid_t launch();
35 void *operator new(size_t size);
36 void operator delete(void *ptr);
37 private:
38 const char* executablePath;
39 const char** args;
40 const char** env;
41 _dyld_test_reader_t stdoutHandler;
42 _dyld_test_reader_t stderrHandler;
43 _dyld_test_crash_handler_t crashHandler;
44 _dyld_test_exit_handler_t exitHandler;
45 pid_t pid;
46 cpu_type_t arch;
47 bool suspended;
48 bool async;
49 };
50
51 #define STDERR_WRITER ^(int fd) { \
52 char buffer[16384]; \
53 ssize_t size = 0; \
54 do { \
55 size = read(fd, &buffer[0], 16384); \
56 buffer[size] = 0; \
57 fprintf(stderr, "%s", &buffer[0]); \
58 } while (size > 0); \
59 }
60
61 #define STDOUT_WRITER ^(int fd) { \
62 char buffer[16384]; \
63 ssize_t size = 0; \
64 do { \
65 size = read(fd, &buffer[0], 16384); \
66 buffer[size] = 0; \
67 fprintf(stdout, "%s", &buffer[0]); \
68 } while (size > 0); \
69 }
70
71 #endif /* __cplusplus */
72
73 #define PASS(...) _PASS(__FILE__,__LINE__,__VA_ARGS__)
74 #define FAIL(...) _FAIL(__FILE__,__LINE__,__VA_ARGS__)
75 #define LOG(...) _LOG(__FILE__,__LINE__,__VA_ARGS__)
76 #define TIMEOUT(seconds) _TIMEOUT(__FILE__,__LINE__,seconds)
77
78 // MARK: Private implementation details
79
80 #if __cplusplus
81 extern "C" {
82 #endif /* __cplusplus */
83 __attribute__((format(printf, 3, 4)))
84 __attribute__ ((noreturn))
85 extern void _PASS(const char* file, unsigned line, const char* format, ...);
86
87 __attribute__((format(printf, 3, 4)))
88 __attribute__ ((noreturn))
89 extern void _FAIL(const char* file, unsigned line, const char* format, ...);
90
91 __attribute__((format(printf, 3, 4)))
92 extern void _LOG(const char* file, unsigned line, const char* format, ...);
93
94 extern void _TIMEOUT(const char* file, unsigned line, uint64_t seconds);
95 #if __cplusplus
96 };
97 #endif /* __cplusplus */
98
99 #endif /* __DYLD_TEST_SUPPORT_H__ */