Skip to contentSkip to conversation

perf tests: Move attr.py temp dir cleanup into finally section

PATCH In review Jiri Olsa 1 participant 2 messages Nov 8, 2012 – Nov 14, 2012 perf events

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

PATCH 1/1 perf tests: Move attr.py temp dir cleanup into finally section

Currently if there's 'Unsup' exception raised, we do not clean up the temp directory. Solving this by adding 'finally' to make the cleanup in any case.

Cc Corey Ashford <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/tests/attr.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
tools/perf/tests/attr.py +16 -14
index 9b25b33c..e702b82 100644
@@ -228,24 +228,26 @@ class Test(object):
     def run(self):
         tempdir = tempfile.mkdtemp();
 
-        # run the test script
-        self.run_cmd(tempdir);
+        try:
+            # run the test script
+            self.run_cmd(tempdir);
 
-        # load events expectation for the test
-        log.info("  loading result events");
-        for f in glob.glob(tempdir + '/event*'):
-            self.load_events(f, self.result);
+            # load events expectation for the test
+            log.info("  loading result events");
+            for f in glob.glob(tempdir + '/event*'):
+                self.load_events(f, self.result);
 
-        # resolve group_fd to event names
-        self.resolve_groups(self.expect);
-        self.resolve_groups(self.result);
+            # resolve group_fd to event names
+            self.resolve_groups(self.expect);
+            self.resolve_groups(self.result);
 
-        # do the expectation - results matching - both ways
-        self.compare(self.expect, self.result)
-        self.compare(self.result, self.expect)
+            # do the expectation - results matching - both ways
+            self.compare(self.expect, self.result)
+            self.compare(self.result, self.expect)
 
-        # cleanup
-        shutil.rmtree(tempdir)
+        finally:
+            # cleanup
+            shutil.rmtree(tempdir)
 
 
 def run_tests(options):
Signature · 1 line
1.7.11.7
#1 lore raw

[tip:perf/core] perf tests: Move attr. py temp dir cleanup into finally section

Commit-ID:  d4fcf0a8b96b23a245a21065c9424e09c8080819
Gitweb:     http://git.kernel.org/tip/d4fcf0a8b96b23a245a21065c9424e09c8080819
Author:     Jiri Olsa <[email protected]>
AuthorDate: Thu, 8 Nov 2012 17:01:01 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 8 Nov 2012 13:16:19 -0300

perf tests: Move attr.py temp dir cleanup into finally section

Currently if there's 'Unsup' exception raised, we do not clean up the temp directory. Solving this by adding 'finally' to make the cleanup in any case.

---
 tools/perf/tests/attr.py |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)
tools/perf/tests/attr.py +16 -14
index 9b25b33c..e702b82 100644
@@ -228,24 +228,26 @@ class Test(object):
     def run(self):
         tempdir = tempfile.mkdtemp();
 
-        # run the test script
-        self.run_cmd(tempdir);
+        try:
+            # run the test script
+            self.run_cmd(tempdir);
 
-        # load events expectation for the test
-        log.info("  loading result events");
-        for f in glob.glob(tempdir + '/event*'):
-            self.load_events(f, self.result);
+            # load events expectation for the test
+            log.info("  loading result events");
+            for f in glob.glob(tempdir + '/event*'):
+                self.load_events(f, self.result);
 
-        # resolve group_fd to event names
-        self.resolve_groups(self.expect);
-        self.resolve_groups(self.result);
+            # resolve group_fd to event names
+            self.resolve_groups(self.expect);
+            self.resolve_groups(self.result);
 
-        # do the expectation - results matching - both ways
-        self.compare(self.expect, self.result)
-        self.compare(self.result, self.expect)
+            # do the expectation - results matching - both ways
+            self.compare(self.expect, self.result)
+            self.compare(self.result, self.expect)
 
-        # cleanup
-        shutil.rmtree(tempdir)
+        finally:
+            # cleanup
+            shutil.rmtree(tempdir)
 
 
 def run_tests(options):