[GRASS-SVN] r51793 - in grass/trunk/lib/raster3d: . test

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 26 10:47:46 EDT 2012


Author: huhabla
Date: 2012-05-26 07:47:46 -0700 (Sat, 26 May 2012)
New Revision: 51793

Added:
   grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c
Modified:
   grass/trunk/lib/raster3d/rle.c
   grass/trunk/lib/raster3d/test/test_g3d_lib.h
   grass/trunk/lib/raster3d/test/test_main.c
   grass/trunk/lib/raster3d/test/test_put_get_value.c
Log:
New test for large files that causes a segmentation fault in the rast3d library.
The rle decoding and encoding is wrong for large numbers (>129032), hints are added to the sources.


Modified: grass/trunk/lib/raster3d/rle.c
===================================================================
--- grass/trunk/lib/raster3d/rle.c	2012-05-26 14:46:33 UTC (rev 51792)
+++ grass/trunk/lib/raster3d/rle.c	2012-05-26 14:47:46 UTC (rev 51793)
@@ -64,8 +64,12 @@
 	return dst;
     }
 
-    /* length = 254 ^ c + 254 * b + a; b, a < 254 */
+    /* TODO implement a corrected version for larger strings */
+    /* This code is simply wrong, it works only for c == 2, critical number for wrong computation is 254*254*2 = 129032 */
+    /* CORRECT: length = 254 ^ 2 + 254 * b + a; b, a < 254 */
 
+    /* WRONG: length = 254 ^ c + 254 * b + a; b, a < 254 */
+
     lPrime = length;
     while ((lPrime = lPrime / 254) != 0)
 	G_RLE_OUTPUT_CODE(254);
@@ -75,6 +79,8 @@
     G_RLE_OUTPUT_CODE(length / 254);
     G_RLE_OUTPUT_CODE(length % 254);
 
+    /* Next should be: length = 254 ^ 3 + 254 ^ 2 * c + 254 * b + a; c, b, a < 254 */
+
     return dst;
 }
 
@@ -105,8 +111,12 @@
 	return src;
     }
 
-    /* length = 254 ^ c + 254 * b + a; b, a < 254 */
+    /* TODO implement a corrected version for larger strings */
+    /* This code is simply wrong, it works only for c == 2, critical number for wrong computation is 254*254*2 = 129032 */
+    /* CORRECT: length = 254 ^ 2 + 254 * b + a; b, a < 254 */
 
+    /* WRONG: length = 254 ^ c + 254 * b + a; b, a < 254 */
+
     *length = G_254_SQUARE;
     while (G_RLE_INPUT_CODE(&code) == 254)
 	*length *= 254;
@@ -115,6 +125,8 @@
     G_RLE_INPUT_CODE(&code);
     *length += code;
 
+    /* Next should be: length = 254 ^ 3 + 254 ^ 2 * c + 254 * b + a; c, b, a < 254 */
+
     return src;
 }
 

Modified: grass/trunk/lib/raster3d/test/test_g3d_lib.h
===================================================================
--- grass/trunk/lib/raster3d/test/test_g3d_lib.h	2012-05-26 14:46:33 UTC (rev 51792)
+++ grass/trunk/lib/raster3d/test/test_g3d_lib.h	2012-05-26 14:47:46 UTC (rev 51793)
@@ -25,5 +25,6 @@
 double compute_time_difference(struct timeval start, struct timeval end);
 int unit_test_coordinate_transform(void);
 int unit_test_put_get_value(void);
+int unit_test_put_get_value_large_file(int depths, int rows, int cols);
 
 #endif

Modified: grass/trunk/lib/raster3d/test/test_main.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_main.c	2012-05-26 14:46:33 UTC (rev 51792)
+++ grass/trunk/lib/raster3d/test/test_main.c	2012-05-26 14:47:46 UTC (rev 51793)
@@ -21,7 +21,7 @@
 
 /*- Parameters and global variables -----------------------------------------*/
 typedef struct {
-    struct Option *unit, *integration;
+    struct Option *unit, *integration, *depths, *rows, *cols;
     struct Flag *full, *testunit, *testint;
 } paramType;
 
@@ -39,7 +39,7 @@
     param.unit->key = "unit";
     param.unit->type = TYPE_STRING;
     param.unit->required = NO;
-    param.unit->options = "coord,putget";
+    param.unit->options = "coord,putget,large";
     param.unit->description = _("Choose the unit tests to run");
 
     param.integration = G_define_option();
@@ -49,6 +49,27 @@
     param.integration->options = "";
     param.integration->description = _("Choose the integration tests to run");
 
