test_ngtf_build.py 2.46 KB
Newer Older
1 2
#!/usr/bin/env python3
# ==============================================================================
3
#  Copyright 2017-2019 Intel Corporation
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
# ==============================================================================
import argparse
import errno
import os
from subprocess import check_output, call
import sys
import shutil
import glob
import platform
import json
import shlex

def command_executor(cmd, verbose=False, msg=None, stdout=None):
    '''
    Executes the command.
    Example: 
      - command_executor('ls -lrt')
      - command_executor(['ls', '-lrt'])
    '''
    if type(cmd) == type([]):  #if its a list, convert to string
        cmd = ' '.join(cmd)
    if verbose:
        tag = 'Running COMMAND: ' if msg is None else msg
        print(tag + cmd)
    if (call(shlex.split(cmd), stdout=stdout) != 0):
        raise Exception("Error running command: " + cmd)

def download(target_name, repo, version):

    # First download to a temp folder
    call(["git", "clone", repo, target_name])

    # Next goto this folder nd determone the name of the root folder
    pwd = os.getcwd()

    # Go to the tree
    os.chdir(target_name)

    # checkout the specified branch
    command_executor(["git", "fetch"], verbose=True)
    command_executor(["git", "checkout", version], verbose=True)

    os.chdir(pwd)

# Get me the current sha for this commit
current_sha = check_output(['git', 'rev-parse', 'HEAD']).strip().decode("utf-8")
print("nGraph SHA: ", current_sha)

# Download ngraph-bridge 
download('ngraph-bridge', 'https://github.com/tensorflow/ngraph-bridge.git', 'master')

# Run ngraph-bridge-build
pwd = os.getcwd()
os.chdir('ngraph-bridge')
command_executor(['./build_ngtf.py', '--ngraph_version', current_sha])

# Now run the tests
os.environ['PYTHONPATH'] = os.getcwd() 
command_executor([
    'python3',
    'test/ci/buildkite/test_runner.py',
    '--artifacts',
    'build_cmake/artifacts',
    '--test_cpp'
])

os.chdir(pwd)