source: rtems/testsuites/sptests/spprofiling01/init.c @ 53ad908

4.115
Last change on this file since 53ad908 was 53ad908, checked in by Sebastian Huber <sebastian.huber@…>, on 03/07/14 at 13:36:22

score: Add SMP lock profiling support

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/profiling.h>
20#include <rtems/bspIo.h>
21#include <rtems.h>
22
23#include <stdio.h>
24#include <string.h>
25
26#include "tmacros.h"
27
28typedef struct {
29  rtems_interrupt_lock a;
30  rtems_interrupt_lock b;
31  rtems_interrupt_lock c;
32  rtems_interrupt_lock d;
33  enum {
34    WAIT_FOR_A,
35    EXPECT_B,
36    EXPECT_D,
37    DONE
38  } state;
39} visitor_context;
40
41static bool is_equal(const rtems_profiling_smp_lock *psl, const char *name)
42{
43  return strcmp(psl->name, name) == 0;
44}
45
46static void visitor(void *arg, const rtems_profiling_data *data)
47{
48  visitor_context *ctx = arg;
49
50  if (data->header.type == RTEMS_PROFILING_SMP_LOCK) {
51    const rtems_profiling_smp_lock *psl = &data->smp_lock;
52
53    switch (ctx->state) {
54      case WAIT_FOR_A:
55        rtems_test_assert(!is_equal(psl, "b"));
56        rtems_test_assert(!is_equal(psl, "c"));
57        rtems_test_assert(!is_equal(psl, "d"));
58
59        if (is_equal(psl, "a")) {
60          ctx->state = EXPECT_B;
61        }
62        break;
63      case EXPECT_B:
64        rtems_test_assert(is_equal(psl, "b"));
65        rtems_interrupt_lock_destroy(&ctx->c);
66        ctx->state = EXPECT_D;
67        break;
68      case EXPECT_D:
69        rtems_test_assert(is_equal(psl, "d"));
70        ctx->state = DONE;
71        break;
72      case DONE:
73        rtems_test_assert(!is_equal(psl, "a"));
74        rtems_test_assert(!is_equal(psl, "b"));
75        rtems_test_assert(!is_equal(psl, "c"));
76        rtems_test_assert(!is_equal(psl, "d"));
77        break;
78    }
79  }
80}
81
82static void lock_init(rtems_interrupt_lock *lock, const char *name)
83{
84  rtems_interrupt_lock_context lock_context;
85
86  rtems_interrupt_lock_initialize(lock, name);
87  rtems_interrupt_lock_acquire(lock, &lock_context);
88  rtems_interrupt_lock_release(lock, &lock_context);
89}
90
91static void test_iterate(void)
92{
93  visitor_context ctx_instance;
94  visitor_context *ctx = &ctx_instance;
95
96  ctx->state = WAIT_FOR_A;
97  lock_init(&ctx->a, "a");
98  lock_init(&ctx->b, "b");
99  lock_init(&ctx->c, "c");
100  lock_init(&ctx->d, "d");
101
102  rtems_profiling_iterate(visitor, ctx);
103
104  rtems_interrupt_lock_destroy(&ctx->a);
105  rtems_interrupt_lock_destroy(&ctx->b);
106
107  if (ctx->state != DONE) {
108    rtems_interrupt_lock_destroy(&ctx->c);
109  }
110
111  rtems_interrupt_lock_destroy(&ctx->d);
112}
113
114static void test_report_xml(void)
115{
116  rtems_status_code sc;
117  int rv;
118
119  sc = rtems_task_wake_after(3);
120  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
121
122  rv = rtems_profiling_report_xml("X", rtems_printf_plugin, NULL, 1, "  ");
123  printf("characters produced by rtems_profiling_report_xml(): %i\n", rv);
124}
125
126static void Init(rtems_task_argument arg)
127{
128  puts("\n\n*** TEST SPPROFILING 1 ***");
129
130  test_iterate();
131  test_report_xml();
132
133  puts("*** END OF TEST SPPROFILING 1 ***");
134
135  rtems_test_exit(0);
136}
137
138#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
139#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
140
141#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
142
143#define CONFIGURE_MAXIMUM_TASKS 1
144
145#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
146
147#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
148
149#define CONFIGURE_INIT
150
151#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.