Home | History | Annotate | Line # | Download | only in nbperf
t_nbperf.sh revision 1.5
      1 # $NetBSD: t_nbperf.sh,v 1.5 2021/02/14 01:27:33 joerg Exp $
      2 #
      3 # Copyright (c) 2012 The NetBSD Foundation, Inc.
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1. Redistributions of source code must retain the above copyright
     10 #    notice, this list of conditions and the following disclaimer.
     11 # 2. Redistributions in binary form must reproduce the above copyright
     12 #    notice, this list of conditions and the following disclaimer in the
     13 #    documentation and/or other materials provided with the distribution.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25 # POSSIBILITY OF SUCH DAMAGE.
     26 #
     27 
     28 cleanup()
     29 {
     30 	rm -f reference.txt input.txt hash.c hash.map testprog
     31 }
     32 
     33 atf_test_case chm
     34 chm_head()
     35 {
     36 	atf_set "descr" "Checks chm algorithm"
     37 	atf_set "require.files" "/usr/share/dict/web2"
     38 	atf_set "require.progs" "cc"
     39 }
     40 chm_body()
     41 {
     42 	for n in 4 32 128 1024 65536; do
     43 		seq 0 $(($n - 1)) > reference.txt
     44 		atf_check -o file:reference.txt \
     45 		    $(atf_get_srcdir)/h_nbperf /usr/share/dict/web2 chm cat \
     46 		    $n $(atf_get_srcdir)/hash_driver.c
     47 		atf_check -o file:hash.map \
     48 		    $(atf_get_srcdir)/h_nbperf /usr/share/dict/web2 chm cat \
     49 		    $n $(atf_get_srcdir)/hash_driver.c
     50 	done
     51 }
     52 chm_clean()
     53 {
     54 	cleanup
     55 }
     56 
     57 atf_test_case chm_fudged
     58 chm_fudged_head()
     59 {
     60 	atf_set "descr" "Checks chm algorithm with fudged hash"
     61 	atf_set "require.progs" "cc"
     62 }
     63 chm_fudged_body()
     64 {
     65 	seq 0 11 > reference.txt
     66 	seq 1 12 > input.txt
     67 
     68 	atf_check -o file:reference.txt \
     69 	    $(atf_get_srcdir)/h_nbperf input.txt "chm -p" cat \
     70 	    12 $(atf_get_srcdir)/hash_driver.c
     71 	atf_check -s exit:1 fgrep -q '^=' hash.c
     72 
     73 	atf_check -o file:reference.txt \
     74 	    $(atf_get_srcdir)/h_nbperf input.txt "chm -f -p" cat \
     75 	    12 $(atf_get_srcdir)/hash_driver.c
     76 	atf_check -s exit:0 fgrep -q '^=' hash.c
     77 }
     78 chm_fudged_clean()
     79 {
     80 	cleanup
     81 }
     82 
     83 atf_test_case chm3
     84 chm3_head()
     85 {
     86 	atf_set "descr" "Checks chm3 algorithm"
     87 	atf_set "require.files" "/usr/share/dict/web2"
     88 	atf_set "require.progs" "cc"
     89 }
     90 chm3_body()
     91 { 
     92 	for n in 4 32 128 1024 65536; do
     93 		seq 0 $(($n - 1)) > reference.txt
     94 		atf_check -o file:reference.txt \
     95 		    $(atf_get_srcdir)/h_nbperf /usr/share/dict/web2 chm3 cat \
     96 		    $n $(atf_get_srcdir)/hash_driver.c
     97 		atf_check -o file:hash.map \
     98 		    $(atf_get_srcdir)/h_nbperf /usr/share/dict/web2 chm3 cat \
     99 		    $n $(atf_get_srcdir)/hash_driver.c
    100 	done
    101 }
    102 chm3_clean()
    103 {
    104 	cleanup
    105 }
    106 
    107 atf_test_case chm3_fudged
    108 chm3_fudged_head()
    109 {
    110 	atf_set "descr" "Checks chm3 algorithm with fudged hash"
    111 	atf_set "require.progs" "cc"
    112 }
    113 chm3_fudged_body()
    114 {
    115 	seq 0 9 > reference.txt
    116 	seq 1 10 > input.txt
    117 
    118 	atf_check -o file:reference.txt \
    119 	    $(atf_get_srcdir)/h_nbperf input.txt "chm3 -p" cat \
    120 	    10 $(atf_get_srcdir)/hash_driver.c
    121 	atf_check -s exit:1 fgrep -q '^=' hash.c
    122 
    123 	atf_check -o file:reference.txt \
    124 	    $(atf_get_srcdir)/h_nbperf input.txt "chm3 -f -p" cat \
    125 	    10 $(atf_get_srcdir)/hash_driver.c
    126 	atf_check -s exit:0 fgrep -q '^= (' hash.c
    127 	atf_check -s exit:0 fgrep -q '^= 2' hash.c
    128 }
    129 chm3_fudged_clean()
    130 {
    131 	cleanup
    132 }
    133 
    134 atf_test_case bpz
    135 bpz_head()
    136 {
    137 	atf_set "descr" "Checks bpz algorithm"
    138 	atf_set "require.files" "/usr/share/dict/web2"
    139 	atf_set "require.progs" "cc"
    140 }
    141 bpz_body()
    142 {
    143 	for n in 4 32 128 1024 65536 131072; do
    144 		seq 0 $(($n - 1)) > reference.txt
    145 		atf_check -o file:reference.txt \
    146 		    $(atf_get_srcdir)/h_nbperf /usr/share/dict/web2 bpz "sort -n" \
    147 		    $n $(atf_get_srcdir)/hash_driver.c
    148 		atf_check -o file:hash.map \
    149 		    $(atf_get_srcdir)/h_nbperf /usr/share/dict/web2 bpz cat \
    150 		    $n $(atf_get_srcdir)/hash_driver.c
    151 	done
    152 }
    153 bpz_clean()
    154 {
    155 	cleanup
    156 }
    157 
    158 atf_test_case bpz_fudged
    159 bpz_fudged_head()
    160 {
    161 	atf_set "descr" "Checks bpz algorithm with fudged hash"
    162 	atf_set "require.progs" "cc"
    163 }
    164 bpz_fudged_body()
    165 {
    166 	seq 0 11 > reference.txt
    167 	seq 1 12 > input.txt
    168 
    169 	atf_check -o file:reference.txt \
    170 	    $(atf_get_srcdir)/h_nbperf input.txt "bpz -p" "sort -n" \
    171 	    12 $(atf_get_srcdir)/hash_driver.c
    172 	atf_check -s exit:1 fgrep -q '^=' hash.c
    173 
    174 	atf_check -o file:reference.txt \
    175 	    $(atf_get_srcdir)/h_nbperf input.txt "bpz -f -p" "sort -n" \
    176 	    12 $(atf_get_srcdir)/hash_driver.c
    177 	atf_check -s exit:0 fgrep -q '^= (' hash.c
    178 	atf_check -s exit:0 fgrep -q '^= 2' hash.c
    179 }
    180 bpz_fudged_clean()
    181 {
    182 	cleanup
    183 }
    184 
    185 atf_test_case handle_dup
    186 handle_dup_head()
    187 {
    188 	atf_set "descr" "Checks different algorithms deal with duplicates"
    189 	atf_set "require.progs" "cc"
    190 }
    191 handle_dup_body()
    192 {
    193 	seq 0 9 > reference.txt
    194 	echo 0 >> reference.txt
    195 	atf_check -s exit:1 -e match:"nbperf: Duplicate keys detected" \
    196 		nbperf -a chm < reference.txt
    197 	atf_check -s exit:1 -e match:"nbperf: Duplicate keys detected" \
    198 		nbperf -a chm3 < reference.txt
    199 	atf_check -s exit:1 -e match:"nbperf: Duplicate keys detected" \
    200 		nbperf -a bpz < reference.txt
    201 }
    202 handle_dup_clean()
    203 {
    204 	cleanup
    205 }
    206 
    207 atf_init_test_cases()
    208 {
    209 	atf_add_test_case chm
    210 	atf_add_test_case chm_fudged
    211 	atf_add_test_case chm3
    212 	atf_add_test_case chm3_fudged
    213 	atf_add_test_case bpz
    214 	atf_add_test_case bpz_fudged
    215 	atf_add_test_case handle_dup
    216 }
    217