Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harness Output in Individual Files #3356

Closed
Alexander-Aghili opened this issue Jul 18, 2024 · 5 comments · Fixed by #3360
Closed

Harness Output in Individual Files #3356

Alexander-Aghili opened this issue Jul 18, 2024 · 5 comments · Fixed by #3360
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature.

Comments

@Alexander-Aghili
Copy link
Contributor

Requested feature: Harness Output in Individual Files
Use case: Easily parse output by having each harness output be an a unique file.
Printing is done to the std output but having each harness output be in a file helps with parsing. Possibly files named based on harness name.
This is currently done in each harness here in kani-driver line 124:

if !self.args.common_args.quiet && self.args.output_format != OutputFormat::Old {
    println!(
        "{}",
        result.render(
            &self.args.output_format,
            harness.attributes.should_panic,
            self.args.coverage
        )
    );
}
@Alexander-Aghili Alexander-Aghili added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label Jul 18, 2024
@jaisnan
Copy link
Contributor

jaisnan commented Jul 18, 2024

Thank you for the feature request! This is a great idea for an improvement. Can you describe a little bit more about how this would be useful for a user in a project, if possible?

@Alexander-Aghili
Copy link
Contributor Author

Alexander-Aghili commented Jul 18, 2024

Hi @jaisnan, for a project our team is working on we wanted the capability to use Kani in a CD/CI capacity, and provide information about the run in a quick easy interface. Having to manually parse the single large output file seems more difficult than having the option of having individual harnesses output into files which can then be managed.

@Alexander-Aghili
Copy link
Contributor Author

I have a test version of what it could look like but I'm not sure if this is how you guys would want to do it:

           if !self.args.common_args.quiet && self.args.output_format != OutputFormat::Old {
                let file_name = String::from("./kani-harness-result/".to_owned() + &harness.pretty_name.clone()); 
                let path = Path::new(&file_name);
                let prefix = path.parent().unwrap();
                std::fs::create_dir_all(prefix).unwrap();

                let file = File::create(file_name.clone());

                let output = result.render(
                    &self.args.output_format,
                    harness.attributes.should_panic,
                    self.args.coverage,
                );

                if let Err(e) = writeln!(file.unwrap(), "{}", output) {
                    eprintln!("Failed to write to file {}: {}", file_name, e);
                }
                println!("{}", output);

            }

Basically it makes a directory structure based on the harness names and then puts the output of a harness into a single file based on its name.
I can make a pull request if you think that's appropriate. It doesn't have a flag to enable it but I assume adding that would be relatively simple.

@jaisnan
Copy link
Contributor

jaisnan commented Jul 18, 2024

Of course! We encourage and welcome external pull requests! Please feel free to add your changes as a PR.

@celinval
Copy link
Contributor

I really like this idea. In fact, I would suggest that this should be done whenever the terse output is selected (which I think should be the default one). In this case, Kani could print the verification summary and save detailed result in a file, like you mentioned.

One feedback for your potential patch is to use the target directory as the base directory of your new result directory.

github-merge-queue bot pushed a commit that referenced this issue Nov 5, 2024
Resolves #3356 

1. Changes allow for directory with individual output of files named by
the full harness name. --output-into-files command line argument will
allow for placing all output of individual harnesses into files named by
the full harness pretty_name. The output directory is either
--target-dir or a hard coded default: "kani_output" directory. (These
can be changed if there is a better interface). Still prints output to
std::out exactly as previous.
2. Previously, all output was placed into std::out. This will allow for
some control over output. It will also enable easier parsing of harness
output.
3. Only solved #3356 but could be expanded to include more features.
4. Ran manually to check the flags and output behaved as expected.
Indeed:
--output-into-files enabled will place output into individual files,
disabled will not
--output-terse will create terse output to command line, regular output
to individual files if --output-into-files is enabled.
--target-dir will place output into target-dir directory when
--output-into-files is enabled, and will not place file output when
disabled.

Let me know if you need specific explanations of code segments, a clean
list of all the testing configurations, or any feature enhancement for
greater configuration options.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.

---------

Co-authored-by: Alexander Aghili <Alexsky2@LEAHs-MacBook-Pro.local>
Co-authored-by: Jaisurya Nanduri <91620234+jaisnan@users.noreply.github.com>
Co-authored-by: Celina G. Val <celinval@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants