genode/repos/base/src/test/ds_ownership/main.cc
Norman Feske 8d1cf08b1a core: fix regression in dataspace ownership test
This patch revives our ds_ownership test from 2012, which just revealed
a regression in core where the dataspace-free operation of the RAM
service would unconditionally destroy dataspace objects from foreign
sessions. The patch fixes the bug and adds an updated version of the
test to the autopilot.

Fixes #2065
2016-08-29 17:29:33 +02:00

54 lines
1.3 KiB
C++

/*
* \brief Testing the distinction between user and owner of a RAM dataspace
* \author Martin Stein
* \author Norman Feske
* \date 2012-04-19
*/
/*
* Copyright (C) 2008-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <ram_session/connection.h>
#include <base/log.h>
#include <base/component.h>
void Component::construct(Genode::Env &env)
{
using namespace Genode;
log("--- dataspace ownership test ---");
static Ram_connection ram_1 { env };
static Ram_connection ram_2 { env };
log("allocate dataspace from one RAM session");
ram_1.ref_account(env.ram_session_cap());
env.ram().transfer_quota(ram_1.cap(), 8*1024);
Ram_dataspace_capability ds = ram_1.alloc(sizeof(unsigned));
log("attempt to free dataspace from foreign RAM session");
ram_2.free(ds);
log("try to attach dataspace to see if it still exists");
env.rm().attach(ds);
log("attach operation succeeded");
log("free dataspace from legitimate RAM session");
size_t const quota_before_free = ram_1.avail();
ram_1.free(ds);
size_t const quota_after_free = ram_1.avail();
if (quota_after_free > quota_before_free)
log("test succeeded");
else
error("test failed");
}