zram01.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  4. #
  5. # Test creates several zram devices with different filesystems on them.
  6. # It fills each device with zeros and checks that compression works.
  7. #
  8. # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
  9. # Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
  10. TCID="zram01"
  11. ERR_CODE=0
  12. . ./zram_lib.sh
  13. # Test will create the following number of zram devices:
  14. dev_num=1
  15. # This is a list of parameters for zram devices.
  16. # Number of items must be equal to 'dev_num' parameter.
  17. zram_max_streams="2"
  18. # The zram sysfs node 'disksize' value can be either in bytes,
  19. # or you can use mem suffixes. But in some old kernels, mem
  20. # suffixes are not supported, for example, in RHEL6.6GA's kernel
  21. # layer, it uses strict_strtoull() to parse disksize which does
  22. # not support mem suffixes, in some newer kernels, they use
  23. # memparse() which supports mem suffixes. So here we just use
  24. # bytes to make sure everything works correctly.
  25. zram_sizes="2097152" # 2MB
  26. zram_mem_limits="2M"
  27. zram_filesystems="ext4"
  28. zram_algs="lzo"
  29. zram_fill_fs()
  30. {
  31. for i in $(seq $dev_start $dev_end); do
  32. echo "fill zram$i..."
  33. local b=0
  34. while [ true ]; do
  35. dd conv=notrunc if=/dev/zero of=zram${i}/file \
  36. oflag=append count=1 bs=1024 status=none \
  37. > /dev/null 2>&1 || break
  38. b=$(($b + 1))
  39. done
  40. echo "zram$i can be filled with '$b' KB"
  41. local mem_used_total=`awk '{print $3}' "/sys/block/zram$i/mm_stat"`
  42. local v=$((100 * 1024 * $b / $mem_used_total))
  43. if [ "$v" -lt 100 ]; then
  44. echo "FAIL compression ratio: 0.$v:1"
  45. ERR_CODE=-1
  46. return
  47. fi
  48. echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK"
  49. done
  50. }
  51. check_prereqs
  52. zram_load
  53. zram_max_streams
  54. zram_compress_alg
  55. zram_set_disksizes
  56. zram_set_memlimit
  57. zram_makefs
  58. zram_mount
  59. zram_fill_fs
  60. zram_cleanup
  61. if [ $ERR_CODE -ne 0 ]; then
  62. echo "$TCID : [FAIL]"
  63. else
  64. echo "$TCID : [PASS]"
  65. fi