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

Fuzz collections for exception safety #18030

Closed
huonw opened this issue Oct 14, 2014 · 3 comments
Closed

Fuzz collections for exception safety #18030

huonw opened this issue Oct 14, 2014 · 3 comments
Labels
A-collections Area: `std::collections` A-testsuite Area: The testsuite used to check the correctness of rustc C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@huonw
Copy link
Member

huonw commented Oct 14, 2014

It's easy to accidentally write something that's unsafe in the presence of unwinding, which is a problem if arbitrary user code is being run. This occurs in many methods inside data structures, e.g. ordered maps do many comparisons, calling the user defined cmp method (which could unwind), and the Clone implementations will call clone on the contained data, which possibly unwinds.

It would be a nice assurance to have these tested (exhaustively, if possible), e.g. sort is tested like this: it creates a random vector, counts how many comparisons are required to sort it, and the tests that failing on any of those comparisons is correct (which it checks by seeing that the destructors are run exactly once). It would be nice to do this with comparison-based data structures and especially the clone implementations.

In the best case, we might have some sort of framework for this. E.g. a function like

fn run_failure_test<T: Clone + Send>(data: T, f: fn(T, g: ||))

f would be called repeatedly with different values of the closure g; the user calls that in the location that should fail. The first call of f will have g just counting how many calls, and later calls will have g failing after a certain number.

That is, the sort test above could be written something like:

fn test(mut v: Vec<DropCounter>, g: ||) {
    v.sort_by(|a, b| { g(); a.cmp(b) })
}
run_failure_test(main, test)

(I guess run_failure_test it might need to take "setup" and "check" closures too.)

@Gankra
Copy link
Contributor

Gankra commented Oct 14, 2014

CC me

@kmcallister kmcallister added the A-collections Area: `std::collections` label Jan 16, 2015
@steveklabnik
Copy link
Member

Triage: I'm not aware of any efforts to actually do this.

@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jul 22, 2017
@steveklabnik
Copy link
Member

Triage: this has become a topic lately, but this issue isn't really helping it actually happen. We'd welcome more testing of the standard library, but I don't think this issue is worth it. Closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collections` A-testsuite Area: The testsuite used to check the correctness of rustc C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants