1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#ifndef TAO_TESTCOMBINEDTHREADS_H
#define TAO_TESTCOMBINEDTHREADS_H
//============================================================================
/**
* @file TestCombinedThreads.h
*
* $Id$
*
* A small test framework library for VxWorks
*
* @author Chad Elliott (elliott_c@ociweb.com)
*
*/
//============================================================================
// *******************************************************************
// Include files.
// *******************************************************************
#include "ace/OS.h"
#include "ace/Auto_Ptr.h"
#include "ace/SString.h"
// *******************************************************************
// Typedefs, forward declarations and defines
// *******************************************************************
typedef int (*TEST_MAIN_TYPE_FUNC)(int, char**);
#define TEST_MAIN_FUNC_DECLARE(X) int X(int argc, char** argv)
#ifndef FULL_PATH
# define FULL_PATH "."
#endif
// *******************************************************************
// Class declaration.
// *******************************************************************
/**
* @class TAO_TestCombinedThreads
*
* @brief Test Framework for VxWorks
*
* This class provides run_test type functionality for VxWorks
* modules. This class is used by c++ files generated by the
* perltest2cpp.pl and vxworks_modify.pl perl scripts.
*/
class TAO_TestCombinedThreads
{
public:
/// func is a function that looks like main(int argc, char** argv).
/// args are the arguments that will be passed to main, it must be NULL
/// termintated.
TAO_TestCombinedThreads (TEST_MAIN_TYPE_FUNC func,
char** args);
TAO_TestCombinedThreads (const TAO_TestCombinedThreads& rhs);
virtual ~TAO_TestCombinedThreads (void);
TAO_TestCombinedThreads& operator= (const TAO_TestCombinedThreads& rhs);
/// spawn a thread and call the main type function.
/// if timeout is == 0, then do not provide a timeout value
/// for any orb->run() calls that were hacked by the vxworks_modify.pl script
virtual int run (unsigned int timeout = 0);
/// Wait for all threads
/// if timeout is == 0, wait forever.
int wait (unsigned int seconds = 0);
/// Wait for the existance of the specified file for the givent amount
/// of seconds
static int waitForFileTimed (const char* file,
unsigned int seconds);
/// Return the orb id associated with the current thread id
static const char* getORBId (void);
/// Get the timeout value for the current thread id
static ACE_Time_Value* getTimeout (void);
/// Get a random port base between 0 and 32767
static int getRandomPortBase (void);
/// Wait on the specified thread name
static int thr_join (ACE_thread_t thr_handle,
ACE_thread_t *thr_id,
void** status = 0);
/// Wait on the specified thread handle
static int thr_join (ACE_hthread_t thr_handle,
void** status = 0);
/// Returns a random string based on the starting point
static ACE_CString getRandomString (const char* base);
protected:
/// This constructor is functionaly the same as the
/// public constructor. It has an extra parameter which is
/// used by the TestServices class.
TAO_TestCombinedThreads (TEST_MAIN_TYPE_FUNC func,
char** args,
int namingServiceHack);
private:
struct TestArgs
{
TEST_MAIN_TYPE_FUNC func_;
int argc_;
char** argv_;
ACE_Time_Value timeout_;
};
/// Initialize the object
void initialize (TEST_MAIN_TYPE_FUNC func = 0,
char** args = 0);
/// Copy an argv array
int copyArgv (char** argv,
char**& dest);
/// Delete the copied arguments.
void deleteArguments (char** args);
/// Static function called by the thread manager
static void* spawned (void* args);
/// Set the timeout for the current thread
static void setTimeout (ACE_Time_Value timeout);
void addNamingServiceTimeout (unsigned int timeout);
/// Associates the given orb id with the current thread id
static void associateORB (const char* orbId);
/// Disassociates the current thread id with its associated orb id
static void disassociateORB (void);
/// Allocate the ORB id map
static void allocateORBIdMap (void);
/// Used by the object manager to delete the ORB id map
static void cleanORBIdMap (void* object, void* params);
/// Allocate the time value map
static void allocateTimeMap (void);
/// Used by the object manager to delete the time value map
static void cleanTimeMap (void* object, void* params);
/// Delete the thread manager
static void destroyThreadManager (void* object, void* params);
TestArgs testArgs_;
auto_ptr<ACE_Time_Value> timeout_;
int namingServiceHack_;
char** args_;
};
#endif /* TAO_TESTCOMBINEDTHREADS_H */
|