remove native 'snprintf' calls, improve test coverage
- Replace all native 'snprintf' calls with 'Genode::String'. - Fix ram quotas and libc configs in effected run scripts. - Verify bit-perfect output of lz_rom test with rom_verify. Fix #72
This commit is contained in:
committed by
Norman Feske
parent
78046dfd66
commit
a44aa90660
@@ -63,9 +63,8 @@ set config {
|
||||
<binary name="test-libc"/>
|
||||
<resource name="RAM" quantum="4M"/>
|
||||
<config>
|
||||
<libc stdout="/log">
|
||||
<vfs> <fs/> </vfs>
|
||||
</libc>
|
||||
<libc stdout="/log"/>
|
||||
<vfs> <fs/> </vfs>
|
||||
</config>
|
||||
<route>
|
||||
<any-service>
|
||||
@@ -78,9 +77,8 @@ set config {
|
||||
<binary name="test-libc"/>
|
||||
<resource name="RAM" quantum="4M"/>
|
||||
<config>
|
||||
<libc stdout="/log">
|
||||
<vfs> <fs/> </vfs>
|
||||
</libc>
|
||||
<libc stdout="/log"/>
|
||||
<vfs> <fs/> </vfs>
|
||||
</config>
|
||||
<route>
|
||||
<any-service>
|
||||
@@ -93,9 +91,8 @@ set config {
|
||||
<binary name="test-libc"/>
|
||||
<resource name="RAM" quantum="4M"/>
|
||||
<config>
|
||||
<libc stdout="/log">
|
||||
<vfs> <fs/> </vfs>
|
||||
</libc>
|
||||
<libc stdout="/log"/>
|
||||
<vfs> <fs/> </vfs>
|
||||
</config>
|
||||
<route>
|
||||
<any-service>
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
build "core init server/log_tee test/printf"
|
||||
build "core init server/log_tee test/log"
|
||||
|
||||
create_boot_directory
|
||||
|
||||
install_config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RAM"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> </any-service>
|
||||
@@ -17,7 +21,7 @@ install_config {
|
||||
<provides> <service name="LOG"/> </provides>
|
||||
</start>
|
||||
|
||||
<start name="test-printf">
|
||||
<start name="test-log">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<route>
|
||||
<any-service> <child name="log_tee"/> <parent/> </any-service>
|
||||
@@ -26,8 +30,8 @@ install_config {
|
||||
</config>
|
||||
}
|
||||
|
||||
build_boot_image "core ld.lib.so init log_tee test-printf"
|
||||
build_boot_image "core ld.lib.so init log_tee test-log"
|
||||
|
||||
append qemu_args "-nographic -m 64"
|
||||
|
||||
run_genode_until {child "test-printf" exited with exit value 0} 10
|
||||
run_genode_until {\[test-log\] Test done.} 10
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
set sha256sum [check_installed sha256sum]
|
||||
|
||||
build {
|
||||
core init
|
||||
drivers/timer
|
||||
lib/libc_noux
|
||||
noux-pkg/coreutils
|
||||
noux/minimal
|
||||
proxy/rom_verify
|
||||
server/log_terminal
|
||||
server/lz_rom
|
||||
}
|
||||
@@ -12,9 +15,12 @@ build {
|
||||
exec sh -c "[cross_dev_prefix]strip bin/coreutils/bin/*"
|
||||
exec tar cfv bin/coreutils.tar -h -C bin/coreutils .
|
||||
|
||||
# get the hash of the tarball to check against after decompression
|
||||
set tar_digest [lindex [exec $sha256sum bin/coreutils.tar] 0]
|
||||
|
||||
create_boot_directory
|
||||
|
||||
install_config {
|
||||
append config {
|
||||
<config verbose="yes">
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
@@ -47,6 +53,19 @@ install_config {
|
||||
<libc/>
|
||||
</config>
|
||||
</start>
|
||||
<start name="rom_verify">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides> <service name="ROM"/> </provides>
|
||||
<config>}
|
||||
append config "<policy label_suffix=\"coreutils.tar\" sha256=\"$tar_digest\"/>"
|
||||
append config {
|
||||
</config>
|
||||
<route>
|
||||
<service name="ROM" label_suffix="coreutils.tar">
|
||||
<child name="lz_rom"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="noux">
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<config verbose="yes">
|
||||
@@ -55,7 +74,7 @@ install_config {
|
||||
</config>
|
||||
<route>
|
||||
<service name="ROM" label="coreutils.tar">
|
||||
<child name="lz_rom"/> </service>
|
||||
<child name="rom_verify"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
|
||||
@@ -63,6 +82,8 @@ install_config {
|
||||
</config>
|
||||
}
|
||||
|
||||
install_config $config
|
||||
|
||||
# Lzip the coreutils tarball
|
||||
exec lzip --force --keep bin/coreutils.tar
|
||||
|
||||
@@ -78,6 +99,8 @@ build_boot_image {
|
||||
log_terminal
|
||||
lz_rom
|
||||
noux
|
||||
rom_verify
|
||||
stdcxx.lib.so
|
||||
timer
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +63,8 @@ append config {
|
||||
<start name="test-libc">
|
||||
<resource name="RAM" quantum="8M"/>
|
||||
<config>
|
||||
<libc stdout="/log" stderr="log">
|
||||
<vfs> <log/> </vfs>
|
||||
</libc>
|
||||
<libc stdout="/log" stderr="log"/>
|
||||
<vfs> <log/> </vfs>
|
||||
</config>
|
||||
</start>
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ create_boot_directory
|
||||
set sha256sum [check_installed sha256sum]
|
||||
|
||||
|
||||
set rom_file bin/test-log
|
||||
set test_digest [exec $sha256sum $rom_file]
|
||||
set ld_digest [lindex [exec $sha256sum bin/ld-linux.lib.so] 0]
|
||||
set test_digest [lindex [exec $sha256sum bin/test-log] 0]
|
||||
|
||||
append config {
|
||||
<config>
|
||||
@@ -35,36 +35,21 @@ append config {
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</default-route>
|
||||
<start name="rom_verify">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides> <service name="ROM"/> </provides>
|
||||
<config>}
|
||||
append config "<policy label=\"init -> test-log\" sha256=\"$test_digest\"/>"
|
||||
append config "<policy label=\"ld.lib.so\" sha256=\"$ld_digest\"/>"
|
||||
append config "<policy label=\"test-log\" sha256=\"$test_digest\"/>"
|
||||
append config {
|
||||
</config>
|
||||
</start>
|
||||
<start name="init" verbose="yes">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<start name="test-log">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<route>
|
||||
<service name="ROM" label_suffix="test-log">
|
||||
<service name="ROM">
|
||||
<child name="rom_verify"/> </service>
|
||||
<any-service>
|
||||
<parent/>
|
||||
</any-service>
|
||||
<any-service> <parent/> </any-service>
|
||||
</route>
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RAM"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<start name="test-log">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<route> <any-service> <parent/> </any-service> </route>
|
||||
</start>
|
||||
</config>
|
||||
</start>
|
||||
</config>
|
||||
}
|
||||
|
||||
@@ -215,11 +215,10 @@ void Rom_hash::Main::handle_session_request(Xml_node request)
|
||||
server_id_space.apply<Session>(server_id, [&] (Session &session) {
|
||||
Genode::size_t ram_quota = request.attribute_value("ram_quota", 0UL);
|
||||
|
||||
char buf[64];
|
||||
Genode::snprintf(buf, sizeof(buf), "ram_quota=%ld", ram_quota);
|
||||
String<64> args("ram_quota=", ram_quota);
|
||||
|
||||
// XXX handle Root::Invalid_args
|
||||
env.upgrade(session.client_id.id(), buf);
|
||||
env.upgrade(session.client_id.id(), args.string());
|
||||
env.parent().session_response(server_id, Parent::SESSION_OK);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -243,11 +243,10 @@ void Chroot::Main::handle_session_request(Xml_node request)
|
||||
|
||||
size_t ram_quota = request.attribute_value("ram_quota", 0UL);
|
||||
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "ram_quota=%ld", ram_quota);
|
||||
String<64> args("ram_quota=", ram_quota);
|
||||
|
||||
// XXX handle Root::Invalid_args
|
||||
env.upgrade(session.client_id.id(), buf);
|
||||
env.upgrade(session.client_id.id(), args.string());
|
||||
env.parent().session_response(server_id, Parent::SESSION_OK);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <base/session_label.h>
|
||||
#include <base/heap.h>
|
||||
#include <base/log.h>
|
||||
#include <base/snprintf.h>
|
||||
#include <util/list.h>
|
||||
|
||||
namespace Log_tee {
|
||||
@@ -44,13 +43,12 @@ class Log_tee::Session_component : public Rpc_object<Log_session>
|
||||
{ }
|
||||
} _log;
|
||||
|
||||
char _prefix[Session_label::capacity()+3];
|
||||
Genode::String<Session_label::capacity()+3> _prefix;
|
||||
|
||||
public:
|
||||
|
||||
Session_component(Env &env, Session_label const &label, char const *args)
|
||||
: _log(env, args)
|
||||
{ snprintf(_prefix, sizeof(_prefix), "[%s] ", label.string()); }
|
||||
: _log(env, args), _prefix("[", label.string(), "] ") { }
|
||||
|
||||
size_t write(Log_session::String const &msg) override
|
||||
{
|
||||
@@ -58,7 +56,7 @@ class Log_tee::Session_component : public Rpc_object<Log_session>
|
||||
size_t n = _log.write(msg);
|
||||
|
||||
/* write to our own log session */
|
||||
log(Cstring(_prefix), msg.string());
|
||||
log(_prefix, msg.string());
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -36,13 +36,15 @@ using namespace Genode;
|
||||
namespace Lz_rom {
|
||||
using namespace Genode;
|
||||
|
||||
typedef Session_state::Args Args;
|
||||
typedef String<Session_label::capacity()> Lz_path;
|
||||
|
||||
struct Session;
|
||||
struct Main;
|
||||
|
||||
typedef Session_state::Args Args;
|
||||
|
||||
struct File_error { };
|
||||
struct Decompression_error { };
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +59,7 @@ struct Lz_rom::Session :
|
||||
Session(Id_space<Parent::Server> &server_space,
|
||||
Parent::Server::Id server_id,
|
||||
Libc::Env &env, Genode::Allocator &alloc,
|
||||
Session_label const &label,
|
||||
Lz_path const &path,
|
||||
LZ_Decoder *decoder);
|
||||
|
||||
Attached_ram_dataspace ram_ds;
|
||||
@@ -79,7 +81,7 @@ struct Lz_rom::Session :
|
||||
Lz_rom::Session::Session(Id_space<Parent::Server> &server_space,
|
||||
Parent::Server::Id server_id,
|
||||
Libc::Env &env, Genode::Allocator &alloc,
|
||||
Session_label const &label,
|
||||
Lz_path const &path,
|
||||
LZ_Decoder *decoder)
|
||||
:
|
||||
server_id(*this, server_space, server_id),
|
||||
@@ -92,7 +94,7 @@ Lz_rom::Session::Session(Id_space<Parent::Server> &server_space,
|
||||
|
||||
/* Get file size */
|
||||
Vfs::Directory_service::Stat stat;
|
||||
if (env.vfs().stat(label.string(), stat) != Stat_result::STAT_OK)
|
||||
if (env.vfs().stat(path.string(), stat) != Stat_result::STAT_OK)
|
||||
throw File_error();
|
||||
if (!stat.size)
|
||||
throw File_error();
|
||||
@@ -100,7 +102,7 @@ Lz_rom::Session::Session(Id_space<Parent::Server> &server_space,
|
||||
/* Open file */
|
||||
Vfs_handle *fh;
|
||||
Open_result res = env.vfs().open(
|
||||
label.string(), Vfs::Directory_service::OPEN_MODE_RDONLY, &fh, alloc);
|
||||
path.string(), Vfs::Directory_service::OPEN_MODE_RDONLY, &fh, alloc);
|
||||
if (res != Open_result::OPEN_OK)
|
||||
throw File_error();
|
||||
Vfs_handle::Guard handle_guard(fh);
|
||||
@@ -265,18 +267,16 @@ void Lz_rom::Main::handle_session_request(Xml_node request)
|
||||
Args const args = request.sub_node("args").decoded_content<Args>();
|
||||
Session_label const request_label =
|
||||
label_from_args(args.string()).last_element();
|
||||
char new_label[request_label.capacity()];
|
||||
snprintf(new_label, sizeof(new_label), "/%s.lz", request_label.string());
|
||||
Session_label const filename(new_label);
|
||||
Lz_path const lz_path("/", request_label.string(), ".lz");
|
||||
|
||||
try {
|
||||
Session *session = new (session_alloc)
|
||||
Session(server_id_space, server_id, env, vfs_alloc, filename, decoder);
|
||||
Session(server_id_space, server_id, env, vfs_alloc, lz_path, decoder);
|
||||
env.parent().deliver_session_cap(
|
||||
server_id, env.ep().manage(*session));
|
||||
return;
|
||||
} catch (File_error) {
|
||||
log("failed to open or read file '", filename, "'");
|
||||
log("failed to open or read file '", lz_path, "'");
|
||||
} catch (Decompression_error) {
|
||||
char const *msg = "";
|
||||
|
||||
@@ -305,7 +305,7 @@ void Lz_rom::Main::handle_session_request(Xml_node request)
|
||||
case LZ_library_error:
|
||||
msg = "a bug was detected in the library"; break;
|
||||
}
|
||||
error("failed to decompress '", filename, "', ", msg);
|
||||
error("failed to decompress '", lz_path, "', ", msg);
|
||||
} catch (...) { }
|
||||
env.parent().session_response(server_id, Parent::INVALID_ARGS);
|
||||
}
|
||||
|
||||
@@ -193,11 +193,10 @@ void Rom_fallback::Main::handle_session_request(Xml_node request)
|
||||
|
||||
size_t ram_quota = request.attribute_value("ram_quota", 0UL);
|
||||
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "ram_quota=%ld", ram_quota);
|
||||
String<64> args("ram_quota=", ram_quota);
|
||||
|
||||
// XXX handle Root::Invalid_args
|
||||
env.upgrade(session.client_id.id(), buf);
|
||||
env.upgrade(session.client_id.id(), args.string());
|
||||
env.parent().session_response(server_id, Parent::SESSION_OK);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user