Commit 240aff80 authored by Alex Richardson's avatar Alex Richardson
Browse files

Add initial tests for update_{llc_,cc_,}test_checks.py

Summary:
This commit adds basic tests for these update script to validate that
they still work as expected. In the future we could extend these tests
whenever new features are added to avoid introducing regressions.

Reviewers: xbolva00, MaskRay, jdoerfert

Reviewed By: jdoerfert

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70660
parent 75e8a91c
Loading
Loading
Loading
Loading
+61 −0
Original line number Diff line number Diff line
import os

import lit.formats
import lit.util

# python 2.7 backwards compatibility
try:
    from shlex import quote as shell_quote
except ImportError:
    from pipes import quote as shell_quote


def add_update_script_substition(name, python_exe=config.python_executable,
                                 extra_args=''):
    script_path = os.path.join(config.llvm_src_root, 'utils', name + '.py')
    assert os.path.isfile(script_path)
    config.substitutions.append(
        ('%' + name, "'%s' %s %s" % (python_exe, script_path, extra_args)))


config.test_format = lit.formats.ShTest(execute_external=False)
config.suffixes = ['.test']

llc_path = os.path.join(config.llvm_tools_dir, 'llc')
if os.path.isfile(llc_path):
    config.available_features.add('llc-binary')
    llc_arg = '--llc-binary ' + shell_quote(llc_path)
    add_update_script_substition('update_llc_test_checks', extra_args=llc_arg)
    add_update_script_substition('update_mir_test_checks', extra_args=llc_arg)

opt_path = os.path.join(config.llvm_tools_dir, 'opt')
if os.path.isfile(opt_path):
    config.available_features.add('opt-binary')
    opt_arg = '--opt-binary ' + shell_quote(opt_path)
    add_update_script_substition('update_test_checks', extra_args=opt_arg)
    add_update_script_substition('update_analyze_test_checks',
                                 extra_args=opt_arg)

llvm_mca_path = os.path.join(config.llvm_tools_dir, 'llvm-mca')
if os.path.isfile(llvm_mca_path):
    config.available_features.add('llvm-mca-binary')
    mca_arg = '--llvm-mca-binary ' + shell_quote(llvm_mca_path)
    add_update_script_substition('update_test_checks', extra_args=mca_arg)

# update_cc_test_checks requires python3
py3_exe = lit.util.which('python3')
if py3_exe:
    config.substitutions.append(('%python3', shell_quote(py3_exe)))
    config.available_features.add('python3')

clang_path = os.path.join(config.llvm_tools_dir, 'clang')
if os.path.isfile(clang_path):
    config.available_features.add('clang-binary')
    if py3_exe:
        # XXX: or use --llvm-bin?
        extra_args = '--clang ' + shell_quote(clang_path)
        if os.path.isfile(opt_path):
            extra_args += ' --opt ' + shell_quote(opt_path)
        add_update_script_substition('update_cc_test_checks',
                                     python_exe=py3_exe,
                                     extra_args=extra_args)
+11 −0
Original line number Diff line number Diff line
// Example input for update_cc_test_checks
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s

long test(long a, int b) {
  return a + b;
}

// A function with a mangled name
__attribute__((overloadable)) long test(long a, int b, int c) {
  return a + b + c;
}
+41 −0
Original line number Diff line number Diff line
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// Example input for update_cc_test_checks
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s

// CHECK-LABEL: @test(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[A_ADDR:%.*]] = alloca i64, align 8
// CHECK-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT:    store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
// CHECK-NEXT:    store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
// CHECK-NEXT:    [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT:    [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT:    [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT:    ret i64 [[ADD]]
//
long test(long a, int b) {
  return a + b;
}

// A function with a mangled name
// CHECK-LABEL: @_Z4testlii(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[A_ADDR:%.*]] = alloca i64, align 8
// CHECK-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT:    [[C_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT:    store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
// CHECK-NEXT:    store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
// CHECK-NEXT:    store i32 [[C:%.*]], i32* [[C_ADDR]], align 4
// CHECK-NEXT:    [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT:    [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT:    [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* [[C_ADDR]], align 4
// CHECK-NEXT:    [[CONV1:%.*]] = sext i32 [[TMP2]] to i64
// CHECK-NEXT:    [[ADD2:%.*]] = add nsw i64 [[ADD]], [[CONV1]]
// CHECK-NEXT:    ret i64 [[ADD2]]
//
__attribute__((overloadable)) long test(long a, int b, int c) {
  return a + b + c;
}
+43 −0
Original line number Diff line number Diff line
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// Example input for update_cc_test_checks
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s

// CHECK-LABEL: define {{[^@]+}}@test
// CHECK-SAME: (i64 [[A:%.*]], i32 [[B:%.*]]) #0
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[A_ADDR:%.*]] = alloca i64, align 8
// CHECK-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT:    store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
// CHECK-NEXT:    store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
// CHECK-NEXT:    [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT:    [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT:    [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT:    ret i64 [[ADD]]
//
long test(long a, int b) {
  return a + b;
}

// A function with a mangled name
// CHECK-LABEL: define {{[^@]+}}@_Z4testlii
// CHECK-SAME: (i64 [[A:%.*]], i32 [[B:%.*]], i32 [[C:%.*]]) #0
// CHECK-NEXT:  entry:
// CHECK-NEXT:    [[A_ADDR:%.*]] = alloca i64, align 8
// CHECK-NEXT:    [[B_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT:    [[C_ADDR:%.*]] = alloca i32, align 4
// CHECK-NEXT:    store i64 [[A:%.*]], i64* [[A_ADDR]], align 8
// CHECK-NEXT:    store i32 [[B:%.*]], i32* [[B_ADDR]], align 4
// CHECK-NEXT:    store i32 [[C:%.*]], i32* [[C_ADDR]], align 4
// CHECK-NEXT:    [[TMP0:%.*]] = load i64, i64* [[A_ADDR]], align 8
// CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[B_ADDR]], align 4
// CHECK-NEXT:    [[CONV:%.*]] = sext i32 [[TMP1]] to i64
// CHECK-NEXT:    [[ADD:%.*]] = add nsw i64 [[TMP0]], [[CONV]]
// CHECK-NEXT:    [[TMP2:%.*]] = load i32, i32* [[C_ADDR]], align 4
// CHECK-NEXT:    [[CONV1:%.*]] = sext i32 [[TMP2]] to i64
// CHECK-NEXT:    [[ADD2:%.*]] = add nsw i64 [[ADD]], [[CONV1]]
// CHECK-NEXT:    ret i64 [[ADD2]]
//
__attribute__((overloadable)) long test(long a, int b, int c) {
  return a + b + c;
}
+3 −0
Original line number Diff line number Diff line
# These tests require clang.
if 'clang-binary' not in config.available_features:
    config.unsupported = True
Loading