zeek/testing/btest/core/file-caching-cloning.test
Johanna Amann 74bb7716f6 Finish implementation of copy method.
All types (besides EntropyVal) now support a native copy operation,
which uses primitives of the underlying datatypes to perform a quick
copy, without serialization.

EntropyVal is the one exception - since that type is rather complex
(many members) and will probably not be copied a lot, if at all, it
makes sense to just use the serialization function.

This will have to be slightly re-written in the near-term-future to use
the new serialization function for that opaque type.

This change also introduces a new x509_from_der bif, which allows to
parse a der into an opaque of x509.

This change removes the d2i_X509_ wrapper function; this was a remnant
when d2i_X509 took non-const arguments. We directly use d2i_X509 at
several places assuming const-ness, so there does not seem to ba a
reason to keep the wrapper.

This change also exposed a problem in the File cache - cases in which an
object was brought back into the cache, and writing occurred in the
file_open event were never correctly handeled as far as I can tell.
2019-05-22 14:29:37 -07:00

49 lines
1.3 KiB
Text

# This checks that the interactions between open-file caching and
# cloning works ok. In the first case, all files can fit
# in the cache, but get cloned before every write. In the
# second case, files are eventually forced out of the cache; later writing
# requires re-opening.
# @TEST-EXEC: zeek -b %INPUT "test_file_prefix=one"
# @TEST-EXEC: btest-diff one0
# @TEST-EXEC: btest-diff one1
# @TEST-EXEC: btest-diff one2
# @TEST-EXEC: zeek -b %INPUT "test_file_prefix=two" "max_files_in_cache=2"
# @TEST-EXEC: btest-diff two0
# @TEST-EXEC: btest-diff two1
# @TEST-EXEC: btest-diff two2
const test_file_prefix = "" &redef;
global file_table: table[string] of file;
global iterations: vector of count = vector(0,1,2,3,4,5,6,7,8);
function write_to_file(c: count)
{
local f: file;
# Take turns writing across three output files.
local filename = fmt("%s%s", test_file_prefix, c % 3 );
if ( filename in file_table )
f = file_table[filename];
else
{
f = open(filename);
file_table[filename] = f;
}
# This when block is a trick to get the frame cloned
# and thus serialize the local file value
when ( local s = fmt("write %d", c) )
print f, s;
}
event file_opened(f: file)
{
print f, "opened";
}
event zeek_init()
{
for ( i in iterations )
write_to_file(iterations[i]);
}