Skip to content

Commit 179b79b

Browse files
authored
Merge branch 'dev' into dev
2 parents d700268 + 345945f commit 179b79b

7 files changed

Lines changed: 161 additions & 70 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ IncludeOS is free software, with "no warranties or restrictions of any kind".
3030
### Key features
3131

3232
* **Extreme memory footprint**: A minimal bootable image, including bootloader, operating system components and a complete C++ standard library is currently 707K when optimized for size.
33-
* **KVM and VirtualBox support** with full virtualization, using [x86 hardware virtualization](https://en.wikipedia.org/wiki/X86_virtualization), available on any modern x86 CPUs). In principle IncludeOS should run on any x86 hardware platform, even on a physical x86 computer, given appropriate drivers. Officially, we develop for- and test on [Linux KVM](http://www.linux-kvm.org/page/Main_Page), which power the [OpenStack IaaS cloud](https://www.openstack.org/), and [VirtualBox](https://www.virtualbox.org), which means that you can run your IncludeOS service on both Linux, Microsoft Windows and macOS.
33+
* **KVM, VirtualBox and VMWare support** with full virtualization, using [x86 hardware virtualization](https://en.wikipedia.org/wiki/X86_virtualization), available on any modern x86 CPUs). In principle IncludeOS should run on any x86 hardware platform, even on a physical x86 computer, given appropriate drivers. Officially, we develop for- and test on [Linux KVM](http://www.linux-kvm.org/page/Main_Page), which power the [OpenStack IaaS cloud](https://www.openstack.org/), and [VirtualBox](https://www.virtualbox.org), which means that you can run your IncludeOS service on both Linux, Microsoft Windows and macOS.
3434
* **C++11/14 support**
3535
* Full C++11/14 language support with [clang](http://clang.llvm.org) v3.8 and later.
3636
* Standard C++ library (STL) [libc++](http://libcxx.llvm.org) from [LLVM](http://llvm.org/).

api/http

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
// limitations under the License.
1818

1919
#pragma once
20-
#ifndef ___HTTP_API___
21-
#define ___HTTP_API___
20+
#ifndef INCLUDEOS_HTTP_API_HPP
21+
#define INCLUDEOS_HTTP_API_HPP
2222

23-
#include "net/http/response.hpp"
24-
#include "net/http/request.hpp"
23+
#include "net/http/client.hpp"
24+
#include "net/http/server.hpp"
2525

26-
#endif //< ___HTTP_API___
26+
#endif //< INCLUDEOS_HTTP_API_HPP

api/hw/block_device.hpp

Lines changed: 126 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is a part of the IncludeOS unikernel - www.includeos.org
22
//
3-
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
3+
// Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
44
// and Alfred Bratterud
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,71 +16,148 @@
1616
// limitations under the License.
1717

1818
#pragma once
19-
#ifndef HW_DRIVE_HPP
20-
#define HW_DRIVE_HPP
19+
#ifndef HW_BLOCK_DEVICE_HPP
20+
#define HW_BLOCK_DEVICE_HPP
2121

22-
#include <memory>
2322
#include <cstdint>
2423
#include <delegate>
24+
#include <memory>
2525

26-
namespace hw
27-
{
28-
29-
/**
30-
* Abstract interface for block devices of various driver types
31-
**/
32-
class Block_device {
33-
public:
34-
using block_t = uint64_t; //< Disk device block size
35-
using buffer_t = std::shared_ptr<uint8_t>;
36-
37-
// Delegate for result of reading a disk sector
38-
//using on_read_func = delegate<void(buffer_t)>;
39-
using on_read_func = delegate<void(buffer_t)>;
26+
namespace hw {
4027

41-
using Device_id = int;
28+
/**
29+
* This class is an abstract interface for block devices
30+
*/
31+
class Block_device {
32+
public:
33+
using block_t = uint64_t; //< Representation for a device's block size
34+
using buffer_t = std::shared_ptr<uint8_t>; //< Representation for a block device's buffer
35+
using Device_id = int32_t; //< Representation for a block device's identifier
36+
using on_read_func = delegate<void(buffer_t)>; //< Delegate for result of reading from a block device
4237

43-
static const char* device_type()
44-
{ return "Block device"; }
38+
/**
39+
* Method to get the type of device
40+
*
41+
* @return The type of device as a C-String
42+
*/
43+
static const char* device_type() noexcept
44+
{ return "Block device"; }
4545

46-
virtual std::string device_name() const = 0;
46+
/**
47+
* Method to get the name of the device
48+
*
49+
* @return The name of the device as a std::string
50+
*/
51+
virtual std::string device_name() const = 0;
4752

48-
Device_id id() const { return id_; }
53+
/**
54+
* Method to get the device's identifier
55+
*
56+
* @return The device's identifier
57+
*/
58+
Device_id id() const noexcept
59+
{ return id_; }
4960

50-
/** Human-readable name of this disk controller */
51-
virtual const char* driver_name() const noexcept = 0;
61+
/**
62+
* Get the human-readable name of this device's controller
63+
*
64+
* @return The human-readable name of this device's controller
65+
*/
66+
virtual const char* driver_name() const noexcept = 0;
5267

53-
/** The size of the disk in whole sectors */
54-
virtual block_t size() const noexcept = 0;
68+
/**
69+
* Get the size of the device as total number of blocks
70+
*
71+
* @return The size of the device as total number of blocks
72+
*/
73+
virtual block_t size() const noexcept = 0;
5574

56-
/** Returns the optimal block size for this device */
57-
virtual block_t block_size() const noexcept = 0;
75+
/**
76+
* Get the optimal block size for this device
77+
*
78+
* @return The optimal block size for this device
79+
*/
80+
virtual block_t block_size() const noexcept = 0;
5881

59-
/**
60-
* Read block(s) from blk and call func with result
61-
* A null-pointer is passed to result if something bad happened
62-
* Validate using !buffer_t:
63-
* if (!buffer)
64-
* error("Device failed to read sector");
65-
**/
66-
virtual void read(block_t blk, on_read_func func) = 0;
67-
virtual void read(block_t blk, size_t count, on_read_func) = 0;
82+
/**
83+
* Read a block of data asynchronously from the device
84+
*
85+
* @param blk
86+
* The block of data to read from the device
87+
*
88+
* @param reader
89+
* An operation to perform asynchronously
90+
*
91+
* @note A nullptr is passed to the reader if an error occurred
92+
* @note Validate the reader's input
93+
*
94+
* @example
95+
* if (buffer == nullptr) {
96+
* error("Device failed to read sector");
97+
* }
98+
*/
99+
virtual void read(block_t blk, on_read_func reader) = 0;
68100

69-
/** read synchronously the block @blk */
70-
virtual buffer_t read_sync(block_t blk) = 0;
71-
virtual buffer_t read_sync(block_t blk, size_t count) = 0;
101+
/**
102+
* Read blocks of data asynchronously from the device
103+
*
104+
* @param blk
105+
* The starting block of data to read from the device
106+
*
107+
* @param count
108+
* The number of blocks to read from the device
109+
*
110+
* @param reader
111+
* An operation to perform asynchronously
112+
*
113+
* @note A nullptr is passed to the reader if an error occurred
114+
* @note Validate the reader's input
115+
*
116+
* @example
117+
* if (buffer == nullptr) {
118+
* error("Device failed to read sector");
119+
* }
120+
*/
121+
virtual void read(block_t blk, size_t count, on_read_func reader) = 0;
72122

73-
virtual void deactivate() = 0;
123+
/**
124+
* Read a block of data synchronously from the device
125+
*
126+
* @param blk
127+
* The block of data to read from the device
128+
*
129+
* @return A buffer containing the data or nullptr if an error occurred
130+
*/
131+
virtual buffer_t read_sync(block_t blk) = 0;
74132

75-
virtual ~Block_device() noexcept = default;
133+
/**
134+
* Read blocks of data synchronously from the device
135+
*
136+
* @param blk
137+
* The starting block of data to read from the device
138+
*
139+
* @param count
140+
* The number of blocks to read from the device
141+
*
142+
* @return A buffer containing the data or nullptr if an error occurred
143+
*/
144+
virtual buffer_t read_sync(block_t blk, size_t count) = 0;
76145

77-
protected:
78-
Block_device();
146+
/**
147+
* Method to deactivate the block device
148+
*/
149+
virtual void deactivate() = 0;
79150

80-
private:
81-
int id_;
82-
}; //< class Drive
151+
/**
152+
* Default destructor
153+
*/
154+
virtual ~Block_device() noexcept = default;
155+
protected:
156+
Block_device();
157+
private:
158+
Device_id id_;
159+
}; //< class Block_device
83160

84161
} //< namespace hw
85162

86-
#endif //< HW_DRIVE_HPP
163+
#endif //< HW_BLOCK_DEVICE_HPP

examples/demo_service/service.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ std::string HTML_RESPONSE()
3434
std::stringstream stream;
3535
stream << "<!DOCTYPE html><html><head>"
3636
<< "<link href='https://fonts.googleapis.com/css?family=Ubuntu:500,300'"
37-
<< "rel='stylesheet' type='text/css'> </head><body>"
37+
<< " rel='stylesheet' type='text/css'>"
38+
<< "<title>IncludeOS Demo Service</title></head><body>"
3839
<< "<h1 style='color: #" << std::hex << ((color >> 8) | 0x020202)
3940
<< "; font-family: \"Arial\", sans-serif'>"
4041
<< "Include<span style='font-weight: lighter'>OS</span></h1>"
41-
<< "<h2>The C++ Unikernel</h2>"
42+
<< "<h2>The C++ Unikernel</h2>"
4243
<< "<p>You have successfully booted an IncludeOS TCP service with simple http. "
4344
<< "For a more sophisticated example, take a look at "
4445
<< "<a href='https://github.com/hioa-cs/IncludeOS/tree/master/examples/acorn'>Acorn</a>.</p>"
@@ -81,14 +82,16 @@ http::Response handle_request(const http::Request& req)
8182
void Service::start(const std::string&)
8283
{
8384
// DHCP on interface 0
84-
auto& inet = net::Inet4::ifconfig(10.0);
85-
// static IP in case DHCP fails
86-
net::Inet4::ifconfig(
87-
{ 10,0,0,42 }, // IP
88-
{ 255,255,255,0 }, // Netmask
89-
{ 10,0,0,1 }, // Gateway
90-
{ 8,8,8,8 }); // DNS
91-
85+
auto& inet = net::Inet4::ifconfig(5.0, [](bool timeout) {
86+
if (timeout) {
87+
// static IP in case DHCP fails
88+
net::Inet4::stack().network_config(
89+
{ 10,0,0,42 }, // IP
90+
{ 255,255,255,0 }, // Netmask
91+
{ 10,0,0,1 }, // Gateway
92+
{ 10,0,0,1 }); // DNS
93+
}
94+
});
9295
// Print some useful netstats every 30 secs
9396
Timers::periodic(5s, 30s,
9497
[&inet] (uint32_t) {

test/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
44

55
option(COVERAGE "Build with coverage generation" OFF)
66
option(SILENT_BUILD "Build with some warnings turned off" ON)
7+
78
option(INFO "Print INFO macro output" OFF)
89
option(DEBUG_INFO "Print debug macro output when DEBUG/DEBUG2 etc. is defined in source" OFF)
910
option(GENERATE_SUPPORT_FILES "Generate external files required by some tests (e.g. tar)" ON)
11+
option(EXTRA_TESTS "Build extra test" OFF)
1012

1113
if ("${ARCH}" STREQUAL "")
1214
set (ARCH "ARCH_X86")
@@ -63,8 +65,6 @@ set(TEST_SOURCES
6365
${TEST}/kernel/unit/kprint_test.cpp
6466
${TEST}/kernel/unit/memmap_test.cpp
6567
${TEST}/kernel/unit/os_test.cpp
66-
# not all CPUs have rdrand
67-
#${TEST}/kernel/unit/rdrand_test.cpp
6868
${TEST}/kernel/unit/service_stub_test.cpp
6969
${TEST}/net/unit/checksum.cpp
7070
${TEST}/net/unit/cookie_test.cpp
@@ -103,7 +103,6 @@ set(TEST_SOURCES
103103
${TEST}/util/unit/statman.cpp
104104
${TEST}/util/unit/syslogd_test.cpp
105105
${TEST}/util/unit/syslog_facility_test.cpp
106-
#${TEST}/util/unit/tar_test.cpp
107106
${TEST}/util/unit/uri_test.cpp
108107
)
109108

@@ -194,6 +193,14 @@ set(MOD_OBJECTS
194193
${INCLUDEOS_ROOT}/mod/uzlib/src/tinfgzip.c
195194
)
196195

196+
if(EXTRA_TESTS)
197+
set(GENERATE_SUPPORT_FILES ON)
198+
message(STATUS "Adding some extra tests")
199+
list(APPEND TEST_SOURCES ${TEST}/kernel/unit/rdrand_test.cpp)
200+
list(APPEND TEST_SOURCES ${TEST}/util/unit/tar_test.cpp)
201+
202+
endif()
203+
197204
if(COVERAGE)
198205
message(STATUS "Coverage")
199206
list(REMOVE_ITEM TEST_SOURCES ${TEST}/util/unit/path_to_regex_no_options.cpp)

test/util/unit/statman.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ CASE( "Creating Statman objects" )
6666
// Statman is both empty and full (no room for more Stat-objects)
6767
EXPECT(statman_.empty());
6868
EXPECT(statman_.full());
69+
70+
EXPECT_THROWS(Stat& stat = statman_.create(Stat::UINT32, "some.new.stat"));
6971
}
7072
}
7173

@@ -320,6 +322,9 @@ CASE("get(\"name\") returns reference to stat with name, throws if not present")
320322
EXPECT_NO_THROW(Stat& res3 = statman_.get("very.important.stat"));
321323
EXPECT_THROWS_AS(Stat& res5 = statman_.get("some.missing.stat"), Stats_exception);
322324

325+
// Can't create stats with empty name
326+
EXPECT_THROWS_AS(Stat& stat6 = statman_.create(Stat::UINT32, ""), Stats_exception);
327+
323328
free((void*)buffer);
324329
}
325330

test/util/unit/tar_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <sys/stat.h>
2222
#include <fcntl.h>
2323
#include <unistd.h>
24-
/*
24+
2525
CASE("Reading single entry tar file")
2626
{
2727
tar::Reader r;
@@ -126,4 +126,3 @@ CASE("Reading tar.gz inside tar file")
126126
EXPECT(inner_e.name().find(".tar.gz") == std::string::npos);
127127
close(fd);
128128
}
129-
*/

0 commit comments

Comments
 (0)