Beispiel #1
0
def run_basic_test(allocator_type):
  print('-- [%s] basic' % allocator_type)
  before_lsof_count = len(get_current_process_lsof().splitlines())

  q = sharedstructures.PriorityQueue(POOL_NAME_PREFIX + allocator_type, allocator_type)
  assert len(q) == 0

  q.push(b"v1");
  assert 1 == len(q)
  q.push(b"v3");
  assert 2 == len(q)
  q.push(b"v20");
  assert 3 == len(q)
  q.push(b"v2");
  assert 4 == len(q)

  assert b"v1" == q.pop()
  assert 3 == len(q)
  assert b"v2" == q.pop()
  assert 2 == len(q)
  assert b"v20" == q.pop()
  assert 1 == len(q)
  assert b"v3" == q.pop()
  assert 0 == len(q)
  try:
    q.pop()
    assert False
  except IndexError:
    pass

  del q  # this should unmap the shared memory pool and close the fd
  sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)

  # make sure we didn't leak an fd
  assert before_lsof_count == len(get_current_process_lsof().splitlines())
Beispiel #2
0
def main():
  try:
    sharedstructures.delete_pool(POOL_NAME)
    run_basic_test()
    print('all tests passed')
    return 0

  finally:
    sharedstructures.delete_pool(POOL_NAME)
Beispiel #3
0
def run_basic_test(allocator_type):
    print('-- [%s] basic' % allocator_type)
    before_lsof_count = len(get_current_process_lsof().splitlines())

    table = sharedstructures.PrefixTree(POOL_NAME_PREFIX + allocator_type,
                                        allocator_type)
    expected = {}

    def insert_both(e, t, k, v):
        t[k] = v
        e[k] = v

    def delete_both(e, t, k):
        del t[k]
        del e[k]

    verify_state(expected, table)
    insert_both(expected, table, b'key1', b'value1')
    verify_state(expected, table)
    insert_both(expected, table, b'key2', b'value2')
    verify_state(expected, table)
    insert_both(expected, table, b'key3', b'value3')
    verify_state(expected, table)

    assert [b'key2', b'key3'] == list(table.keys_from(b'key2'))
    assert [(b'key2', b'value2'),
            (b'key3', b'value3')] == list(table.items_from(b'key2'))

    assert [b'key3'] == list(table.keys_from(b'key3'))
    assert [(b'key3', b'value3')] == list(table.items_from(b'key3'))

    assert [] == list(table.keys_from(b'key4'))
    assert [] == list(table.items_from(b'key4'))

    delete_both(expected, table, b'key2')
    verify_state(expected, table)
    try:
        del table[b'key2']
        assert False, "del table[\'key2\'] did not raise KeyError"
    except KeyError:
        pass
    verify_state(expected, table)

    insert_both(expected, table, b'key1', b'value0')
    verify_state(expected, table)
    delete_both(expected, table, b'key1')
    verify_state(expected, table)
    delete_both(expected, table, b'key3')
    verify_state(expected, table)

    assert {} == expected

    del table  # this should unmap the shared memory pool and close the fd
    sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)

    # make sure we didn't leak an fd
    assert before_lsof_count == len(get_current_process_lsof().splitlines())
def main():
    try:
        sharedstructures.delete_pool('test-vector')
        run_basic_test()
        print('all tests passed')
        return 0

    finally:
        sharedstructures.delete_pool('test-vector')
def run_basic_test(allocator_type):
    print("-- [%s] basic" % allocator_type)
    before_lsof_count = len(get_current_process_lsof().splitlines())

    table = sharedstructures.HashTable(POOL_NAME_PREFIX + allocator_type,
                                       allocator_type)
    expected = {}

    def insert_both(e, t, k, v):
        t[k] = v
        e[k] = v

    def delete_both(e, t, k):
        del t[k]
        del e[k]

    verify_state(expected, table)
    insert_both(expected, table, b'key1', b'value1')
    verify_state(expected, table)
    insert_both(expected, table, b'key2', b'value2')
    verify_state(expected, table)
    insert_both(expected, table, b'key3', b'value3')
    verify_state(expected, table)

    delete_both(expected, table, b'key2')
    verify_state(expected, table)
    try:
        del table[b'key2']
        assert False, "del table[\'key2\'] did not raise KeyError"
    except KeyError:
        pass
    verify_state(expected, table)

    insert_both(expected, table, b'key1', b'value0')
    verify_state(expected, table)
    delete_both(expected, table, b'key1')
    verify_state(expected, table)
    delete_both(expected, table, b'key3')
    verify_state(expected, table)

    assert {} == expected

    del table  # this should unmap the shared memory pool and close the fd
    sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)

    # this will fail if the test prints anything after before_lsof is taken since
    # the stdout/stderr offsets will be different
    assert before_lsof_count == len(get_current_process_lsof().splitlines())
