summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bartell <pbartell@amazon.com>2021-03-19 17:30:20 -0700
committerGitHub <noreply@github.com>2021-03-19 17:30:20 -0700
commitf39765be2226889510a1237f3b2fa1cf1ed4a652 (patch)
tree12e9dab1b1a36cfabfb1f2261cd2ff99ffe12e16
parentf1da2515c296ac81ef9280471ee0db616d49e618 (diff)
downloadfreertos-git-f39765be2226889510a1237f3b2fa1cf1ed4a652.tar.gz
Kernel UT: Enable preprocessor when running cflow in callgraph.py (#530)
* Add INCLUDE_DIR to the commandline call to cflow in callgraph.py This removes dependent functions from the list when they are disabled in the FreeRTOS config. * Add argparse to callgraph.py so that no output file is created on failure.
-rw-r--r--FreeRTOS/Test/CMock/testdir.mk2
-rwxr-xr-xFreeRTOS/Test/CMock/tools/callgraph.py33
2 files changed, 31 insertions, 4 deletions
diff --git a/FreeRTOS/Test/CMock/testdir.mk b/FreeRTOS/Test/CMock/testdir.mk
index df043a224..e832de60b 100644
--- a/FreeRTOS/Test/CMock/testdir.mk
+++ b/FreeRTOS/Test/CMock/testdir.mk
@@ -120,7 +120,7 @@ $(MOCK_HDR_LIST) $(MOCK_SRC_LIST) : $(PROJECT_DIR)/$(PROJECT).yml $(MOCK_FILES_F
# Generate callgraph for coverage filtering
$(PROJ_DIR)/callgraph.json : $(PROJ_SRC_LIST)
mkdir -p $(PROJ_DIR)
- python3 $(UT_ROOT_DIR)/tools/callgraph.py $^ > $@
+ python3 $(UT_ROOT_DIR)/tools/callgraph.py --out $@ $^
# preprocess proj files to expand macros for coverage
$(PROJ_DIR)/%.i : $(KERNEL_DIR)/%.c
diff --git a/FreeRTOS/Test/CMock/tools/callgraph.py b/FreeRTOS/Test/CMock/tools/callgraph.py
index 7c3f57d32..cc9d57564 100755
--- a/FreeRTOS/Test/CMock/tools/callgraph.py
+++ b/FreeRTOS/Test/CMock/tools/callgraph.py
@@ -24,6 +24,7 @@
# https://www.FreeRTOS.org
# https://github.com/FreeRTOS
###############################################################################
+import argparse
import json
import os
import re
@@ -31,12 +32,36 @@ import subprocess
import sys
from typing import Dict, List, Set
-target_files = sys.argv[1:]
+arg_parser = argparse.ArgumentParser(
+ description="Parse each input .c file and generate a callgraph.json containing"
+ " a map from each function name to a list of the other functions which the first"
+ " function calls."
+)
+
+arg_parser.add_argument(
+ "-o", "--out", required=True, help="Output callgraph.json file path."
+)
+
+arg_parser.add_argument("in_files", nargs="+", help="Input .c files to be parsed.")
+args = arg_parser.parse_args()
+
+if vars(args)["out"] and not os.path.isdir(os.path.dirname(vars(args)["out"])):
+ print("The output directory does not exist.", file=sys.stderr)
+ sys.exit(1)
+
+target_files = args.in_files
for f in target_files:
if not os.path.isfile(f):
print("ERROR: Input file {} does not exist.".format(f))
- exit(1)
+ sys.exit(1)
+
+includes = ""
+# Get INCLUDE_DIR from envrionment
+if "INCLUDE_DIR" in os.environ:
+ includes = os.environ["INCLUDE_DIR"]
+else:
+ print("WARNING: INCLUDE_DIR variable was not found in the envrionment.")
ret = subprocess.run(
[
@@ -46,6 +71,7 @@ ret = subprocess.run(
"--omit-arguments",
"--omit-symbol-names",
"--all",
+ includes,
]
+ target_files,
capture_output=True,
@@ -103,4 +129,5 @@ for key in callmap:
temp_list = list(callmap[key])
callmap_list[key] = temp_list
-print(json.dumps(callmap_list))
+with open(args.out, "w") as outfile:
+ json.dump(callmap_list, outfile)