1/*
2 * Copyright (c) 2014-2016 ARM Limited
3 * All rights reserved
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Authors: Andreas Sandberg
18 */
19
20#ifndef _TESTS_NOMALI_TEST_HELPERS_H
21#define _TESTS_NOMALI_TEST_HELPERS_H
22
23#include <libnomali/nomali.h>
24#include "test_helpers.h"
25
26#define E_NOMALI_BAIL(c)                                \
27    do {                                                \
28        nomali_error_t error;                           \
29        if ((error = (c)) != NOMALI_E_OK) {             \
30            test_bail(# c " failed: %s (%i)",           \
31                      nomali_errstr(error), error);     \
32        }                                               \
33    } while (0)
34
35#define E_NOMALI_TEST(t, c)                             \
36    do {                                                \
37        if ((error = (c)) != NOMALI_E_OK) {             \
38            test_diag(# c " failed: %s (%i)",           \
39                      nomali_errstr(error), error);     \
40            test_fail(t);                               \
41        } else {                                        \
42            test_ok(t);                                 \
43        }                                               \
44    } while (0)
45
46#define NOMALI_TEST_REG(t, handle, reg, test)                           \
47    do {                                                                \
48        uint32_t value;                                                 \
49        E_NOMALI_BAIL(                                                  \
50            nomali_reg_read(handle, &value, (reg)));                    \
51        if (!(test)) {                                                  \
52            test_fail(t);                                               \
53        } else {                                                        \
54            test_ok(t);                                                 \
55        }                                                               \
56    } while (0)
57
58
59
60#endif /* _TESTS_NOMALI_TEST_HELPERS_H */
61