[MOAB-dev] r3392 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Tue Dec 1 10:52:36 CST 2009


Author: kraftche
Date: 2009-12-01 10:52:36 -0600 (Tue, 01 Dec 2009)
New Revision: 3392

Modified:
   MOAB/trunk/BitTagServer.cpp
   MOAB/trunk/TagTest.cpp
Log:
Add test to check for bug caught by valgrind last night:  test basic
  bit tag functionality using a sufficiently large number of tag values
  so as to require multiple pages of tag values.
  
Fix another bug exposed by the above test.


Modified: MOAB/trunk/BitTagServer.cpp
===================================================================
--- MOAB/trunk/BitTagServer.cpp	2009-12-01 14:30:15 UTC (rev 3391)
+++ MOAB/trunk/BitTagServer.cpp	2009-12-01 16:52:36 UTC (rev 3392)
@@ -175,7 +175,7 @@
     }
     
     while (count) {
-      size_t pcount = std::min( (MBEntityID)per_page, count );
+      size_t pcount = std::min( (MBEntityID)(per_page - offset), count );
       if (pageList[type][page])
         pageList[type][page]->get_bits( offset, pcount, storedBitsPerEntity, data );
       else
@@ -210,7 +210,7 @@
       if (!pageList[type][page])
         pageList[type][page] = new BitPage( storedBitsPerEntity, def );
 
-      size_t pcount = std::min( (MBEntityID)per_page, count );
+      size_t pcount = std::min( (MBEntityID)(per_page - offset), count );
       pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, data );
       data += pcount;
       count -= pcount; 
@@ -236,7 +236,7 @@
     count = i->second - i->first + 1;
     
     while (count) {
-      size_t pcount = std::min( (MBEntityID)per_page, count );
+      size_t pcount = std::min( (MBEntityID)(per_page - offset), count );
       if (page < pageList[type].size() && pageList[type][page])
         pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, val );
       count -= pcount; 

Modified: MOAB/trunk/TagTest.cpp
===================================================================
--- MOAB/trunk/TagTest.cpp	2009-12-01 14:30:15 UTC (rev 3391)
+++ MOAB/trunk/TagTest.cpp	2009-12-01 16:52:36 UTC (rev 3392)
@@ -29,6 +29,7 @@
 void test_get_set_variable_length_dense();
 void test_get_set_variable_length_mesh();
 void test_get_ents_with_default_value();
+void test_bit_tag_big();
 
 void regression_one_entity_by_var_tag();
 void regression_tag_on_nonexistent_entity();
@@ -62,6 +63,7 @@
   failures += RUN_TEST( test_get_set_variable_length_dense );
   failures += RUN_TEST( test_get_set_variable_length_mesh );  
   failures += RUN_TEST( test_get_ents_with_default_value );  
+  failures += RUN_TEST( test_bit_tag_big );  
   failures += RUN_TEST( regression_one_entity_by_var_tag );
   failures += RUN_TEST( regression_tag_on_nonexistent_entity );
   
@@ -1675,6 +1677,48 @@
   CHECK_EQUAL( edge, result.back() );
 }
 
+void test_bit_tag_big()
+{
+  MBCore moab;
+  MBInterface &mb = moab;
+  MBErrorCode rval;
+  const size_t NUM_VTX = 30000;
+
+    // create a lot of vertices
+  std::vector<double> coords(3*NUM_VTX,0.0);
+  MBRange verts;
+  rval = mb.create_vertices( &coords[0], NUM_VTX, verts );
+  CHECK_ERR( rval );
+  CHECK_EQUAL( NUM_VTX, (size_t)verts.size() );
+
+    // create a bit tag
+  MBTag tag = test_create_tag( mb, "bb", 4, MB_TAG_BIT, MB_TYPE_BIT, 0);
+    // for each vertex, store last four bits of handle as tag value
+  std::vector<unsigned char> values(NUM_VTX);
+  std::vector<unsigned char>::iterator it = values.begin();
+  for (MBRange::iterator j = verts.begin(); j != verts.end(); ++j, ++it)
+    *it = (unsigned char)(*j & 0xF);
+  rval = mb.tag_set_data( tag, verts, &values[0] );
+  CHECK_ERR( rval );
+  
+    // retreive values
+  std::vector<unsigned char> values2( NUM_VTX, 0 );
+  rval = mb.tag_get_data( tag, verts, &values2[0] );
+  CHECK_EQUAL( values, values2 );
+  
+    // retreive entities
+  unsigned char value = 0xC;
+  MBRange expected, results;
+  for (MBRange::reverse_iterator j = verts.rbegin(); j != verts.rend(); ++j)
+    if ((unsigned char)(*j & 0xF) == value)
+      expected.insert(*j);
+  const void* vals[] = { &value };
+  rval = mb.get_entities_by_type_and_tag( 0, MBVERTEX, &tag, vals, 1, results );
+  CHECK_ERR(rval);
+  CHECK_EQUAL( expected, results );
+}
+
+
 void setup_mesh( MBInterface& mb )
 {
   MBRange vertex_handles;



More information about the moab-dev mailing list