@@ -178,6 +178,14 @@ def meson_build_system(self, deps):
178178 self .ndctl = os .path .abspath ('/usr/bin/ndctl' )
179179 self .daxctl = os .path .abspath ('/usr/bin/daxctl' )
180180
181+ def get_shutdown_state (self , region ):
182+ """
183+ The method returns the shutdown state as a string, which can be either "clean" or "dirty".
184+ """
185+ cmd = 'ndctl list -DH -r %s | grep shutdown_state' % region
186+ self .output = process .system_output (cmd , sudo = True , shell = True )
187+ return (str (self .output ).split ("\" " )[3 ])
188+
181189 def setUp (self ):
182190 """
183191 Build 'ndctl' and setup the binary.
@@ -1149,6 +1157,30 @@ def test_devmap_Optimisation(self):
11491157 self .fail ("Namespace creation with 1GB alignment"
11501158 "must have failed!" )
11511159
1160+ @avocado .fail_on (pmem .PMemException )
1161+ def test_inject_SMART_errors (self ):
1162+ """
1163+ Test to verify the error injection feature of ndctl inject-smart
1164+ for a pmem device
1165+ """
1166+ region = self .get_default_region ()
1167+ if self .get_shutdown_state (region ) == "clean" :
1168+ self .log .info ("shutdown state is clean" )
1169+ cmd = 'ndctl list -DH -r %s | grep dev' % region
1170+ self .output = process .system_output (cmd , sudo = True , shell = True )
1171+ cmd = 'ndctl inject-smart %s -U' % str (self .output ).split ("\" " )[3 ]
1172+ self .output = process .system_output (cmd , sudo = True , shell = True )
1173+ if self .get_shutdown_state (region ) == "dirty" :
1174+ self .log .info ("shutdown state is dirty Error injection is successful." )
1175+ else :
1176+ self .fail ("Error injection failed" )
1177+ cmd = 'ndctl list -DH -r %s | grep dev' % region
1178+ self .output = process .system_output (cmd , sudo = True , shell = True )
1179+ cmd = 'ndctl inject-smart %s -N' % str (self .output ).split ("\" " )[3 ]
1180+ self .output = process .system_output (cmd , sudo = True , shell = True )
1181+ if self .get_shutdown_state (region ) == "clean" :
1182+ self .log .info ("shutdown state is clean" )
1183+
11521184 @avocado .fail_on (pmem .PMemException )
11531185 def tearDown (self ):
11541186 if hasattr (self , 'part' ) and self .part :
0 commit comments