pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


fstest_make_numtree1.ksh93 - filesystem stress test using parallel makefile
Posted by Anonymous on Fri 19th Jul 2024 13:30
raw | new post

  1. #!/bin/ksh93
  2.  
  3. #
  4. # fstest_make_numtree1.ksh93 - filesystem stress test using parallel makefile
  5. #
  6. # The script builds a makefile to generate number sequence
  7. # The resulting Makefile is intended to be used with
  8. # $ bmake -j128 all # as filesystem test
  9. #
  10. # Written by Roland Mainz <roland.mainz@nrubsig.org>
  11. #
  12.  
  13. function genmakefile_make_number_seq
  14. {
  15.         set -o nounset
  16.         nameref out_maketarget=$1
  17.         integer start_i=$2
  18.         integer stop_i=$3
  19.         typeset payload=$4
  20.         integer i
  21.         typeset -a make_targets
  22.  
  23.         if (( (stop_i - start_i) > 10 )) ; then
  24.                 (( i=(stop_i - start_i)/2 ))
  25.                 genmakefile_make_number_seq make_targets[0] $start_i $(( start_i+i )) "$payload"
  26.                 genmakefile_make_number_seq make_targets[1] $(( start_i+i )) $stop_i  "$payload"
  27.         else
  28.                 for ((i=start_i ; i < stop_i ; i++ )) ; do
  29.                         printf 'i_%d:\n' i
  30.                         printf '\t@printf "%d\\t%s\\n" >"i_%d"\n' i "$payload" i
  31.                         make_targets+=( "i_$i" )
  32.                 done
  33.         fi
  34.  
  35.         out_maketarget="i_${start_i}_${stop_i}"
  36.         printf 'i_%d_%d: %s\n' start_i stop_i "${make_targets[*]}"
  37.  
  38.         printf '\tcat '
  39.         printf '%q ' "${make_targets[@]}"
  40.         printf ' >"%s"\n' "$out_maketarget"
  41.  
  42.         return 0
  43. }
  44.  
  45. function genmakefile
  46. {
  47.         set -o nounset
  48.         typeset make_target
  49.         integer max_num=$1
  50.         typeset string_payload=$2
  51.  
  52.         genmakefile_make_number_seq make_target 0 ${max_num} "${string_payload}"
  53.  
  54.         printf 'all: %s\n' "$make_target"
  55.  
  56.         return 0
  57. }
  58.  
  59. function parallal_make
  60. {
  61.         if true ; then
  62.                 # BSD make
  63.                 bmake -j 128 "$@"
  64.         else
  65.                 # GNU make
  66.                 make --load-average 128 -j 128 "$@"
  67.         fi
  68. }
  69.  
  70. function main
  71. {
  72.         set -o nounset
  73.         typeset subcmd="$1"
  74.  
  75.         compound config=(
  76.                 # workdir
  77.                 typeset workdir="$PWD/fstest_make_numtree1_workdir"
  78.                 # max number of iterations
  79.                 integer max_num=4000
  80.                 # 8192 bytes of payload
  81.                 typeset string_payload="$(
  82.                         integer p ;
  83.                         for ((p=0 ; p < 8192 ; p++ )) ; do
  84.                                 printf '%x' $((p%0x10)) ;
  85.                         done)"
  86.         )
  87.  
  88.         #
  89.         # We need BSD make, as GNU make -j128 somehow does not
  90.         # yield parallism
  91.         #
  92.         if [[ "$(which 'bmake' 2>'/dev/null')" == '' ]] ; then
  93.                 print -u2 -f $"%s: bmake (BSD make) required\n" "${.sh.file}"
  94.                 return 1
  95.         fi
  96.         if [[ "$(which 'seq' 2>'/dev/null')" == '' ]] ; then
  97.                 print -u2 -f $"%s: seq required\n" "${.sh.file}"
  98.                 return 1
  99.         fi
  100.  
  101.         #
  102.         # subcmd dispatch
  103.         #
  104.         case "$subcmd" in
  105.                 'generate')
  106.                         set -o xtrace
  107.                         mkdir -p -- "${config.workdir}"
  108.                         cd -- "${config.workdir}" || return $?
  109.  
  110.                         genmakefile ${config.max_num} "${config.string_payload}" >"make_numtree1.Makefile"
  111.                         set +o xtrace
  112.                         ;;
  113.                 'run')
  114.                         set -o xtrace
  115.                         cd -- "${config.workdir}" || return $?
  116.  
  117.                         time parallal_make -f "make_numtree1.Makefile" all
  118.                         set +o xtrace
  119.                         ;;
  120.                 'clean')
  121.                         set -o xtrace
  122.                         rm -rf -- "${config.workdir}"
  123.                         set +o xtrace
  124.                         ;;
  125.                 # all-in-one
  126.                 'all')
  127.                         set -o xtrace
  128.                         (
  129.                                 set -o errexit
  130.                                 rm -rf -- "${config.workdir}"
  131.                                 mkdir -p -- "${config.workdir}"
  132.                                 cd -- "${config.workdir}" || return $?
  133.  
  134.                                 genmakefile ${config.max_num} "${config.string_payload}" >"make_numtree1.Makefile"
  135.  
  136.                                 time parallal_make -f "make_numtree1.Makefile" all
  137.                                 ls -l "i_0_${config.max_num}"
  138.  
  139.                                 # compare results (minus payload) with output of /usr/bin/seq
  140.                                 diff -u <(awk '{ print $1 }' "i_0_${config.max_num}") <(seq 0 $(( config.max_num-1 )))
  141.                                 set +o xtrace
  142.  
  143.                                 # we only reach this if we did not leave the
  144.                                 # subshell via errexit
  145.                                 printf $"#### Run OK ####\n"
  146.                         )
  147.                         return $?
  148.                         ;;
  149.  
  150.                 *)
  151.                         print -u2 -f \
  152.                                 $"%s: Unknown subcmd, supported are 'generate', 'run', 'clean', 'all'\n" \
  153.                                 "${.sh.file}"
  154.                         return 1
  155.                         ;;
  156.         esac
  157.  
  158.         return 0
  159. }
  160.  
  161. builtin mkdir
  162. builtin printf
  163.  
  164. main "$@"
  165. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at