Revert "Drop requirement for user code to call CBase_foo::pup(p)"
[charm.git] / tests / charm++ / megatest / inherit.C
1 #include "inherit.h"
2 #include <stdlib.h>
3
4
5 readonly<CProxy_inhCoord> coordinator;
6 readonly<CkGroupID> id_gp,id_g1,id_g2,id_g3,id_g13;
7 readonly<CkArrayID> id_ap,id_a1,id_a2,id_a3,id_a13;
8
9 void inherit_moduleinit(void)
10 {
11   coordinator=CProxy_inhCoord::ckNew();
12   id_gp=CProxy_gp::ckNew(); 
13   id_g1=CProxy_g1::ckNew(); 
14   id_g2=CProxy_g2::ckNew(); 
15   id_g3=CProxy_g3::ckNew(); 
16   id_g13=CProxy_g13::ckNew();
17   id_ap=CProxy_ap::ckNew(1); 
18   id_a1=CProxy_a1::ckNew(1); 
19   id_a2=CProxy_a2::ckNew(1); 
20   id_a3=CProxy_a3::ckNew(1); 
21   id_a13=CProxy_a13::ckNew(1);
22 }
23
24 void inherit_init(void) 
25 {
26   ((CProxy_inhCoord)coordinator).startTest();
27 }
28
29 /*This integer lets us tell which method we called,
30 so if it's not the method that executes we'll be able to tell.
31 */
32 enum {
33   typeChare=1000,
34   typeGroup=2000,
35   typeArray=4000,
36   genParent= 100,
37   genChild1= 300,
38   genChild2= 700,
39   genChild3= 900,
40   genChild13=390,
41   methParent=  1,
42   methLex   =  5,
43   methInh   =  7
44 };
45
46 class inhCoord : public CBase_inhCoord {
47   int sendCount;
48   int doneCount;
49   
50   //Chare tests:
51   void as_cp(CProxy_cp &p,int gen) {
52     p.parent(typeChare+genParent+methParent);sendCount++;
53     p.inhLexical(typeChare+genParent+methLex);sendCount++;
54     p.inhVirtual(typeChare+gen+methInh);sendCount++;  
55   }
56   void as_c1(CProxy_c1 &p,int gen) {
57     as_cp(p,gen);
58     p.parent(typeChare+genParent+methParent);sendCount++;
59     p.inhLexical(typeChare+genChild1+methLex);sendCount++;
60     p.inhVirtual(typeChare+gen+methInh);sendCount++;  
61   }
62   void as_c2(CProxy_c2 &p,int gen) {
63     as_c1(p,gen);
64     p.parent(typeChare+genParent+methParent);sendCount++;
65     p.inhLexical(typeChare+genChild2+methLex);sendCount++;
66     p.inhVirtual(typeChare+gen+methInh);sendCount++;  
67   }
68   void as_c3(CProxy_c3 &p,int gen) {
69     as_cp(p,gen);    
70     p.parent(typeChare+genParent+methParent);sendCount++;
71     p.inhLexical(typeChare+genChild3+methLex);sendCount++;
72     p.inhVirtual(typeChare+gen+methInh);sendCount++;  
73   }
74   void as_c13(CProxy_c13 &p,int gen) {
75     as_c1(p,gen); 
76     as_c3(p,gen); 
77     p.inhLexical(typeChare+genChild13+methLex);sendCount++;
78     p.inhVirtual(typeChare+gen+methInh);sendCount++;  
79   }
80
81   //Group tests: (copy-and-paste programming at its worst!)
82   int groupDest;
83   void as_gp(CProxy_gp &p,int gen) {
84     p[groupDest].parent(typeGroup+genParent+methParent);sendCount++;
85     p[groupDest].inhLexical(typeGroup+genParent+methLex);sendCount++;
86     p[groupDest].inhVirtual(typeGroup+gen+methInh);sendCount++;  
87   }
88   void as_g1(CProxy_g1 &p,int gen) {
89     as_gp(p,gen);
90     p[groupDest].parent(typeGroup+genParent+methParent);sendCount++;
91     p[groupDest].inhLexical(typeGroup+genChild1+methLex);sendCount++;
92     p[groupDest].inhVirtual(typeGroup+gen+methInh);sendCount++;  
93   }
94   void as_g2(CProxy_g2 &p,int gen) {
95     as_g1(p,gen);
96     p[groupDest].parent(typeGroup+genParent+methParent);sendCount++;
97     p[groupDest].inhLexical(typeGroup+genChild2+methLex);sendCount++;
98     p[groupDest].inhVirtual(typeGroup+gen+methInh);sendCount++;  
99   }
100   void as_g3(CProxy_g3 &p,int gen) {
101     as_gp(p,gen);    
102     p[groupDest].parent(typeGroup+genParent+methParent);sendCount++;
103     p[groupDest].inhLexical(typeGroup+genChild3+methLex);sendCount++;
104     p[groupDest].inhVirtual(typeGroup+gen+methInh);sendCount++;  
105   }
106   void as_g13(CProxy_g13 &p,int gen) {
107     as_g1(p,gen); 
108     as_g3(p,gen); 
109     p[groupDest].inhLexical(typeGroup+genChild13+methLex);sendCount++;
110     p[groupDest].inhVirtual(typeGroup+gen+methInh);sendCount++;  
111   }
112
113   //Array tests:
114   void as_ap(CProxy_ap &p,int gen) {
115     p[0].parent(typeArray+genParent+methParent);sendCount++;
116     p[0].inhLexical(typeArray+genParent+methLex);sendCount++;
117     p[0].inhVirtual(typeArray+gen+methInh);sendCount++;  
118   }
119   void as_a1(CProxy_a1 &p,int gen) {
120     as_ap(p,gen);
121     p[0].parent(typeArray+genParent+methParent);sendCount++;
122     p[0].inhLexical(typeArray+genChild1+methLex);sendCount++;
123     p[0].inhVirtual(typeArray+gen+methInh);sendCount++;  
124   }
125   void as_a2(CProxy_a2 &p,int gen) {
126     as_a1(p,gen);
127     p[0].parent(typeArray+genParent+methParent);sendCount++;
128     p[0].inhLexical(typeArray+genChild2+methLex);sendCount++;
129     p[0].inhVirtual(typeArray+gen+methInh);sendCount++;  
130   }
131   void as_a3(CProxy_a3 &p,int gen) {
132     as_ap(p,gen);    
133     p[0].parent(typeArray+genParent+methParent);sendCount++;
134     p[0].inhLexical(typeArray+genChild3+methLex);sendCount++;
135     p[0].inhVirtual(typeArray+gen+methInh);sendCount++;  
136   }
137   void as_a13(CProxy_a13 &p,int gen) {
138     as_a1(p,gen); 
139     as_a3(p,gen); 
140     p[0].inhLexical(typeArray+genChild13+methLex);sendCount++;
141     p[0].inhVirtual(typeArray+gen+methInh);sendCount++;  
142   }
143   
144 public:
145   inhCoord() { groupDest=0; }
146   void startTest(void) {
147     sendCount=0;
148     doneCount=0;  
149     groupDest=(1+groupDest)%(CkNumPes());
150     
151     {CProxy_cp p=CProxy_cp::ckNew(); as_cp(p,genParent);}
152     {CProxy_c1 p=CProxy_c1::ckNew(); as_c1(p,genChild1);}
153     {CProxy_c2 p=CProxy_c2::ckNew(); as_c2(p,genChild2);}
154     {CProxy_c3 p=CProxy_c3::ckNew(); as_c3(p,genChild3);}
155     {CProxy_c13 p=CProxy_c13::ckNew(); as_c13(p,genChild13);}
156
157     {CProxy_gp p(id_gp); as_gp(p,genParent);}
158     {CProxy_g1 p(id_g1); as_g1(p,genChild1);}
159     {CProxy_g2 p(id_g2); as_g2(p,genChild2);}
160     {CProxy_g3 p(id_g3); as_g3(p,genChild3);}
161     {CProxy_g13 p(id_g13); as_g13(p,genChild13);}
162
163     {CProxy_ap p(id_ap); as_ap(p,genParent);}
164     {CProxy_a1 p(id_a1); as_a1(p,genChild1);}
165     {CProxy_a2 p(id_a2); as_a2(p,genChild2);}
166     {CProxy_a3 p(id_a3); as_a3(p,genChild3);}
167     {CProxy_a13 p(id_a13); as_a13(p,genChild13);}
168   }
169   void done(void) {
170     if (++doneCount==sendCount)
171       megatest_finish();
172   }
173 };
174
175 /************ Called if an incorrect method is executed *********/
176 void badMeth(const char *cls,const char *meth,int t)
177 {
178   CkError("ERROR! Incorrect method %s::%s called instead of %d!\n",
179           cls,meth,t);
180   CkAbort("Incorrect method executed");
181 }
182
183 /************ Class definitions ***********/
184 //Declares the constructor and normal methods
185 #define BASIC(className,parentName,type,gen) \
186 public: \
187         className() : parentName() {} \
188         className(CkMigrateMessage *m) : parentName(m) {} \
189         void inhLexical(int t) { \
190                 if (t!=type+gen+methLex) badMeth(#className,"inhLexical",t); \
191                 ((CProxy_inhCoord)coordinator).done();\
192         }\
193         virtual void inhVirtual(int t) { \
194                 if (t!=type+gen+methInh) badMeth(#className,"inhVirtual",t); \
195                 ((CProxy_inhCoord)coordinator).done();\
196         }\
197         virtual void pup(PUP::er &p) {\
198                 parentName::pup(p);\
199         }\
200
201 //Declares the parent method
202 #define PARENT(className,type) \
203 public: \
204         void parent(int t) { \
205                 if (t!=type+genParent+methParent) badMeth(#className,"parent",t); \
206                 ((CProxy_inhCoord)coordinator).done();\
207         }\
208
209 //Declares a complete child class
210 #define CHILD(className,type,gen) \
211 class className : public CBase_##className { \
212         BASIC(className,CBase_##className,type,gen) \
213 };\
214
215 //----- chares ------
216 class cp : public CBase_cp { 
217   BASIC(cp,CBase_cp,typeChare,genParent) 
218   PARENT(cp,typeChare) 
219 };
220 CHILD(c1,typeChare,genChild1)
221 CHILD(c2,typeChare,genChild2)
222 CHILD(c3,typeChare,genChild3)
223 CHILD(c13,typeChare,genChild13)
224
225 //------ groups ------
226 class gp : public CBase_gp { 
227   BASIC(gp,CBase_gp,typeGroup,genParent) 
228   PARENT(gp,typeGroup) 
229 };
230 CHILD(g1,typeGroup,genChild1)
231 CHILD(g2,typeGroup,genChild2)
232 CHILD(g3,typeGroup,genChild3)
233 CHILD(g13,typeGroup,genChild13)
234
235 //------ arrays ------
236 class ap : public CBase_ap { 
237   BASIC(ap,CBase_ap,typeArray,genParent) 
238   PARENT(ap,typeArray) 
239 };
240 CHILD(a1,typeArray,genChild1)
241 CHILD(a2,typeArray,genChild2)
242 CHILD(a3,typeArray,genChild3)
243 CHILD(a13,typeArray,genChild13)
244
245 MEGATEST_REGISTER_TEST(inherit,"olawlor",0)
246 #include "inherit.def.h"
247
248