Skip to content

Commit

Permalink
Merge pull request #33 from distributed-system-analysis/exception_ass…
Browse files Browse the repository at this point in the history
…ert_cleanups

no naked asserts, remove dead or redundant code
  • Loading branch information
bengland2 authored Mar 14, 2022
2 parents e8d3224 + 3e96714 commit 500bb02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
28 changes: 7 additions & 21 deletions invoke_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
'''

import multiprocessing
import shutil
import os
import time

import smallfile
from smallfile import unittest_module, SMFRunException
from sync_files import touch
import os
import time


# this class launches multiple threads with SmallfileWorkload instances
Expand Down Expand Up @@ -60,22 +62,6 @@ def run(self):
# including multi-threaded test
# to run, just do "python invoke_process.py"

def deltree(dir_tree):
assert len(dir_tree) > 6
if not os.path.exists(dir_tree):
return
assert os.path.isdir(dir_tree)
for (dir, subdirs, files) in os.walk(dir_tree, topdown=False):
for f in files:
os.unlink(os.path.join(dir, f))
for d in subdirs:
os.rmdir(os.path.join(dir, d))
os.rmdir(dir_tree)


ok = 0


class Test(unittest_module.TestCase):

def setUp(self):
Expand All @@ -84,15 +70,15 @@ def setUp(self):
self.invok.verbose = True
self.invok.tid = 'regtest'
self.invok.start_log()
deltree(self.invok.src_dirs[0])
shutil.rmtree(self.invok.src_dirs[0], ignore_errors=True)
os.makedirs(self.invok.src_dirs[0], 0o644)

def test_multiproc_stonewall(self):
self.invok.log.info('starting stonewall test')
thread_ready_timeout = 4
thread_count = 4
for tree in self.invok.top_dirs:
deltree(tree)
shutil.rmtree(tree)
os.mkdir(tree)
for dir in self.invok.src_dirs:
os.mkdir(dir)
Expand Down Expand Up @@ -143,7 +129,7 @@ def test_multiproc_stonewall(self):
assert rtnd_invok.elapsed_time is not None
assert rtnd_invok.rq_final is not None
assert rtnd_invok.filenum_final is not None
if rtnd_invok.status != ok:
if rtnd_invok.status != rtnd_invok.OK:
raise SMFRunException('subprocess failure for %s invocation %s: '
% (str(t), str(rtnd_invok)))

Expand Down
3 changes: 2 additions & 1 deletion output_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def output_results(invoke_list, test_params):
# add up work that it did
# and determine time interval over which test ran

assert isinstance(invk, smallfile.SmallfileWorkload)
if not isinstance(invk, smallfile.SmallfileWorkload):
raise SMFResultException('invoke is of wrong type: %s' % str(invk))
if invk.status:
status = 'ERR: ' + os.strerror(invk.status)
else:
Expand Down
18 changes: 11 additions & 7 deletions smallfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class SMFResultException(Exception):
class SMFRunException(Exception):
pass

def myassert(bool_expr):
if (not bool_expr):
raise SMFRunException('assertion failed!')

# abort routine just cleans up threads

Expand Down Expand Up @@ -786,8 +789,9 @@ def end_test(self):
# during do_workload()
if self.test_ended():
return
assert self.end_time is None and self.rq_final is None and self.filenum_final is None

myassert(self.end_time is None and
self.rq_final is None and
self.filenum_final is None)
self.rq_final = self.rq
self.filenum_final = self.filenum
self.end_time = time.time()
Expand Down Expand Up @@ -968,11 +972,11 @@ def create_biggest_buf(self, contents_random):

# initialize to a single random byte
biggest_buf = bytearray([self.randstate.randrange(0, 255)])
assert len(biggest_buf) == 1
myassert(len(biggest_buf) == 1)
powerof2 = 1
powersum = 1
for j in range(0, self.biggest_buf_size_bits - 1):
assert len(biggest_buf) == powersum
myassert(len(biggest_buf) == powersum)
powerof2 *= 2
powersum += powerof2
# biggest_buf length is now 2^j - 1
Expand All @@ -987,8 +991,8 @@ def create_biggest_buf(self, contents_random):
# by just using different offset into biggest_buf

biggest_buf.extend(biggest_buf[0:self.buf_offset_range])
assert (len(biggest_buf) ==
self.biggest_buf_size + self.buf_offset_range)
myassert(
len(biggest_buf) == self.biggest_buf_size + self.buf_offset_range)
return biggest_buf

# allocate buffer of correct size with offset based on filenum, tid, etc.
Expand Down Expand Up @@ -1029,7 +1033,7 @@ def prepare_buf(self):
unique_offset = ((int(self.tid)+1) * self.filenum) % max_buffer_offset
except ValueError:
unique_offset = self.filenum % max_buffer_offset
assert total_space + unique_offset < len(self.biggest_buf)
myassert(total_space + unique_offset < len(self.biggest_buf))
#if self.verbose:
# self.log.debug('unique_offset: %d' % unique_offset)

Expand Down

0 comments on commit 500bb02

Please sign in to comment.