New data structure sparse_xarray.
[pspp-builds.git] / tests / libpspp / sparse-xarray-test.sh
1 #!/bin/sh
2
3 # This program tests the sparse_xarray abstract data type implementation.
4
5 set -e
6
7 : ${top_builddir:=.}
8 RUN_TEST="${top_builddir}/tests/libpspp/sparse-xarray-test --verbosity=0"
9
10 # Each on-disk sparse_xarray eats up a file descriptor, so for the
11 # tests that involve on-disk sparse_xarrays we need to limit the
12 # maximum length of the queue.  Figure out how many file descriptors
13 # we can let the test program open at once.
14 OPEN_MAX=`getconf OPEN_MAX 2>/dev/null`
15 case $OPEN_MAX in
16     [0-9]*)
17         # Divide by 2 because some fds are used by other code.
18         queue_limit=`expr $OPEN_MAX / 2` 
19         ;;
20     undefined) 
21         # Assume that any system with a dynamic fd limit has a large limit.
22         queue_limit=500 
23         ;;
24     *)
25         case `uname -m 2>/dev/null` in
26             CYGWIN*)
27                 # Cygwin claims a 256-fd limit as OPEN_MAX in <limits.h>.
28                 queue_limit=128
29                 ;;
30             MINGW*)
31                 # The following email claims that Mingw should have a
32                 # 2048-fd limit:
33                 # http://www.mail-archive.com/squid-users@squid-cache.org/msg35249.html
34                 queue_limit=1024
35                 ;;
36             *)
37                 # This seems fairly conservative these days.
38                 queue_limit=50
39                 ;;
40         esac
41         ;;
42 esac
43
44 # Test completely in-memory sparse_xarray.  --values=3 would be a
45 # slightly better test but takes much longer.
46 $RUN_TEST --columns=3 --max-rows=3 --max-memory-rows=3 --values=2
47
48 # Test on-disk sparse_xarrays.
49 for max_memory_rows in 0 1 2; do
50     $RUN_TEST --columns=2 --max-rows=3 --max-memory-rows=$max_memory_rows --values=2 --queue-limit=$queue_limit
51 done
52
53 # Test copying back and forth between a pair of sparse_xarrays in
54 # memory.
55 $RUN_TEST --columns=2 --max-rows=2 --max-memory-rows=2 --values=2 --xarrays=2 --no-write-rows --no-copy-columns
56
57 # Test copying back and forth between a pair of sparse_xarrays on
58 # disk.  These parameters are ridiculously low, but it's necessary
59 # unless we want the tests to take a very long time.
60 for max_memory_rows in 0 1; do
61     $RUN_TEST --columns=1 --max-rows=2 --max-memory-rows=$max_memory_rows --values=2 --xarrays=2 --queue-limit=`expr $queue_limit / 2` --no-write-rows --no-copy-columns
62 done