Beispiel #6
0
def main():
    try:
        for allocator_type in ('simple', 'logarithmic'):
            sharedstructures.delete_pool('test-table')
            run_basic_test(allocator_type)
            run_conditional_writes_test(allocator_type)
            run_reorganization_test(allocator_type)
            run_types_test(allocator_type)
            run_complex_types_test(allocator_type)
            run_incr_test(allocator_type)
            run_concurrent_readers_test(allocator_type)
        print('all tests passed')
        return 0

    finally:
        sharedstructures.delete_pool('test-table')
Beispiel #7
0
def main():
    try:
        for allocator_type in ALLOCATOR_TYPES:
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_basic_test(allocator_type)
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_raw_test(allocator_type)
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_concurrent_producers_test(allocator_type)
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_concurrent_consumers_test(allocator_type)
        print('all tests passed')
        return 0

    finally:
        for allocator_type in ALLOCATOR_TYPES:
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
Beispiel #8
0
def main():
    try:
        for allocator_type in ALLOCATOR_TYPES:
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_basic_test(allocator_type)
            run_conditional_writes_test(allocator_type)
            run_reorganization_test(allocator_type)
            run_types_test(allocator_type)
            run_complex_types_test(allocator_type)
            run_incr_test(allocator_type)
            run_concurrent_readers_test(allocator_type)
        print('all tests passed')
        return 0

    finally:
        for allocator_type in ALLOCATOR_TYPES:
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
def main():
  try:
    for allocator_type in ('simple', 'logarithmic'):
      sharedstructures.delete_pool('test-table')
      run_basic_test(allocator_type)
      sharedstructures.delete_pool('test-table')
      run_conditional_writes_test(allocator_type)
      sharedstructures.delete_pool('test-table')
      run_collision_test(allocator_type)
      # TODO: enable this test again when the python module supports incr
      # sharedstructures.delete_pool('test-table')
      # run_incr_test(allocator_type)
      sharedstructures.delete_pool('test-table')
      run_concurrent_readers_test(allocator_type)
    print('all tests passed')
    return 0

  finally:
    sharedstructures.delete_pool('test-table')
def main():
    try:
        for allocator_type in ALLOCATOR_TYPES:
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_basic_test(allocator_type)
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_conditional_writes_test(allocator_type)
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_collision_test(allocator_type)
            # TODO: enable this test again when the python module supports incr
            # sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            # run_incr_test(allocator_type)
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
            run_concurrent_readers_test(allocator_type)
        print('all tests passed')
        return 0

    finally:
        for allocator_type in ALLOCATOR_TYPES:
            sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)
