Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/clusterfuzz/_internal/bot/tasks/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def cleanup_task_state():

def is_supported_cpu_arch_for_job():
"""Return true if the current cpu architecture can run this job."""
cpu_arch = environment.get_cpu_arch()
cpu_arch = environment.get_target_cpu_arch()
if not cpu_arch:
# No cpu architecture check is defined for this platform, bail out.
return True
Expand Down
6 changes: 4 additions & 2 deletions src/clusterfuzz/_internal/platforms/android/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ def get_build_version():
return match.group(1)


def get_cpu_arch():
"""Return cpu architecture."""
def get_target_cpu_arch():
"""Return target cpu architecture,
i.e. the cpu architecture where the fuzzer will run.
"""
return adb.get_property('ro.product.cpu.abi')


Expand Down
9 changes: 7 additions & 2 deletions src/clusterfuzz/_internal/system/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,18 @@ def get_asan_options(redzone_size, malloc_context_size, quarantine_size_mb,
return asan_options


def get_cpu_arch():
def get_target_cpu_arch():
"""Return cpu architecture."""
if is_android():
# FIXME: Handle this import in a cleaner way.
from clusterfuzz._internal.platforms import android
return android.settings.get_cpu_arch()
return android.settings.get_target_cpu_arch()

return get_host_cpu_arch()


def get_host_cpu_arch():
Comment thread
g-ortuno marked this conversation as resolved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this method. Could we replace calls to platform_util.machine().lower() or similar with this method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion:D

Shall we create a new PR for fixing this Tech Debt?

I see several places where we use it, and worse when we are treating the platform on upper case (lol, we should create multiple conventions for CF repo)

Functions calling this function: machine

  File                     Function            Line
0 socks.py                 getpeername          369 machine (note: getproxypeername returns the proxy)
1 __init__.py              version             1140 list(platform.architecture()) + [platform.machine()])
2 test_contracts.py        test_cpu_count       240 @unittest.skipIf(MACOS and platform.machine() == 'arm64',
3 test_memleaks.py         fewtimes_if_linux    369 @unittest.skipIf(MACOS and platform.machine() == 'arm64',
4 test_osx.py              cpu_count            149 @unittest.skipIf(platform.machine() == 'arm64', "skipped due to #1892")
5 test_system.py           assertGreater        516 @unittest.skipIf(MACOS and platform.machine() == 'arm64',
6 markers.py               format_full_version  249 "platform_machine": platform.machine(),
7 markers.py               format_full_version  183 "platform_machine": platform.machine(),
8 test_windows_wrappers.py win_launcher_exe      58 if (platform.machine() == "ARM64":
9 environment.py           get_host_cpu_arch    236 machine = platform_util.machine().lower()
a common.py                get_platform         222 if (platform.machine() == 'arm64' or platform.processor() == 'arm':
b socks.py                 getpeername          369 machine (note: getproxypeername returns the proxy)
c __init__.py              version             1140 list(platform.architecture()) + [platform.machine()])
d test_contracts.py        test_cpu_count       240 @unittest.skipIf(MACOS and platform.machine() == 'arm64',
e test_memleaks.py         fewtimes_if_linux    369 @unittest.skipIf(MACOS and platform.machine() == 'arm64',
f test_osx.py              cpu_count            149 @unittest.skipIf(platform.machine() == 'arm64', "skipped due to #1892")
g test_system.py           assertGreater        516 @unittest.skipIf(MACOS and platform.machine() == 'arm64',
h markers.py               format_full_version  249 "platform_machine": platform.machine(),
i markers.py               format_full_version  183 "platform_machine": platform.machine(),
j test_windows_wrappers.py win_launcher_exe      58 if (platform.machine() == "ARM64":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, what do you think about only fixing the ones we added in the previous CL? I think that would be the one in src/clusterfuzz/_internal/bot/tasks/update_task.py?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we need to change just src/clusterfuzz/_internal/bot/tasks/update_task.py for our purposes. I just filed this bug 564549745 for tracking above's issues:D

"""Returns cpu architecture of the current host."""
machine = platform_util.machine().lower()
if machine in ('arm64', 'aarch64'):
return 'arm64'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,41 +303,41 @@ class IsSupportedCpuArchForJobTest(unittest.TestCase):
def setUp(self):
helpers.patch_environ(self)
helpers.patch(self, [
'clusterfuzz._internal.system.environment.get_cpu_arch',
'clusterfuzz._internal.system.environment.get_target_cpu_arch',
])

def test_no_bot_cpu_arch(self):
"""Test when no cpu arch is defined on bot."""
self.mock.get_cpu_arch.return_value = None
self.mock.get_target_cpu_arch.return_value = None
environment.set_value('CPU_ARCH', 'arm64')
self.assertTrue(commands.is_supported_cpu_arch_for_job())

def test_no_job_cpu_arch_requirement(self):
"""Test when job specifies no CPU_ARCH requirement."""
self.mock.get_cpu_arch.return_value = 'arm64'
self.mock.get_target_cpu_arch.return_value = 'arm64'
environment.set_value('CPU_ARCH', None)
self.assertTrue(commands.is_supported_cpu_arch_for_job())

def test_matching_single_string(self):
"""Test when job specifies matching single string CPU_ARCH."""
self.mock.get_cpu_arch.return_value = 'arm64'
self.mock.get_target_cpu_arch.return_value = 'arm64'
environment.set_value('CPU_ARCH', 'arm64')
self.assertTrue(commands.is_supported_cpu_arch_for_job())

def test_non_matching_single_string(self):
"""Test when job specifies non-matching single string CPU_ARCH."""
self.mock.get_cpu_arch.return_value = 'arm64'
self.mock.get_target_cpu_arch.return_value = 'arm64'
environment.set_value('CPU_ARCH', 'x86_64')
self.assertFalse(commands.is_supported_cpu_arch_for_job())

def test_matching_comma_separated_string(self):
"""Test when job specifies comma-separated CPU_ARCH."""
self.mock.get_cpu_arch.return_value = 'arm64'
self.mock.get_target_cpu_arch.return_value = 'arm64'
environment.set_value('CPU_ARCH', 'x86_64, arm64')
self.assertTrue(commands.is_supported_cpu_arch_for_job())

def test_matching_list(self):
"""Test when job specifies a list of supported architectures."""
self.mock.get_cpu_arch.return_value = 'arm64'
self.mock.get_target_cpu_arch.return_value = 'arm64'
environment.set_value('CPU_ARCH', ['x86_64', 'arm64'])
self.assertTrue(commands.is_supported_cpu_arch_for_job())
Original file line number Diff line number Diff line change
Expand Up @@ -481,42 +481,42 @@ def test_function():


class GetCpuArchTest(unittest.TestCase):
"""Tests for get_cpu_arch."""
"""Tests for get_target_cpu_arch."""

def setUp(self):
test_helpers.patch_environ(self)
test_helpers.patch(self, [
'clusterfuzz._internal.system.environment.is_android',
'platform.machine',
'clusterfuzz._internal.platforms.android.settings.get_cpu_arch',
'clusterfuzz._internal.platforms.android.settings.get_target_cpu_arch',
])
self.mock.is_android.return_value = False

def test_android(self):
"""Test Android architecture delegation."""
self.mock.is_android.return_value = True
self.mock.get_cpu_arch.return_value = 'arm64_v8a'
self.assertEqual('arm64_v8a', environment.get_cpu_arch())
self.mock.get_target_cpu_arch.return_value = 'arm64_v8a'
self.assertEqual('arm64_v8a', environment.get_target_cpu_arch())

def test_arm64(self):
"""Test ARM64 architecture detection."""
self.mock.machine.return_value = 'arm64'
self.assertEqual('arm64', environment.get_cpu_arch())
self.assertEqual('arm64', environment.get_target_cpu_arch())

def test_aarch64(self):
"""Test aarch64 normalized to arm64."""
self.mock.machine.return_value = 'aarch64'
self.assertEqual('arm64', environment.get_cpu_arch())
self.assertEqual('arm64', environment.get_target_cpu_arch())

def test_x86_64(self):
"""Test x86_64 architecture detection."""
self.mock.machine.return_value = 'x86_64'
self.assertEqual('x86_64', environment.get_cpu_arch())
self.assertEqual('x86_64', environment.get_target_cpu_arch())

def test_amd64(self):
"""Test amd64 normalized to x86_64."""
self.mock.machine.return_value = 'AMD64'
self.assertEqual('x86_64', environment.get_cpu_arch())
self.assertEqual('x86_64', environment.get_target_cpu_arch())


class GetDefaultToolPathTest(unittest.TestCase):
Expand Down
Loading