]> granicus.if.org Git - postgis/commitdiff
Add upgrade mode and start to get raster working. Bah, going to need to handle pre...
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 22 May 2012 15:13:51 +0000 (15:13 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 22 May 2012 15:13:51 +0000 (15:13 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9782 b70326c6-7e19-0410-871a-916f4a2858ee

regress/run_test.pl

index 621e05b7b1b82254bd970c18b628ceb972def24d..0d8156006d4d7fb73e94b32b32931afff242a2ae 100755 (executable)
@@ -32,9 +32,10 @@ if ( @ARGV < 1 )
 ##################################################################
 
 $DB = "postgis_reg";
-$SHP2PGSQL = "../loader/shp2pgsql";
-$PGSQL2SHP = "../loader/pgsql2shp";
-$RASTER2PGSQL = "../../loader/raster2pgsql";
+$REGDIR = abs_path(dirname($0));
+$SHP2PGSQL = $REGDIR . "/../loader/shp2pgsql";
+$PGSQL2SHP = $REGDIR . "/../loader/pgsql2shp";
+$RASTER2PGSQL = $REGDIR . "/../../loader/raster2pgsql";
 
 
 ##################################################################
@@ -55,6 +56,7 @@ GetOptions (
        'verbose' => \$VERBOSE,
        'clean' => \$OPT_CLEAN,
        'nodrop' => \$OPT_NODROP, 
+       'upgrade' => \$OPT_UPGRADE,
        'nocreate' => \$OPT_NOCREATE,
        'topology' => \$OPT_WITH_TOPO,
        'raster' => \$OPT_WITH_RASTER,
@@ -81,7 +83,6 @@ $ENV{"PGOPTIONS"} = $PGOPTIONS;
 $PATH = $ENV{"PATH"};
 
 # Calculate the regression directory locations
-$REGDIR = abs_path(dirname($0));
 $STAGED_INSTALL_DIR = $REGDIR . "/00-regress-install";
 $STAGED_SCRIPTS_DIR = $STAGED_INSTALL_DIR . "/share/contrib/postgis";
 
@@ -254,7 +255,8 @@ foreach $TEST (@ARGV)
        }
        elsif ( -r "${TEST}.tif" )
        {
-               # run_raster_loader_test
+               my $rv = run_raster_loader_test();
+               pass() if $rv;
        }
        elsif ( -r "${TEST}.sql" )
        {
@@ -412,7 +414,7 @@ sub run_simple_sql
 {
        my $sql = shift;
 
-       if ( ! -r "$sql" ) 
+       if ( ! -r $sql ) 
        {
                fail("can't read $sql");
                return 0;
@@ -689,6 +691,88 @@ sub run_dumper_and_check_output
 }
 
 
+##################################################################
+# This runs the loader once and checks the output of it.
+# It will NOT run if neither the expected SQL nor the expected
+# select results file exists, unless you pass true for the final
+# parameter.
+#
+# $1 - Description of this run of the loader, used for error messages.
+# $2 - Table name to load into.
+# $3 - The name of the file containing what the
+#      SQL generated by shp2pgsql should look like.
+# $4 - The name of the file containing the expected results of
+#      SELECT rast FROM _tblname should look like.
+# $5 - Command line options for raster2pgsql.
+# $6 - If you pass true, this will run the loader even if neither
+#      of the expected results files exists (though of course
+#      the results won't be compared with anything).
+##################################################################
+sub run_raster_loader_and_check_output
+{
+       my $description = shift;
+       my $tblname = shift;
+       my $expected_sql_file = shift;
+       my $expected_select_results_file = shift;
+       my $loader_options = shift;
+       my $run_always = shift;
+       
+       # ON_ERROR_STOP is used by psql to return non-0 on an error
+       my $psql_opts="--no-psqlrc --variable ON_ERROR_STOP=true";
+
+       my $cmd, $rv;
+       my $outfile = "${TMPDIR}/loader.out";
+       my $errfile = "${TMPDIR}/loader.err";
+
+       if ( $run_always || -r $expected_sql_file || -r $expected_select_results_file ) 
+       {
+               show_progress();
+
+               # Produce the output SQL file.
+               $cmd = "$RASTER2PGSQL $loader_options -C -f the_rast ${TEST}.tif $tblname > $outfile 2> $errfile";
+               $rv = system($cmd);
+               
+               if ( $rv )
+               {
+                   fail("$description: running raster2pgsql", $errfile);
+                   return 0;
+           }
+           
+           if ( -r $expected_sql_file )
+           {
+               show_progress();
+                       my $diff = diff($outfile, $expected_sql_file, {STYLE=>"Unified"});
+                       if ( $diff )
+                       {
+                               fail(" $description: actual SQL does not match expected.", "$outfile");
+                               return 0;
+                       }
+               
+        }
+
+               # Run the loader SQL script.
+               show_progress();
+               $cmd = "psql $psql_opts -f $outfile $DB > $errfile 2>&1";
+       $rv = system($cmd);
+       if ( $rv )
+       {
+               fail(" $description: running raster2pgsql output","$errfile");
+               return 0;
+       }
+
+       # Run the select script (if there is one)
+       if ( -r "${TEST}.select.sql" )
+       {
+               $rv = run_simple_test("${TEST}.select.sql",$expected_select_results_file, $description);
+               return 0 if ( ! $rv );
+       }
+       }
+       
+    return 1;
+}
+
+
+
 ##################################################################
 #  run_loader_test 
 #
@@ -774,6 +858,40 @@ sub run_loader_test
        return 1;
 }
 
+
+##################################################################
+#  run_raster_loader_test 
+##################################################################
+sub run_raster_loader_test
+{
+       # See if there is a custom command-line options file
+       my $opts_file = "${TEST}.opts";
+       my $custom_opts="";
+       
+       if ( -r $opts_file )
+       {
+               open(FILE, $opts_file);
+               my @opts = <FILE>;
+               close(FILE);
+               @opts = grep(!/^\s*#/, @opts);
+               map(s/\n//, @opts);
+               $custom_opts = join(" ", @opts);
+       }
+
+       my $tblname="loadedshp";
+
+       # If we have some expected files to compare with, run in geography mode.
+       if ( ! run_raster_loader_and_check_output("test", $tblname, "${TEST}.sql.expected", "${TEST}.select.expected", $custom_opts, "true") )
+       {
+               return 0;
+       }
+       
+       drop_table($tblname);
+       
+       return 1;
+}
+
+
 ##################################################################
 # Count database objects
 ##################################################################
@@ -813,7 +931,7 @@ sub create_spatial
 
        if ( $OPT_EXTENSIONS ) 
        {
-#              prepare_spatial_extensions();
+               prepare_spatial_extensions();
        }
        else
        {
@@ -821,6 +939,7 @@ sub create_spatial
        }
 }
 
+
 sub load_sql_file
 {
        my $file = shift;
@@ -838,14 +957,35 @@ sub load_sql_file
                my $cmd = "psql $psql_opts -Xf $file $DB >> $REGRESS_LOG 2>&1";
                print "  $file\n" if $VERBOSE;
                my $rv = system($cmd);
-               if ( $rv )
-               {
-                       die "\nError encountered loading $file, see $REGRESS_LOG for details\n\n";
-               }
+               die "\nError encountered loading $file, see $REGRESS_LOG for details\n\n"
+                   if $rv;
        }
        return 1;
 }
 
+# Prepare the database for spatial operations (extension method)
+sub prepare_spatial_extensions
+{
+       print "Preparing db '${DB}' using 'CREATE EXTENSION'\n"; 
+
+       # ON_ERROR_STOP is used by psql to return non-0 on an error
+       my $psql_opts = "--no-psqlrc --variable ON_ERROR_STOP=true";
+    my $cmd = "psql $psql_opts -c \"CREATE EXTENSION postgis\" $DB >> $REGRESS_LOG 2>&1";
+    my $rv = system($cmd);
+
+       die "\nError encountered creating EXTENSION POSTGIS, see $REGRESS_LOG for details\n\n"
+           if $rv;
+
+    if ( $OPT_WITH_TOPO )
+    {
+        $cmd = "psql $psql_opts -c \"CREATE EXTENSION postgis_topology\" $DB >> $REGRESS_LOG 2>&1";
+        $rv = system($cmd);
+       die "\nError encountered creating EXTENSION POSTGIS_TOPOLOGY, see $REGRESS_LOG for details\n\n"
+           if $rv;
+    }
+    return 1;
+}
+
 # Prepare the database for spatial operations (old method)
 sub prepare_spatial
 {
@@ -870,6 +1010,56 @@ sub prepare_spatial
        return 1;
 }
 
+# Upgrade an existing database (soft upgrade)
+sub upgrade_spatial
+{
+    print "Upgrading PostGIS in '${DB}' \n" ;
+
+    my $script = `ls ${STAGED_SCRIPTS_DIR}/postgis_upgrade_*_minor.sql`;
+    chomp($script);
+
+    if ( -e $script )
+    {
+        print "Upgrading core\n";
+        load_sql_file($script);
+    }
+    else
+    {
+        die "$script not found\n";
+    }
+    
+    if ( $OPT_WITH_TOPO ) 
+    {
+        my $script = `ls ${STAGED_SCRIPTS_DIR}/topology_upgrade_*_minor.sql`;
+        chomp($script);
+        if ( -e $script )
+        {
+            print "Upgrading topology\n";
+            load_sql_file($script);
+        }
+        else
+        {
+            die "$script not found\n";
+        }
+    }
+    
+    if ( $OPT_WITH_RASTER ) 
+    {
+        my $script = `ls ${STAGED_SCRIPTS_DIR}/rtpostgis_upgrade_*_minor.sql`;
+        chomp($script);
+        if ( -e $script )
+        {
+            print "Upgrading raster\n";
+            load_sql_file($script);
+        }
+        else
+        {
+            die "$script not found\n";
+        }
+    }
+    return 1;
+}
+
 sub drop_spatial
 {
        my $ok = 1;
@@ -887,6 +1077,28 @@ sub drop_spatial
        return 1;
 }
 
+sub drop_spatial_extensions
+{
+    # ON_ERROR_STOP is used by psql to return non-0 on an error
+    my $psql_opts="--no-psqlrc --variable ON_ERROR_STOP=true";
+    my $ok = 1; 
+    my $cmd, $rv;
+    
+    if ( $OPT_WITH_TOPO )
+    {
+        $cmd = "psql $psql_opts -c \"DROP EXTENSION postgis_topology\" $DB >> $REGRESS_LOG 2>&1";
+        $rv = system($cmd);
+       $ok = 0 if $rv;
+    }
+    
+    $cmd = "psql $psql_opts -c \"DROP EXTENSION postgis\" $DB >> $REGRESS_LOG 2>&1";
+    $rv = system($cmd);
+       die "\nError encountered dropping EXTENSION POSTGIS, see $REGRESS_LOG for details\n\n"
+           if $rv;
+
+    return $ok;
+}
+
 # Drop spatial from an existing database
 sub uninstall_spatial
 {