Beispiel #11
0
def run_basic_test():
  print('-- basic')
  before_lsof_count = len(get_current_process_lsof().splitlines())

  v = sharedstructures.IntVector(POOL_NAME)

  limit = 1024

  assert len(v) == 0
  v.expand(10)
  assert len(v) == 10
  v.expand(5)
  assert len(v) == 10
  v.expand(limit)
  assert len(v) == limit

  # load, store
  for x in range(limit):
    assert v.load(x) == 0
  for x in range(limit):
    v.store(x, x)
  for x in range(limit):
    assert v.load(x) == x

  # exchange
  for x in range(limit):
    assert v.exchange(x, x + 10) == x
  for x in range(limit):
    assert v.load(x) == x + 10
  for x in range(limit):
    assert v.exchange(x, x) == x + 10
  for x in range(limit):
    assert v.load(x) == x

  # compare_exchange
  for x in range(limit):
    assert v.compare_exchange(x, 10, 15) == x
  for x in range(limit):
    assert v.load(x) == (15 if (x == 10) else x)
  v.store(10, 10)

  # add, subtract
  for x in range(limit):
    assert v.add(x, 30) == x
  for x in range(limit):
    assert v.load(x) == x + 30
  for x in range(limit):
    assert v.subtract(x, 30) == x + 30
  for x in range(limit):
    assert v.load(x) == x

  # bitwise_and, bitwise_or
  for x in range(limit):
    assert v.bitwise_or(x, 0x7F) == x
  for x in range(limit):
    assert v.load(x) == x | 0x7F
  for x in range(limit):
    assert v.bitwise_and(x, ~0x7F) == x | 0x7F
  for x in range(limit):
    assert v.load(x) == x & ~0x7F

  # reset for xor test
  for x in range(limit):
    v.store(x, x)

  # bitwise_xor
  for x in range(limit):
    assert v.bitwise_xor(x, 0x7F) == x
  for x in range(limit):
    assert v.load(x) == x ^ 0x7F
  for x in range(limit):
    assert v.bitwise_xor(x, 0x7F) == x ^ 0x7F
  for x in range(limit):
    assert v.load(x) == x

  del v  # this should unmap the shared memory pool and close the fd
  sharedstructures.delete_pool(POOL_NAME)

  # make sure we didn't leak an fd
  assert before_lsof_count == len(get_current_process_lsof().splitlines())
Beispiel #12
0
def run_basic_test(allocator_type):
    print('-- [%s] basic' % allocator_type)
    before_lsof_count = len(get_current_process_lsof().splitlines())

    q = sharedstructures.Queue(POOL_NAME_PREFIX + allocator_type,
                               allocator_type)
    assert len(q) == 0
    assert q.bytes() == 0

    def test_queue(q, reverse):
        print('-- [%s]   %s queue operation' %
              (allocator_type, "reverse" if reverse else "forward"))

        q_push(q, reverse, b"v1")
        assert 1 == len(q)
        q_push(q, reverse, "val2")
        assert 2 == len(q)
        q_push(q, reverse, 47)
        assert 3 == len(q)
        q_push(q, reverse, None)
        assert 4 == len(q)
        q_push(q, reverse, (None, False, True, 37, 2.0, ['lol', 'hax'], {
            1: 2
        }))
        assert 5 == len(q)

        assert b"v1" == q_pop(q, not reverse)
        assert 4 == len(q)
        assert "val2" == q_pop(q, not reverse)
        assert 3 == len(q)
        assert 47 == q_pop(q, not reverse)
        assert 2 == len(q)
        assert None == q_pop(q, not reverse)
        assert 1 == len(q)
        assert (None, False, True, 37, 2.0, ['lol', 'hax'], {
            1: 2
        }) == q_pop(q, not reverse)
        assert 0 == len(q)
        assert q.bytes() == 0
        try:
            q_pop(q, not reverse)
            assert False
        except IndexError:
            pass

    test_queue(q, False)
    test_queue(q, True)

    def test_stack(q, front):
        print("-- [%s]   %s stack operation" %
              (allocator_type, "front" if front else "back"))

        q_push(q, front, b"v1")
        assert 1 == len(q)
        q_push(q, front, "val2")
        assert 2 == len(q)
        q_push(q, front, 47)
        assert 3 == len(q)
        q_push(q, front, None)
        assert 4 == len(q)
        q_push(q, front, (None, False, True, 37, 2.0, ['lol', 'hax'], {1: 2}))
        assert 5 == len(q)

        assert (None, False, True, 37, 2.0, ['lol', 'hax'], {
            1: 2
        }) == q_pop(q, front)
        assert 4 == len(q)
        assert None == q_pop(q, front)
        assert 3 == len(q)
        assert 47 == q_pop(q, front)
        assert 2 == len(q)
        assert "val2" == q_pop(q, front)
        assert 1 == len(q)
        assert b"v1" == q_pop(q, front)
        assert 0 == len(q)
        assert q.bytes() == 0
        try:
            q_pop(q, front)
            assert False
        except IndexError:
            pass

    test_stack(q, False)
    test_stack(q, True)

    del q  # this should unmap the shared memory pool and close the fd
    sharedstructures.delete_pool(POOL_NAME_PREFIX + allocator_type)

    # make sure we didn't leak an fd
    assert before_lsof_count == len(get_current_process_lsof().splitlines())