diff --git a/repos/libports/src/test/spark/machinery.adb b/repos/libports/src/test/spark/machinery.adb index 23a3e4795f..47e835ed2c 100644 --- a/repos/libports/src/test/spark/machinery.adb +++ b/repos/libports/src/test/spark/machinery.adb @@ -2,6 +2,11 @@ pragma Ada_2012; package body Machinery is + function Number_Of_Bits (Machinery : Machinery_Type) return Number_Of_Bits_Type is + begin + return Machinery'Size; + end Number_Of_Bits; + procedure Initialize (Machinery : out Machinery_Type) is begin Machinery := ( Temperature => 25 ); diff --git a/repos/libports/src/test/spark/machinery.ads b/repos/libports/src/test/spark/machinery.ads index 947ed05397..db446d06fc 100644 --- a/repos/libports/src/test/spark/machinery.ads +++ b/repos/libports/src/test/spark/machinery.ads @@ -2,10 +2,17 @@ package Machinery is pragma Pure; + type Number_Of_Bits_Type is mod 2**32 with Size => 32; + type Temperature_Type is mod 2**32 with Size => 32; type Machinery_Type is private; + function Number_of_bits (Machinery : Machinery_Type) return Number_Of_Bits_Type + with Export, + Convention => C, + External_Name => "_ZN5Spark14number_of_bitsERKNS_9MachineryE"; + procedure Initialize (Machinery : out Machinery_Type) with Export, Convention => C, diff --git a/repos/libports/src/test/spark/machinery.h b/repos/libports/src/test/spark/machinery.h index b1c79dcc15..dd1cfdf662 100644 --- a/repos/libports/src/test/spark/machinery.h +++ b/repos/libports/src/test/spark/machinery.h @@ -20,6 +20,13 @@ namespace Spark { template struct Object { + /** + * Exception type + */ + struct Object_size_mismatch { }; + + static constexpr Genode::size_t bytes() { return BYTES; } + long _space[(BYTES + sizeof(long) - 1)/sizeof(long)] { }; }; @@ -31,6 +38,15 @@ namespace Spark { Genode::uint32_t temperature() const; }; + + Genode::size_t number_of_bits(Machinery const &); + + template + static inline void assert_valid_object_size() + { + if (number_of_bits(*(T *)nullptr) > T::bytes()*8) + throw typename T::Object_size_mismatch(); + } } @@ -38,6 +54,8 @@ static inline void test_spark_object_construction() { using namespace Genode; + Spark::assert_valid_object_size(); + Spark::Machinery machinery { }; auto check = [&] (char const *msg, Genode::uint32_t expected)