Beispiel #1
0
def sqlite_reader(request):
    write_sqlite3()

    def _():
        os.remove(SQLITE_FILENAME)

    request.addfinalizer(_)

    samples_config = sqlite_format.SamplesConfig(table_name='traces',
                                                 pk_column_name='trace_id',
                                                 dtype='uint8',
                                                 samples_column_name='samples')
    metadata_config = sqlite_format.MetadataConfig(table_name='traces',
                                                   pk_column_name='trace_id',
                                                   metadata_defs={
                                                       'plaintext': 'uint8',
                                                       'plain_t': 'uint8',
                                                       'ciphertext': 'uint8',
                                                       'indices': 'U2',
                                                   })
    headers_config = sqlite_format.HeadersConfig(table_name='headers',
                                                 tag_column_name='tag',
                                                 value_column_name='value',
                                                 dtype_column_name='dtype')
    return sqlite_format.SQLiteFormatReader(filename=SQLITE_FILENAME,
                                            samples_config=samples_config,
                                            metadata_config=metadata_config,
                                            headers_config=headers_config)
Beispiel #2
0
def test_ths_without_headers(filename):
    ths = estraces.read_ths_from_sqlite(
        filename,
        samples_config=sqlite_format.SamplesConfig(),
        metadata_config=sqlite_format.MetadataConfig(metadata_defs={'plaintext': 'uint8'})
    )
    assert isinstance(ths, estraces.TraceHeaderSet)
    assert len(ths) == 10
    assert [] == list(ths.headers.keys())
    assert not ths._reader.fetch_header('tag')
Beispiel #3
0
def test_samples_shape_is_not_too_slow(lots_of_traces):

    ths = estraces.read_ths_from_sqlite(
        lots_of_traces,
        samples_config=sqlite_format.SamplesConfig(),
        metadata_config=sqlite_format.MetadataConfig(metadata_defs={'plaintext': 'uint8'})
    )
    assert isinstance(ths, estraces.TraceHeaderSet)
    stm = 's_ths.samples.shape'
    s_ths = ths[:100]
    t1 = timeit.timeit(stm, globals={'s_ths': s_ths}, number=10)
    s_ths = ths[:10]
    t2 = timeit.timeit(stm, globals={'s_ths': s_ths}, number=10)
    assert t1 / t2 < 10
Beispiel #4
0
def test_raises_exception_with_wrong_header_config(filename):
    samples_config = sqlite_format.SamplesConfig(table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples')
    metadata_config = sqlite_format.MetadataConfig()
    headers_config = sqlite_format.HeadersConfig(table_name='headers', tag_column_name='tags', value_column_name='value', dtype_column_name='dtype')

    ths = estraces.read_ths_from_sqlite(
        filename,
        samples_config=samples_config,
        metadata_config=metadata_config,
        headers_config=headers_config
    )
    with pytest.raises(sqlite_format.SQLiteError):
        ths.headers['key']

    with pytest.raises(sqlite_format.SQLiteError):
        ths._reader.fetch_header('key')
Beispiel #5
0
def test_raises_exception_configuring_non_existing_samples_col(filename):
    samples_config = sqlite_format.SamplesConfig(
        table_name='traces',
        pk_column_name='trace_id',
        dtype='uint8',
        samples_column_name='sampless'
    )
    metadata_config = sqlite_format.MetadataConfig()
    headers_config = sqlite_format.HeadersConfig()

    ths = estraces.read_ths_from_sqlite(
        filename,
        samples_config=samples_config,
        metadata_config=metadata_config,
        headers_config=headers_config
    )
    with pytest.raises(sqlite_format.SQLiteError):
        ths[0].samples[:]
    with pytest.raises(sqlite_format.SQLiteError):
        ths.samples[:]
    with pytest.raises(sqlite_format.SQLiteError):
        ths._reader.get_trace_size(0)

    samples_config = sqlite_format.SamplesConfig(
        table_name='tracess',
        pk_column_name='trace_id',
        dtype='uint8',
        samples_column_name='samples'
    )

    ths = estraces.read_ths_from_sqlite(
        filename,
        samples_config=samples_config,
        metadata_config=metadata_config,
        headers_config=headers_config
    )
    with pytest.raises(sqlite_format.SQLiteError):
        ths[0].samples[:]
    with pytest.raises(sqlite_format.SQLiteError):
        ths.samples[:]
    with pytest.raises(sqlite_format.SQLiteError):
        ths._reader.get_trace_size(0)
Beispiel #6
0
def test_raises_exception_fetching_non_existing_header(filename):
    samples_config = sqlite_format.SamplesConfig(table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples')
    metadata_config = sqlite_format.MetadataConfig(
        table_name='traces',
        pk_column_name='trace_id',
        metadata_defs={
            'plaintext': 'uint8',
            'ciphertext': 'uint8',
        }
    )
    headers_config = sqlite_format.HeadersConfig(table_name='headers', tag_column_name='tag', value_column_name='value', dtype_column_name='dtype')

    ths = estraces.read_ths_from_sqlite(
        filename,
        samples_config=samples_config,
        metadata_config=metadata_config,
        headers_config=headers_config
    )
    with pytest.raises(KeyError):
        ths.headers['woop']
Beispiel #7
0
def test_raises_exception_configuring_non_existing_metadata(filename):
    samples_config = sqlite_format.SamplesConfig(table_name='traces', pk_column_name='trace_id', dtype='uint8', samples_column_name='samples')
    metadata_config = sqlite_format.MetadataConfig(
        table_name='traces',
        pk_column_name='trace_id',
        metadata_defs={
            'plaintext': 'uint8',
            'ciphertext': 'uint8',
            'woop': 'uint8'
        }
    )
    headers_config = sqlite_format.HeadersConfig()

    ths = estraces.read_ths_from_sqlite(
        filename,
        samples_config=samples_config,
        metadata_config=metadata_config,
        headers_config=headers_config
    )
    with pytest.raises(sqlite_format.SQLiteError):
        ths[0].metadatas['woop']
    with pytest.raises(sqlite_format.SQLiteError):
        ths.metadatas['woop']