Commit 734169f9 authored by Liviu Rau's avatar Liviu Rau Committed by Commit Bot

[torque] Add support for torque output comparison

Bug: v8:9641
Change-Id: Ia85d14677e8eb7d2d14ff7eb150a1b0b279642f4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1998078
Commit-Queue: Liviu Rau <liviurau@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65892}
parent 51d6f2d6
......@@ -207,6 +207,10 @@ declare_args() {
# Use token threaded dispatch for the regular expression interpreter.
# Use switch-based dispatch if this is false
v8_enable_regexp_interpreter_threaded_dispatch = true
# Enable additional targets necessary for verification of torque
# file generation
v8_verify_torque_generation_invariance = false
}
# Derived defaults.
......@@ -1100,59 +1104,114 @@ if (!v8_enable_i18n_support) {
torque_files -= [ "src/objects/intl-objects.tq" ]
}
action("run_torque") {
visibility = [
":*",
"tools/debug_helper/:*",
"tools/gcmole/:*",
"test/cctest/:*",
]
# Template for running torque
# When building with v8_verify_torque_generation_invariance=true we need
# to be able to run torque for both 32 and 64 bits in the same build
template("run_torque") {
if (target_name == "") {
suffix = ""
} else {
suffix = "_$target_name"
}
deps = [ ":torque($v8_generator_toolchain)" ]
toolchain = invoker.toolchain
script = "tools/run.py"
action("run_torque" + suffix) {
visibility = [
":*",
"tools/debug_helper/:*",
"tools/gcmole/:*",
"test/cctest/:*",
]
sources = torque_files
deps = [ ":torque($toolchain)" ]
outputs = [
"$target_gen_dir/torque-generated/bit-fields-tq.h",
"$target_gen_dir/torque-generated/builtin-definitions-tq.h",
"$target_gen_dir/torque-generated/interface-descriptors-tq.inc",
"$target_gen_dir/torque-generated/field-offsets-tq.h",
"$target_gen_dir/torque-generated/class-verifiers-tq.cc",
"$target_gen_dir/torque-generated/class-verifiers-tq.h",
"$target_gen_dir/torque-generated/enum-verifiers-tq.cc",
"$target_gen_dir/torque-generated/objects-printer-tq.cc",
"$target_gen_dir/torque-generated/class-definitions-tq.cc",
"$target_gen_dir/torque-generated/class-definitions-tq-inl.h",
"$target_gen_dir/torque-generated/class-definitions-tq.h",
"$target_gen_dir/torque-generated/class-debug-readers-tq.cc",
"$target_gen_dir/torque-generated/class-debug-readers-tq.h",
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.cc",
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.h",
"$target_gen_dir/torque-generated/csa-types-tq.h",
"$target_gen_dir/torque-generated/instance-types-tq.h",
"$target_gen_dir/torque-generated/internal-class-definitions-tq.h",
"$target_gen_dir/torque-generated/internal-class-definitions-tq-inl.h",
]
foreach(file, torque_files) {
filetq = string_replace(file, ".tq", "-tq-csa")
outputs += [
"$target_gen_dir/torque-generated/$filetq.cc",
"$target_gen_dir/torque-generated/$filetq.h",
script = "tools/run.py"
sources = torque_files
destination_folder = "$target_gen_dir/torque-generated$suffix"
files = [
"bit-fields-tq.h",
"builtin-definitions-tq.h",
"interface-descriptors-tq.inc",
"field-offsets-tq.h",
"class-verifiers-tq.cc",
"class-verifiers-tq.h",
"enum-verifiers-tq.cc",
"objects-printer-tq.cc",
"class-definitions-tq.cc",
"class-definitions-tq-inl.h",
"class-definitions-tq.h",
"class-debug-readers-tq.cc",
"class-debug-readers-tq.h",
"exported-macros-assembler-tq.cc",
"exported-macros-assembler-tq.h",
"csa-types-tq.h",
"instance-types-tq.h",
"internal-class-definitions-tq.h",
"internal-class-definitions-tq-inl.h",
]
outputs = []
foreach(file, files) {
outputs += [ "$destination_folder/$file" ]
}
foreach(file, torque_files) {
filetq = string_replace(file, ".tq", "-tq-csa")
outputs += [
"$destination_folder/$filetq.cc",
"$destination_folder/$filetq.h",
]
}
args = [
"./" + rebase_path(
get_label_info(":torque($toolchain)", "root_out_dir") + "/torque",
root_build_dir),
"-o",
rebase_path("$destination_folder", root_build_dir),
"-v8-root",
rebase_path(".", root_build_dir),
]
if (defined(invoker.args)) {
args += invoker.args
}
args += torque_files
}
}
args = [
"./" + rebase_path(get_label_info(":torque($v8_generator_toolchain)",
"root_out_dir") + "/torque",
root_build_dir),
"-o",
rebase_path("$target_gen_dir/torque-generated", root_build_dir),
"-v8-root",
rebase_path(".", root_build_dir),
]
args += torque_files
# Default run_torque action
run_torque("") {
toolchain = v8_generator_toolchain
}
if (v8_verify_torque_generation_invariance) {
run_torque("x86") {
toolchain = "//build/toolchain/linux:clang_x86"
}
run_torque("x64") {
args = [ "-m32" ]
toolchain = "//build/toolchain/linux:clang_x64"
}
action("compare_torque_runs") {
deps = [
":run_torque_x64",
":run_torque_x86",
]
report_file = "$target_gen_dir/torque_comparison_results.txt"
script = "tools/compare_torque_output.py"
args = [
rebase_path("$target_gen_dir/torque-generated_x64", root_build_dir),
rebase_path("$target_gen_dir/torque-generated_x86", root_build_dir),
rebase_path(report_file, root_build_dir),
]
outputs = [ report_file ]
}
}
group("v8_maybe_icu") {
......
......@@ -227,6 +227,7 @@
'release_x64_tsan_minimal_symbols',
'v8_linux64_ubsan_rel_ng': 'release_x64_ubsan_minimal_symbols',
'v8_odroid_arm_rel_ng': 'release_arm',
'v8_linux_torque_compare': 'torque_compare',
# TODO(machenbach): Remove after switching to x64 on infra side.
'v8_win_dbg': 'debug_x86_trybot',
'v8_win_compile_dbg': 'debug_x86_trybot',
......@@ -546,6 +547,10 @@
# Official configs for x86.
'official_x86': [
'release_bot', 'x86', 'official'],
# Torque compare test
'torque_compare': [
'release_bot', 'verify_torque']
},
'mixins': {
......@@ -830,6 +835,10 @@
'gn_args': 'target_cpu="x86"',
},
'verify_torque': {
'gn_args': 'v8_verify_torque_generation_invariance=true',
},
'sample': {
'gn_args': 'v8_monolithic=true is_component_build=false '
'v8_use_external_startup_data=false use_custom_libcxx=false',
......
#!/usr/bin/env python
# Copyright 2020 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Compare two folders and print any differences between files to both a
results file and stderr.
Specifically we use this to compare the output of Torque generator for
both x86 and x64 (-m32) toolchains.
"""
import difflib
import filecmp
import itertools
import os
import sys
assert len(sys.argv) > 3
folder1 = sys.argv[1]
folder2 = sys.argv[2]
results_file_name = sys.argv[3]
with open(results_file_name, "w") as results_file:
def write(line):
# Print line to both results file and stderr
sys.stderr.write(line)
results_file.write(line)
def has_one_sided_diff(dcmp, side, side_list):
# Check that we do not have files only on one side of the comparison
if side_list:
write("Some files exist only in %s\n" % side)
for fl in side_list:
write(fl)
return side_list
def has_content_diff(dcmp):
# Check that we do not have content differences in the common files
_, diffs, _ = filecmp.cmpfiles(
dcmp.left, dcmp.right,
dcmp.common_files, shallow=False)
if diffs:
write("Found content differences between %s and %s\n" %
(dcmp.left, dcmp.right))
for name in diffs:
write("File diff %s\n" % name)
left_file = os.path.join(dcmp.left, name)
right_file = os.path.join(dcmp.right, name)
with open(left_file) as f1, open(right_file) as f2:
diff = difflib.unified_diff(
f1.readlines(), f2.readlines(),
dcmp.left, dcmp.right)
for l in itertools.islice(diff, 100):
write(l)
write("\n\n")
return diffs
dcmp = filecmp.dircmp(folder1, folder2)
has_diffs = has_one_sided_diff(dcmp, dcmp.left, dcmp.left_only) \
or has_one_sided_diff(dcmp, dcmp.right, dcmp.right_only) \
or has_content_diff(dcmp)
if has_diffs:
sys.exit(1)
#!/usr/bin/env python
# Copyright 2020 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import re
import subprocess
import sys
import tempfile
import unittest
TOOLS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
COMPARE_SCRIPT = os.path.join(TOOLS_DIR, 'compare_torque_output.py')
TEST_DATA = os.path.join(TOOLS_DIR, 'unittests', 'testdata', 'compare_torque')
class PredictableTest(unittest.TestCase):
def setUp(self):
fd, self.tmp_file = tempfile.mkstemp()
os.close(fd)
def _compare_from(self, test_folder):
file1 = os.path.join(TEST_DATA, test_folder, 'f1')
file2 = os.path.join(TEST_DATA, test_folder, 'f2')
proc = subprocess.Popen([
'python', '-u',
COMPARE_SCRIPT, file1, file2, self.tmp_file
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
_, err = proc.communicate()
return proc.returncode, err
def test_content_diff(self):
exitcode, output = self._compare_from('test1')
self.assertEqual(1, exitcode)
full_match = r'^Found.*-line 2\+line 2 with diff.*\+line 3\n\n$'
self.assertRegexpMatches(output, re.compile(full_match, re.M | re.S))
def test_no_diff(self):
exitcode, output = self._compare_from('test2')
self.assertEqual(0, exitcode)
self.assertFalse(output)
def test_right_only(self):
exitcode, output = self._compare_from('test3')
self.assertEqual(1, exitcode)
self.assertRegexpMatches(output, r'Some files exist only in.*f2\nfile3')
def test_left_only(self):
exitcode, output = self._compare_from('test4')
self.assertEqual(1, exitcode)
self.assertRegexpMatches(output, r'Some files exist only in.*f1\nfile4')
def tearDown(self):
os.unlink(self.tmp_file)
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2 with diff
line 3
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
line 1
line 2
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment