components/parallel/TESTING
changeset 7757 b1ac9348d4f0
equal deleted inserted replaced
7756:a14f5c91f91a 7757:b1ac9348d4f0
       
     1 The following scripts test the various components that make up GNU parallel.
       
     2 They are based on examples in the GNU parallel man pages.
       
     3 
       
     4 Note that the last one for sql has been obstificated to not disclose the
       
     5 testers username and password or the name of the database.
       
     6 
       
     7 There are lots more examples in the GNU parallel man page that can be used
       
     8 to provide further testing if needed.
       
     9 
       
    10 ----
       
    11 
       
    12 $ cat niceload-test.sh
       
    13 #!/bin/sh
       
    14 PATH=/usr/bin
       
    15 echo "Testing niceload"
       
    16 echo
       
    17 echo "EXAMPLE: See niceload in action"
       
    18 echo "     In terminal 1 run: top"
       
    19 echo
       
    20 echo "     In terminal 2 run:"
       
    21 echo
       
    22 echo "     niceload perl -e '$|=1;do{$l==$r or print \".\";"
       
    23 echo "     $l=$r}until(($r=time-$^T)>50)'"
       
    24 echo
       
    25 echo "     This will print a '.' every second for 50 seconds and eat a"
       
    26 echo "     lot of CPU. When the load rises to 1.0 the process is"
       
    27 echo "     suspended."
       
    28 echo
       
    29 niceload -q perl -e '$|=1;do{$l==$r or print "."; $l=$r}until(($r=time-$^T)>50)'
       
    30 
       
    31 ----
       
    32 
       
    33 $ cat parallel-test.sh
       
    34 #!/bin/sh
       
    35 PATH=/usr/bin:/usr/sbin
       
    36 echo Testing parallel...
       
    37 echo
       
    38 echo EXAMPLE: Composed commands
       
    39 echo     A job can consist of several commands. This will print the
       
    40 echo     number of files in each directory:
       
    41 echo
       
    42 rm -rf test-dir
       
    43 mkdir -p test-dir/a test-dir/b test-dir/c test-dir/d
       
    44 (cd test-dir/a; touch 1 2 3 4 5 6 7 8 9 10 11 12)
       
    45 (cd test-dir/b; touch 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
       
    46 (cd test-dir/c; touch 1 2 3 4 5 6 7 8)
       
    47 (cd test-dir/d; touch 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
       
    48 (cd test-dir; ls | parallel 'echo -n {}" "; ls {}|wc -l')
       
    49 echo
       
    50 echo "    To put the output in a file called <name>.dir:"
       
    51 echo
       
    52 (cd test-dir; ls | parallel '(echo -n {}" "; ls {}|wc -l) > {}.dir')
       
    53 cat test-dir/a.dir
       
    54 cat test-dir/b.dir
       
    55 cat test-dir/c.dir
       
    56 cat test-dir/d.dir
       
    57 echo
       
    58 echo EXAMPLE: Group output lines
       
    59 echo     When running jobs that output data, you often do not want
       
    60 echo     the output of multiple jobs to run together. GNU parallel
       
    61 echo     defaults to grouping the output of each job, so the output
       
    62 echo     is printed when the job finishes. If you want the output to
       
    63 echo     be printed while the job is running you can use -u.
       
    64 echo
       
    65 echo     Compare the output of:
       
    66 echo
       
    67 parallel traceroute ::: foss.org.my debian.org freenetproject.org
       
    68 echo
       
    69 echo     to the output of:
       
    70 echo
       
    71 parallel -u traceroute ::: foss.org.my debian.org freenetproject.org
       
    72 echo
       
    73 echo EXAMPLE: Keep order of output same as order of input
       
    74 echo      Normally the output of a job will be printed as soon as it
       
    75 echo      completes. Sometimes you want the order of the output to
       
    76 echo      remain the same as the order of the input. This is often
       
    77 echo      important, if the output is used as input for another
       
    78 echo      system. -k will make sure the order of output will be in the
       
    79 echo      same order as input even if later jobs end before earlier
       
    80 echo      jobs.
       
    81 echo
       
    82 echo      Append a string to every line in a text file:
       
    83 echo      If you remove -k some of the lines may come out in the wrong
       
    84 echo      order.
       
    85 echo
       
    86 echo BEFORE:
       
    87 echo
       
    88 cat textfile
       
    89 echo
       
    90 echo AFTER:
       
    91 echo
       
    92 cat textfile | parallel -k echo {} append_string
       
    93 
       
    94 ----
       
    95 
       
    96 $ cat parcat-test.sh
       
    97 #!/bin/sh
       
    98 PATH=/usr/bin
       
    99 echo "Testing parcat"
       
   100 echo
       
   101 echo "mkfifo slot-{1..5}-digit-{0..9}"
       
   102 echo "parallel -j5 'seq 100000 | grep {} > slot-{%}-digit-{}' ::: {0..9} &"
       
   103 echo "parallel parcat slot-{1..5}-digit-{} '>' digit-{} ::: {0..9}"
       
   104 echo
       
   105 rm -f slot* digit*
       
   106 mkfifo slot-{1..5}-digit-{0..9}
       
   107 parallel -j5 'seq 100000 | grep {} > slot-{%}-digit-{}' ::: {0..9} &
       
   108 parallel parcat slot-{1..5}-digit-{} '>' digit-{} ::: {0..9}
       
   109 
       
   110 ----
       
   111 
       
   112 $ cat sem-test.sh
       
   113 #!/bin/sh
       
   114 PATH=/usr/bin:/usr/sbin:/usr/perl5/5.22/bin
       
   115 echo Testing sem
       
   116 echo
       
   117 echo EXAMPLE: Gzipping *.log
       
   118 echo      Run one gzip process per CPU core. Block until a CPU core
       
   119 echo      becomes available.
       
   120 echo
       
   121 rm -rf test-dir
       
   122 mkdir test-dir
       
   123 mkfile -v 150k test-dir/a.log
       
   124 mkfile -v 150k test-dir/b.log
       
   125 mkfile -v 150k test-dir/c.log
       
   126 mkfile -v 150k test-dir/d.log
       
   127 mkfile -v 150k test-dir/e.log
       
   128 mkfile -v 150k test-dir/f.log
       
   129 mkfile -v 150k test-dir/g.log
       
   130 mkfile -v 150k test-dir/h.log
       
   131 mkfile -v 150k test-dir/i.log
       
   132 mkfile -v 150k test-dir/j.log
       
   133 mkfile -v 150k test-dir/k.log
       
   134 mkfile -v 150k test-dir/l.log
       
   135 mkfile -v 150k test-dir/m.log
       
   136 mkfile -v 150k test-dir/n.log
       
   137 mkfile -v 150k test-dir/o.log
       
   138 mkfile -v 150k test-dir/p.log
       
   139 mkfile -v 150k test-dir/q.log
       
   140 mkfile -v 150k test-dir/r.log
       
   141 for i in `ls test-dir/*.log` ; do
       
   142   echo $i
       
   143   sem -j+0 gzip $i ";" echo done
       
   144 done
       
   145 sem --wait
       
   146 echo
       
   147 echo "EXAMPLE: Protecting pod2html from itself"
       
   148 echo "    pod2html creates two files: pod2htmd.tmp and pod2htmi.tmp"
       
   149 echo "    which it does not clean up. It uses these two files for a"
       
   150 echo "    short time. But if you run multiple pod2html in parallel"
       
   151 echo "    (e.g. in a Makefile with make -j) you need to protect"
       
   152 echo "    pod2html from running twice at the same time. sem running as"
       
   153 echo "    a mutex will do just that:"
       
   154 echo
       
   155 #cp .../components/perl512/perl-5.12.4/Porting/pumpkin.pod .
       
   156 sem --fg --id pod2html pod2html pumpkin.pod > pumpkin.html
       
   157 sem --fg --id pod2html rm -f pod2htmd.tmp pod2htmi.tmp
       
   158 
       
   159 ----
       
   160 
       
   161 $ cat sql-test.sh
       
   162 #!/bin/sh
       
   163 PATH=/usr/bin:/usr/sbin:/usr/perl5/5.22/bin
       
   164 echo Testing sql
       
   165 echo
       
   166 echo EXAMPLE: Attaching to the BugDB database.
       
   167 echo
       
   168 sql oracle://<USERNAME>:<PASSWORD>@<DATABASE NAME>
       
   169 
       
   170 ----