+    param.depths = G_define_option();
+    param.depths->key = "depths";
+    param.depths->type = TYPE_INTEGER;
+    param.depths->required = NO;
+    param.depths->answer = "20";
+    param.depths->description = _("The number of depths to be used for the large file put value test");
+
+    param.rows = G_define_option();
+    param.rows->key = "rows";
+    param.rows->type = TYPE_INTEGER;
+    param.rows->required = NO;
+    param.rows->answer = "5400";
+    param.rows->description = _("The number of rows to be used for the large file put value test");
+
+    param.cols = G_define_option();
+    param.cols->key = "cols";
+    param.cols->type = TYPE_INTEGER;
+    param.cols->required = NO;
+    param.cols->answer = "10800";
+    param.cols->description = _("The number of columns to be used for the large file put value test");
+
     param.testunit = G_define_flag();
     param.testunit->key = 'u';
     param.testunit->description = _("Run all unit tests");
@@ -70,6 +91,7 @@
 int main(int argc, char *argv[]) {
     struct GModule *module;
     int returnstat = 0, i;
+    int depths, rows, cols;
 
     /* Initialize GRASS */
     G_gisinit(argv[0]);
@@ -83,7 +105,11 @@
 
     if (G_parser(argc, argv))
         exit(EXIT_FAILURE);
-    
+ 
+    depths = atoi(param.depths->answer);
+    rows   = atoi(param.rows->answer);
+    cols   = atoi(param.cols->answer);
+   
     /* Initiate the defaults for testing */
     Rast3d_init_defaults();
 
@@ -91,6 +117,7 @@
     if (param.testunit->answer || param.full->answer) {
         returnstat += unit_test_coordinate_transform();
         returnstat += unit_test_put_get_value();
+        returnstat += unit_test_put_get_value_large_file(depths, rows, cols);
     }
 
     /*Run the integration tests */
@@ -109,6 +136,8 @@
                         returnstat += unit_test_coordinate_transform();
                     if (strcmp(param.unit->answers[i], "putget") == 0)
                         returnstat += unit_test_put_get_value();
+                    if (strcmp(param.unit->answers[i], "large") == 0)
+                        returnstat += unit_test_put_get_value_large_file(depths, rows, cols);
                     
                     i++;
                 }
@@ -123,7 +152,6 @@
 
         }
     }
-
     
     if (returnstat != 0)
         G_warning("Errors detected while testing the g3d lib");

Modified: grass/trunk/lib/raster3d/test/test_put_get_value.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_put_get_value.c	2012-05-26 14:46:33 UTC (rev 51792)
+++ grass/trunk/lib/raster3d/test/test_put_get_value.c	2012-05-26 14:47:46 UTC (rev 51793)
@@ -19,7 +19,6 @@
 #include "test_g3d_lib.h"
 #include "grass/interpf.h"
 
-static int test_large_file(void);
 static int test_put_get_value_dcell(void);
 static int test_put_get_value_fcell(void);
 static int test_put_get_value_resampling(void);
@@ -32,7 +31,7 @@
 /* *************************************************************** */
 /* Perfrome the coordinate transformation tests ****************** */
 /* *************************************************************** */
-int unit_test_put_get_value(void)
+int unit_test_put_get_value()
 {
     int sum = 0;
 
@@ -41,7 +40,6 @@
     sum += test_put_get_value_dcell();
     sum += test_put_get_value_fcell();
     sum += test_put_get_value_resampling();
-    sum += test_large_file();
 
 
     if (sum > 0)
@@ -555,61 +553,3 @@
     
     return sum;
 }
-
-
-/* *************************************************************** */
-
-int test_large_file(void)
-{
-     int sum = 0; 
-    int x, y, z;
-    FCELL value;
-    FCELL value_ref;
-    
-    G_message("Testing FCELL put function for large files");
-    
-    RASTER3D_Region region;
-    RASTER3D_Map *map = NULL;
-    
-    /* We need to set up a specific region for the new g3d map.
-     * First we safe the default region. */
-    Rast3d_get_window(&region);
-    
-    region.bottom = 0.0;
-    region.top = 1000;
-    region.south = 1000;
-    region.north = 8500;
-    region.west = 5000;
-    region.east = 10000;
-    region.rows = 100;
-    region.cols = 100;
-    region.depths = 100;
-        
-    Rast3d_adjust_region(&region);
-        
-    map = Rast3d_open_new_opt_tile_size("test_put_get_value_fcell_large", RASTER3D_USE_CACHE_XY, &region, FCELL_TYPE, 1);
-    
-    /* The window is the same as the map region ... of course */
-    Rast3d_set_window_map(map, &region);
-    
-    for(z = 0; z < region.depths; z++) {
-	G_percent(z, region.depths, 1);
-        for(y = 0; y < region.rows; y++) {
-            for(x = 0; x < region.cols; x++) {
-                /* Add cols, rows and depths and put this in the map */
-                value = x + y + z;
-                Rast3d_put_value(map, x, y, z, &value, FCELL_TYPE);
-            }
-        }
-    }
-    G_percent(1, 1, 1);
-    /* Write everything to the disk */
-    Rast3d_flush_all_tiles(map);
-    Rast3d_close(map);
-    
-    //G_remove("grid3", "test_put_get_value_dcell_large");
-    
-    return sum;
-}
-
-

