source: ThirdParty/mpqc_open/src/lib/util/ref/reftest.cc@ 398fcd

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 398fcd was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 6.0 KB
Line 
1//
2// reftest.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#include <util/ref/ref.h>
29#include <util/ref/reftestx.h>
30
31#if HAVE_PTHREAD==1 && REF_USE_LOCKS==1
32#include <pthread.h>
33#endif
34
35using namespace std;
36
37using sc::Y;
38using sc::X;
39using sc::Ref;
40
41void
42test1()
43{
44 Y *y1p = new Y;
45 Y *y2p = new Y;
46 X *x1p = y1p;
47 X *x2p = y2p;
48 void *vy1p = (void*) y1p;
49 void *vy2p = (void*) y2p;
50 void *vx1p = (void*) x1p;
51 void *vx2p = (void*) x2p;
52 Ref<Y> y1 = y1p;
53 Ref<Y> y2 = y2p;
54 cout << "X::nx after Ref<Y> assignment: " << X::nx << "(2)" << endl;
55 cout << "y1->nreference() after Ref<Y> assignment: "
56 << y1->nreference() << "(1)" << endl;
57 Ref<X> x1(y1);
58 Ref<X> x2(y2);
59 cout << "X::nx after Ref<X> assignment: " << X::nx << "(2)" << endl;
60 cout << "y1->nreference() after Ref<X> assignment: "
61 << y1->nreference() << "(2)" << endl;
62 x1 = y1;
63 x2 = y2;
64 Ref<Y> yb1, yb2;
65 yb1 << x1;
66 yb2 << x2;
67
68 cout << "x1 = " << (void*)x1.pointer() << "(" << vx1p << ")" << endl;
69 cout << "x2 = " << (void*)x2.pointer() << "(" << vx2p << ")" << endl;
70 cout << "y1 = " << (void*)y1.pointer() << "(" << vy1p << ")" << endl;
71 cout << "y2 = " << (void*)y2.pointer() << "(" << vy2p << ")" << endl;
72 cout << "yb1 = " << (void*)yb1.pointer()
73 << "(" << (void*)y1.pointer() << ")" << endl;
74 cout << "yb2 = " << (void*)yb2.pointer()
75 << "(" << (void*)y2.pointer() << ")" << endl;
76}
77
78void
79test2()
80{
81 Ref<Y> y1 = new Y;
82 Ref<Y> y2 = new Y;
83 cout << "X::nx after Ref<Y> assignment: " << X::nx << "(2)" << endl;
84 cout << "y1->nreference() after Ref<Y> assignment: "
85 << y1->nreference() << "(1)" << endl;
86 Ref<X> x1(y1);
87 Ref<X> x2(y2);
88 cout << "X::nx after Ref<X> assignment: " << X::nx << "(2)" << endl;
89 cout << "y1->nreference() after Ref<X> assignment: "
90 << y1->nreference() << "(2)" << endl;
91 x1 = y1;
92 x2 = y2;
93 if (x1 > x2) {
94 Ref<X> tmp = x1;
95 x1 = x2;
96 x2 = tmp;
97 y1 << x1;
98 y2 << x2;
99 }
100
101 cout << "x1 == x1: " << (x1 == x1) << "(1)";
102 cout << " x1 == x2: " << (x1 == x2) << "(0)";
103 cout << " x1 == y1: " << (x1 == y1) << "(1)";
104 cout << " x1 == y2: " << (x1 == y2) << "(0)" << endl;
105 cout << "x1 != x1: " << (x1 != x1) << "(0)";
106 cout << " x1 != x2: " << (x1 != x2) << "(1)";
107 cout << " x1 != y1: " << (x1 != y1) << "(0)";
108 cout << " x1 != y2: " << (x1 != y2) << "(1)" << endl;
109 cout << "x1 < x1: " << (x1 < x1) << "(0)";
110 cout << " x1 < x2: " << (x1 < x2) << "(1)";
111 cout << " x1 < y1: " << (x1 < y1) << "(0)";
112 cout << " x1 < y2: " << (x1 < y2) << "(1)" << endl;
113 cout << "x1 <= x1: " << (x1 <= x1) << "(1)";
114 cout << " x1 <= x2: " << (x1 <= x2) << "(1)";
115 cout << " x1 <= y1: " << (x1 <= y1) << "(1)";
116 cout << " x1 <= y2: " << (x1 <= y2) << "(1)" << endl;
117 cout << "x1 > x1: " << (x1 > x1) << "(0)";
118 cout << " x1 > x2: " << (x1 > x2) << "(0)";
119 cout << " x1 > y1: " << (x1 > y1) << "(0)";
120 cout << " x1 > y2: " << (x1 > y2) << "(0)" << endl;
121 cout << "x1 >= x1: " << (x1 >= x1) << "(1)";
122 cout << " x1 >= x2: " << (x1 >= x2) << "(0)";
123 cout << " x1 >= y1: " << (x1 >= y1) << "(1)";
124 cout << " x1 >= y2: " << (x1 >= y2) << "(0)" << endl;
125}
126
127void
128test3()
129{
130 cout << "nx = " << X::nx << "(0) (outer scope on entry)" << endl;
131 {
132 Ref<X> x1 = new X;
133 Ref<X> x2 = new X;
134 X *x2p = x2.pointer();
135 cout << "nx = " << X::nx << "(2) (inner scope after alloc)" << endl;
136#if REF_MANAGE
137 x2->unmanage();
138#endif
139
140 x2 = x1.pointer();
141 if (x1 != x1) abort();
142 if (x2 != x1) abort();
143#if REF_MANAGE
144 // x2 was unmanaged, so delete it manually
145 delete x2p;
146#endif
147 cout << "nx = " << X::nx << "(1) (inner scope after assign)" << endl;
148
149
150 int i;
151 for (i=1000000; i; i--) {
152 x1->reference();
153 }
154 for (i=1000000; i; i--) {
155 x1->dereference();
156 }
157 for (i=1000000; i; i--) {
158 Ref<X> y = x1;
159 }
160
161 cout << "nx = " << X::nx << "(1) (inner scope)" << endl;
162 }
163
164 cout << "nx = " << X::nx << "(0) (outer scope on exit)" << endl;
165}
166
167#if HAVE_PTHREAD==1 && REF_USE_LOCKS==1
168static Ref<X> sx1, sx2;
169void *
170test4_run(void *)
171{
172 for (int i=0; i<20000; i++) {
173 Ref<X> x1 = sx1;
174 Ref<X> x2 = sx2;
175 x1 = x2;
176 x1 = x2;
177 x1 = x1;
178 x1 = 0;
179 }
180 return 0;
181}
182void
183test4()
184{
185 cout << "test4: running pthread tests" << endl;
186 sx1 = new X;
187 sx2 = new X;
188 sx1->use_locks(true);
189 sx2->use_locks(true);
190 for (int iter=0; iter<10; iter++) {
191 const int nthread = 2;
192 pthread_t id[4];
193 for (int i=0; i<nthread; i++) {
194 pthread_create(&id[i],0,test4_run,0);
195 }
196 for (int i=0; i<nthread; i++) {
197 void *v;
198 pthread_join(id[i],&v);
199 }
200 }
201 sx1 = 0;
202 sx2 = 0;
203}
204#else
205void test4() {}
206#endif
207
208int
209main()
210{
211 cout << "X::nx before test1: " << X::nx << "(0)" << endl;
212 test1();
213 cout << "X::nx before test2: " << X::nx << "(0)" << endl;
214 test2();
215 cout << "X::nx before test3: " << X::nx << "(0)" << endl;
216 test3();
217 cout << "X::nx before test4: " << X::nx << "(0)" << endl;
218 test4();
219
220 cout << "X::nx before exit: " << X::nx << "(0)" << endl;
221
222 return 0;
223}
224
225/////////////////////////////////////////////////////////////////////////////
226
227// Local Variables:
228// mode: c++
229// c-file-style: "CLJ"
230// End:
Note: See TracBrowser for help on using the repository browser.