Merge lp:~sylvain-pineau/checkbox/gpu_test_2to3 into lp:checkbox

Proposed by Sylvain Pineau
Status: Merged
Merged at revision: 1419
Proposed branch: lp:~sylvain-pineau/checkbox/gpu_test_2to3
Merge into: lp:checkbox
Diff against target: 195 lines (+57/-31) (has conflicts)
2 files modified
debian/changelog (+5/-0)
scripts/gpu_test (+52/-31)
Text conflict in debian/changelog
To merge this branch: bzr merge lp:~sylvain-pineau/checkbox/gpu_test_2to3
Reviewer Review Type Date Requested Status
Marc Tardif (community) Approve
Sylvain Pineau (community) Needs Resubmitting
Review via email: mp+109111@code.launchpad.net

Description of the change

gpu_test conversion to python 3.
pexpect dependency removed, and Flash/firefox test is now launched with normal user.

To post a comment you must log in.
1417. By Sylvain Pineau

debian/changelog updated

Revision history for this message
Marc Tardif (cr3) wrote :

1. I noticed you are now checking that the script runs as root. Instead of checking for the UID, I would suggest you check for the effective UID. What do you think?

The rest looks good as far as the conversion is concerned, and I really like how you had the courage to replace pexpect in the gpu_test script. If you have a moment, I have a few syntactic suggestions:

1. When using the with statement, the variable assigned to the output of the given function is typically only used within the scope of the code block. This is not a problem with this merge request, nor does it prevent the code from working because Python variables continue existing outside of some code blocks. So, I would suggest using the self.tempfile variable instead of f outside the with code block:

        os.chmod(self.tempfile, stat.S_IROTH)
        subprocess.call(
            'sudo -H -u %s firefox %s' % (os.getenv('SUDO_USER'), self.tempfile),
            stdout=open(os.devnull, 'w'),
            stderr=subprocess.STDOUT,
            shell=True)

2. When specifying an encoding to the encode() method, I would suggest not passing anything instead of "utf-8" that is the default value anyways.

