source: rtems-central/generate_membench.py @ b37bd6a

Last change on this file since b37bd6a was b37bd6a, checked in by Sebastian Huber <sebastian.huber@…>, on 03/13/23 at 12:45:37

spec: Place test suites in design groups

  • Property mode set to 100755
File size: 25.9 KB
Line 
1#!/usr/bin/env python
2# SPDX-License-Identifier: BSD-2-Clause
3""" Generates memory benchmarks. """
4
5# Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26# POSSIBILITY OF SUCH DAMAGE.
27
28import argparse
29import logging
30import os
31import sys
32import textwrap
33from typing import NamedTuple, List, Optional
34
35from rtemsspec.content import to_camel_case
36from rtemsspec.items import ItemCache
37from rtemsspec.membench import generate
38from rtemsspec.sphinxcontent import SphinxContent, SphinxMapper
39from rtemsspec.util import load_config
40
41
42class _Test(NamedTuple):
43    path: str
44    name: str
45    links: List[str]
46    topic: str
47    desc: Optional[str]
48    init: str
49    config: str
50
51
52_CONFIG_DEFAULT = """#define TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
53
54#define TASK_STORAGE_SIZE \\
55  RTEMS_TASK_STORAGE_SIZE( \\
56    RTEMS_MINIMUM_STACK_SIZE, \\
57    TASK_ATTRIBUTES \
58  )
59
60#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
61
62#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 0
63
64#define CONFIGURE_DISABLE_NEWLIB_REENTRANCY
65
66#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
67
68#define CONFIGURE_IDLE_TASK_STORAGE_SIZE RTEMS_MINIMUM_STACK_SIZE
69
70#define CONFIGURE_MAXIMUM_TASKS 1
71
72#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
73
74#define CONFIGURE_INIT_TASK_ATTRIBUTES TASK_ATTRIBUTES
75
76#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
77
78#define CONFIGURE_INIT_TASK_CONSTRUCT_STORAGE_SIZE TASK_STORAGE_SIZE"""
79
80_CONFIG_SMP_1 = """#define CONFIGURE_MAXIMUM_PROCESSORS 1
81
82#if defined(RTEMS_SMP)
83#define CONFIGURE_SCHEDULER_EDF_SMP
84#endif
85
86""" + _CONFIG_DEFAULT
87
88_TEXT = ("The system shall provide a benchmark program to show the static "
89         "memory usage of")
90
91_TEST = "This static memory usage benchmark program facilitates"
92
93_LINKS_BASIC = ["../../req/mem-basic"]
94
95_TESTS = [
96    _Test(
97        "rtems",
98        "basic",
99        ["/req/mem-benchmark"],
100        "a basic application configuration",
101        """This resource benchmark is configured for exactly one processor,
102no clock driver, no Newlib reentrancy support, and no file system.""",
103        """/* Nothing to do */""", _CONFIG_DEFAULT),
104    _Test(
105        "rtems",
106        "smp-1",
107        ["mem-basic"],
108        """a basic application configuration with
109${/acfg/if/max-processors:/name} defined to one using the SMP EDF scheduler
110(${/acfg/if/scheduler-edf-smp:/name})""",
111        None,
112        """/* Nothing to do */""",
113        _CONFIG_SMP_1),
114    _Test(
115        "rtems",
116        "smp-global-2",
117        ["mem-smp-1"],
118        """a basic application configuration with
119${/acfg/if/max-processors:/name} defined to two using the global SMP EDF
120scheduler (${/acfg/if/scheduler-edf-smp:/name})""",
121        None,
122        """/* Nothing to do */""",
123        """#define CONFIGURE_MAXIMUM_PROCESSORS 2
124
125#if defined(RTEMS_SMP)
126#define CONFIGURE_SCHEDULER_EDF_SMP
127#endif
128
129""" + _CONFIG_DEFAULT),
130    _Test(
131        "rtems",
132        "smp-global-4",
133        ["mem-smp-1"],
134        """a basic application configuration with
135${/acfg/if/max-processors:/name} defined to four using the global SMP EDF
136scheduler (${/acfg/if/scheduler-edf-smp:/name})""",
137        None,
138        """/* Nothing to do */""",
139        """#define CONFIGURE_MAXIMUM_PROCESSORS 4
140
141#if defined(RTEMS_SMP)
142#define CONFIGURE_SCHEDULER_EDF_SMP
143#endif
144
145""" + _CONFIG_DEFAULT),
146    _Test(
147        "rtems",
148        "smp-part-2",
149        ["mem-smp-1"],
150        """a basic application configuration with
151${/acfg/if/max-processors:/name} defined to two using one SMP EDF scheduler
152for each configured processor (${/acfg/if/scheduler-edf-smp:/name})""",
153        None,
154        """/* Nothing to do */""",
155        """#define CONFIGURE_MAXIMUM_PROCESSORS 2
156
157#if defined(RTEMS_SMP)
158#define CONFIGURE_SCHEDULER_EDF_SMP
159
160#include <rtems/scheduler.h>
161
162RTEMS_SCHEDULER_EDF_SMP( a );
163
164RTEMS_SCHEDULER_EDF_SMP( b );
165
166#define NAME( x ) rtems_build_name( x, ' ', ' ', ' ' )
167
168#define CONFIGURE_SCHEDULER_TABLE_ENTRIES \\
169  RTEMS_SCHEDULER_TABLE_EDF_SMP( a, NAME( 'A' ) ), \\
170  RTEMS_SCHEDULER_TABLE_EDF_SMP( b, NAME( 'B' ) )
171
172#define CONFIGURE_SCHEDULER_ASSIGNMENTS \\
173  RTEMS_SCHEDULER_ASSIGN( 0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY ), \\
174  RTEMS_SCHEDULER_ASSIGN( 1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY )
175#endif
176
177""" + _CONFIG_DEFAULT),
178    _Test(
179        "rtems",
180        "smp-part-4",
181        ["mem-smp-1"],
182        """a basic application configuration with
183${/acfg/if/max-processors:/name} defined to four using one SMP EDF scheduler
184for each configured processor (${/acfg/if/scheduler-edf-smp:/name})""",
185        None,
186        """/* Nothing to do */""",
187        """#define CONFIGURE_MAXIMUM_PROCESSORS 4
188
189#if defined(RTEMS_SMP)
190#define CONFIGURE_SCHEDULER_EDF_SMP
191
192#include <rtems/scheduler.h>
193
194RTEMS_SCHEDULER_EDF_SMP( a );
195
196RTEMS_SCHEDULER_EDF_SMP( b );
197
198RTEMS_SCHEDULER_EDF_SMP( c );
199
200RTEMS_SCHEDULER_EDF_SMP( d );
201
202#define NAME( x ) rtems_build_name( x, ' ', ' ', ' ' )
203
204#define CONFIGURE_SCHEDULER_TABLE_ENTRIES \\
205  RTEMS_SCHEDULER_TABLE_EDF_SMP( a, NAME( 'A' ) ), \\
206  RTEMS_SCHEDULER_TABLE_EDF_SMP( b, NAME( 'B' ) ), \\
207  RTEMS_SCHEDULER_TABLE_EDF_SMP( c, NAME( 'C' ) ), \\
208  RTEMS_SCHEDULER_TABLE_EDF_SMP( d, NAME( 'D' ) )
209
210#define CONFIGURE_SCHEDULER_ASSIGNMENTS \\
211  RTEMS_SCHEDULER_ASSIGN( 0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY ), \\
212  RTEMS_SCHEDULER_ASSIGN( 1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY ), \\
213  RTEMS_SCHEDULER_ASSIGN( 2, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY ), \\
214  RTEMS_SCHEDULER_ASSIGN( 3, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY )
215#endif
216
217""" + _CONFIG_DEFAULT),
218    _Test(
219        "bsp",
220        "clock",
221        ["../if/group-clock", "/rtems/req/mem-basic"],
222        """a basic application configuration with the clock driver enabled
223(${/acfg/if/appl-needs-clock-driver:/name})""",
224        None,
225        """/* Nothing to do */""",
226        _CONFIG_DEFAULT.replace(
227            "CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER",
228            "CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER")),
229    _Test(
230        "rtems/clock",
231        "set",
232        _LINKS_BASIC,
233        """a basic application configuration with a
234call to ${../if/set:/name}""",
235        None,
236        "(void) rtems_clock_set( NULL );",
237        _CONFIG_DEFAULT),
238    _Test(
239        "rtems/clock",
240        "set-get-tod",
241        _LINKS_BASIC,
242        """a basic application configuration with calls to
243${../if/set:/name} and ${../if/get-tod:/name}""",
244        None,
245        """(void) rtems_clock_set( NULL );
246(void) rtems_clock_get_tod( NULL );""",
247        _CONFIG_DEFAULT),
248    _Test(
249        "rtems/clock",
250        "get-uptime",
251        _LINKS_BASIC,
252        """a basic application configuration with a
253call to ${../if/get-uptime:/name}""",
254        None,
255        "(void) rtems_clock_get_uptime( NULL );",
256        _CONFIG_DEFAULT),
257    _Test(
258        "rtems/barrier",
259        "wait-rel",
260        _LINKS_BASIC,
261        """a basic application configuration with
262${/acfg/if/max-barriers:/name} defined to one and calls to
263${../if/create:/name}, ${../if/wait:/name}, and ${../if/release:/name}""",
264        None,
265        """(void) rtems_barrier_create( 0, 0, 0, NULL );
266(void) rtems_barrier_wait( 0, 0 );
267(void) rtems_barrier_release( 0, NULL );""",
268        """#define CONFIGURE_MAXIMUM_BARRIERS 1
269
270""" + _CONFIG_DEFAULT),
271    _Test(
272        "rtems/barrier",
273        "wait-rel-del",
274        _LINKS_BASIC,
275        """a basic application configuration
276with ${/acfg/if/max-barriers:/name} defined to one and calls to
277${../if/create:/name}, ${../if/wait:/name}, ${../if/release:/name}, and
278${../if/delete:/name}""",
279        None,
280        """(void) rtems_barrier_create( 0, 0, 0, NULL );
281(void) rtems_barrier_wait( 0, 0 );
282(void) rtems_barrier_release( 0, NULL );
283(void) rtems_barrier_delete( 0 );""",
284        """#define CONFIGURE_MAXIMUM_BARRIERS 1
285
286""" + _CONFIG_DEFAULT),
287    _Test(
288        "rtems/event",
289        "snd-rcv",
290        _LINKS_BASIC,
291        """a basic application configuration with calls to ${../if/send:/name}
292and ${../if/receive:/name}""",
293        None,
294        """(void) rtems_event_send( 0, 0 );
295(void) rtems_event_receive( 0, 0, 0, NULL );""",
296        _CONFIG_DEFAULT),
297    _Test(
298        "rtems/fatal",
299        "fatal",
300        ["../../req/group"] + _LINKS_BASIC,
301        """a basic application configuration with a call to
302${../if/fatal:/name}""",
303        None,
304        "rtems_fatal( 0, 0 );",
305        _CONFIG_DEFAULT),
306    _Test(
307        "rtems/message",
308        "snd-rcv",
309        _LINKS_BASIC,
310        """a basic application configuration with calls to
311${../if/construct:/name}, ${../if/send:/name}, and
312${../if/receive:/name}""",
313        None,
314        """(void) rtems_message_queue_construct( NULL, NULL );
315(void) rtems_message_queue_send( 0, NULL, 0 );
316(void) rtems_message_queue_receive( 0, NULL, NULL, 0, 0 );""",
317        _CONFIG_DEFAULT),
318    _Test(
319        "rtems/message",
320        "ugt-rcv",
321        _LINKS_BASIC,
322        """a basic application configuration with calls to
323${../if/construct:/name}, ${../if/urgent:/name}, and
324${../if/receive:/name}""",
325        None,
326        """(void) rtems_message_queue_construct( NULL, NULL );
327(void) rtems_message_queue_urgent( 0, NULL, 0 );
328(void) rtems_message_queue_receive( 0, NULL, NULL, 0, 0 );""",
329        _CONFIG_DEFAULT),
330    _Test(
331        "rtems/message",
332        "bcst-rcv",
333        _LINKS_BASIC,
334        """a basic application configuration with calls to
335${../if/construct:/name}, ${../if/broadcast:/name}, and
336${../if/receive:/name}""",
337        None,
338        """(void) rtems_message_queue_construct( NULL, NULL );
339(void) rtems_message_queue_broadcast( 0, NULL, 0, NULL );
340(void) rtems_message_queue_receive( 0, NULL, NULL, 0, 0 );""",
341        _CONFIG_DEFAULT),
342    _Test(
343        "rtems/message",
344        "snd-rcv-del",
345        _LINKS_BASIC,
346        """a basic application configuration with calls to
347${../if/construct:/name}, ${../if/send:/name},
348${../if/receive:/name}, and ${../if/delete:/name}""",
349        None,
350        """(void) rtems_message_queue_construct( NULL, NULL );
351(void) rtems_message_queue_send( 0, NULL, 0 );
352(void) rtems_message_queue_receive( 0, NULL, NULL, 0, 0 );
353(void) rtems_message_queue_delete( 0 );""",
354        _CONFIG_DEFAULT),
355    _Test(
356        "rtems/part",
357        "get-ret",
358        _LINKS_BASIC,
359        """a basic application configuration with
360${/acfg/if/max-partitions:/name} defined to one and calls to
361${../if/create:/name}, ${../if/get-buffer:/name}, and
362${../if/return-buffer:/name}""",
363        None,
364        """(void) rtems_partition_create( 0, NULL, 0, 0, 0, NULL );
365(void) rtems_partition_get_buffer( 0, NULL );
366(void) rtems_partition_return_buffer( 0, NULL );""",
367        """#define CONFIGURE_MAXIMUM_PARTITIONS 1
368
369""" + _CONFIG_DEFAULT),
370    _Test(
371        "rtems/part",
372        "get-ret-del",
373        _LINKS_BASIC,
374        """a basic application configuration with
375${/acfg/if/max-partitions:/name} defined to one and calls to
376${../if/create:/name}, ${../if/get-buffer:/name}, ${../if/return-buffer:/name},
377and ${../if/delete:/name}""",
378        None,
379        """(void) rtems_partition_create( 0, NULL, 0, 0, 0, NULL );
380(void) rtems_partition_get_buffer( 0, NULL );
381(void) rtems_partition_return_buffer( 0, NULL );
382(void) rtems_partition_delete( 0 );""",
383        """#define CONFIGURE_MAXIMUM_PARTITIONS 1
384
385""" + _CONFIG_DEFAULT),
386    _Test(
387        "rtems/ratemon",
388        "period",
389        _LINKS_BASIC,
390        """a basic application configuration with
391${/acfg/if/max-periods:/name} defined to one and calls to
392${../if/create:/name} and ${../if/period:/name}""",
393        None,
394        """(void) rtems_rate_monotonic_create( 0, NULL );
395(void) rtems_rate_monotonic_period( 0, 0 );""",
396        """#define CONFIGURE_MAXIMUM_PERIODS 1
397
398""" + _CONFIG_DEFAULT),
399    _Test(
400        "rtems/ratemon",
401        "period-del",
402        _LINKS_BASIC,
403        """a basic application configuration with
404${/acfg/if/max-periods:/name} defined to one and calls to
405${../if/create:/name}, ${../if/period:/name}, and
406${../if/delete:/name}""",
407        None,
408        """(void) rtems_rate_monotonic_create( 0, NULL );
409(void) rtems_rate_monotonic_period( 0, 0 );
410(void) rtems_rate_monotonic_delete( 0 );""",
411        """#define CONFIGURE_MAXIMUM_PERIODS 1
412
413""" + _CONFIG_DEFAULT),
414    _Test(
415        "rtems/scheduler",
416        "add-cpu",
417        ["../../req/group", "../../req/mem-smp-1"],
418        """a basic application configuration with a
419call to ${../if/add-processor:/name}""",
420        None,
421        "(void) rtems_scheduler_add_processor( 0, 0 );",
422        _CONFIG_SMP_1),
423    _Test(
424        "rtems/scheduler",
425        "rm-cpu",
426        ["../../req/group", "../../req/mem-smp-1"],
427        """a basic application configuration with a
428call to ${../if/remove-processor:/name}""",
429        None,
430        "(void) rtems_scheduler_remove_processor( 0, 0 );",
431        _CONFIG_SMP_1),
432    _Test(
433        "rtems/sem",
434        "obt-rel",
435        _LINKS_BASIC,
436        """a basic application configuration with
437${/acfg/if/max-semaphores:/name} defined to one and calls to
438${../if/create:/name}, ${../if/obtain:/name}, and ${../if/release:/name}""",
439        None,
440        """(void) rtems_semaphore_create( 0, 0, 0, 0, NULL );
441(void) rtems_semaphore_obtain( 0, 0, 0 );
442(void) rtems_semaphore_release( 0 );""",
443        """#define CONFIGURE_MAXIMUM_SEMAPHORES 1
444
445""" + _CONFIG_DEFAULT),
446    _Test(
447        "rtems/sem",
448        "obt-rel-del",
449        _LINKS_BASIC,
450        """a basic application configuration with
451${/acfg/if/max-semaphores:/name} defined to one and calls to
452${../if/create:/name}, ${../if/obtain:/name}, ${../if/release:/name}, and
453${../if/delete:/name}""",
454        None,
455        """(void) rtems_semaphore_create( 0, 0, 0, 0, NULL );
456(void) rtems_semaphore_obtain( 0, 0, 0 );
457(void) rtems_semaphore_release( 0 );
458(void) rtems_semaphore_delete( 0 );""",
459        """#define CONFIGURE_MAXIMUM_SEMAPHORES 1
460
461""" + _CONFIG_DEFAULT),
462    _Test(
463        "rtems/signal",
464        "catch-snd",
465        _LINKS_BASIC,
466        """a basic application configuration with calls to ${../if/catch:/name}
467and ${../if/send:/name}""",
468        None,
469        """(void) rtems_signal_catch( NULL, 0 );
470(void) rtems_signal_send( 0, 0 );""",
471        _CONFIG_DEFAULT),
472    _Test(
473        "rtems/task",
474        "delete",
475        _LINKS_BASIC,
476        """a basic application configuration with a
477call to ${../if/delete:/name}""",
478        None,
479        "(void) rtems_task_delete( 0 );",
480        _CONFIG_DEFAULT),
481    _Test(
482        "rtems/task",
483        "exit",
484        _LINKS_BASIC,
485        """a basic application configuration with a
486call to ${../if/exit:/name}""",
487        None,
488        "rtems_task_exit();",
489        _CONFIG_DEFAULT),
490    _Test(
491        "rtems/task",
492        "restart",
493        _LINKS_BASIC,
494        """a basic application configuration with a
495call to ${../if/restart:/name}""",
496        None,
497        "(void) rtems_task_restart( 0, 0 );",
498        _CONFIG_DEFAULT),
499    _Test(
500        "rtems/task",
501        "sus-res",
502        _LINKS_BASIC,
503        """a basic application configuration with
504calls to ${../if/suspend:/name} and ${../if/resume:/name}""",
505        None,
506        """(void) rtems_task_suspend( 0 );
507(void) rtems_task_resume( 0 );""",
508        _CONFIG_DEFAULT),
509    _Test(
510        "rtems/task",
511        "set-priority",
512        _LINKS_BASIC,
513        """a basic application configuration with a
514call to ${../if/set-priority:/name}""",
515        None,
516        "(void) rtems_task_set_priority( 0, 0, NULL );",
517        _CONFIG_DEFAULT),
518    _Test(
519        "rtems/task",
520        "get-priority",
521        _LINKS_BASIC,
522        """a basic application configuration with a
523call to ${../if/get-priority:/name}""",
524        None,
525        "(void) rtems_task_get_priority( 0, 0, NULL );",
526        _CONFIG_DEFAULT),
527    _Test(
528        "rtems/task",
529        "mode",
530        _LINKS_BASIC,
531        """a basic application configuration with a
532call to ${../if/mode:/name}""",
533        None,
534        "(void) rtems_task_mode( 0, 0, 0 );",
535        _CONFIG_DEFAULT),
536    _Test(
537        "rtems/task",
538        "wake-after",
539        _LINKS_BASIC,
540        """a basic application configuration with a
541call to ${../if/wake-after:/name}""",
542        None,
543        "(void) rtems_task_wake_after( 0 );",
544        _CONFIG_DEFAULT),
545    _Test(
546        "rtems/task",
547        "wake-when",
548        _LINKS_BASIC,
549        """a basic application configuration with a
550call to ${../if/wake-when:/name}""",
551        None,
552        "(void) rtems_task_wake_when( NULL );",
553        _CONFIG_DEFAULT),
554    _Test(
555        "rtems/task",
556        "set-scheduler",
557        _LINKS_BASIC,
558        """a basic application configuration with a
559call to ${../if/set-scheduler:/name}""",
560        None,
561        "(void) rtems_task_set_scheduler( 0, 0, 0 );",
562        _CONFIG_DEFAULT),
563    _Test(
564        "rtems/task",
565        "get-scheduler",
566        _LINKS_BASIC,
567        """a basic application configuration with a
568call to ${../if/get-scheduler:/name}""",
569        None,
570        "(void) rtems_task_get_scheduler( 0, NULL );",
571        _CONFIG_DEFAULT),
572    _Test(
573        "rtems/task",
574        "set-affinity",
575        _LINKS_BASIC,
576        """a basic application configuration with a
577call to ${../if/set-affinity:/name}""",
578        None,
579        "(void) rtems_task_set_affinity( 0, 0, NULL );",
580        _CONFIG_DEFAULT),
581    _Test(
582        "rtems/task",
583        "get-affinity",
584        _LINKS_BASIC,
585        """a basic application configuration with a
586call to ${../if/get-affinity:/name}""",
587        None,
588        "(void) rtems_task_get_affinity( 0, 0, NULL );",
589        _CONFIG_DEFAULT),
590    _Test(
591        "rtems/timer",
592        "after",
593        _LINKS_BASIC,
594        """a basic application configuration with calls to
595${../if/create:/name} and ${../if/fire-after:/name}""",
596        None,
597        """(void) rtems_timer_create( 0, NULL );
598(void) rtems_timer_fire_after( 0, 0, NULL, NULL );""",
599        _CONFIG_DEFAULT),
600    _Test(
601        "rtems/timer",
602        "when",
603        _LINKS_BASIC,
604        """a basic application configuration with calls to
605${../if/create:/name} and ${../if/fire-when:/name}""",
606        None,
607        """(void) rtems_timer_create( 0, NULL );
608(void) rtems_timer_fire_when( 0, NULL, NULL, NULL );""",
609        _CONFIG_DEFAULT),
610    _Test(
611        "rtems/timer",
612        "cancel",
613        _LINKS_BASIC,
614        """a basic application configuration with calls to
615${../if/create:/name} and ${../if/cancel:/name}""",
616        None,
617        """(void) rtems_timer_create( 0, NULL );
618(void) rtems_timer_cancel( 0 );""",
619        _CONFIG_DEFAULT),
620    _Test(
621        "rtems/timer",
622        "reset",
623        _LINKS_BASIC,
624        """a basic application configuration with calls to
625${../if/create:/name} and ${../if/reset:/name}""",
626        None,
627        """(void) rtems_timer_create( 0, NULL );
628(void) rtems_timer_reset( 0 );""",
629        _CONFIG_DEFAULT),
630    _Test(
631        "rtems/timer",
632        "delete",
633        _LINKS_BASIC,
634        """a basic application configuration with calls to
635${../if/create:/name} and ${../if/delete:/name}""",
636        None,
637        """(void) rtems_timer_create( 0, NULL );
638(void) rtems_timer_delete( 0 );""",
639        _CONFIG_DEFAULT),
640    _Test(
641        "rtems/timer",
642        "srv-init",
643        _LINKS_BASIC,
644        """a basic application configuration with a call to
645${../if/initiate-server:/name}""",
646        None,
647        "(void) rtems_timer_initiate_server( 0, 0, 0 );",
648        """static void *task_stack_allocate( size_t size )
649{
650  (void) size;
651  return NULL;
652}
653
654static void task_stack_deallocate( void *stack )
655{
656  (void) stack;
657}
658
659#define CONFIGURE_TASK_STACK_ALLOCATOR task_stack_allocate
660
661#define CONFIGURE_TASK_STACK_DEALLOCATOR task_stack_deallocate
662
663""" + _CONFIG_DEFAULT),
664    _Test(
665        "rtems/timer",
666        "srv-after",
667        _LINKS_BASIC,
668        """a basic application configuration with calls to
669${../if/create:/name} and ${../if/server-fire-after:/name}""",
670        None,
671        """(void) rtems_timer_create( 0, NULL );
672(void) rtems_timer_server_fire_after( 0, 0, NULL, NULL );""",
673        _CONFIG_DEFAULT),
674    _Test(
675        "rtems/timer",
676        "srv-when",
677        _LINKS_BASIC,
678        """a basic application configuration with calls to
679${../if/create:/name} and ${../if/server-fire-when:/name}""",
680        None,
681        """(void) rtems_timer_create( 0, NULL );
682(void) rtems_timer_server_fire_when( 0, NULL, NULL, NULL );""",
683        _CONFIG_DEFAULT),
684    _Test(
685        "rtems/userext",
686        "create",
687        _LINKS_BASIC,
688        """a basic application configuration with
689${/acfg/if/max-user-extensions:/name} defined to one and a call to
690${../if/create:/name}""",
691        None,
692        "(void) rtems_extension_create( 0, NULL, NULL );",
693        """#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
694
695""" + _CONFIG_DEFAULT),
696    _Test(
697        "rtems/userext",
698        "delete",
699        _LINKS_BASIC,
700        """a basic application configuration with
701${/acfg/if/max-user-extensions:/name} defined to one and calls to
702${../if/create:/name} and ${../if/delete:/name}""",
703        None,
704        """(void) rtems_extension_create( 0, NULL, NULL );
705(void) rtems_extension_delete( 0 );""",
706        """#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
707
708""" + _CONFIG_DEFAULT),
709]  # yapf: disable
710
711
712def _indent(lines: str, level: int = 2) -> str:
713    space = " " * level
714    return lines.replace("\n", f"\n{space}").replace(f"\n{space}\n", "\n\n")
715
716
717def _text(lines: str, level: int = 2) -> str:
718    wrapper = textwrap.TextWrapper()
719    wrapper.break_long_words = False
720    wrapper.break_on_hyphens = False
721    wrapper.width = 79 - level
722    return _indent("\n".join(wrapper.wrap(lines)), level)
723
724
725def _block(lines: Optional[str], level: int = 2) -> str:
726    if lines:
727        return f"""|
728  {_text(lines, level)}"""
729    return "null"
730
731
732def _links(links: List[str]) -> str:
733    text: List[str] = []
734    for link in links:
735        if "group" in link:
736            break
737    else:
738        links.insert(0, "group")
739    for link in links:
740        text.append(f"""- role: requirement-refinement
741  uid: {link}""")
742    return "\n".join(text)
743
744
745def _generate_files() -> None:
746    for test in _TESTS:
747        module = os.path.basename(test.path)
748        base = f"testsuites/membench/mem-{module}-{test.name}"
749        source = f"{base}.c"
750        build_spec = f"modules/rtems/spec/build/{base}.yml"
751        with open(build_spec, "w", encoding="utf-8") as out:
752            out.write(f"""SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
753build-type: test-program
754cflags: []
755copyrights:
756- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
757cppflags: []
758cxxflags: []
759enabled-by: true
760features: c cprogram
761includes: []
762ldflags: []
763links: []
764source:
765- {source}
766stlib: []
767target: {base}.norun.exe
768type: build
769use-after: []
770use-before: []
771""")
772        req_spec = f"/{test.path}/req/mem-{test.name}"
773        text = _text(f"{_TEXT} {test.topic}.")
774        with open(f"spec{req_spec}.yml", "w", encoding="utf-8") as out:
775            out.write(f"""SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
776copyrights:
777- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de
778enabled-by: true
779links:
780{_links(test.links)}
781non-functional-type: quality
782rationale: null
783references: []
784requirement-type: non-functional
785text: |
786  {text}
787type: requirement
788""")
789        val_spec = f"spec/{test.path}/val/mem-{test.name}.yml"
790        brief = _text(f"{_TEST} {test.topic}.")
791        test_suite_name = to_camel_case(f"Mem {test.name}")
792        with open(val_spec, "w", encoding="utf-8") as out:
793            out.write(f"""SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
794copyrights:
795- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
796enabled-by: true
797links:
798- role: requirement-refinement
799  uid: /testsuites/membench
800- role: validation
801  uid: ../req/mem-{test.name}
802test-brief: |
803  {brief}
804test-code: |
805  static void Init( rtems_task_argument arg )
806  {{
807    (void) arg;
808
809    {_indent(test.init, 4)}
810  }}
811
812  {_indent(test.config)}
813
814  #define CONFIGURE_INIT
815
816  #include <rtems/confdefs.h>
817test-description: {_block(test.desc)}
818test-includes:
819- rtems.h
820test-local-includes: []
821test-target: {source}
822type: memory-benchmark
823""")
824
825
826def _post_process(path: str) -> None:
827    config = load_config("config.yml")
828    item_cache = ItemCache(config["spec"])
829    root = item_cache["/rtems/req/mem-basic"]
830    content = SphinxContent()
831    table_pivots = ["/rtems/req/mem-basic", "/rtems/req/mem-smp-1"]
832    generate(content, root, SphinxMapper(root), table_pivots, path)
833    print(content)
834
835
836def main() -> None:
837    """ Generates memory benchmarks. """
838    parser = argparse.ArgumentParser()
839    parser.add_argument(
840        '--log-level',
841        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
842        type=str.upper,
843        default="ERROR",
844        help="log level")
845    parser.add_argument('--log-file',
846                        type=str,
847                        default=None,
848                        help="log to this file")
849    parser.add_argument('--post-process', help="post-process the ELF files")
850    args = parser.parse_args(sys.argv[1:])
851    logging.basicConfig(filename=args.log_file, level=args.log_level)
852    if args.post_process:
853        _post_process(args.post_process)
854    else:
855        _generate_files()
856
857
858if __name__ == "__main__":
859    main()
Note: See TracBrowser for help on using the repository browser.