source: rtems-central/generate_membench.py @ 25310de

Last change on this file since 25310de was 25310de, checked in by Sebastian Huber <sebastian.huber@…>, on 03/15/23 at 07:04:30

generate_membench.py: Remove unused variable

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