1#!/bin/sh
2
3# Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
4# LLNL-CODE-425250.
5# All rights reserved.
6#
7# This file is part of Silo. For details, see silo.llnl.gov.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12#
13#    * Redistributions of source code must retain the above copyright
14#      notice, this list of conditions and the disclaimer below.
15#    * Redistributions in binary form must reproduce the above copyright
16#      notice, this list of conditions and the disclaimer (as noted
17#      below) in the documentation and/or other materials provided with
18#      the distribution.
19#    * Neither the name of the LLNS/LLNL nor the names of its
20#      contributors may be used to endorse or promote products derived
21#      from this software without specific prior written permission.
22#
23# THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
24# "AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
25# LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26# A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
27# LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
28# CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29# EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
30# PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
31# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32# LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
33# NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
34# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35#
36# This work was produced at Lawrence Livermore National Laboratory under
37# Contract  No.   DE-AC52-07NA27344 with  the  DOE.  Neither the  United
38# States Government  nor Lawrence  Livermore National Security,  LLC nor
39# any of  their employees,  makes any warranty,  express or  implied, or
40# assumes   any   liability   or   responsibility  for   the   accuracy,
41# completeness, or usefulness of any information, apparatus, product, or
42# process  disclosed, or  represents  that its  use  would not  infringe
43# privately-owned   rights.  Any  reference   herein  to   any  specific
44# commercial products,  process, or  services by trade  name, trademark,
45# manufacturer or otherwise does not necessarily constitute or imply its
46# endorsement,  recommendation,   or  favoring  by   the  United  States
47# Government or Lawrence Livermore National Security, LLC. The views and
48# opinions  of authors  expressed  herein do  not  necessarily state  or
49# reflect those  of the United  States Government or  Lawrence Livermore
50# National  Security, LLC,  and shall  not  be used  for advertising  or
51# product endorsement purposes.
52
53# -----------------------------------------------------------------------------
54# Test hzip compression capability in silo by generating compressed data
55# file, copying it, re-generating w/o compression and then diffing it with
56# browser against the original.
57#
58# Programmer: Mark C. Miller
59# Creation:   July 21, 2008
60#
61# Modifications:
62#   Mark C. Miller, Wed Feb  4 20:58:34 PST 2009
63#   Made it more lenient about the compressed file size being larger. That
64#   can happen for toy datasets.
65# -----------------------------------------------------------------------------
66
67# Diddle the the directory because Autotest is not at all designed to handle
68# tests the way this one was written
69if test -n "$1"; then
70    topDir=$1
71    if test -e $topDir/../../multi_test; then
72        topDir=$1/../..
73    fi
74else
75    topDir=.
76fi
77
78#
79# Create data with compression (only on HDF5 driver) and save files
80#
81$topDir/multi_test DB_HDF5 hzip 1>/dev/null 2>&1
82rm -rf h5_hzip_files
83mkdir h5_hzip_files
84mv multi_*d.h5 h5_hzip_files/.
85
86#
87# Create data without compression
88#
89$topDir/multi_test DB_HDF5 1>/dev/null 2>&1
90
91#
92# Now, run browser and make sure we don't get any errors in the diff
93#
94result=0
95for df in multi_*.h5; do
96    # confirm compressed files are smaller (or at least not too much bigger)
97    hzip_file_size=`ls -l h5_hzip_files/$df | tr -s ' ' | cut -d' ' -f5`
98    orig_file_size=`ls -l $df | tr -s ' ' | cut -d' ' -f5`
99    orig_file_size_x2=`expr $orig_file_size \* 2`
100    if test ! $hzip_file_size -lt $orig_file_size_x2; then
101        result=1
102        break
103    fi
104    # do a diff on the files
105    rm -f testhzip.out
106    $topDir/../tools/browser/browser -q -e diff $df h5_hzip_files/$df 1>testhzip.out 2>&1
107    if test `cat testhzip.out | wc -l | tr -d ' '` -gt 0; then
108        result=1
109        break
110    fi
111done
112
113#
114# Cleanup
115#
116rm -rf h5_hzip_files
117rm -f testhzip.out
118
119exit $result
120