def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(ROOT, MFS_REGULAR_FILE, "test") inum = self.lookup(ROOT, "test") st = self.stat(ROOT) if st.type != MFS_DIRECTORY: raise Failure("Stat gave wrong type here") st = self.stat(inum) if st.size != 0: raise Failure("Stat gave wrong size") if st.type != MFS_REGULAR_FILE: raise Failure("Stat gave wrong type lolololo") buf1 = gen_block(1) self.write(inum, buf1, 0) st = self.stat(inum) if st.size != MFS_BLOCK_SIZE: raise Failure("Stat gave wrong size") if st.type != MFS_REGULAR_FILE: raise Failure("Stat gave wrong type") self.shutdown() self.server.wait() self.done()
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(0, MFS_REGULAR_FILE, "test") inum = self.lookup(ROOT, "test") buf = gen_block(1) self.write(inum, buf, 0) buf = gen_block(2) self.write(inum, buf, MAX_FILE_BLOCKS - 1) buf = gen_block(3) self.write(inum, buf, 0) buf = gen_block(4) self.write(inum, buf, MAX_FILE_BLOCKS - 1) st = self.stat(inum) if st.type != MFS_REGULAR_FILE: raise Failure("Stat gave wrong type") if st.size != MAX_FILE_BLOCKS * MFS_BLOCK_SIZE: raise Failure("Stat gave wrong size") self.shutdown() self.server.wait() self.done()
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(0, MFS_REGULAR_FILE, "test") inum = self.lookup(0, "test") buf = [gen_block(i) for i in range(MAX_FILE_BLOCKS + 1)] for i in range(MAX_FILE_BLOCKS): self.write(inum, buf[i], i) i = MAX_FILE_BLOCKS r = self.libmfs.MFS_Write(inum, byref(buf[i]), i) if r != -1: raise Failure("MFS_Write should fail on inalid block number") for i in range(MAX_FILE_BLOCKS): self.read_and_check(inum, i, buf[i]) i = MAX_FILE_BLOCKS r = self.libmfs.MFS_Read(inum, byref(buf[i]), i) if r != -1: raise Failure("MFS_Read should fail on inalid block number") self.shutdown() self.server.wait() self.done()
def run(self): image = "testimage" if os.path.exists(self.project_path + "/" + image): os.remove(self.project_path + "/" + image) self.loadlib() self.start_server(image) self.mfs_init("localhost", self.port) self.creat(ROOT, MFS_REGULAR_FILE, "test") inum = self.lookup(ROOT, "test") self.write(inum, gen_block(1), 0) if self.lookup(ROOT, "test") != inum: raise Failure("Wrong inum") self.read_and_check(inum, 0, gen_block(1)) self.shutdown() self.server.wait() #self.mfs_init("localhost", self.port) self.start_server(image, port=self.port) if self.lookup(ROOT, "test") != inum: raise Failure("Wrong inum") self.read_and_check(inum, 0, gen_block(1)) self.shutdown() self.server.wait() self.done()
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) inum = self.lookup(ROOT, ".") if inum != ROOT: raise Failure("'.' in root should point to root inode") inum = self.lookup(ROOT, "..") if inum != ROOT: raise Failure("'..' in root should point to root inode") self.shutdown() self.server.wait() self.done()
def run_server(self, threads, buffers, schedalg, n=None): minport = 5000 maxport = 10000 root = os.path.join(self.test_path, "files") for i in range(5): port = random.randint(minport, maxport) self.log("Starting server on port " + str(port)) args = ["server", str(port), str(threads), str(buffers), schedalg] if n is not None: args.append(str(n)) serverProc = self.startexe(args, cwd=root) time.sleep(0.2) # wait for server to respond serverProc.poll() if serverProc.returncode is None: conn = httplib.HTTPConnection("localhost", port, timeout=2) self.quiet_get(conn, "/home.html") try: response = conn.getresponse() response.read() except Exception: pass serverProc.poll() if serverProc.returncode is None: time.sleep(0.1) self.port = port self.serverProc = serverProc return serverProc try: serverProc.kill() except: pass raise Failure("Could not start server")
def check(self, mfs): mfs.log("checking " + self.fullpath() + "\n") for i in range(len(self.blocks)): if self.blocks[i] is not None: mfs.read_and_check(self.inum, i, gen_block(self.blocks[i])) st = mfs.stat(self.inum) if st.size != self.size(): raise Failure("Incorrect size for file " + self.fullpath())
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(ROOT, MFS_DIRECTORY, "testdir") inum = self.lookup(ROOT, "testdir") if self.lookup(inum, ".") != inum: raise Failure("'.' in directory should point to directory itself") if self.lookup(inum, "..") != ROOT: raise Failure("'..' in directory should point to parent") self.shutdown() self.server.wait() self.done()
def client_run(self, conn): try: response = conn.getresponse() msg = response.read() conn.close() if (len(msg) == 0): self.fail("missing body in response") except Exception as inst: self.fail("Client failed with error: " + str(inst)) raise Failure("Client failed with error: " + str(inst))
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) toolong = "A" * 60 r = self.libmfs.MFS_Creat(ROOT, MFS_REGULAR_FILE, toolong) if r != -1: raise Failure("Name argument too long did not result in failure") self.shutdown() self.server.wait() self.done()
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(ROOT, MFS_REGULAR_FILE, "testdir") inum = self.lookup(ROOT, "testdir") r = self.libmfs.MFS_Lookup(inum, "testfile") if r != -1: raise Failure("MFS_Lookup should fail if pinum is not a directory") self.shutdown() self.server.wait() self.done()
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(ROOT, MFS_DIRECTORY, "test") inum = self.lookup(ROOT, "test") self.unlink(ROOT, "test") inum = self.libmfs.MFS_Lookup(ROOT, "test") if inum != -1: raise Failure("MFS_Lookup should fail on an unlinked file") self.shutdown() self.server.wait() self.done()
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(ROOT, MFS_DIRECTORY, "testdir") inum = self.lookup(ROOT, "testdir") self.creat(inum, MFS_REGULAR_FILE, "testfile") self.lookup(inum, "testfile") r = self.libmfs.MFS_Unlink(ROOT, "testdir") if r != -1: raise Failure("MFS_Unlink should fail on non-empty dir") self.unlink(inum, "testfile") self.unlink(ROOT, "testdir") self.shutdown() self.server.wait() self.done()
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(ROOT, MFS_DIRECTORY, "testdir") inum = self.lookup(ROOT, "testdir") for i in range(MAX_FILES_PER_DIR): self.creat(inum, MFS_REGULAR_FILE, str(i)) i = MAX_FILES_PER_DIR r = self.libmfs.MFS_Creat(inum, MFS_REGULAR_FILE, str(i)) if r != -1: raise Failure("MFS_Creat should fail if directory is full") for i in range(MAX_FILES_PER_DIR): self.lookup(inum, str(i)) self.shutdown() self.server.wait() self.done()
def start_server(self, image=None, libs=None, port=None): if image is None: image = "testimage" if os.path.exists(self.project_path + "/" + image): os.remove(self.project_path + "/" + image) minport = 5000 maxport = 10000 for i in xrange(5): if port != None: self.port = port else: self.port = random.randint(minport, maxport) self.log("Starting server on port " + str(self.port)) self.server = self.startexe( ["server", str(self.port), image], libs=libs) time.sleep(0.2) if (self.server.poll() != None): self.server.kill() self.server = None else: return raise Failure("Could not start server")
def run(self): self.loadlib() self.start_server() self.mfs_init("localhost", self.port) self.creat(0, MFS_REGULAR_FILE, "test") inum = self.lookup(0, "test") buf1 = gen_block(1) self.write(inum, buf1, 0) buf2 = BlockBuffer() self.read(inum, buf2, 0) print buf1[:20], buf1[-20:] print buf2[:20], buf2[-20:] if not bufs_equal(buf1, buf2): raise Failure("Corrupt data returned by read") self.shutdown() self.server.wait() self.done()
def read_and_check(self, inum, block, expected): buf = BlockBuffer() self.read(inum, buf, block) if not bufs_equal(buf, expected): raise Failure("Corrupt data returned by read")
def creat(self, inum, type, name): r = self.libmfs.MFS_Creat(inum, type, name) if r != 0: raise Failure("MFS_Creat returned failure " + "inum=" + str(inum) + " type=" + str(type) + " name=" + repr(name)) return r
def check(self, mfs): for child in self.children.values(): child_inum = mfs.lookup(self.inum, child.name) if child_inum != child.inum: raise Failure("Incorrect inum for " + child.fullpath()) child.check(mfs)
def loadlib(self): self.libmfs = cdll.LoadLibrary(self.project_path + "/libmfs.so") for func in self.library_functions: if not hasattr(self.libmfs, func): raise Failure("libmfs should export fucntion '" + func + "'") return self.libmfs
def unlink(self, pinum, name): r = self.libmfs.MFS_Unlink(pinum, name) if r != 0: raise Failure("MFS_Unlink returned failure " + "pinum=" + str(pinum) + " name=" + repr(name)) return r
def write(self, inum, buf, block): r = self.libmfs.MFS_Write(inum, byref(buf), block) if r != 0: raise Failure("MFS_Write returned failure " + "inum=" + str(inum) + " block=" + str(block))
def mfs_init(self, hostname, port): r = self.libmfs.MFS_Init(hostname, port) if r != 0: raise Failure("MFS_Init returned failure") return r
def stat(self, inum): st = StatStruct() r = self.libmfs.MFS_Stat(inum, byref(st)) if r != 0: raise Failure("MFS_Stat returned failure inum=" + str(inum)) return st
def lookup(self, inum, name): r = self.libmfs.MFS_Lookup(inum, name) if r < 0: raise Failure("MFS_Lookup returned failure " + "inum=" + str(inum) + " name=" + repr(name)) return r
def shutdown(self): r = self.libmfs.MFS_Shutdown() if r != 0: raise Failure("MFS_Shutdown returned failure") return r