Added: grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c
===================================================================
--- grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c	                        (rev 0)
+++ grass/trunk/lib/raster3d/test/test_put_get_value_large_file.c	2012-05-26 14:47:46 UTC (rev 51793)
@@ -0,0 +1,120 @@
+
+/*****************************************************************************
+*
+* MODULE:       Grass g3d Library
+* AUTHOR(S):    Soeren Gebbert, Braunschweig (GER) Jun 2011
+* 		        soerengebbert <at> googlemail <dot> com
+*               
+* PURPOSE:	Unit and Integration tests
+*
+* COPYRIGHT:    (C) 2000 by the GRASS Development Team
+*
+*               This program is free software under the GNU General Public
+*               License (>=v2). Read the file COPYING that comes with GRASS
+*               for details.
+*
+*****************************************************************************/
+#include <stdlib.h>
+#include <string.h>
+#include "test_g3d_lib.h"
+#include "grass/interpf.h"
+
+static int test_large_file(int depths, int rows, int cols);
+
+/* *************************************************************** */
+/* Perfrome the coordinate transformation tests ****************** */
+/* *************************************************************** */
+int unit_test_put_get_value_large_file(int depths, int rows, int cols)
+{
+    int sum = 0;
+
+    G_message(_("\n++ Running g3d put/get value large file unit tests ++"));
+
+    sum += test_large_file(depths, rows, cols);
+
+
+    if (sum > 0)
+	G_warning(_("\n-- g3d put/get value large file unit tests failure --"));
+    else
+	G_message(_("\n-- g3d put/get value large file unit tests finished successfully --"));
+
+    return sum;
+}
+
+/* *************************************************************** */
+
+int test_large_file(int depths, int rows, int cols)
+{
+    int sum = 0; 
+    int x, y, z;
+    DCELL value;
+    
+    G_message("Testing DCELL put function for large files");
+    
+    RASTER3D_Region region;
+    RASTER3D_Map *map = NULL;
+    
+    /* We need to set up a specific region for the new g3d map.
+     * First we safe the default region. */
+    Rast3d_get_window(&region);
+    
+    region.bottom = -365.5;
+    region.top = 365.5;
+    region.south = -90;
+    region.north = 90;
+    region.west = -180;
+    region.east = 180;
+    region.rows = rows;
+    region.cols = cols;
+    region.depths = depths;
+        
+    Rast3d_adjust_region(&region);
+        
+    G_message("Creating 3D raster map");
+
+    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, 2048);
+    
+    /* The window is the same as the map region ... of course */
+    Rast3d_set_window_map(map, &region);
+    
+    int count = 1;
+    for(z = 0; z < region.depths; z++) {
+	G_percent(z, region.depths, 1);
+        for(y = 0; y < region.rows; y++) {
+            for(x = 0; x < region.cols; x++) {
+                /* Add cols, rows and depths and put this in the map */
+                value = x + y + z + x * y * z / count++;
+                Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
+            }
+        }
+    }
+
+    G_percent(1, 1, 1);
+    /* Write everything to the disk */
+    Rast3d_flush_all_tiles(map);
+    Rast3d_close(map);
+         
+    G_message("Verifying 3D raster map");
+
+    map = Rast3d_open_cell_old("test_put_get_value_dcell_large", G_mapset(), &region, DCELL_TYPE, 2048);
+    
+    count = 1;
+    for(z = 0; z < region.depths; z++) {
+	G_percent(z, region.depths, 1);
+        for(y = 0; y < region.rows; y++) {
+            for(x = 0; x < region.cols; x++) {
+                /* Add cols, rows and depths and put this in the map */
+                Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
+                if(value != (double)(x + y + z  + x * y * z/count++))
+			sum++;
+            }
+        }
+    }
+    G_percent(1, 1, 1);
+    Rast3d_close(map);
+    
+    G_remove("grid3", "test_put_get_value_dcell_large");
+    
+    return sum;
+}
+



More information about the grass-commit mailing list