From a3450be0fb4f226bce610bae285f02f9d8d0af24 Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Tue, 27 Oct 2020 14:50:28 +0100
Subject: [PATCH] [tests] refine test to test new ptests' behavior

---
 tests/metrics/libc.c                   |  6 ++++--
 tests/metrics/oracle/libc.0.res.oracle | 29 +++++++++++++-------------
 tests/metrics/oracle/libc.1.res.oracle | 29 +++++++++++++-------------
 tests/metrics/oracle/libc.json         |  1 +
 4 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/tests/metrics/libc.c b/tests/metrics/libc.c
index 0c4aaf13fb4..83556b3d9b4 100644
--- a/tests/metrics/libc.c
+++ b/tests/metrics/libc.c
@@ -1,9 +1,8 @@
 /* run.config
    STDOPT: #"-metrics-no-libc -metrics-eva-cover"
    STDOPT: #"-metrics-libc -metrics-eva-cover"
-   STDOPT: #"-metrics-libc -metrics-output @PTEST_DIR@/result/libc.json"
    LOG: libc.json
-   OPT:
+   STDOPT: #"-metrics-libc -metrics-output @PTEST_DIR@/result/libc.json"
 */
 #include <ctype.h>
 #include <stdio.h> // defines external variables
@@ -24,6 +23,8 @@ int g() { // called via fp
   return isalpha(42);
 }
 
