zram01.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  3. # Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
  4. # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
  5. #
  6. # Test creates several zram devices with different filesystems on them.
  7. # It fills each device with zeros and checks that compression works.
  8. TST_CNT=7
  9. TST_TESTFUNC="do_test"
  10. TST_NEEDS_CMDS="awk bc dd"
  11. . zram_lib.sh
  12. # Test will create the following number of zram devices:
  13. dev_num=4
  14. # This is a list of parameters for zram devices.
  15. # Number of items must be equal to 'dev_num' parameter.
  16. zram_max_streams="2 3 5 8"
  17. FS_SIZE="402653184"
  18. FS_TYPE="btrfs"
  19. RAM_SIZE=$(awk '/MemTotal:/ {print $2}' /proc/meminfo)
  20. if [ "$RAM_SIZE" -lt 1048576 ]; then
  21. tst_res TINFO "not enough space for Btrfs"
  22. FS_SIZE="26214400"
  23. FS_TYPE="ext2"
  24. fi
  25. # The zram sysfs node 'disksize' value can be either in bytes,
  26. # or you can use mem suffixes. But in some old kernels, mem
  27. # suffixes are not supported, for example, in RHEL6.6GA's kernel
  28. # layer, it uses strict_strtoull() to parse disksize which does
  29. # not support mem suffixes, in some newer kernels, they use
  30. # memparse() which supports mem suffixes. So here we just use
  31. # bytes to make sure everything works correctly.
  32. zram_sizes="26214400 26214400 26214400 $FS_SIZE"
  33. zram_mem_limits="25M 25M 25M $((FS_SIZE/1024/1024))M"
  34. zram_filesystems="ext3 ext4 xfs $FS_TYPE"
  35. zram_fill_fs()
  36. {
  37. for i in $(seq 0 $(($dev_num - 1))); do
  38. tst_res TINFO "filling zram$i (it can take long time)"
  39. local b=0
  40. while true; do
  41. dd conv=notrunc if=/dev/zero of=zram${i}/file \
  42. oflag=append count=1 bs=1024 status=none \
  43. >/dev/null 2>err.txt || break
  44. b=$(($b + 1))
  45. done
  46. if [ $b -eq 0 ]; then
  47. [ -s err.txt ] && tst_res TWARN "dd error: $(cat err.txt)"
  48. tst_brk TBROK "cannot fill zram $i"
  49. fi
  50. tst_res TPASS "zram$i was filled with '$b' KB"
  51. if [ ! -f "/sys/block/zram$i/mm_stat" ]; then
  52. if [ $i -eq 0 ]; then
  53. tst_res TCONF "zram compression ratio test requires zram mm_stat sysfs file"
  54. fi
  55. continue
  56. fi
  57. local compr_size=`awk '{print $2}' "/sys/block/zram$i/mm_stat"`
  58. local v=$((100 * 1024 * $b / $compr_size))
  59. local r=`echo "scale=2; $v / 100 " | bc`
  60. if [ "$v" -lt 100 ]; then
  61. tst_res TFAIL "compression ratio: $r:1"
  62. break
  63. fi
  64. tst_res TPASS "compression ratio: $r:1"
  65. done
  66. }
  67. do_test()
  68. {
  69. case $1 in
  70. 1) zram_max_streams;;
  71. 2) zram_compress_alg;;
  72. 3) zram_set_disksizes;;
  73. 4) zram_set_memlimit;;
  74. 5) zram_makefs;;
  75. 6) zram_mount;;
  76. 7) zram_fill_fs;;
  77. esac
  78. }
  79. tst_run