From d4a5a87947402381580f1edb53111e5bb263267c Mon Sep 17 00:00:00 2001
From: Andre Maroneze <andre.maroneze@cea.fr>
Date: Tue, 1 Mar 2022 18:41:41 +0100
Subject: [PATCH] [tests] fix compatibility with dune

---
 tests/libc/check_full_libc.sh                  | 12 +++++-------
 tests/libc/check_parsing_individual_headers.ml | 15 ++++++++-------
 tests/libc/oracle/fc_libc.2.res.oracle         |  2 +-
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/tests/libc/check_full_libc.sh b/tests/libc/check_full_libc.sh
index bce6a2f6159..f325a41b0bd 100755
--- a/tests/libc/check_full_libc.sh
+++ b/tests/libc/check_full_libc.sh
@@ -4,14 +4,12 @@
 
 errors=0
 
-if [ "$#" -ge 1 ] && [ -d "$1" ]; then
-    cd "$1"
-else
-    cd share/libc
-fi
+test_dir=$(pwd)
+share_libc="$1"
+cd "$share_libc"
 
 for A in *.h */*.h; do
-    if ! grep -q $A ../../tests/libc/fc_libc.c
+    if ! grep -q $A "$test_dir/fc_libc.c"
     then
         echo "missing include in tests/libc/fc_libc.c: $A"
         errors=$((errors+1))
@@ -24,7 +22,7 @@ for A in *.h */*.h; do
 done
 
 for A in *.c */*.c; do
-    if ! grep -q $A __fc_runtime.c ../../tests/libc/fc_libc.c
+    if ! grep -q $A __fc_runtime.c "$test_dir/fc_libc.c"
     then
         echo "missing include in share/libc/__fc_runtime.c or tests/libc/fc_libc.c: $A"
         errors=$((errors+1))
diff --git a/tests/libc/check_parsing_individual_headers.ml b/tests/libc/check_parsing_individual_headers.ml
index 29066eb45e4..cd7d83b4448 100644
--- a/tests/libc/check_parsing_individual_headers.ml
+++ b/tests/libc/check_parsing_individual_headers.ml
@@ -7,16 +7,17 @@ let header_re = Str.regexp ".*\\.h$"
 let is_header f = Str.string_match header_re f 0
 
 (* Files which are *not* supposed to be parsed *)
-let blacklist () =
-  let libc = (Filename.concat (Sys.getenv "FRAMAC_SHARE") "libc") in
+let blacklist libc_dir =
   List.map (fun f ->
-      Datatype.Filepath.of_string (Filename.concat libc f))
+      Datatype.Filepath.concat libc_dir f)
     ["tgmath.h"; "complex.h"; "__fc_machdep_linux_shared.h"]
 
 (* only goes down one level, which is enough for the libc *)
-let collect_headers libc_dir =
+let collect_headers () =
+  let libc_dir = Kernel.Share.get_dir ~mode:`Must_exist "libc" in
+  let libc_dir_files = Array.to_list (Sys.readdir (libc_dir :> string)) in
   let contents =
-    List.map (Filename.concat libc_dir) (Array.to_list (Sys.readdir libc_dir))
+    List.map (Filename.concat (libc_dir :> string)) libc_dir_files
   in
   let subdirs = List.filter Sys.is_directory contents in
   let base_headers = List.filter is_header contents in
@@ -29,7 +30,7 @@ let collect_headers libc_dir =
     ) base_headers subdirs
   in
   let all_headers = List.sort Extlib.compare_ignore_case all_headers in
-  let to_skip = blacklist () in
+  let to_skip = blacklist libc_dir in
   List.iter (fun header ->
       let header_path = Datatype.Filepath.of_string header in
       if List.mem header_path to_skip then
@@ -42,4 +43,4 @@ let collect_headers libc_dir =
     ) all_headers
 
 let () =
-  Db.Main.apply (collect_headers (Filename.concat (Sys.getenv "FRAMAC_SHARE") "libc"))
+  Db.Main.extend collect_headers
diff --git a/tests/libc/oracle/fc_libc.2.res.oracle b/tests/libc/oracle/fc_libc.2.res.oracle
index 4bd6354e3b0..dc3e1747f8b 100644
--- a/tests/libc/oracle/fc_libc.2.res.oracle
+++ b/tests/libc/oracle/fc_libc.2.res.oracle
@@ -1,3 +1,4 @@
+[kernel] Parsing fc_libc.c (with preprocessing)
 [kernel] Parsing FRAMAC_SHARE/libc/__fc_alloc_axiomatic.h (with preprocessing)
 [kernel] Parsing FRAMAC_SHARE/libc/__fc_builtin.h (with preprocessing)
 [kernel] Parsing FRAMAC_SHARE/libc/__fc_define_blkcnt_t.h (with preprocessing)
@@ -154,4 +155,3 @@ skipping FRAMAC_SHARE/libc/tgmath.h
 [kernel] Parsing FRAMAC_SHARE/libc/wchar.h (with preprocessing)
 [kernel] Parsing FRAMAC_SHARE/libc/wctype.h (with preprocessing)
 [kernel] Parsing FRAMAC_SHARE/libc/wordexp.h (with preprocessing)
-[kernel] Parsing fc_libc.c (with preprocessing)
-- 
GitLab