• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "utils.rsh"
18
19#define DEFINE_TEST(T)                                      \
20  T g_##T=7, notUsed_##T;                                   \
21  /* Test Allocations in between other global variables */  \
22  rs_allocation allocNotUsed_##T;                           \
23  /* Test statics in between other global variables */      \
24  static T static_##T;                                      \
25  /* Test taking addresses of globals */                    \
26  static T *ptr1_##T;                                       \
27  static T *ptr2_##T;                                       \
28  T __attribute__((kernel)) T##_kernel1(T in) {             \
29    return g_##T;                                           \
30  }                                                         \
31  T __attribute__((kernel)) T##_kernel2(T in) {             \
32    return *ptr1_##T + *ptr2_##T;                           \
33  }                                                         \
34  void T##_test_init(rs_allocation a) {                     \
35    /* Test static local variable */                        \
36    rsForEach(T##_kernel1, a, a);                           \
37    T actual = get_##T(a, 19);                              \
38    if (!checkEq((T)(7), actual)) {                         \
39      rsDebug("failed "#T, actual);                         \
40      rsSendToClientBlocking(RS_MSG_TEST_FAILED);           \
41      return;                                               \
42    }                                                       \
43    rsDebug("succeeded "#T, actual);                        \
44    rsSendToClientBlocking(RS_MSG_TEST_PASSED);             \
45  }                                                         \
46  void T##_test(rs_allocation a, T expected) {              \
47    /* Test static local variable */                        \
48    static T localStatic;                                   \
49    localStatic = g_##T;                                    \
50    static_##T = localStatic;                               \
51    ptr1_##T = &g_##T;                                      \
52    ptr2_##T = &static_##T;                                 \
53    rsForEach(T##_kernel2, a, a);                           \
54    T actual = get_##T(a, 19);                              \
55    if (!checkEq(expected * 2, actual)) {                   \
56      rsDebug("failed "#T, actual);                         \
57      rsSendToClientBlocking(RS_MSG_TEST_FAILED);           \
58      return;                                               \
59    }                                                       \
60    rsDebug("succeeded "#T, actual);                        \
61    rsSendToClientBlocking(RS_MSG_TEST_PASSED);             \
62  }
63
64