3. I noticed that you changed the type of x_res, y_res, hsize and vsize to integers. So, instead of casting the division of those variables to int, you might like to use integer division instead:

  DesktopSwitch = ChangeViewport(
    hsize, vsize, x_res // hsize, y_res // vsize)

review: Needs Fixing
1418. By Sylvain Pineau

Fixed minor syntax issues after peer review

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Fixed the code after Marc's review

review: Needs Resubmitting
Revision history for this message
Marc Tardif (cr3) wrote :

Thanks, merging!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-06-07 15:39:38 +0000
3+++ debian/changelog 2012-06-07 16:12:18 +0000
4@@ -70,9 +70,14 @@
5
6
7 [Sylvain Pineau]
8+<<<<<<< TREE
9 * [FEATURE] Python 2 to 3 conversion:
10 * scripts/gst_pipeline_test. Migrated to PyGI.
11 * Fullscreen playbacks are now performed with Totem instead of gst_pipeline_test.
12+=======
13+ * [FEATURE] Python 2 to 3 conversion:
14+ * scripts/gpu_test
15+>>>>>>> MERGE-SOURCE
16 * scripts/pm_log_check: added a slightly modified version of OEM team's pm_check.py
17 script to analyze pm_test logs
18 * jobs/stress.txt.in: add OEM team's stress tests (including reboot and poweroff)
19
20=== modified file 'scripts/gpu_test'
21--- scripts/gpu_test 2012-05-22 18:01:21 +0000
22+++ scripts/gpu_test 2012-06-07 16:12:18 +0000
23@@ -1,11 +1,11 @@
24-#!/usr/bin/python
25+#!/usr/bin/python3
26
27 import re
28 import os
29+import stat
30 import sys
31 import time
32-import pexpect
33-from subprocess import call, STDOUT
34+import subprocess
35 from threading import Thread
36 from tempfile import NamedTemporaryFile
37 from math import cos, sin
38@@ -17,10 +17,14 @@
39 """
40
41 def run(self):
42- pexpect.run('glxgears -geometry 400x400', timeout=None)
43+ subprocess.call(
44+ 'glxgears -geometry 400x400',
45+ stdout=open(os.devnull, 'w'),
46+ stderr=subprocess.STDOUT,
47+ shell=True)
48
49 def terminate(self):
50- call('wmctrl -i -c %s' % self.id, shell=True)
51+ subprocess.call('wmctrl -i -c %s' % self.id, shell=True)
52
53
54 class RotateGlxThread(Thread):
55@@ -40,8 +44,9 @@
56 x = int(200 * self.offset + 100 * sin(j * 0.2))
57 y = int(200 * self.offset + 100 * cos(j * 0.2))
58 coords = "%s,%s" % (x, y)
59- call('wmctrl -i -r %s -e 0,%s,-1,-1' % (self.id, coords),
60- shell=True)
61+ subprocess.call(
62+ 'wmctrl -i -r %s -e 0,%s,-1,-1' % (self.id, coords),
63+ shell=True)
64 time.sleep(0.002 * self.offset)
65 if self.cancel:
66 return
67@@ -60,11 +65,11 @@
68 def run(self):
69 while(1):
70 for i in range(self.size):
71- call('wmctrl -s %s' % i, shell=True)
72+ subprocess.call('wmctrl -s %s' % i, shell=True)
73 time.sleep(0.5)
74 if self.cancel:
75 # Switch back to workspace #1
76- call('wmctrl -s 0', shell=True)
77+ subprocess.call('wmctrl -s 0', shell=True)
78 return
79
80
81@@ -85,12 +90,13 @@
82 while(1):
83 for i in range(self.hsize):
84 for j in range(self.vsize):
85- call('wmctrl -o %s,%s' % (self.xsize * j, self.ysize * i),
86- shell=True)
87+ subprocess.call(
88+ 'wmctrl -o %s,%s' % (self.xsize * j, self.ysize * i),
89+ shell=True)
90 time.sleep(0.5)
91 if self.cancel:
92 # Switch back to viewport #1
93- call('wmctrl -o 0,0', shell=True)
94+ subprocess.call('wmctrl -o 0,0', shell=True)
95 return
96
97
98@@ -112,13 +118,18 @@
99
100 with NamedTemporaryFile(suffix='.html', delete=False) as f:
101 self.tempfile = f.name
102- f.write("%s" % source)
103+ f.write(source.encode())
104 f.close()
105- call('firefox %s' % f.name, stdout=open(os.devnull, 'w'),
106- stderr=STDOUT, shell=True)
107+ os.chmod(self.tempfile, stat.S_IROTH)
108+ subprocess.call(
109+ 'sudo -H -u %s firefox %s' % (os.getenv('SUDO_USER'),
110+ self.tempfile),
111+ stdout=open(os.devnull, 'w'),
112+ stderr=subprocess.STDOUT,
113+ shell=True)
114
115 def terminate(self):
116- call('wmctrl -c firefox', shell=True)
117+ subprocess.call('wmctrl -c firefox', shell=True)
118 os.unlink(self.tempfile)
119
120
121@@ -143,15 +154,19 @@
122 f = open('/var/log/kern.log', 'r')
123 with f:
124 if re.findall(r'gpu\s+hung', f.read(), flags=re.I):
125- print "GPU hung Detected"
126+ print("GPU hung Detected")
127 sys.exit(1)
128
129
130 def main():
131+ if not (os.geteuid() == 0):
132+ print("Must be run as root.")
133+ return 1
134+
135 check_gpu()
136 GlxWindows = []
137 GlxRotate = []
138- call("pkill 'glxgears|firefox'", shell=True)
139+ subprocess.call("pkill 'glxgears|firefox'", shell=True)
140
141 FlashVideo = FlashVideoThread()
142 FlashVideo.start()
143@@ -160,33 +175,39 @@
144 GlxWindows.append(GlxThread())
145 GlxWindows[i].start()
146 time.sleep(0.5)
147- windows = pexpect.run('wmctrl -l | grep glxgears')
148+ windows = subprocess.check_output(
149+ 'wmctrl -l | grep glxgears',
150+ shell=True)
151 for app in sorted(windows.splitlines(), reverse=True):
152- if not 'glxgears' in app:
153+ if not b'glxgears' in app:
154 continue
155- GlxWindows[i].id = re.match(r'^(0x\w+)', app).group(0)
156+ GlxWindows[i].id = str(
157+ re.match(b'^(0x\w+)', app).group(0), 'utf-8')
158 break
159 GlxRotate.append(RotateGlxThread(GlxWindows[i].id, i + 1))
160 GlxRotate[i].start()
161
162 if is_unity_2d_running():
163- size = int(pexpect.run(
164- 'gconftool --get /apps/metacity/general/num_workspaces'))
165+ size = int(subprocess.check_output(
166+ 'gconftool --get /apps/metacity/general/num_workspaces',
167+ shell=True))
168 DesktopSwitch = ChangeWorkspace(size)
169 else:
170- (x_res, y_res) = re.search(r'DG:\s+(\d+)x(\d+)',
171- pexpect.run('wmctrl -d')).groups()
172- hsize = int(pexpect.run(
173- 'gconftool --get /apps/compiz-1/general/screen0/options/hsize'))
174- vsize = int(pexpect.run(
175- 'gconftool --get /apps/compiz-1/general/screen0/options/vsize'))
176+ (x_res, y_res) = re.search(b'DG:\s+(\d+)x(\d+)',
177+ subprocess.check_output('wmctrl -d', shell=True)).groups()
178+ hsize = int(subprocess.check_output(
179+ 'gconftool --get /apps/compiz-1/general/screen0/options/hsize',
180+ shell=True))
181+ vsize = int(subprocess.check_output(
182+ 'gconftool --get /apps/compiz-1/general/screen0/options/vsize',
183+ shell=True))
184 DesktopSwitch = ChangeViewport(
185- hsize, vsize, int(x_res) / hsize, int(y_res) / vsize)
186+ hsize, vsize, int(x_res) // hsize, int(y_res) // vsize)
187 DesktopSwitch.start()
188
189 time.sleep(20)
190 # Suspend/resume the SUT
191- call('fwts -q s3 --s3-sleep-delay=30', shell=True)
192+ subprocess.call('fwts -q s3 --s3-sleep-delay=30', shell=True)
193 time.sleep(20)
194
195 for i in range(2):

Subscribers

People subscribed via source and target branches