Difference between revisions of "LDC Lit-based testsuite"
JohanEngelen (talk | contribs) (Start Lit page) |
JohanEngelen (talk | contribs) (work in progress) |
||
Line 11: | Line 11: | ||
The rest of this page will describe important functionality of the testsuite. It is very instructive to look at LLVM/Clang/LDC tests to see how different kind of tests can be constructed! | The rest of this page will describe important functionality of the testsuite. It is very instructive to look at LLVM/Clang/LDC tests to see how different kind of tests can be constructed! | ||
+ | == A simple test case example == | ||
+ | To add a test case to the testsuite, all you have to do is create a file inside a subdirectory of the <tt>tests</tt> directory (not the <tt>d2</tt> subdirectory!). | ||
+ | |||
+ | Let's say we created a file <tt>tests/codegen/attr_fastmath.d</tt>: | ||
+ | <source lang="d"> | ||
+ | // RUN: %ldc -O0 -release -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll | ||
+ | |||
+ | import ldc.attributes; | ||
+ | |||
+ | @fastmath | ||
+ | double foo(double a, double b) | ||
+ | { | ||
+ | // CHECK: fmul fast | ||
+ | auto c += a * b; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | == Substitutions == | ||
+ | |||
+ | == "Features" == | ||
+ | |||
+ | == More complicated example == | ||
+ | <source lang="d"> | ||
+ | // Tests @target attribute for x86 | ||
+ | |||
+ | // REQUIRES: atleast_llvm307 | ||
+ | // REQUIRES: target_X86 | ||
+ | |||
+ | // RUN: %ldc -O -c -mcpu=i386 -mtriple i386-linux-gnu -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll | ||
+ | // RUN: %ldc -O -c -mcpu=i386 -mtriple i386-linux-gnu -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s | ||
+ | |||
+ | import ldc.attributes; | ||
+ | |||
+ | // LLVM-LABEL: define{{.*}} void @{{.*}}foo | ||
+ | // ASM-LABEL: _D15attr_target_x863fooFPfPffZv: | ||
+ | void foo(float *A, float* B, float K) { | ||
+ | for (int i = 0; i < 128; ++i) | ||
+ | A[i] *= B[i] + K; | ||
+ | // ASM-NOT: addps | ||
+ | } | ||
+ | |||
+ | // LLVM-LABEL: define{{.*}} void @{{.*}}foo_sse | ||
+ | // LLVM-SAME: #[[SSE:[0-9]+]] | ||
+ | // ASM-LABEL: _D15attr_target_x867foo_sseFPfPffZv: | ||
+ | @(target("sse")) | ||
+ | void foo_sse(float *A, float* B, float K) { | ||
+ | for (int i = 0; i < 128; ++i) | ||
+ | A[i] *= B[i] + K; | ||
+ | // ASM: addps | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | ---- | ||
[[Category:LDC]] | [[Category:LDC]] |
Revision as of 08:50, 25 May 2016
This page describes the Lit-based test suite used for testing LDC.
Lit
Lit is a tool created by the LLVM developers to run compiler tests, written in Python.
Read about it from the horse's mouth: LLVM Blog: 'lit' it.
Lit is an important piece of LLVM's Testing Infrastructure.
LDC uses the Python package as available from https://pypi.python.org/pypi/lit , which can be best installed using Python's pip.
The rest of this page will describe important functionality of the testsuite. It is very instructive to look at LLVM/Clang/LDC tests to see how different kind of tests can be constructed!
A simple test case example
To add a test case to the testsuite, all you have to do is create a file inside a subdirectory of the tests directory (not the d2 subdirectory!).
Let's say we created a file tests/codegen/attr_fastmath.d:
// RUN: %ldc -O0 -release -c -output-ll -of=%t.ll %s && FileCheck %s < %t.ll
import ldc.attributes;
@fastmath
double foo(double a, double b)
{
// CHECK: fmul fast
auto c += a * b;
}
Substitutions
"Features"
More complicated example
// Tests @target attribute for x86
// REQUIRES: atleast_llvm307
// REQUIRES: target_X86
// RUN: %ldc -O -c -mcpu=i386 -mtriple i386-linux-gnu -output-ll -of=%t.ll %s && FileCheck %s --check-prefix LLVM < %t.ll
// RUN: %ldc -O -c -mcpu=i386 -mtriple i386-linux-gnu -output-s -of=%t.s %s && FileCheck %s --check-prefix ASM < %t.s
import ldc.attributes;
// LLVM-LABEL: define{{.*}} void @{{.*}}foo
// ASM-LABEL: _D15attr_target_x863fooFPfPffZv:
void foo(float *A, float* B, float K) {
for (int i = 0; i < 128; ++i)
A[i] *= B[i] + K;
// ASM-NOT: addps
}
// LLVM-LABEL: define{{.*}} void @{{.*}}foo_sse
// LLVM-SAME: #[[SSE:[0-9]+]]
// ASM-LABEL: _D15attr_target_x867foo_sseFPfPffZv:
@(target("sse"))
void foo_sse(float *A, float* B, float K) {
for (int i = 0; i < 128; ++i)
A[i] *= B[i] + K;
// ASM: addps
}