This is an archive of the discontinued LLVM Phabricator instance.

[Analyzer] Refactor analyzer testing scripts
ClosedPublic

Authored by george.karpenkov on Sep 21 2017, 2:59 PM.

Details

Summary
  • Exporting needed function for future reuse
  • Idiomatic python: using with file as f instead of try/finally
  • Fixing some indentation issues
  • No need to reinvent python multiprocessing.getCPUCount()
  • Removing a function parameter which is always the same under all invocations
  • Adding some docstrings

Diff Detail

Repository
rL LLVM

Event Timeline

Do not import self from CmpRuns

dcoughlin accepted this revision.Sep 21 2017, 6:33 PM
dcoughlin added a reviewer: NoQ.
dcoughlin added a subscriber: NoQ.

This is great as long as multiprocessing.cpu_count() preserves the behavior we want. Does it?

Also, please make sure to add @NoQ to static analyzer reviews!

utils/analyzer/SATestBuild.py
133 ↗(On Diff #116296)

Seems reasonable and a nice clean up. Does it work on Windows, Linux, and macOS? The documentation says it is allowed to not be implemented.

This revision is now accepted and ready to land.Sep 21 2017, 6:33 PM

Does it work on Windows, Linux, and macOS?

It definitely works on OS X and Unix.
It's Windows implementation is the same one we have, so it is not worse (apparently it can fail on some obscure Windows versions, but so can the current implementation).

This is great as long as multiprocessing.cpu_count() preserves the behavior we want. Does it?

Yes, the implementation is almost exactly the same as ours:

In [1]: import multiprocessing

In [2]: multiprocessing.cpu_count??
Signature: multiprocessing.cpu_count()
Source:
def cpu_count():
    '''
    Returns the number of CPUs in the system
    '''
    if sys.platform == 'win32':
        try:
            num = int(os.environ['NUMBER_OF_PROCESSORS'])
        except (ValueError, KeyError):
            num = 0
    elif 'bsd' in sys.platform or sys.platform == 'darwin':
        comm = '/sbin/sysctl -n hw.ncpu'
        if sys.platform == 'darwin':
            comm = '/usr' + comm
        try:
            with os.popen(comm) as p:
                num = int(p.read())
        except ValueError:
            num = 0
    else:
        try:
            num = os.sysconf('SC_NPROCESSORS_ONLN')
        except (ValueError, OSError, AttributeError):
            num = 0

    if num >= 1:
        return num
    else:
        raise NotImplementedError('cannot determine number of cpus')

Also, please make sure to add @NoQ to static analyzer reviews!

OK!

This revision was automatically updated to reflect the committed changes.