+int h() { return 0; }
+
 int (*fp)() = g;
 
 int getopt(int argc, char * const argv[],
@@ -34,5 +35,6 @@ int getopt(int argc, char * const argv[],
 int main() {
   fp();
   getopt(0, 0, 0);
+  h();
   return isblank(0);
 }
diff --git a/tests/metrics/oracle/libc.0.res.oracle b/tests/metrics/oracle/libc.0.res.oracle
index 1742799970d..1353173e068 100644
--- a/tests/metrics/oracle/libc.0.res.oracle
+++ b/tests/metrics/oracle/libc.0.res.oracle
@@ -1,8 +1,8 @@
 [kernel] Parsing tests/metrics/libc.c (with preprocessing)
-[metrics] Defined functions (5)
+[metrics] Defined functions (6)
   =====================
    bar (0 call); f (0 call); foo (0 call); g (address taken) (0 call);
-   main (0 call); 
+   h (1 call); main (0 call); 
   
   Specified-only functions (0)
   ============================
@@ -22,18 +22,18 @@
   
   Global metrics
   ============== 
-  Sloc = 12
+  Sloc = 15
   Decision point = 0
   Global variables = 1
   If = 0
   Loop = 0
   Goto = 0
-  Assignment = 5
-  Exit point = 5
-  Function = 5
-  Function call = 5
+  Assignment = 6
+  Exit point = 6
+  Function = 6
+  Function call = 6
   Pointer dereferencing = 1
-  Cyclomatic complexity = 5
+  Cyclomatic complexity = 6
 [eva] Analyzing a complete application starting at main
 [eva] Computing initial state
 [eva] Initial state computed
@@ -44,8 +44,8 @@
 [eva] done for function main
 [eva:summary] ====== ANALYSIS SUMMARY ======
   ----------------------------------------------------------------------------
-  4 functions analyzed (out of 5): 80% coverage.
-  In these functions, 10 statements reached (out of 10): 100% coverage.
+  5 functions analyzed (out of 6): 83% coverage.
+  In these functions, 13 statements reached (out of 13): 100% coverage.
   ----------------------------------------------------------------------------
   No errors or warnings raised during the analysis.
   ----------------------------------------------------------------------------
@@ -58,15 +58,16 @@
   ----------------------------------------------------------------------------
 [metrics] Eva coverage statistics
   =======================
-  Syntactically reachable functions = 4 (out of 5)
-  Semantically reached functions = 4
+  Syntactically reachable functions = 5 (out of 6)
+  Semantically reached functions = 5
   Coverage estimation = 100.0%
 [metrics] References to non-analyzed functions
   ------------------------------------
 [metrics] Statements analyzed by Eva
   --------------------------
-  10 stmts in analyzed functions, 10 stmts analyzed (100.0%)
+  13 stmts in analyzed functions, 13 stmts analyzed (100.0%)
   bar: 2 stmts out of 2 (100.0%)
   foo: 2 stmts out of 2 (100.0%)
   g: 2 stmts out of 2 (100.0%)
-  main: 4 stmts out of 4 (100.0%)
+  h: 2 stmts out of 2 (100.0%)
+  main: 5 stmts out of 5 (100.0%)
diff --git a/tests/metrics/oracle/libc.1.res.oracle b/tests/metrics/oracle/libc.1.res.oracle
index 690ea20f9c4..d92d25d82ea 100644
--- a/tests/metrics/oracle/libc.1.res.oracle
+++ b/tests/metrics/oracle/libc.1.res.oracle
@@ -1,8 +1,8 @@
 [kernel] Parsing tests/metrics/libc.c (with preprocessing)
-[metrics] Defined functions (6)
+[metrics] Defined functions (7)
   =====================
    bar (1 call); f (0 call); foo (1 call); g (address taken) (0 call);
-   getopt (1 call); main (0 call); 
+   getopt (1 call); h (1 call); main (0 call); 
   
   Specified-only functions (122)
   ==============================
@@ -55,18 +55,18 @@
   
   Global metrics
   ============== 
-  Sloc = 17
+  Sloc = 20
   Decision point = 0
   Global variables = 17
   If = 0
   Loop = 0
   Goto = 0
-  Assignment = 8
-  Exit point = 6
-  Function = 128
-  Function call = 7
+  Assignment = 9
+  Exit point = 7
+  Function = 129
+  Function call = 8
   Pointer dereferencing = 1
-  Cyclomatic complexity = 6
+  Cyclomatic complexity = 7
 [eva] Analyzing a complete application starting at main
 [eva] Computing initial state
 [eva] Initial state computed
@@ -77,8 +77,8 @@
 [eva] done for function main
 [eva:summary] ====== ANALYSIS SUMMARY ======
   ----------------------------------------------------------------------------
-  4 functions analyzed (out of 5): 80% coverage.
-  In these functions, 10 statements reached (out of 10): 100% coverage.
+  5 functions analyzed (out of 6): 83% coverage.
+  In these functions, 13 statements reached (out of 13): 100% coverage.
   ----------------------------------------------------------------------------
   No errors or warnings raised during the analysis.
   ----------------------------------------------------------------------------
@@ -91,16 +91,17 @@
   ----------------------------------------------------------------------------
 [metrics] Eva coverage statistics
   =======================
-  Syntactically reachable functions = 7 (out of 128)
-  Semantically reached functions = 7
+  Syntactically reachable functions = 8 (out of 129)
+  Semantically reached functions = 8
   Coverage estimation = 100.0%
 [metrics] References to non-analyzed functions
   ------------------------------------
 [metrics] Statements analyzed by Eva
   --------------------------
-  15 stmts in analyzed functions, 15 stmts analyzed (100.0%)
+  18 stmts in analyzed functions, 18 stmts analyzed (100.0%)
   bar: 2 stmts out of 2 (100.0%)
   foo: 2 stmts out of 2 (100.0%)
   g: 2 stmts out of 2 (100.0%)
   getopt: 5 stmts out of 5 (100.0%)
-  main: 4 stmts out of 4 (100.0%)
+  h: 2 stmts out of 2 (100.0%)
+  main: 5 stmts out of 5 (100.0%)
diff --git a/tests/metrics/oracle/libc.json b/tests/metrics/oracle/libc.json
index bf512214d4c..5f7f5afbe20 100644
--- a/tests/metrics/oracle/libc.json
+++ b/tests/metrics/oracle/libc.json
@@ -5,6 +5,7 @@
     { "foo": { "calls": 1, "address_taken": false } },
     { "g": { "calls": 0, "address_taken": true } },
     { "getopt": { "calls": 1, "address_taken": false } },
+    { "h": { "calls": 1, "address_taken": false } },
     { "main": { "calls": 0, "address_taken": false } }
   ],
   "specified-only-functions": [
-- 
GitLab