MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mmstest.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <ndb_global.h>
20 
21 #include <NdbOut.hpp>
22 #include "NdbThread.h"
23 #include <NdbMem.h>
24 #include <NdbMain.h>
25 
26 NDB_COMMAND(ndbmem, "ndbmem", "ndbmem", "Test the ndbmem functionality", 4096){
27 
28  ndbout << "Starting test of NdbMem" << endl;
29  ndbout << "=======================" << endl;
30 
31  ndbout << "Creating NdbMem" << endl;
32  NdbMem_Create();
33 
34 
35  ndbout << "NdbMem - test 1" << endl;
36  if (argc == 2){
37  int size1 = atoi(argv[1]);
38  ndbout << "Allocate and test "<<size1<<" bytes of memory" << endl;
39  char* mem1 = (char*)NdbMem_Allocate(size1);
40  ndbout << "mem1 = " << hex << (int)mem1 << endl;
41  if (mem1 != NULL){
42  char* p1;
43 
44  // Write to the memory allocated
45  p1 = mem1;
46  for(int i = 0; i < size1; i++){
47  *p1 = (char)(i%256);
48  p1++;
49  }
50 
51  // Read from the memory and check value
52  char read1;
53  char* pread1;
54  pread1 = mem1;
55  for(int i = 0; i < size1; i++){
56  read1 = *pread1;
57  //ndbout << i << "=" << read1 << endl;
58  if (read1 != (i%256))
59  ndbout << "Byte " << i << " was not correct, read1=" << read1 << endl;
60  pread1++;
61  }
62 
63  ndbout << "Freeing NdbMem" << endl;
64  NdbMem_Free(mem1);
65  }
66 
67  ndbout << "Destroying NdbMem" << endl;
68  NdbMem_Destroy();
69  }else{
70  ndbout << "Usage: ndbmem <size(bytes)>"<< endl;
71  }
72 
73  return NULL;
74 
75 }
76 
77 
78