3434enum {
3535 OPT_TRACE_OUTPUT = 1000 ,
3636 OPT_PRINT_CONFIG,
37+ OPT_VALIDATE_CONFIG,
3738 OPT_SAILCOV,
3839 OPT_ENABLE_EXPERIMENTAL_EXTENSIONS,
3940 OPT_PRINT_DTS,
4243static bool do_show_times = false ;
4344bool do_report_arch = false ;
4445bool do_print_dts = false ;
46+ char *config_file = NULL ;
47+ bool do_validate_config = false ;
4548char *term_log = NULL ;
4649static const char *trace_log_path = NULL ;
4750FILE *trace_log = NULL ;
@@ -101,27 +104,28 @@ char *sailcov_file = NULL;
101104#endif
102105
103106static struct option options[] = {
104- {" device-tree-blob" , required_argument, 0 , ' b' },
105- {" terminal-log" , required_argument, 0 , ' t' },
106- {" show-times" , required_argument, 0 , ' p' },
107- {" report-arch" , no_argument, 0 , ' a' },
108- {" test-signature" , required_argument, 0 , ' T' },
109- {" signature-granularity" , required_argument, 0 , ' g' },
110- {" rvfi-dii" , required_argument, 0 , ' r' },
111- {" help" , no_argument, 0 , ' h' },
112- {" config" , required_argument, 0 , ' c' },
113- {" print-default-config" , no_argument, 0 , OPT_PRINT_CONFIG},
114- {" trace" , optional_argument, 0 , ' v' },
115- {" no-trace" , optional_argument, 0 , ' V' },
116- {" trace-output" , required_argument, 0 , OPT_TRACE_OUTPUT},
117- {" inst-limit" , required_argument, 0 , ' l' },
107+ {" device-tree-blob" , required_argument, 0 , ' b' },
108+ {" terminal-log" , required_argument, 0 , ' t' },
109+ {" show-times" , required_argument, 0 , ' p' },
110+ {" report-arch" , no_argument, 0 , ' a' },
111+ {" test-signature" , required_argument, 0 , ' T' },
112+ {" signature-granularity" , required_argument, 0 , ' g' },
113+ {" rvfi-dii" , required_argument, 0 , ' r' },
114+ {" help" , no_argument, 0 , ' h' },
115+ {" config" , required_argument, 0 , ' c' },
116+ {" print-default-config" , no_argument, 0 , OPT_PRINT_CONFIG },
117+ {" validate-config" , no_argument, 0 , OPT_VALIDATE_CONFIG},
118+ {" trace" , optional_argument, 0 , ' v' },
119+ {" no-trace" , optional_argument, 0 , ' V' },
120+ {" trace-output" , required_argument, 0 , OPT_TRACE_OUTPUT },
121+ {" inst-limit" , required_argument, 0 , ' l' },
118122 {" enable-experimental-extensions" , no_argument, 0 ,
119- OPT_ENABLE_EXPERIMENTAL_EXTENSIONS },
123+ OPT_ENABLE_EXPERIMENTAL_EXTENSIONS },
120124#ifdef SAILCOV
121- {" sailcov-file" , required_argument, 0 , OPT_SAILCOV },
125+ {" sailcov-file" , required_argument, 0 , OPT_SAILCOV },
122126#endif
123- {" print-device-tree" , no_argument, 0 , OPT_PRINT_DTS },
124- {0 , 0 , 0 , 0 }
127+ {" print-device-tree" , no_argument, 0 , OPT_PRINT_DTS },
128+ {0 , 0 , 0 , 0 }
125129};
126130
127131static void print_usage (const char *argv0, int ec)
@@ -139,6 +143,17 @@ static void print_usage(const char *argv0, int ec)
139143 exit (ec);
140144}
141145
146+ static void validate_config (const char *conf_file)
147+ {
148+ const char *s = zconfig_is_valid (UNIT) ? " valid" : " invalid" ;
149+ if (conf_file) {
150+ fprintf (stdout, " Configuration in %s is %s.\n " , conf_file, s);
151+ } else {
152+ fprintf (stdout, " Default configuration is %s.\n " , s);
153+ }
154+ exit (0 );
155+ }
156+
142157static void report_arch (void )
143158{
144159 fprintf (stdout, " RV%" PRIu64 " \n " , zxlen);
@@ -248,6 +263,7 @@ static int process_args(int argc, char **argv)
248263 case ' c' : {
249264 if (access (optarg, R_OK) == 0 ) {
250265 sail_config_set_file (optarg);
266+ config_file = strdup (optarg);
251267 have_config = true ;
252268 } else {
253269 fprintf (stderr, " configuration file '%s' does not exist.\n " , optarg);
@@ -258,6 +274,9 @@ static int process_args(int argc, char **argv)
258274 case OPT_PRINT_CONFIG:
259275 printf (" %s" , DEFAULT_JSON);
260276 exit (0 );
277+ case OPT_VALIDATE_CONFIG:
278+ do_validate_config = true ;
279+ break ;
261280 case OPT_PRINT_DTS:
262281 do_print_dts = true ;
263282 break ;
@@ -319,14 +338,15 @@ static int process_args(int argc, char **argv)
319338 std::filesystem::remove (path);
320339 }
321340
322- if (optind > argc || (optind == argc && !rvfi && !do_print_dts)) {
341+ if (optind > argc
342+ || (optind == argc && !rvfi && !do_print_dts && !do_validate_config)) {
323343 fprintf (stderr, " No elf file provided.\n " );
324344 print_usage (argv[0 ], 0 );
325345 }
326346 if (dtb_file)
327347 read_dtb (dtb_file);
328348
329- if (!rvfi && !do_report_arch && !do_print_dts)
349+ if (!rvfi && !do_report_arch && !do_print_dts && !do_validate_config )
330350 fprintf (stdout, " Running file %s.\n " , argv[optind]);
331351 return optind;
332352}
@@ -430,9 +450,9 @@ void init_sail_reset_vector(uint64_t entry)
430450 zPC = rom_base;
431451}
432452
433- void init_sail (uint64_t elf_entry)
453+ void init_sail (uint64_t elf_entry, const char *config_file )
434454{
435- zinit_model (UNIT );
455+ zinit_model (config_file != nullptr ? config_file : " " );
436456 if (rvfi) {
437457 /*
438458 rv_ram_base = UINT64_C(0x80000000);
@@ -449,11 +469,11 @@ void init_sail(uint64_t elf_entry)
449469}
450470
451471/* reinitialize to clear state and memory, typically across tests runs */
452- void reinit_sail (uint64_t elf_entry)
472+ void reinit_sail (uint64_t elf_entry, const char *config_file )
453473{
454474 model_fini ();
455475 model_init ();
456- init_sail (elf_entry);
476+ init_sail (elf_entry, config_file );
457477}
458478
459479void write_signature (const char *file)
@@ -658,6 +678,9 @@ int main(int argc, char **argv)
658678 if (do_report_arch) {
659679 report_arch ();
660680 }
681+ if (do_validate_config) {
682+ validate_config (config_file);
683+ }
661684 if (do_print_dts) {
662685 print_dts ();
663686 }
@@ -684,7 +707,7 @@ int main(int argc, char **argv)
684707 (void )load_sail (argv[i], /* main_file=*/ false );
685708 }
686709
687- init_sail (entry);
710+ init_sail (entry, config_file );
688711
689712 if (gettimeofday (&init_end, NULL ) < 0 ) {
690713 fprintf (stderr, " Cannot gettimeofday: %s\n " , strerror (errno));
@@ -695,7 +718,7 @@ int main(int argc, char **argv)
695718 run_sail ();
696719 if (rvfi) {
697720 /* Reset for next test */
698- reinit_sail (entry);
721+ reinit_sail (entry, config_file );
699722 }
700723 } while (rvfi);
701724
0 commit comments