[llvm-dev] [clang] Running a single testcase

Sedat Dilek via llvm-dev
Mon, 07 May 2018 15:13:04 -0000

On Mon, May 7, 2018 at 4:03 PM, Amara Emerson <aemerson at apple.com>
wrote:
> On 7 May 2018, at 11:01, Sedat Dilek via llvm-dev <llvm-dev at
lists.llvm.org>
> wrote:
>
> On Mon, May 7, 2018 at 5:52 AM, Brian Cain <brian.cain at gmail.com>
wrote:
>
> The simplest way to run a clang test case that I know of is to clone both
> llvm and clang repos, run all the tests, then run an individual test.
>
> IIRC like so:
>
> git clone llvm ......
> cd llvm/tools
> git clone clang .....
> cd ../../
> mkdir build
> cd build
> cmake ../llvm
> ninja check-clang
> ./bin/llvm-lit -v ./tools/clang/test/Sema/asm.c
>
>
> Hi Brian,
>
> The cmake-line should be...
>
> # apt-get install ninja-build
> $ cmake -G Ninja ../llvm
>
> Unfortunately, on the latest Git my build fails which gcc-7 (see
> attached file for details).
> Do I really need to build clang-from-git?
> I have llvm-7/clang-7 binaries installed on my system?
>
> But I run the test after symlinking clang-7 ---> clang...
>
> $ ./bin/llvm-lit -v ./tools/clang/test/Sema/asm.c
> llvm-lit: /home/sdi/src/llvm/llvm/utils/lit/lit/llvm/config.py:334:
> note: using clang: /usr/bin/clang
> llvm-lit: /home/sdi/src/llvm/llvm/utils/lit/lit/llvm/subst.py:126:
> note: Did not find c-index-test in
> /home/sdi/src/llvm/build/./bin:/home/sdi/src/llvm/build/./bin
> llvm-lit: /home/sdi/src/llvm/llvm/utils/lit/lit/llvm/subst.py:126:
> note: Did not find clang-check in
> /home/sdi/src/llvm/build/./bin:/home/sdi/src/llvm/build/./bin
> llvm-lit: /home/sdi/src/llvm/llvm/utils/lit/lit/llvm/subst.py:126:
> note: Did not find opt in
> /home/sdi/src/llvm/build/./bin:/home/sdi/src/llvm/build/./bin
>
>
>
> That looks like your system ran out of memory during linking, which on
debug
> builds is possible especially if you use parallel jobs with -j. You can’t
> use a different clang binary to run tests and expect them to work, the
tests
> are specific to each individual version of the compiler.
>
> Try using -DCMAKE_BUILD_TYPE=Release which requires less memory to link,
> unless you really need debug info in the binary, in which case try running
> ninja -j1 to avoid parallel jobs.
>

Hi Amara,

yes, that sounds reasonable.

I looked into my old build_llvm-toolchain.sh script and adapted it to
build only the necessary stuff (see below).

First, I thought I can reduce build-time by...

sdi at iniza:~/src/llvm-toolchain/build$ ninja check-llvm-tools-llvm-lit
[1808/1809] Running lit suite
/home/sdi/src/llvm-toolchain/llvm/test/tools/llvm-lit
Testing Time: 0.11s
  Expected Failures  : 1

The test runs with some warnings...

sdi at iniza:~/src/llvm-toolchain/build$ ./bin/llvm-lit -v
./tools/clang/test/Sema/asm.c
llvm-lit: /home/sdi/src/llvm-toolchain/llvm/utils/lit/lit/llvm/config.py:334:
note: using clang: /usr/bin/clang
llvm-lit: /home/sdi/src/llvm-toolchain/llvm/utils/lit/lit/llvm/subst.py:126:
note: Did not find c-index-test in
/home/sdi/src/llvm-toolchain/build/./bin:/home/sdi/src/llvm-toolchain/build/./bin
llvm-lit: /home/sdi/src/llvm-toolchain/llvm/utils/lit/lit/llvm/subst.py:126:
note: Did not find clang-check in
/home/sdi/src/llvm-toolchain/build/./bin:/home/sdi/src/llvm-toolchain/build/./bin
llvm-lit: /home/sdi/src/llvm-toolchain/llvm/utils/lit/lit/llvm/subst.py:126:
note: Did not find clang-diff in
/home/sdi/src/llvm-toolchain/build/./bin:/home/sdi/src/llvm-toolchain/build/./bin
llvm-lit: /home/sdi/src/llvm-toolchain/llvm/utils/lit/lit/llvm/subst.py:126:
note: Did not find clang-format in
/home/sdi/src/llvm-toolchain/build/./bin:/home/sdi/src/llvm-toolchain/build/./bin
-- Testing: 1 tests, 1 threads --
PASS: Clang :: Sema/asm.c (1 of 1)
Testing Time: 0.11s
  Expected Passes    : 1

... but it looks like stuff is missing, so I did...

sdi at iniza:~/src/llvm-toolchain/build$ ninja check-clang
[1012/1013] Running the Clang regression tests
llvm-lit: /home/sdi/src/llvm-toolchain/llvm/utils/lit/lit/llvm/config.py:334:
note: using clang: /home/sdi/src/llvm-toolchain/build/bin/clang
Testing Time: 200.66s
  Expected Passes    : 12028
  Expected Failures  : 18
  Unsupported Tests  : 256

sdi at iniza:~/src/llvm-toolchain/build$ ./bin/llvm-lit -v
./tools/clang/test/Sema/asm.c
llvm-lit: /home/sdi/src/llvm-toolchain/llvm/utils/lit/lit/llvm/config.py:334:
note: using clang: /home/sdi/src/llvm-toolchain/build/bin/clang
-- Testing: 1 tests, 1 threads --
PASS: Clang :: Sema/asm.c (1 of 1)
Testing Time: 0.10s
  Expected Passes    : 1

This now looks good to me.

How can I force to use a different clang than
"/home/sdi/src/llvm-toolchain/build/bin/clang"?
I have no symlink to /usr/bin/clang.

Thanks.

Regards,
- Sedat -

P.S.: New build-script

[build_clang-with-ninja.sh  ]

#!/bin/sh

export LANG=C
export LC_ALL=C

cd build

CMAKE="cmake"

CMAKE_OPTS="-G Ninja -DCMAKE_C_COMPILER=clang-7
-DCMAKE_CXX_COMPILER=clang++-7 -DLLVM_PARALLEL_COMPILE_JOBS=2
-DLLVM_PARALLEL_LINK_JOBS=1 -DCMAKE_BUILD_TYPE=RELEASE
-DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD=X86"

$CMAKE ../llvm $CMAKE_OPTS

ninja check-clang
- EOF -