Index: lnt/testing/profile/profile.py =================================================================== --- lnt/testing/profile/profile.py +++ lnt/testing/profile/profile.py @@ -80,7 +80,8 @@ return tf.name else: - open(filename, 'w').write(s) + with open(filename, 'wb') as f: + f.write(s) return filename def save(self, filename=None, profileDir=None, prefix=''): @@ -115,7 +116,7 @@ Implementation note: the string is base64 encoded. """ - return base64.b64encode(self.impl.serialize()) + return base64.b64encode(self.impl.serialize()).decode('ascii') def upgrade(self): """ Index: lnt/testing/profile/profilev1impl.py =================================================================== --- lnt/testing/profile/profilev1impl.py +++ lnt/testing/profile/profilev1impl.py @@ -60,7 +60,7 @@ if fname is None: return bytes(compressed_obj) else: - with open(fname, 'w') as fd: + with open(fname, 'wb') as fd: fd.write(compressed_obj) def getVersion(self): Index: tests/runtest/Inputs/test-suite-cmake/fake-cmake =================================================================== --- tests/runtest/Inputs/test-suite-cmake/fake-cmake +++ tests/runtest/Inputs/test-suite-cmake/fake-cmake @@ -58,6 +58,8 @@ $CMAKE_SRC_DIR/fake-results-fail-compile.json \ $CMAKE_SRC_DIR/fake-results-fail-exec.json \ $CMAKE_SRC_DIR/fake-results-profile.json \ + $CMAKE_SRC_DIR/fake-results-profile-import.json \ + $CMAKE_SRC_DIR/fake-results.perf_data \ . echo "Dummy" > CMakeCache.txt echo CMAKE_C_COMPILER:FILEPATH=$CMAKE_C_COMPILER >> CMakeCache.txt @@ -72,6 +74,8 @@ $CMAKE_SRC_DIR/fake-results-fail-compile.json \ $CMAKE_SRC_DIR/fake-results-fail-exec.json \ $CMAKE_SRC_DIR/fake-results-profile.json \ + $CMAKE_SRC_DIR/fake-results-profile-import.json \ + $CMAKE_SRC_DIR/fake-results.perf_data \ subtest fi exit 0 Index: tests/runtest/Inputs/test-suite-cmake/fake-lit-profile-import =================================================================== --- /dev/null +++ tests/runtest/Inputs/test-suite-cmake/fake-lit-profile-import @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import argparse, shutil +parser = argparse.ArgumentParser(description='dummy lit') +parser.add_argument('-o') +parser.add_argument('-j', type=int) +parser.add_argument('bar') +args, _ = parser.parse_known_args() + +shutil.copyfile(args.bar + '/fake-results-profile-import.json', args.o) +with open(args.o, 'r') as f: + report_tmp = f.read() + report = report_tmp.replace('${PATH_TO_PROFILE}', args.bar + '/fake-results.perf_data') + +with open(args.o, 'w') as f: + f.write(report) Index: tests/runtest/Inputs/test-suite-cmake/fake-results-profile-import.json =================================================================== --- /dev/null +++ tests/runtest/Inputs/test-suite-cmake/fake-results-profile-import.json @@ -0,0 +1,17 @@ +{ + "tests": [ + { + "name": "test-suite :: bar", + "code": "PASS", + "elapsed": "1.0", + "metrics": { + "compile_time": 1.3, + "exec_time": 1.4, + "score": 1.5, + "hash": "xyz", + "profile": "${PATH_TO_PROFILE}", + "unknown": "unknown" + } + } + ] +} Index: tests/runtest/test_suite-profile-import.py =================================================================== --- /dev/null +++ tests/runtest/test_suite-profile-import.py @@ -0,0 +1,27 @@ +# Check importing test-suite profiles into db +# RUN: rm -rf %t.SANDBOX +# RUN: lnt runtest test-suite \ +# RUN: --sandbox %t.SANDBOX \ +# RUN: --no-timestamp \ +# RUN: --test-suite %S/Inputs/test-suite-cmake \ +# RUN: --cc %{shared_inputs}/FakeCompilers/clang-r154331 \ +# RUN: --use-cmake %S/Inputs/test-suite-cmake/fake-cmake \ +# RUN: --use-make %S/Inputs/test-suite-cmake/fake-make \ +# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit-profile-import \ +# RUN: --use-perf=all \ +# RUN: -j2 \ +# RUN: --verbose \ +# RUN: > %t.log 2> %t.err +# RUN: rm -rf %t.DB +# RUN: lnt create %t.DB >> %t.log 2>> %t.err +# RUN: lnt import %t.DB %t.SANDBOX/build/report.json \ +# RUN: --show-sample-count >> %t.log 2>> %t.err +# RUN: python %s %t.DB + +import sys +import glob +import glob +from lnt.testing.profile.profilev2impl import ProfileV2 + +profile = glob.glob('%s/data/profiles/*.lntprof' % sys.argv[1])[0] +assert ProfileV2.checkFile(profile) Index: tests/runtest/test_suite-profile.shtest =================================================================== --- tests/runtest/test_suite-profile.shtest +++ tests/runtest/test_suite-profile.shtest @@ -12,7 +12,6 @@ # RUN: -j2 \ # RUN: --exec-multisample=2 \ # RUN: --verbose \ -# RUN: --commit 1 \ # RUN: > %t.log 2> %t.err # RUN: FileCheck --check-prefix CHECK-USE-PERF-ALL < %t.err %s # CHECK-USE-PERF-ALL: Configuring with { Index: tests/testing/profilev1impl.py =================================================================== --- tests/testing/profilev1impl.py +++ tests/testing/profilev1impl.py @@ -47,7 +47,7 @@ with tempfile.NamedTemporaryFile() as f: Profile.saveFromRendered(s, filename=f.name) - p2 = ProfileV1.deserialize(open(f.name)) + p2 = ProfileV1.deserialize(open(f.name, "rb")) self.assertEqual(p2.data, self.test_data)