]> rtime.felk.cvut.cz Git - hercules2020/jailhouse-build.git/commitdiff
Test memguard call return value.
authorJoel Matejka <joel.matejka@cvut.cz>
Mon, 29 Oct 2018 18:09:20 +0000 (19:09 +0100)
committerJoel Matejka <joel.matejka@cvut.cz>
Tue, 30 Oct 2018 03:11:28 +0000 (04:11 +0100)
test/memguard-test.c

index 6b8dd0aa7862ddec0d2e0e979b614aef3f563dea..53cc8447a29bf10ccb6b4cad2cd8a8b682788b04 100644 (file)
@@ -8,22 +8,57 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <time.h>
+#include <inttypes.h>
 
 #ifndef SYS_prem_memguard_check
 #define SYS_prem_memguard_check 793
 #endif
 
+/* Return value:
+ * 0-31  - Total time
+ * 32-55 - Sum of memory events
+ * 61    - Memory budget overrun
+ * 62    - Timeout
+ * 63    - Error */
+#define RET_TIM_POS                    0
+#define RET_MEM_POS                    32
+#define RET_OVER_MEM_POS       61
+#define RET_OVER_TIM_POS       62
+
+#define RET_TIM_MASK           0xFFFFFFFFlu
+#define RET_MEM_MASK           0xFFFFFFlu
+#define RET_OVER_MEM_MASK      0x1lu
+#define RET_OVER_TIM_MASK      0x1lu
+
 #define RANDOM_ARRAY_SIZE 16777216 // 16M * 8 = 128 MB array
 
 uint64_t random_values[RANDOM_ARRAY_SIZE];
 volatile uint64_t sum;
 
+
+
 enum prem_phase {
        PREM_COMPATIBLE = 0,
        PREM_MEMORY     = 1,
        PREM_COMPUTE    = 2,
 };
 
+struct test_case{
+       uint64_t budget_time;
+       uint64_t budget_memory;
+       uint8_t flags;
+       uint64_t measured_time;
+       uint64_t measured_memory;
+       uint8_t status;
+};
+
+
+
+static inline void decode_retval(uint64_t retval, uint64_t * timval, uint64_t * cntval){
+       *timval = (retval >> RET_TIM_POS) & RET_TIM_MASK;
+       *cntval = (retval >> RET_MEM_POS) & RET_MEM_MASK;
+}
+
 void compute_kernel(int time_ms){
     struct timespec ts;
     uint64_t current_us, end_us;
@@ -68,6 +103,8 @@ int main(int argc, char *argv[])
 {
     cpu_set_t set;
     int cpu = 0;
+    long retval;
+    uint64_t timval, cntval;
 
     if (argc > 1)
        cpu = atoi(argv[1]);
@@ -82,42 +119,58 @@ int main(int argc, char *argv[])
     printf("X1\n");
     fflush(stdout);
     //prem_memguard_check(950000, 1933440000, 1);
-    prem_memguard_check(100000, 1000, MGF_PERIODIC);
+    retval = prem_memguard_check(100000, 1000, MGF_PERIODIC | MGF_MASK_INT);
     compute_kernel(1000);
     //prem_memguard_check(0, 0, 1);
 
+       /* First result does not make sense */
+    decode_retval(retval, &timval, &cntval);
+       printf("tim: %lu cnt: %lu\n", timval, cntval);
+       
     printf("X2\n");
     fflush(stdout);
     //prem_memguard_check(1050000, 2136960000, 1);
-    prem_memguard_check(1050000, 2136960000, 0);
+    retval = prem_memguard_check(1050000, 2136960000, 0);
     compute_kernel(1000);
     //prem_memguard_check(0, 0, 1);
+    
+    decode_retval(retval, &timval, &cntval);
+       printf("tim: %lu cnt: %lu\n", timval, cntval);
 
     printf("X3\n");
     fflush(stdout);
     //prem_memguard_check(1000000, 500, 1);
-    prem_memguard_check(100000, 500, MGF_PERIODIC);
+    retval = prem_memguard_check(100000, 500, MGF_PERIODIC);
     memory_kernel(100000000);
     //prem_memguard_check(0, 0, 1);
+    
+    decode_retval(retval, &timval, &cntval);
+       printf("tim: %lu cnt: %lu\n", timval, cntval);
 
     printf("X4\n");
     fflush(stdout);
     //prem_memguard_check(1000000, 1500, 1);
-    prem_memguard_check(1000000, 15000000, 0);
+    retval = prem_memguard_check(1000000, 15000000, 0);
     memory_kernel(100000000);
     //prem_memguard_check(0, 0, 1);
+    
+    decode_retval(retval, &timval, &cntval);
+       printf("tim: %lu cnt: %lu\n", timval, cntval);
 
     printf("X5\n");
     fflush(stdout);
     //prem_memguard_check(1000000, 10000, 1);
-    prem_memguard_check(1000000, 100000, 0);
+    retval = prem_memguard_check(1000000, 100000, 0);
     random_memory_kernel(100000000);
     //prem_memguard_check(0, 0, 1);
+    
+    decode_retval(retval, &timval, &cntval);
+       printf("tim: %lu cnt: %lu\n", timval, cntval);
 
     printf("X6\n");
     fflush(stdout);
     //prem_memguard_check(1000000, 10000000, 1);
-    prem_memguard_check(1000000, 100000000, 0);
+    retval = prem_memguard_check(1000000, 100000000, 0);
     random_memory_kernel(100000000);
 
     prem_memguard_check(0, 0, 0);