Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions lnt/tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ def run_test(self, opts):
if opts.exec_mode and opts.build_dir is None and not opts.exec_interleaved_builds:
self._fatal("--exec requires --build-dir (or use --exec-interleaved-builds)")

if opts.build_dir and not opts.exec_mode and not opts.exec_interleaved_builds:
self._fatal("--build-dir can only be used with --exec or --exec-interleaved-builds")

if opts.exec_interleaved_builds:
# --exec-interleaved-builds implies --exec
opts.exec_mode = True
Expand All @@ -216,13 +213,15 @@ def run_test(self, opts):
build_dir)

if opts.build_dir:
# Validate build directory
opts.build_dir = os.path.abspath(opts.build_dir)
if not os.path.exists(opts.build_dir):
self._fatal("--build-dir does not exist: %r" % opts.build_dir)
cmakecache = os.path.join(opts.build_dir, 'CMakeCache.txt')
if not os.path.exists(cmakecache):
self._fatal("--build-dir is not a configured build: %r" % opts.build_dir)
# In --exec mode, validate that build_dir already exists and is configured
# In --build mode, we'll create the directory if needed
if opts.exec_mode:
if not os.path.exists(opts.build_dir):
self._fatal("--build-dir does not exist: %r" % opts.build_dir)
cmakecache = os.path.join(opts.build_dir, 'CMakeCache.txt')
if not os.path.exists(cmakecache):
self._fatal("--build-dir is not a configured build: %r" % opts.build_dir)

if opts.cc is not None:
opts.cc = resolve_command_path(opts.cc)
Expand Down Expand Up @@ -336,15 +335,15 @@ def run_test(self, opts):
self.start_time = timestamp()

# Work out where to put our build stuff
if opts.exec_mode and opts.build_dir:
# In exec mode with --build-dir, use the specified build directory
if opts.build_dir and (opts.exec_mode or opts.build):
# With --build-dir, use the specified build directory (for both --build and --exec modes)
basedir = opts.build_dir
elif opts.exec_interleaved_builds:
# For exec-interleaved-builds, each build uses its own directory
# We'll return early from _run_interleaved_builds(), so basedir doesn't matter
basedir = opts.sandbox_path
else:
# Normal mode or build mode: use sandbox/build or sandbox/test-<timestamp>
# Normal mode: use sandbox/build or sandbox/test-<timestamp>
if opts.timestamp_build:
ts = self.start_time.replace(' ', '_').replace(':', '-')
build_dir_name = "test-%s" % ts
Expand Down
65 changes: 65 additions & 0 deletions tests/runtest/test_suite-build-dir.shtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Test --build-dir option with --build and --exec modes

# Test 1: --build with --build-dir to create a build in a custom location
# RUN: rm -rf %t.SANDBOX %t.CUSTOM_BUILD
# RUN: mkdir -p %t.CUSTOM_BUILD
# 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 \
# RUN: --build \
# RUN: --build-dir %t.CUSTOM_BUILD/mybuild \
# RUN: > %t.build.log 2> %t.build.err
# RUN: filecheck --check-prefix CHECK-BUILD-CUSTOM < %t.build.err %s
# CHECK-BUILD-CUSTOM: Building tests (--build mode)...
# CHECK-BUILD-CUSTOM: Build complete. Build directory: {{.*}}CUSTOM_BUILD/mybuild
# CHECK-BUILD-CUSTOM: Use --exec --build-dir {{.*}}CUSTOM_BUILD/mybuild to run tests.

# Verify that build files were created in the custom location
# RUN: test -f %t.CUSTOM_BUILD/mybuild/CMakeCache.txt

# Test 2: --exec with --build-dir using the custom build location
# RUN: lnt runtest test-suite \
# RUN: --sandbox %t.SANDBOX \
# RUN: --no-timestamp \
# RUN: --exec \
# RUN: --build-dir %t.CUSTOM_BUILD/mybuild \
# RUN: --use-cmake %S/Inputs/test-suite-cmake/fake-cmake \
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
# RUN: --output %t.exec.report \
# RUN: > %t.exec.log 2> %t.exec.err
# RUN: filecheck --check-prefix CHECK-EXEC-CUSTOM < %t.exec.err %s
# CHECK-EXEC-CUSTOM-NOT: Configuring
# CHECK-EXEC-CUSTOM-NOT: Building
# CHECK-EXEC-CUSTOM: Testing

# Verify that report was created in the custom build directory
# RUN: test -f %t.CUSTOM_BUILD/mybuild/report.json

# Test 3: Error case - --exec with --build-dir pointing to non-existent directory should fail
# RUN: not lnt runtest test-suite \
# RUN: --sandbox %t.SANDBOX \
# RUN: --no-timestamp \
# RUN: --exec \
# RUN: --build-dir %t.NONEXISTENT \
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
# RUN: > %t.err1.log 2> %t.err1.err
# RUN: filecheck --check-prefix CHECK-ERR-NONEXISTENT < %t.err1.err %s
# CHECK-ERR-NONEXISTENT: --build-dir does not exist

# Test 4: Error case - --exec with --build-dir pointing to unconfigured directory should fail
# RUN: rm -rf %t.UNCONFIGURED
# RUN: mkdir -p %t.UNCONFIGURED
# RUN: not lnt runtest test-suite \
# RUN: --sandbox %t.SANDBOX \
# RUN: --no-timestamp \
# RUN: --exec \
# RUN: --build-dir %t.UNCONFIGURED \
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
# RUN: > %t.err2.log 2> %t.err2.err
# RUN: filecheck --check-prefix CHECK-ERR-UNCONFIGURED < %t.err2.err %s
# CHECK-ERR-UNCONFIGURED: --build-dir is not a configured build