[PATCH 09/10] perf, test: Use ARRAY_SIZE in parse events tests

From: Jiri Olsa
Date: Tue Jul 03 2012 - 18:02:45 EST


Use ARRAY_SIZE instead of defining the sizes separately for
each test arrays.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/parse-events-test.c | 29 ++++++++++-------------------
1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/tools/perf/util/parse-events-test.c b/tools/perf/util/parse-events-test.c
index a0f61a2..ef5cce0 100644
--- a/tools/perf/util/parse-events-test.c
+++ b/tools/perf/util/parse-events-test.c
@@ -587,8 +587,6 @@ static struct test__event_st test__events[] = {
},
};

-#define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
-
static struct test__event_st test__events_pmu[] = {
[0] = {
.name = "cpu/config=10,config1,config2=3,period=1000/u",
@@ -600,9 +598,6 @@ static struct test__event_st test__events_pmu[] = {
},
};

-#define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
- sizeof(struct test__event_st))
-
struct test__term {
const char *str;
__u32 type;
@@ -718,21 +713,17 @@ int parse_events__test(void)
{
int ret;

- do {
- ret = test_events(test__events, TEST__EVENTS_CNT);
- if (ret)
- break;
-
- if (test_pmu()) {
- ret = test_events(test__events_pmu,
- TEST__EVENTS_PMU_CNT);
- if (ret)
- break;
- }
+#define TEST_EVENTS(tests) \
+do { \
+ ret = test_events(tests, ARRAY_SIZE(tests)); \
+ if (ret) \
+ return ret; \
+} while (0)

- ret = test_terms(test__terms, TEST__TERMS_CNT);
+ TEST_EVENTS(test__events);

- } while (0);
+ if (test_pmu())
+ TEST_EVENTS(test__events_pmu);

- return ret;
+ return test_terms(test__terms, ARRAY_SIZE(test__terms));
}
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/