01-get_functions.t 6.7 KB

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