Advertisement
CSenshi

OS - FUSE (test dir)

Jul 9th, 2019
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.97 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # to run please change mode
  4. # chmod +x check_dir.bash
  5.  
  6. if [ "$#" -ne 1 ]; then
  7.     echo "Illegal number of parameters"
  8.     echo 'Call : ./check_dir.sh mounted_dir'
  9.     exit 1
  10. fi
  11.  
  12. MOUNT_DIR=$1
  13. ERR=5
  14. cd $MOUNT_DIR
  15.  
  16. CMD="   Command : "
  17.  
  18. create_rec(){
  19.     if [[ $1 -le 1 ]]
  20.     then
  21.         return
  22.     else
  23.         echo $CMD mkdir dir_rec_$1
  24.         mkdir dir_rec_$1
  25.        
  26.         echo $CMD cd dir_rec_$1
  27.         cd dir_rec_$1
  28.        
  29.         create_rec $[$1-1]
  30.        
  31.         echo $CMD cd ..
  32.         cd ..
  33.     fi
  34. }
  35.  
  36. iter_rec(){
  37.     if [[ $1 -le 1 ]]
  38.     then
  39.         return
  40.     else
  41.         echo $CMD ls
  42.         ls
  43.         echo $CMD pwd
  44.         pwd
  45.         echo
  46.        
  47.         echo $CMD cd dir_rec_$1
  48.         cd dir_rec_$1
  49.        
  50.         iter_rec $[$1-1]
  51.        
  52.         echo $CMD cd ..
  53.         cd ..
  54.     fi
  55. }
  56.  
  57. test1(){
  58.     echo "Test 1 : Creating $1 Folders ..."
  59.     for i in $(seq 1 $1);
  60.     do
  61.         echo $CMD mkdir dir_$i
  62.         mkdir dir_$i
  63.     done
  64.     echo "Done!"
  65.     echo
  66. }
  67.  
  68. test2(){
  69.     echo "Test 2 : Creating $1 depth subdirectories (/a/b/c/d/e/f...)"
  70.     create_rec $1
  71.     echo "Done!"
  72.     echo
  73. }
  74.  
  75. test3(){
  76.     echo "Test 3 : pwd, ls ..."
  77.     echo $CMD 'pwd : '
  78.     pwd
  79.     echo
  80.    
  81.     echo $CMD 'ls  : '
  82.     ls
  83.     echo
  84.    
  85.     echo $CMD 'ls -al: '
  86.     ls -al
  87.     echo
  88.    
  89.     iter_rec $1
  90.     echo "Done!"
  91.     echo
  92. }
  93.  
  94.  
  95. test4(){
  96.     echo "Test 4 : Creating directories with large names ..."
  97.    
  98.     len=128
  99.     chars="A B C D E F G H I J K L M N O P Q R S T U V X Y Z "
  100.     for a in $chars; do
  101.         dir_name=$a
  102.         for i in $(seq 1 $len);
  103.         do
  104.             dir_name=$dir_name$a
  105.         done
  106.         echo mkdir "$a$a$a... ($len x)"
  107.         mkdir $dir_name
  108.     done;
  109.     ls
  110.     echo "Done!"
  111.     echo
  112. }
  113.  
  114.  
  115. test5(){
  116.     echo "Test 3 : Testing Rmdir ..."
  117.    
  118.     echo mkdir dir1 dir2 dir3 dir_to_rem1 dir_to_rem2
  119.     mkdir dir1 dir2 dir3 dir_to_rem1 dir_to_rem2
  120.     echo
  121.    
  122.     echo ls
  123.     ls
  124.     echo
  125.    
  126.     echo rmdir dir_to_rem1
  127.     rmdir dir_to_rem1
  128.     echo
  129.    
  130.     echo rmdir dir_to_rem2
  131.     rmdir dir_to_rem2
  132.     echo
  133.    
  134.     echo rmdir NO_DIR
  135.     rmdir NO_DIR
  136.     echo
  137.    
  138.     echo mkdir subdir1 subdir1/subdir2 subdir1/subdir2/subdir3
  139.     mkdir subdir1 subdir1/subdir2 subdir1/subdir2/subdir3
  140.     echo
  141.    
  142.     echo "!!! Trying to delete non empty directory !!!"
  143.     echo rmdir subdir1
  144.     rmdir subdir1
  145.     echo
  146.    
  147.     echo ls
  148.     ls
  149.     echo
  150.    
  151.     echo "Done!"
  152.     echo
  153. }
  154.  
  155. run_test(){
  156.     TOTAL_DIR_NUM=10
  157.    
  158.     # Base Test Make 10 Directories
  159.     test1 $TOTAL_DIR_NUM
  160.    
  161.     # Create 10 Subdirectories
  162.     test2 $TOTAL_DIR_NUM
  163.    
  164.     # pwd and ls
  165.     test3 $TOTAL_DIR_NUM
  166.    
  167.     # Checking rmdir
  168.     test5
  169.    
  170.     # Create Folders with large name
  171.     test4
  172. }
  173.  
  174.  
  175. START=$(date +%s.%N)
  176. run_test
  177. END=$(date +%s.%N)
  178. DIFF=$(echo "$END - $START" | bc)
  179.  
  180. echo "Elapsed time : $DIFF seconds"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement