-
Notifications
You must be signed in to change notification settings - Fork 91
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
Double open write, write/truncate/flush #302
Comments
Hm, wouldn't have expected this, this buffering stuff is tricky. For today I'm done, maybe will tackle this tomorrow . |
Yeah, I found the OS behavior weird and pyfakefs totally reasonable, but this stuff is obviously tricky. Is this all coming from POSIX, or what, the buffering "rules"? |
I don't think that POSIX defines the specific buffering behavior, other than the fact that there is a buffering layer. This is up to the OS and/or Python. I haven't checked, but from what I have seen in the Python code, it pretty much relies on standard OS behavior. Anyway, we better implement the weird behavior in |
@agroce : I started trying to fix this issue and found at least one existing test not matching reality, so I started rewriting some of the tests to run both on |
PS, I'm using pyfakefs as a case study in a journal paper for December; I'm running the test harness on code mutants of fake_filessytem.py. Right now, we cover about 50% of the code with the harness that includes just os.open (vs. "Python" open), and of the mutants of that code, kill 64% reliably within 60 seconds. I'm investigating the mutants that are covered but not killed; many will simply be equivalent (reversing a list whose order doesn't matter) but some may show me some weakness in the test harness. I'll ping you once I am further along in this. |
Sounds good! Didn't know that you are also into mutation testing, but could have guessed... Never had to do with that - it still sounds a little alien to me, but the concept is interesting. |
@agroce, just this morning I was promoting TSTL at my company. Please make sure I a copy of your paper. |
@jmcgeheeiv -- Thanks! Will make sure to send you guys a copy once there's a draft, which might be a while (December deadline so other things in advance). It's a paper extending to testing the work in http://www.cs.cmu.edu/~agroce/ase15.pdf (which was on formal verification/bounded correctness proofs). By the way, does it sound plausible that, right now when os.open and Python open can't be combined:
|
They can't be combined because of too many errors there?
I'm not sure I understand that. You have 2 versions of the harness, one for |
Oh, and I just had a quick look at the paper you mentioned - I think I will check it out in the evening, this may answer some of my questions... |
Alas, it won't really answer them that well. I'll expand on my sort of cryptic question. What I'm mutating is the file fake_filesystem.py. I used muupi (https://github.com/apepkuss/muupi -- code by a former MS student of mine) to generate 800 or so variants, all of which are fake_filesystem.py + some small change. See https://github.com/agroce/cbmcmutate/tree/master/journal/pyfakefs_mutants for the files. Probably some of these don't change semantics in a way that should be detected (e.g. they just reverse a list whose order is irrelevant). Many do something harmful. I'm trying to see which ones the TSTL harness can detect within 60 seconds, fairly reliably. There is basically just one test harness, fakeosmodule.tstl (you can see the version I'm using here: https://github.com/agroce/cbmcmutate/blob/master/journal/fakeosmodule.tstl) but I can run it either:
So I only get one kind of file open in any test. The first version of the test harness seems to catch most (so far, all) of the mutants (changes to fake_filesystem.py) that I can detect. Which is about 64% of the ones whose code it even covers at all. Switching to using "Python open" so far adds no new problems detected, but it has a ways to go to check all the mutants. |
Ah, ok, that clarifies it a bit! I'm a little surprised that |
Yes, unfortunately. In some language an optimizing compiler can detect some, but in Python it's manual work. This paper is partly about some ways of (maybe) making that a little less painful, if you're really interested in getting solid testing. |
Ah ok, that sounds interesting! |
Basic idea is to use TSTL (or another tool) to generate a single test that:
The hope is that figuring out why that test passes (when the mutated code presumably interacts with as much as possible) might help. |
Nice - that means bringing together random testing and mutation testing, so that one verifies the other. |
In the end, mutation testing is only useful when you combine it with something else (which is why mutation testing maybe wasn't the best name choice...) I've got a file listing all the mutations of fake_filesystem.py that I covered, but didn't detect. Some categories of missed mutants seem obvious:
Did we decide not to test st_mode for some reason? It's commented out. Throwing out mutants that aren't killed, whose diff contains anything in: ["st_atime","st_ctime","st_mtime","ChangeDiskUsage","epoch","st_nlink","reversed"]
|
Adding case sensitivity seems to break things. Sending bug report. I'm on latest OS X, so both it and the fake file system (due to the platform check in init) should be non case sensitive. |
Added a couple of bugs (or at least look like bugs) based on the mutant results. Symlink, no surprise. Should we be fine with ignoring:
if there are any of these that should break things if changed, or we should test, let me know |
You can look at the github mutants directory, file interestingMutants.txt to see some not killed mutants. Diff is with respect to original.py which isn't quite your current version. |
Shall be fixed (see #255)
Mostly, I think. Incorrect I probably will have a look at your results sometime later this week - thanks for the information! |
Great. Just checked, and st_mode still mismatches on OS X, so I'll also consider that safe to ignore. Just submitted another case sensitivity related bug, discovered via the unkilled mutants telling me we weren't checking that code. |
The st_mode stuff still seems to have some bugs - I will check this some time later. |
import pyfakefs.fake_filesystem
import os
fs = pyfakefs.fake_filesystem.FakeFilesystem()
fs.CreateDirectory('/Volumes')
fs.CreateDirectory('/Volumes/ramdisk')
fs.CreateDirectory('/Volumes/ramdisk/test')
os0 = pyfakefs.fake_filesystem.FakeOsModule(fs)
opener0 = pyfakefs.fake_filesystem.FakeFileOpen(fs)
component0 = "alpha"
path0 = "/Volumes/ramdisk/test"
path0 += "/" + component0
str0 = ""
str0 += 'a'
str0 += 'a'
str0 += 'a'
str0 += 'a'
str0 += 'a'
str0 += 'a'
file0 = opener0(path0,'w')
file1 = opener0(path0,'w')
file0.write(str0)
file0.truncate()
file1.flush()
result = os0.path.getsize(path0)
print result
pyfakefs 0
OS 6
The text was updated successfully, but these errors were encountered: