Skip to content

Commit

Permalink
Increase test coverage for TBRAnalyzer.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Nov 27, 2023
1 parent cabf700 commit 9d26a46
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/Gradient/Assignments.C
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,67 @@ double f19(double a, double b) {
//CHECK-NEXT: }
//CHECK-NEXT: }

double f20(double x, double y) {
auto& r = x;
r = 3;
x = r * y;
return x; // 3y
}

//CHECK: void f20_grad(double x, double y, clad::array_ref<double> _d_x, clad::array_ref<double> _d_y) {
//CHECK-NEXT: double *_d_r = 0;
//CHECK-NEXT: double _t0;
//CHECK-NEXT: double _t1;
//CHECK-NEXT: double _t2;
//CHECK-NEXT: _d_r = &* _d_x;
//CHECK-NEXT: double &r = x;
//CHECK-NEXT: _t0 = r;
//CHECK-NEXT: r = 3;
//CHECK-NEXT: _t1 = x;
//CHECK-NEXT: _t2 = y;
//CHECK-NEXT: x = r * _t2;
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_x += 1;
//CHECK-NEXT: {
//CHECK-NEXT: x = _t1;
//CHECK-NEXT: double _r_d1 = * _d_x;
//CHECK-NEXT: double _r0 = _r_d1 * _t2;
//CHECK-NEXT: *_d_r += _r0;
//CHECK-NEXT: double _r1 = r * _r_d1;
//CHECK-NEXT: * _d_y += _r1;
//CHECK-NEXT: * _d_x -= _r_d1;
//CHECK-NEXT: * _d_x;
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: r = _t0;
//CHECK-NEXT: double _r_d0 = *_d_r;
//CHECK-NEXT: *_d_r -= _r_d0;
//CHECK-NEXT: }
//CHECK-NEXT: }

double f21 (double x, double y) {
y = (y++, x);
return y;
}

//CHECK-NEXT: void f21_grad(double x, double y, clad::array_ref<double> _d_x, clad::array_ref<double> _d_y) {
//CHECK-NEXT: double _t0;
//CHECK-NEXT: _t0 = y;
//CHECK-NEXT: y = (y++ , x);
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_y += 1;
//CHECK-NEXT: {
//CHECK-NEXT: y = _t0;
//CHECK-NEXT: double _r_d0 = * _d_y;
//CHECK-NEXT: * _d_y += 0;
//CHECK-NEXT: y--;
//CHECK-NEXT: * _d_x += _r_d0;
//CHECK-NEXT: * _d_y -= _r_d0;
//CHECK-NEXT: * _d_y;
//CHECK-NEXT: }
//CHECK-NEXT: }

#define TEST(F, x, y) \
{ \
Expand Down Expand Up @@ -971,4 +1032,6 @@ int main() {
VAR_TEST(f17, "i", 3, 4, 5, &result[0]); // CHECK-EXEC: {2.00}
VAR_TEST(f18, "i, j", 3, 4, 5, &result[0], &result[1]); // CHECK-EXEC: {3.00, 2.00}
TEST(f19, 1, 2); // CHECK-EXEC: {2.00, 2.00}
TEST(f20, 1, 2); // CHECK-EXEC: {0.00, 3.00}
TEST(f21, 6, 4); // CHECK-EXEC: {1.00, 0.00}
}
47 changes: 47 additions & 0 deletions test/Gradient/Gradients.C
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,52 @@ double f_cond3(double x, double c) {

double f_cond3_grad(double x, double c, clad::array_ref<double> _d_x, clad::array_ref<double> _d_y);

double f_cond4(double x, double y) {
int i = 0;
double arr[] = {x, y};
if (x > 0) {
y = arr[i] * x;
}
return y;
}

//CHECK: void f_cond4_grad(double x, double y, clad::array_ref<double> _d_x, clad::array_ref<double> _d_y) {
//CHECK-NEXT: int _d_i = 0;
//CHECK-NEXT: clad::array<double> _d_arr(2UL);
//CHECK-NEXT: bool _cond0;
//CHECK-NEXT: double _t0;
//CHECK-NEXT: double _t1;
//CHECK-NEXT: int i = 0;
//CHECK-NEXT: double arr[2] = {x, y};
//CHECK-NEXT: _cond0 = x > 0;
//CHECK-NEXT: if (_cond0) {
//CHECK-NEXT: _t0 = y;
//CHECK-NEXT: _t1 = x;
//CHECK-NEXT: y = arr[i] * _t1;
//CHECK-NEXT: }
//CHECK-NEXT: goto _label0;
//CHECK-NEXT: _label0:
//CHECK-NEXT: * _d_y += 1;
//CHECK-NEXT: if (_cond0) {
//CHECK-NEXT: {
//CHECK-NEXT: y = _t0;
//CHECK-NEXT: double _r_d0 = * _d_y;
//CHECK-NEXT: double _r0 = _r_d0 * _t1;
//CHECK-NEXT: _d_arr[i] += _r0;
//CHECK-NEXT: double _r1 = arr[i] * _r_d0;
//CHECK-NEXT: * _d_x += _r1;
//CHECK-NEXT: * _d_y -= _r_d0;
//CHECK-NEXT: * _d_y;
//CHECK-NEXT: }
//CHECK-NEXT: }
//CHECK-NEXT: {
//CHECK-NEXT: * _d_x += _d_arr[0];
//CHECK-NEXT: * _d_y += _d_arr[1];
//CHECK-NEXT: }
//CHECK-NEXT: }

double f_cond4_grad(double x, double c, clad::array_ref<double> _d_x, clad::array_ref<double> _d_y);

double f_if1(double x, double y) {
if (x > y)
return x;
Expand Down Expand Up @@ -904,6 +950,7 @@ int main() {
TEST(f_cond1, 3, 2); // CHECK-EXEC: Result is = {1.00, 0.00}
TEST(f_cond2, 3, -1); // CHECK-EXEC: Result is = {1.00, 0.00}
TEST(f_cond3, 3, -1); // CHECK-EXEC: Result is = {1.00, -1.00}
TEST(f_cond4, 3, -1); // CHECK-EXEC: Result is = {6.00, 0.00}
TEST(f_if1, 3, 2); // CHECK-EXEC: Result is = {1.00, 0.00}
TEST(f_if2, -5, -4); // CHECK-EXEC: Result is = {0.00, -1.00}
clad::gradient(&S::f);
Expand Down

0 comments on commit 9d26a46

Please sign in to comment.