lockid_test.cpp

00001 /*<std-header orig-src='shore'>
00002 
00003  $Id: lockid_test.cpp,v 1.5 2010/12/08 17:37:49 nhall Exp $
00004 
00005 SHORE -- Scalable Heterogeneous Object REpository
00006 
00007 Copyright (c) 1994-99 Computer Sciences Department, University of
00008                       Wisconsin -- Madison
00009 All Rights Reserved.
00010 
00011 Permission to use, copy, modify and distribute this software and its
00012 documentation is hereby granted, provided that both the copyright
00013 notice and this permission notice appear in all copies of the
00014 software, derivative works or modified versions, and any portions
00015 thereof, and that both notices appear in supporting documentation.
00016 
00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00021 
00022 This software was developed with support by the Advanced Research
00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00025 Further funding for this work was provided by DARPA through
00026 Rome Research Laboratory Contract No. F30602-97-2-0247.
00027 
00028 */
00029 
00030 #include "w_defines.h"
00031 
00032 /*  -- do not edit anything above this line --   </std-header>*/
00033 #include "sm_vas.h"
00034 
00035 // To get the extid_t:
00036 // #include "sm_s.h"
00037 
00038 vid_t    vol(1000);
00039 stid_t   stor(vol,900);
00040 lpid_t   page(stor, 50);
00041 rid_t    rec(page, 6);
00042 extid_t  extent;
00043 kvl_t    kvl;
00044 typedef lockid_t::user1_t user1_t;
00045 typedef lockid_t::user2_t user2_t;
00046 typedef lockid_t::user3_t user3_t;
00047 typedef lockid_t::user4_t user4_t;
00048 user1_t  u1(1);
00049 user2_t  u2(u1.u1, 2);
00050 user3_t  u3(u1.u1, u2.u2, 3);
00051 user4_t  u4(u1.u1, u2.u2, u3.u3, 4);
00052 
00053 
00054 void dump(lockid_t &l)
00055 {
00056     cout << "Lock: lspace " << l.lspace() << endl;
00057     cout << "\t vid()=" << l.vid() << endl;
00058 
00059     stid_t stor;
00060     l.extract_stid(stor);
00061     cout << "\t store()=" << l.store() << " stid_t=(" << stor << ")" << endl;
00062 
00063 
00064     lpid_t page;
00065     l.extract_lpid(page);
00066     cout << "\t page()=" << l.page() << " (lpid_t=" << page << ")" << endl;
00067 
00068     rid_t rec;
00069     l.extract_rid(rec);
00070     cout << "\t slot()=" << l.slot() << " (rid_t=" << rec << ")" << endl;
00071 
00072     extid_t extent;
00073     l.extract_extent(extent);
00074     cout << "\t extent()=" << l.extent() << " (extid_t=" << extent << ")" << endl;
00075 
00076 #if  defined(DEBUG_DESPERATE)
00077     // Removed b/c it's hash-based and makes the -out files differ
00078     // and I do want to compare...
00079     kvl_t kvl;
00080     l.extract_kvl(kvl);
00081     cout << "\t kvl" << "(" << kvl << ")" << endl;
00082 #endif
00083 
00084     user1_t u1;
00085     l.extract_user1(u1);
00086     cout << "\t u1()=" << l.u1() << " user1_t=(" << u1 << ")" << endl;
00087 
00088     user2_t u2;
00089     l.extract_user2(u2);
00090     cout << "\t u2()=" << l.u2() << " (user2_t=" << u2 << ")" << endl;
00091 
00092     user3_t u3;
00093     l.extract_user3(u3);
00094     cout << "\t u3()=" << l.u3() << " ( user3_t=" << u3 << ")" << endl;
00095 
00096     user4_t u4;
00097     l.extract_user4(u4);
00098     cout << "\t u4()=" << l.u4() << " ( user4_t=" << u4 << ")" << endl;
00099 
00100 #if defined(DEBUG_DESPERATE)
00101     // debugging
00102     {
00103     cout << "hex/dec dump - b" << endl;
00104     u_char *p = (u_char *)&l;
00105     for(int i=0; i < int(sizeof(l)); i++) {
00106         cout << i << ":" << ::hex << unsigned(*p)
00107             << "/" << ::dec << unsigned(*p) << " " ;
00108         p++;
00109     }
00110     cout << endl;
00111     }
00112     {
00113     cout << "hex/dec dump - s" << endl;
00114     uint2_t *p = (uint2_t *)&l;
00115     for(int i=0; i < int(sizeof(l)/sizeof(uint2_t)); i++) {
00116         cout << i << ":" << ::hex << unsigned(*p)
00117             << "/" << ::dec << unsigned(*p) << " ";
00118         p++;
00119     }
00120     cout << endl;
00121     }
00122     {
00123     cout << "hex/dec dump - w" << endl;
00124     u_int *p = (u_int *)&l;
00125     for(int i=0; i < int(sizeof(l)/sizeof(uint_t)); i++) {
00126         cout << i << ":" << ::hex << unsigned(*p)
00127             << "/" << ::dec << unsigned(*p) << " ";
00128         p++;
00129     }
00130     cout << endl;
00131     }
00132 #endif
00133 }
00134 
00135 int
00136 main(int /*argc*/, char* /*argv*/[])
00137 {
00138     extent.vol = vol;
00139     extent.ext = 33;
00140 
00141     const char     *keybuf = "Admiral Richard E. Byrd";
00142     const char     *elembuf= "Most of the confusion in the world comes from not knowing how little we need.";
00143     vec_t    key(keybuf, strlen(keybuf));
00144     vec_t    elem(elembuf, strlen(elembuf));
00145     kvl.set(stor, key, elem);
00146 
00147     cout << "Sources: " << endl
00148         <<  "\t vol " << vol << endl
00149         <<  "\t store " << stor << endl
00150         <<  "\t page " << page << endl
00151         <<  "\t rec " << rec << endl
00152         <<  "\t kvl " << kvl << endl
00153         <<  "\t extent " << extent << endl
00154         <<  "\t u1 " << u1 << endl
00155         <<  "\t u2 " << u2 << endl
00156         <<  "\t u3 " << u3 << endl
00157         <<  "\t u4 " << u4 << endl
00158         ;
00159 
00160     {
00161         lockid_t l(vol);
00162         cout << "{ Volume lock " << l << endl;
00163         dump(l);
00164         cout << "}" << endl;
00165     }
00166     {
00167         lockid_t l(stor);
00168         cout << "Store lock " << l << endl;
00169         dump(l);
00170         cout << "}" << endl;
00171     }
00172     {
00173         lockid_t l(page);
00174         cout << "Page lock " << l << endl;
00175         dump(l);
00176         cout << "}" << endl;
00177     }
00178     {
00179         lockid_t l(rec);
00180         cout << "Record lock " << l << endl;
00181         dump(l);
00182         cout << "}" << endl;
00183     }
00184     {
00185         lockid_t l(kvl);
00186         cout << "Kvl lock " << l << endl;
00187         cout << "}" << endl;
00188     }
00189     {
00190         lockid_t l(extent);
00191         cout << "Extent lock " << l << endl;
00192         dump(l);
00193         cout << "}" << endl;
00194     }
00195     {
00196         lockid_t l(u1);
00197         cout << "User 1 lock " << l << endl;
00198         dump(l);
00199         cout << "}" << endl;
00200     }
00201     {
00202         lockid_t l(u2);
00203         cout << "User 2 lock " << l << endl;
00204         dump(l);
00205         cout << "}" << endl;
00206     }
00207     {
00208         lockid_t l(u3);
00209         cout << "User 3 lock " << l << endl;
00210         dump(l);
00211         cout << "}" << endl;
00212     }
00213     {
00214         lockid_t l(u4);
00215         cout << "User 4 lock " << l << endl;
00216         dump(l);
00217         cout << "}" << endl;
00218     }
00219 }
00220 

Generated on Thu Dec 9 08:42:26 2010 for Shore Storage Manager by  doxygen 1.4.7