01-function_tests.t 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. use warnings;
  2. use strict;
  3. use Test::More 'tests' => 17;
  4. use Test::Fatal;
  5. use Disk::SMART;
  6. $ENV{'MOCK_TEST_DATA'} =
  7. 'smartctl 5.41 2011-06-09 r3365 [x86_64-linux-2.6.32-32-pve] (local build)
  8. Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
  9. === START OF INFORMATION SECTION ===
  10. Model Family: Seagate Barracuda 7200.10
  11. Device Model: ST3250410AS
  12. Serial Number: 6RYBDDDQ
  13. Firmware Version: 3.AAF
  14. User Capacity: 250,059,350,016 bytes [250 GB]
  15. Sector Size: 512 bytes logical/physical
  16. Device is: In smartctl database [for details use: -P show]
  17. ATA Version is: 7
  18. ATA Standard is: Exact ATA specification draft version not indicated
  19. Local Time is: Wed Oct 15 17:16:35 2014 CDT
  20. SMART support is: Available - device has SMART capability.
  21. SMART support is: Enabled
  22. === START OF READ SMART DATA SECTION ===
  23. SMART overall-health self-assessment test result: PASSED
  24. General SMART Values:
  25. Offline data collection status: (0x82) Offline data collection activity
  26. was completed without error.
  27. Auto Offline Data Collection: Enabled.
  28. Self-test execution status: ( 0) The previous self-test routine completed
  29. without error or no self-test has ever
  30. been run.
  31. Total time to complete Offline
  32. data collection: ( 430) seconds.
  33. Offline data collection
  34. capabilities: (0x5b) SMART execute Offline immediate.
  35. Auto Offline data collection on/off support.
  36. Suspend Offline collection upon new
  37. command.
  38. Offline surface scan supported.
  39. Self-test supported.
  40. No Conveyance Self-test supported.
  41. Selective Self-test supported.
  42. SMART capabilities: (0x0003) Saves SMART data before entering
  43. power-saving mode.
  44. Supports SMART auto save timer.
  45. Error logging capability: (0x01) Error logging supported.
  46. General Purpose Logging supported.
  47. Short self-test routine
  48. recommended polling time: ( 1) minutes.
  49. Extended self-test routine
  50. recommended polling time: ( 64) minutes.
  51. SCT capabilities: (0x0001) SCT Status supported.
  52. SMART Attributes Data Structure revision number: 10
  53. Vendor Specific SMART Attributes with Thresholds:
  54. ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
  55. 1 Raw_Read_Error_Rate 0x000f 100 253 006 Pre-fail Always - 0
  56. 3 Spin_Up_Time 0x0003 098 098 000 Pre-fail Always - 0
  57. 4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 19
  58. 5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 0
  59. 7 Seek_Error_Rate 0x000f 070 060 030 Pre-fail Always - 10571330
  60. 9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 1100
  61. 10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
  62. 12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 19
  63. 187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always - 0
  64. 189 High_Fly_Writes 0x003a 100 100 000 Old_age Always - 0
  65. 190 Airflow_Temperature_Cel 0x0022 065 050 045 Old_age Always - 35 (Min/Max 13/50)
  66. 194 Temperature_Celsius 0x0022 035 050 000 Old_age Always - 35 (0 13 0 0)
  67. 195 Hardware_ECC_Recovered 0x001a 066 060 000 Old_age Always - 59046455
  68. 197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
  69. 198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
  70. 199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always - 0
  71. 200 Multi_Zone_Error_Rate 0x0000 100 253 000 Old_age Offline - 0
  72. 202 Data_Address_Mark_Errs 0x0032 100 253 000 Old_age Always - 0
  73. SMART Error Log Version: 1
  74. No Errors Logged
  75. SMART Self-test log structure revision number 1
  76. Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
  77. # 1 Short offline Completed without error 00% 1100 -
  78. # 2 Short offline Completed without error 00% 1100 -
  79. # 3 Extended offline Aborted by host 90% 1100 -
  80. # 4 Short offline Completed without error 00% 1100 -
  81. # 5 Short offline Completed without error 00% 1100 -
  82. # 6 Short offline Completed without error 00% 1099 -
  83. SMART Selective self-test log data structure revision number 1
  84. SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS
  85. 1 0 0 Not_testing
  86. 2 0 0 Not_testing
  87. 3 0 0 Not_testing
  88. 4 0 0 Not_testing
  89. 5 0 0 Not_testing
  90. Selective self-test flags (0x0):
  91. After scanning selected spans, do NOT read-scan remainder of disk.
  92. If Selective self-test is pending on power-up, resume after 0 minute delay.';
  93. my $disk = '/dev/test_good';
  94. my $smart = Disk::SMART->new($disk);
  95. #Positive testing
  96. is( $smart->get_disk_temp($disk), 2, 'get_disk_temp() returns device temperature' );
  97. is( $smart->get_disk_health($disk), 'PASSED', 'get_disk_health() returns health status' );
  98. is( $smart->get_disk_model($disk), 'ST3250410AS', 'get_disk_model() returns device model' );
  99. is( $smart->get_disk_errors($disk), 'No Errors Logged', 'get_disk_errors() returns proper string' );
  100. my %attribs = $smart->get_disk_attributes($disk);
  101. is( keys %attribs, 18, 'get_disk_attributes() returns hash of device attributes' );
  102. is( $smart->run_short_test($disk), 'Completed without error', 'run_short_test() returns proper string' );
  103. $ENV{'MOCK_TEST_DATA'} =~ s/ST3250410AS//;
  104. $ENV{'MOCK_TEST_DATA'} =~ s/187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always - 0/187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always - 1/;
  105. is( $smart->update_data($disk), undef, 'update_data() updated object with changed device data' );
  106. is( $smart->get_disk_model($disk), 'N/A', 'get_disk_model() returns N/A with changed device data' );
  107. is( $smart->get_disk_temp($disk), 2, 'get_disk_temp() returns device temperature' );
  108. is( $smart->get_disk_health($disk), 'PASSED: 187 - Reported_Uncorrect = 1', 'get_disk_health() returns failed attribute status when SMART attribute 187 > 0' );
  109. #Negative testing
  110. $disk = '/dev/test_bad';
  111. like( exception { $smart->get_disk_temp($disk); }, qr/$disk not found in object/, 'get_disk_temp() returns failure when passed invalid device' );
  112. like( exception { $smart->get_disk_health($disk); }, qr/$disk not found in object/, 'get_disk_health() returns failure when passed invalid device' );
  113. like( exception { $smart->get_disk_errors($disk); }, qr/$disk not found in object/, 'get_disk_model() returns failure when passed invalid device' );
  114. like( exception { $smart->get_disk_errors($disk); }, qr/$disk not found in object/, 'get_disk_errors() returns failure when passed invalid device' );
  115. like( exception { $smart->get_disk_attributes($disk); }, qr/$disk not found in object/, 'get_disk_attributes() returns failure when passed invalid device' );
  116. like( exception { $smart->run_short_test($disk); }, qr/$disk not found in object/, 'run_short_test() returns failure when passed invalid device' );
  117. $ENV{'MOCK_TEST_DATA'} = undef;
  118. like( exception { $smart->update_data($disk); }, qr/couldn't poll/, 'update_data() returns falure when passed invalid device' );