Set LANG=C to make sure the output of hwclock will have
the same output in all tested systems, regardless of their
language settings. After the test is done, we restore
current system language settings.

Thanks to Jason Wang, who spotted the the problem, and for
Gregory Smith, that pointed out the solution.

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 client/tests/hwclock/hwclock.py |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/client/tests/hwclock/hwclock.py b/client/tests/hwclock/hwclock.py
index 12f8c54..990959c 100644
--- a/client/tests/hwclock/hwclock.py
+++ b/client/tests/hwclock/hwclock.py
@@ -1,16 +1,40 @@
 from autotest_lib.client.bin import test, utils
 from autotest_lib.client.common_lib import error
-import re
+import re, os, logging
 
 class hwclock(test.test):
     version = 1
 
-    def run_once(self, seconds=1):
+    def setup(self):
+        """
+        Set up language environment, necessary to get the expected format
+        for hwclock output.
+        """
+        self.lang = os.environ['LANG']
+        logging.info('Current system locale is set to %s', self.lang)
+        logging.info('Setting system locale to C')
+        os.environ['LANG'] = 'C'
+
+
+    def run_once(self):
+        """
+        Set hwclock back to a date in 1980 and verify if the changes took
+        effect in the system.
+        """
+        logging.info('Setting hwclock to 2/2/80 03:04:00')
         utils.system('/sbin/hwclock --set --date "2/2/80 03:04:00"')
         date = utils.system_output('/sbin/hwclock')
         if not re.match('Sat *Feb *2 *03:04:.. 1980', date):
-            raise error.TestFail('Failed to set hwclock back to the eighties')
+            raise error.TestFail('Failed to set hwclock back to the eighties. '
+                                 'Output of hwclock is %s', date)
 
 
     def cleanup(self):
+        """
+        Restore hardware clock to current system time and also restore language
+        settings.
+        """
+        logging.info('Setting the hardware clock to the system time')
         utils.system('/sbin/hwclock --systohc --noadjfile --utc')
+        logging.info('Restoring system language settings')
+        os.environ['LANG'] = self.lang
-- 
1.6.6.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to