JDevlieghere created this revision.
JDevlieghere added a reviewer: labath.
This adds the necessary boiler plate to capture and replay API tests.
http://lists.llvm.org/pipermail/lldb-dev/2020-April/016100.html
Repository:
rLLDB LLDB
https://reviews.llvm.org/D77588
Files:
lldb/bindings/headers.swig
lldb/bindings/interface/SBReproducer.i
lldb/bindings/interfaces.swig
lldb/bindings/python.swig
lldb/include/lldb/API/SBReproducer.h
lldb/packages/Python/lldbsuite/test/decorators.py
lldb/source/API/SBReproducer.cpp
lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
lldb/test/API/lit.cfg.py
lldb/test/API/lldbtest.py
Index: lldb/test/API/lldbtest.py
===================================================================
--- lldb/test/API/lldbtest.py
+++ lldb/test/API/lldbtest.py
@@ -1,6 +1,6 @@
from __future__ import absolute_import
import os
-
+import tempfile
import subprocess
import sys
@@ -86,6 +86,14 @@
shutil.copy(python, copied_python)
cmd[0] = copied_python
+ reproducer_path = os.path.join(tempfile.gettempdir(), testFile)
+ if 'lldb-repro-capture' in test.config.available_features:
+ test.config.environment[
+ 'LLDB_REPRODUCER_CAPTURE_PATH'] = reproducer_path
+ elif 'lldb-repro-replay' in test.config.available_features:
+ test.config.environment[
+ 'LLDB_REPRODUCER_REPLAY_PATH'] = reproducer_path
+
timeoutInfo = None
try:
out, err, exitCode = lit.util.executeCommand(
Index: lldb/test/API/lit.cfg.py
===================================================================
--- lldb/test/API/lit.cfg.py
+++ lldb/test/API/lit.cfg.py
@@ -60,6 +60,17 @@
config.environment['LLDB_CAPTURE_REPRODUCER'] = os.environ[
'LLDB_CAPTURE_REPRODUCER']
+# Support running the test suite under the lldb-repro wrapper. This makes it
+# possible to capture a test suite run and then rerun all the test from the
+# just captured reproducer.
+lldb_repro_mode = lit_config.params.get('lldb-run-with-repro', None)
+if lldb_repro_mode:
+ lit_config.note("Running Shell test with lldb-repo in {} mode.".format(lldb_repro_mode))
+ if lldb_repro_mode == 'capture':
+ config.available_features.add('lldb-repro-capture')
+ elif lldb_repro_mode == 'replay':
+ config.available_features.add('lldb-repro-replay')
+
# Clean the module caches in the test build directory. This is necessary in an
# incremental build whenever clang changes underneath, so doing it once per
# lit.py invocation is close enough.
Index: lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
===================================================================
--- lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
+++ lldb/test/API/functionalities/reproducers/attach/TestReproducerAttach.py
@@ -20,6 +20,7 @@
@skipIfWindows
@skipIfRemote
@skipIfiOSSimulator
+ @skipIfReproducer
def test_reproducer_attach(self):
"""Test thread creation after process attach."""
exe = '%s_%d' % (self.testMethodName, os.getpid())
Index: lldb/source/API/SBReproducer.cpp
===================================================================
--- lldb/source/API/SBReproducer.cpp
+++ lldb/source/API/SBReproducer.cpp
@@ -124,6 +124,15 @@
return nullptr;
}
+const char *SBReproducer::APIReplay(const char *path) {
+ static std::string error;
+ if (auto e = Reproducer::Initialize(ReproducerMode::Replay, FileSpec(path))) {
+ error = llvm::toString(std::move(e));
+ return error.c_str();
+ }
+ return nullptr;
+}
+
const char *SBReproducer::Replay(const char *path) {
return SBReproducer::Replay(path, false);
}
Index: lldb/packages/Python/lldbsuite/test/decorators.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/decorators.py
+++ lldb/packages/Python/lldbsuite/test/decorators.py
@@ -854,3 +854,11 @@
return "ASAN unsupported"
return None
return skipTestIfFn(is_asan)(func)
+
+def skipIfReproducer(func):
+ """Skip this test if the environment is set up to run LLDB with reproducers."""
+ def is_reproducer():
+ if ('LLDB_REPRODUCER_CAPTURE_PATH' in os.environ or 'LLDB_REPRODUCER_REPLAY_PATH' in os.environ):
+ return "reproducers unsupported"
+ return None
+ return skipTestIfFn(is_reproducer)(func)
Index: lldb/include/lldb/API/SBReproducer.h
===================================================================
--- lldb/include/lldb/API/SBReproducer.h
+++ lldb/include/lldb/API/SBReproducer.h
@@ -22,6 +22,7 @@
static const char *Capture(const char *path);
static const char *Replay(const char *path);
static const char *Replay(const char *path, bool skip_version_check);
+ static const char *APIReplay(const char *path);
static const char *GetPath();
static bool SetAutoGenerate(bool b);
static bool Generate();
Index: lldb/bindings/python.swig
===================================================================
--- lldb/bindings/python.swig
+++ lldb/bindings/python.swig
@@ -129,6 +129,11 @@
%pythoncode%{
debugger_unique_id = 0
+if 'LLDB_REPRODUCER_CAPTURE_PATH' in os.environ:
+ SBReproducer.Capture(os.environ['LLDB_REPRODUCER_CAPTURE_PATH'])
+ SBReproducer.SetAutoGenerate(True)
+elif 'LLDB_REPRODUCER_REPLAY_PATH' in os.environ:
+ SBReproducer.APIReplay(os.environ['LLDB_REPRODUCER_REPLAY_PATH'])
SBDebugger.Initialize()
debugger = None
target = None
Index: lldb/bindings/interfaces.swig
===================================================================
--- lldb/bindings/interfaces.swig
+++ lldb/bindings/interfaces.swig
@@ -54,6 +54,7 @@
%include "./interface/SBProcessInfo.i"
%include "./interface/SBQueue.i"
%include "./interface/SBQueueItem.i"
+%include "./interface/SBReproducer.i"
%include "./interface/SBSection.i"
%include "./interface/SBSourceManager.i"
%include "./interface/SBStream.i"
Index: lldb/bindings/interface/SBReproducer.i
===================================================================
--- /dev/null
+++ lldb/bindings/interface/SBReproducer.i
@@ -0,0 +1,17 @@
+//===-- SWIG Interface for SBReproducer--------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+namespace lldb {
+class SBReproducer
+{
+ public:
+ static const char *Capture(const char *path);
+ static const char *APIReplay(const char *path);
+ static bool SetAutoGenerate(bool b);
+};
+}
Index: lldb/bindings/headers.swig
===================================================================
--- lldb/bindings/headers.swig
+++ lldb/bindings/headers.swig
@@ -47,6 +47,7 @@
#include "lldb/API/SBProcessInfo.h"
#include "lldb/API/SBQueue.h"
#include "lldb/API/SBQueueItem.h"
+#include "lldb/API/SBReproducer.h"
#include "lldb/API/SBSection.h"
#include "lldb/API/SBSourceManager.h"
#include "lldb/API/SBStream.h"
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits