Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes bug 1148587 - 0x221 is the wrong adapter hex #2702

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion webapp-django/crashstats/manage/tests/sample-graphics.csv
Expand Up @@ -43,12 +43,15 @@
002F .43 ieee 1394 controller
00333 1ACPI\GenuineIntel_-_x86_Family_6_Model_23\_0 1ACPI\GenuineIntel_-_x86_Family_6_Model_23\_0
6800 n/a
08b2 123abc logitech QuickCam� Pro 4000
08b2 123abc logitech QuickCam� Pro 4000
08f0 n/a n/a
0553 Aiptek USA
0200, 0x0201 DS38xx Oregon Scientific
6128_ USB\VID_0C45&PID_6148&REV_0101 USB PC Camera Plus
X0X0 Some rubbish
0407 Lava Computer MFG Inc.
0221 LavaPort Quad-650 PCI C/D

;
;============
; END OF LIST
Expand Down
48 changes: 34 additions & 14 deletions webapp-django/crashstats/manage/tests/test_utils.py
Expand Up @@ -3,7 +3,10 @@

from nose.tools import eq_

from crashstats.manage.utils import parse_graphics_devices_iterable
from crashstats.manage.utils import (
parse_graphics_devices_iterable,
string_hex_to_hex_string
)


SAMPLE_CSV_FILE = os.path.join(
Expand All @@ -14,6 +17,14 @@

class TestUtils(TestCase):

def test_string_hex_to_hex_string(self):
eq_(string_hex_to_hex_string('919A'), '0x919a')
eq_(string_hex_to_hex_string('0x919A'), '0x919a')

eq_(string_hex_to_hex_string('221'), '0x0221')
eq_(string_hex_to_hex_string('0221'), '0x0221')
eq_(string_hex_to_hex_string('0x0221'), '0x0221')

def test_parse_graphics_devices_iterable(self):
iterable = open(SAMPLE_CSV_FILE)
try:
Expand All @@ -27,50 +38,50 @@ def test_parse_graphics_devices_iterable(self):
eq_(
things[0],
{
'adapter_hex': '0x2f',
'adapter_hex': '0x002f',
'adapter_name': '.43 ieee 1394 controller',
'vendor_hex': '0x33',
'vendor_hex': '0x0033',
'vendor_name': 'Paradyne Corp.'
}
)
# same vendor as before
eq_(
things[1],
{
'adapter_hex': '0x333',
'adapter_hex': '0x0333',
'adapter_name': '1ACPI\\GenuineIntel_-_x86_Family_6_Model_'
'23\\_0 1ACPI\\GenuineIntel_-_x86_Family_6'
'_Model_23\\_0',
'vendor_hex': '0x33',
'vendor_hex': '0x0033',
'vendor_name': 'Paradyne Corp.'
}
)
# non-utf-8 encoded charater here
eq_(
things[2],
{
'adapter_hex': '0x8b2',
'adapter_name': u'123abc logitech QuickCam\xae Pro 4000',
'vendor_hex': '0x33',
'adapter_hex': '0x08b2',
'adapter_name': u'123abc logitech QuickCam\ufffd Pro 4000',
'vendor_hex': '0x0033',
'vendor_name': 'Paradyne Corp.'
}
)
# two adapter_hexes split up
eq_(
things[3],
{
'adapter_hex': '0x200',
'adapter_hex': '0x0200',
'adapter_name': 'DS38xx Oregon Scientific',
'vendor_hex': '0x553',
'vendor_hex': '0x0553',
'vendor_name': 'Aiptek USA'
}
)
eq_(
things[4],
{
'adapter_hex': '0x201',
'adapter_hex': '0x0201',
'adapter_name': 'DS38xx Oregon Scientific',
'vendor_hex': '0x553',
'vendor_hex': '0x0553',
'vendor_name': 'Aiptek USA'
}
)
Expand All @@ -81,11 +92,20 @@ def test_parse_graphics_devices_iterable(self):
'adapter_hex': '0x6128',
'adapter_name': 'USB\\VID_0C45&PID_6148&REV_0101 USB PC '
'Camera Plus',
'vendor_hex': '0x553',
'vendor_hex': '0x0553',
'vendor_name': 'Aiptek USA'
}
)
eq_(len(things), 6)
eq_(
things[6],
{
'adapter_hex': '0x0221',
'adapter_name': 'LavaPort Quad-650 PCI C/D',
'vendor_hex': '0x0407',
'vendor_name': 'Lava Computer MFG Inc.'
}
)
eq_(len(things), 7)

finally:
iterable.close()
6 changes: 3 additions & 3 deletions webapp-django/crashstats/manage/tests/test_views.py
Expand Up @@ -927,13 +927,13 @@ def mocked_post(url, **options):
eq_(
data[0],
{
'vendor_hex': '0x33',
'adapter_hex': '0x2f',
'vendor_hex': '0x0033',
'adapter_hex': '0x002f',
'vendor_name': 'Paradyne Corp.',
'adapter_name': '.43 ieee 1394 controller'
}
)
eq_(len(data), 6)
eq_(len(data), 7)
return Response('true')

rpost.side_effect = mocked_post
Expand Down
13 changes: 7 additions & 6 deletions webapp-django/crashstats/manage/utils.py
@@ -1,13 +1,14 @@
def _string_hex_to_hex_string(snippet):
def string_hex_to_hex_string(snippet):
"""The PCIDatabase.com uses shortened hex strings (e.g. '919A')
whereas in Socorro we use the full represenation, but still as a
string (e.g. '0x919a').
Also, note that when converting the snippet to a 16 base int, we
can potentially lose the leading zeros, but we want to make sure
we always return a 4 character string preceeded by 0x.
This function tries to make that conversion.
"""
assert isinstance(snippet, basestring)
if not snippet.startswith('0x'):
snippet = '0x%s' % snippet
return hex(int(snippet, 16))
return '0x' + format(int(snippet, 16), '04x')


def parse_graphics_devices_iterable(iterable, delimiter='\t'):
Expand Down Expand Up @@ -42,7 +43,7 @@ def parse_graphics_devices_iterable(iterable, delimiter='\t'):
split = [x.strip() for x in line.rstrip().split(delimiter)]
if len(split) == 2 and split[0]:
vendor_hex, vendor_name = split
vendor_hex = _string_hex_to_hex_string(vendor_hex)
vendor_hex = string_hex_to_hex_string(vendor_hex)
elif len(split) == 3 and not split[0] and split[1] and split[2]:
if split[2] in ('n/a', 'n/a n/a'):
# some adapter names appear to be entered in this
Expand All @@ -56,7 +57,7 @@ def parse_graphics_devices_iterable(iterable, delimiter='\t'):
if adapter_hex.endswith('_'):
adapter_hex = adapter_hex[:-1]
try:
adapter_hex = _string_hex_to_hex_string(adapter_hex)
adapter_hex = string_hex_to_hex_string(adapter_hex)
yield {
'vendor_hex': vendor_hex,
'vendor_name': vendor_name,
Expand Down