zram01.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License as
  6. # published by the Free Software Foundation; either version 2 of
  7. # the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it would be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # Test creates several zram devices with different filesystems on them.
  15. # It fills each device with zeros and checks that compression works.
  16. #
  17. # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
  18. # Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
  19. TCID="zram01"
  20. ERR_CODE=0
  21. . ./zram_lib.sh
  22. # Test will create the following number of zram devices:
  23. dev_num=1
  24. # This is a list of parameters for zram devices.
  25. # Number of items must be equal to 'dev_num' parameter.
  26. zram_max_streams="2"
  27. # The zram sysfs node 'disksize' value can be either in bytes,
  28. # or you can use mem suffixes. But in some old kernels, mem
  29. # suffixes are not supported, for example, in RHEL6.6GA's kernel
  30. # layer, it uses strict_strtoull() to parse disksize which does
  31. # not support mem suffixes, in some newer kernels, they use
  32. # memparse() which supports mem suffixes. So here we just use
  33. # bytes to make sure everything works correctly.
  34. zram_sizes="2097152" # 2MB
  35. zram_mem_limits="2M"
  36. zram_filesystems="ext4"
  37. zram_algs="lzo"
  38. zram_fill_fs()
  39. {
  40. local mem_free0=$(free -m | awk 'NR==2 {print $4}')
  41. for i in $(seq 0 $(($dev_num - 1))); do
  42. echo "fill zram$i..."
  43. local b=0
  44. while [ true ]; do
  45. dd conv=notrunc if=/dev/zero of=zram${i}/file \
  46. oflag=append count=1 bs=1024 status=none \
  47. > /dev/null 2>&1 || break
  48. b=$(($b + 1))
  49. done
  50. echo "zram$i can be filled with '$b' KB"
  51. done
  52. local mem_free1=$(free -m | awk 'NR==2 {print $4}')
  53. local used_mem=$(($mem_free0 - $mem_free1))
  54. local total_size=0
  55. for sm in $zram_sizes; do
  56. local s=$(echo $sm | sed 's/M//')
  57. total_size=$(($total_size + $s))
  58. done
  59. echo "zram used ${used_mem}M, zram disk sizes ${total_size}M"
  60. local v=$((100 * $total_size / $used_mem))
  61. if [ "$v" -lt 100 ]; then
  62. echo "FAIL compression ratio: 0.$v:1"
  63. ERR_CODE=-1
  64. zram_cleanup
  65. return
  66. fi
  67. echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK"
  68. }
  69. check_prereqs
  70. zram_load
  71. zram_max_streams
  72. zram_compress_alg
  73. zram_set_disksizes
  74. zram_set_memlimit
  75. zram_makefs
  76. zram_mount
  77. zram_fill_fs
  78. zram_cleanup
  79. zram_unload
  80. if [ $ERR_CODE -ne 0 ]; then
  81. echo "$TCID : [FAIL]"
  82. else
  83. echo "$TCID : [PASS]"
  84. fi