@@ -49,6 +49,11 @@ struct files {
4949struct db {
5050 struct files src ;
5151 struct files src_test ;
52+ struct files src_freertos ;
53+ struct files src_posix ;
54+ struct files src_stubs ;
55+ struct files src_cooperative ;
56+ struct files src_preemptive ;
5257 struct files hdr ;
5358 struct files hdr_test ;
5459 const char * odir ; /* amast(-test).h and amast(-test).c are placed here */
@@ -129,15 +134,23 @@ static void db_init(struct db *db, const char *db_fname, const char *odir) {
129134 fname [strcspn (fname , "\n" )] = 0 ;
130135
131136 if (strstr (fname , ".c" ) != NULL ) {
137+ struct files * files = & db -> src ;
132138 if (strstr (fname , "test" ) != NULL ) {
133- assert (db -> src_test .len < AM_COUNTOF (db -> src_test .content ));
134- read_file (& db -> src_test , fname );
135- db -> src_test .len ++ ;
136- } else {
137- assert (db -> src .len < AM_COUNTOF (db -> src .content ));
138- read_file (& db -> src , fname );
139- db -> src .len ++ ;
139+ files = & db -> src_test ;
140+ } else if (strstr (fname , "/libs/pal/freertos/" ) != NULL ) {
141+ files = & db -> src_freertos ;
142+ } else if (strstr (fname , "/libs/pal/posix/" ) != NULL ) {
143+ files = & db -> src_posix ;
144+ } else if (strstr (fname , "/libs/pal/stubs/" ) != NULL ) {
145+ files = & db -> src_stubs ;
146+ } else if (strstr (fname , "/libs/ao/cooperative/" ) != NULL ) {
147+ files = & db -> src_cooperative ;
148+ } else if (strstr (fname , "/libs/ao/preemptive/" ) != NULL ) {
149+ files = & db -> src_preemptive ;
140150 }
151+ AM_ASSERT (files -> len < AM_COUNTOF (files -> content ));
152+ read_file (files , fname );
153+ files -> len ++ ;
141154 continue ;
142155 }
143156 if (strstr (fname , ".h" ) != NULL ) {
@@ -360,71 +373,200 @@ static void create_amast_test_h_file(
360373 fclose (hdr_file );
361374}
362375
363- static void create_amast_c_file (
364- struct db * db , int * ntests , char (* tests )[PATH_MAX ]
365- ) {
376+ struct amast_file_cfg {
377+ struct db * db ;
378+ int * ntests ;
379+ char (* tests )[PATH_MAX ];
380+ int tests_max ;
381+ struct files * files ;
382+ const char (* inc )[PATH_MAX ];
383+ int ninc ;
384+ const char * amast_fname ;
385+ const char * note ;
386+ bool keep_open ;
387+ };
388+
389+ static FILE * create_amast_file (struct amast_file_cfg * cfg ) {
366390 char fname [PATH_MAX ];
367- snprintf (fname , sizeof (fname ), "%s/amast.c " , db -> odir );
391+ snprintf (fname , sizeof (fname ), "%s/%s " , cfg -> db -> odir , cfg -> amast_fname );
368392 FILE * src_file = fopen (fname , "w" );
369393 if (!src_file ) {
370394 fprintf (stderr , "Failed to create %s\n" , fname );
371395 exit (EXIT_FAILURE );
372396 }
373397
374- add_amast_description (src_file , "source" , & db -> src );
398+ add_amast_description (src_file , cfg -> note , cfg -> files );
375399
376- add_amast_includes_std (src_file , & db -> src );
377- fprintf (src_file , "#include \"amast_config.h\"\n" );
378- fprintf (src_file , "#include \"amast.h\"\n" );
400+ add_amast_includes_std (src_file , cfg -> files );
401+ for (int i = 0 ; i < cfg -> ninc ; ++ i ) {
402+ fprintf (src_file , "%s\n" , cfg -> inc [i ]);
403+ }
379404 fprintf (src_file , "\n" );
380405
381- /* Copy content of all source files to amast.c */
382- for (int i = 0 ; i < db -> src .len ; i ++ ) {
383- fprintf (src_file , "\n/* %s */\n\n" , get_repo_fname (db -> src .fnames [i ]));
384- assert (* ntests < (AM_COUNTOF (* tests ) - 1 ));
385- AM_ASSERT (strstr (db -> src .fnames [i ], "test" ) == NULL );
406+ /* Copy content of all source files to cfg->amast_fname */
407+ for (int i = 0 ; i < cfg -> files -> len ; i ++ ) {
408+ fprintf (
409+ src_file , "\n/* %s */\n\n" , get_repo_fname (cfg -> files -> fnames [i ])
410+ );
411+ AM_ASSERT (* cfg -> ntests < cfg -> tests_max );
412+ AM_ASSERT (strstr (cfg -> db -> src .fnames [i ], "test" ) == NULL );
386413 file_append (
387- db -> src .content [i ], db -> src .fnames [i ], src_file , ntests , tests
414+ cfg -> files -> content [i ],
415+ cfg -> files -> fnames [i ],
416+ src_file ,
417+ cfg -> ntests ,
418+ cfg -> tests
388419 );
389420 }
390421
422+ if (cfg -> keep_open ) {
423+ return src_file ;
424+ }
391425 fclose (src_file );
426+ return NULL ;
392427}
393428
394- static void create_amast_test_c_file (
395- struct db * db , int * ntests , char (* tests )[PATH_MAX ]
429+ static void create_amast_c_file (
430+ struct db * db , int * ntests , char (* tests )[PATH_MAX ], int tests_max
396431) {
397- char fname [PATH_MAX ];
398- snprintf (fname , sizeof (fname ), "%s/amast_test.c" , db -> odir );
399- FILE * src_file = fopen (fname , "w" );
400- if (!src_file ) {
401- fprintf (stderr , "Failed to create %s\n" , fname );
402- exit (EXIT_FAILURE );
403- }
432+ static const char inc [][PATH_MAX ] = {
433+ "#include \"amast_config.h\"" , "#include \"amast.h\""
434+ };
435+ struct amast_file_cfg cfg = {
436+ .db = db ,
437+ .ntests = ntests ,
438+ .tests = tests ,
439+ .tests_max = tests_max ,
440+ .files = & db -> src ,
441+ .inc = inc ,
442+ .ninc = AM_COUNTOF (inc ),
443+ .amast_fname = "amast.c" ,
444+ .note = "source"
445+ };
446+ create_amast_file (& cfg );
447+ }
404448
405- add_amast_description (src_file , "source" , & db -> src_test );
449+ static void create_amast_freertos_c_file (
450+ struct db * db , int * ntests , char (* tests )[PATH_MAX ], int tests_max
451+ ) {
452+ static const char inc [][PATH_MAX ] = {
453+ "#include \"amast_config.h\"" , "#include \"amast.h\""
454+ };
455+ struct amast_file_cfg cfg = {
456+ .db = db ,
457+ .ntests = ntests ,
458+ .tests = tests ,
459+ .tests_max = tests_max ,
460+ .files = & db -> src_freertos ,
461+ .inc = inc ,
462+ .ninc = AM_COUNTOF (inc ),
463+ .amast_fname = "amast_freertos.c" ,
464+ .note = "source"
465+ };
466+ create_amast_file (& cfg );
467+ }
406468
407- add_amast_includes_std (src_file , & db -> src_test );
408- fprintf (src_file , "#include \"amast_config.h\"\n" );
409- fprintf (src_file , "#include \"amast.h\"\n" );
410- fprintf (src_file , "#include \"amast_test.h\"\n" );
411- fprintf (src_file , "\n" );
469+ static void create_amast_posix_c_file (
470+ struct db * db , int * ntests , char (* tests )[PATH_MAX ], int tests_max
471+ ) {
472+ static const char inc [][PATH_MAX ] = {
473+ "#include \"amast_config.h\"" , "#include \"amast.h\""
474+ };
475+ struct amast_file_cfg cfg = {
476+ .db = db ,
477+ .ntests = ntests ,
478+ .tests = tests ,
479+ .tests_max = tests_max ,
480+ .files = & db -> src_posix ,
481+ .inc = inc ,
482+ .ninc = AM_COUNTOF (inc ),
483+ .amast_fname = "amast_posix.c" ,
484+ .note = "source"
485+ };
486+ create_amast_file (& cfg );
487+ }
412488
413- /* Copy content of all source files to amast.c */
414- for (int i = 0 ; i < db -> src_test .len ; i ++ ) {
415- fprintf (
416- src_file , "\n/* %s */\n\n" , get_repo_fname (db -> src_test .fnames [i ])
417- );
418- assert (* ntests < (AM_COUNTOF (* tests ) - 1 ));
419- AM_ASSERT (strstr (db -> src_test .fnames [i ], "test" ) != NULL );
420- file_append (
421- db -> src_test .content [i ],
422- db -> src_test .fnames [i ],
423- src_file ,
424- ntests ,
425- tests
426- );
427- }
489+ static void create_amast_stubs_c_file (
490+ struct db * db , int * ntests , char (* tests )[PATH_MAX ], int tests_max
491+ ) {
492+ static const char inc [][PATH_MAX ] = {
493+ "#include \"amast_config.h\"" , "#include \"amast.h\""
494+ };
495+ struct amast_file_cfg cfg = {
496+ .db = db ,
497+ .ntests = ntests ,
498+ .tests = tests ,
499+ .tests_max = tests_max ,
500+ .files = & db -> src_stubs ,
501+ .inc = inc ,
502+ .ninc = AM_COUNTOF (inc ),
503+ .amast_fname = "amast_stubs.c" ,
504+ .note = "source"
505+ };
506+ create_amast_file (& cfg );
507+ }
508+
509+ static void create_amast_cooperative_c_file (
510+ struct db * db , int * ntests , char (* tests )[PATH_MAX ], int tests_max
511+ ) {
512+ static const char inc [][PATH_MAX ] = {
513+ "#include \"amast_config.h\"" , "#include \"amast.h\""
514+ };
515+ struct amast_file_cfg cfg = {
516+ .db = db ,
517+ .ntests = ntests ,
518+ .tests = tests ,
519+ .tests_max = tests_max ,
520+ .files = & db -> src_cooperative ,
521+ .inc = inc ,
522+ .ninc = AM_COUNTOF (inc ),
523+ .amast_fname = "amast_cooperative.c" ,
524+ .note = "source"
525+ };
526+ create_amast_file (& cfg );
527+ }
528+
529+ static void create_amast_preemptive_c_file (
530+ struct db * db , int * ntests , char (* tests )[PATH_MAX ], int tests_max
531+ ) {
532+ static const char inc [][PATH_MAX ] = {
533+ "#include \"amast_config.h\"" , "#include \"amast.h\""
534+ };
535+ struct amast_file_cfg cfg = {
536+ .db = db ,
537+ .ntests = ntests ,
538+ .tests = tests ,
539+ .tests_max = tests_max ,
540+ .files = & db -> src_preemptive ,
541+ .inc = inc ,
542+ .ninc = AM_COUNTOF (inc ),
543+ .amast_fname = "amast_preemptive.c" ,
544+ .note = "source"
545+ };
546+ create_amast_file (& cfg );
547+ }
548+
549+ static void create_amast_test_c_file (
550+ struct db * db , int * ntests , char (* tests )[PATH_MAX ], int tests_max
551+ ) {
552+ static const char inc [][PATH_MAX ] = {
553+ "#include \"amast_config.h\"" ,
554+ "#include \"amast.h\"" ,
555+ "#include \"amast_test.h\""
556+ };
557+ struct amast_file_cfg cfg = {
558+ .db = db ,
559+ .ntests = ntests ,
560+ .tests = tests ,
561+ .tests_max = tests_max ,
562+ .files = & db -> src_test ,
563+ .inc = inc ,
564+ .ninc = AM_COUNTOF (inc ),
565+ .amast_fname = "amast_test.c" ,
566+ .note = "source" ,
567+ .keep_open = true
568+ };
569+ FILE * src_file = create_amast_file (& cfg );
428570
429571 /* Add the final main function to amast_test.c */
430572 fprintf (src_file , "\nint main(void) {\n" );
@@ -444,10 +586,18 @@ static void create_amast_test_c_file(
444586static void create_amast_files (struct db * db ) {
445587 char tests [32 ][PATH_MAX ];
446588 int ntests = 0 ;
589+
447590 create_amast_h_file (db , & ntests , tests );
448591 create_amast_test_h_file (db , & ntests , tests );
449- create_amast_c_file (db , & ntests , tests );
450- create_amast_test_c_file (db , & ntests , tests );
592+
593+ create_amast_c_file (db , & ntests , tests , AM_COUNTOF (tests ));
594+ create_amast_freertos_c_file (db , & ntests , tests , AM_COUNTOF (tests ));
595+ create_amast_posix_c_file (db , & ntests , tests , AM_COUNTOF (tests ));
596+ create_amast_stubs_c_file (db , & ntests , tests , AM_COUNTOF (tests ));
597+ create_amast_cooperative_c_file (db , & ntests , tests , AM_COUNTOF (tests ));
598+ create_amast_preemptive_c_file (db , & ntests , tests , AM_COUNTOF (tests ));
599+
600+ create_amast_test_c_file (db , & ntests , tests , AM_COUNTOF (tests ));
451601}
452602
453603static void print_help (const char * cmd ) {
0 commit comments