Skip to content
Merged
9 changes: 6 additions & 3 deletions include/StackUsageAnalyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ enum class DescriptiveErrorCode
AllocaUserControlled = 7,
AllocaTooLarge = 8,
AllocaUsageWarning = 9,
InvalidBaseReconstruction = 10
InvalidBaseReconstruction = 10,
ConstParameterNotModified = 11
};

template<>
struct EnumTraits<DescriptiveErrorCode>
{
static constexpr std::array<std::string_view, 11> names = {
static constexpr std::array<std::string_view, 12> names = {
"None",
"StackBufferOverflow",
"NegativeStackIndex",
Expand All @@ -127,7 +128,8 @@ struct EnumTraits<DescriptiveErrorCode>
"AllocaUserControlled",
"AllocaTooLarge",
"AllocaUsageWarning",
"InvalidBaseReconstruction"
"InvalidBaseReconstruction",
"ConstParameterNotModified"
};
};

Expand All @@ -149,6 +151,7 @@ struct Diagnostic

DiagnosticSeverity severity = DiagnosticSeverity::Warning;
DescriptiveErrorCode errCode = DescriptiveErrorCode::None;
std::string ruleId;
std::vector<std::string> variableAliasingVec;
std::string message;
};
Expand Down
30 changes: 21 additions & 9 deletions run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def normalize(s: str) -> str:
line = line.rstrip("\n")
# "a b c" -> "a b c"
parts = line.strip().split()
lines.append(" ".join(parts))
normalized = " ".join(parts)
# Normalize spacing around pointer/reference symbols for cross-platform demangler output.
normalized = normalized.replace(" *", "*").replace("* ", "*")
normalized = normalized.replace(" &", "&").replace("& ", "&")
lines.append(normalized)
return "\n".join(lines).strip()


Expand Down Expand Up @@ -108,7 +112,7 @@ def check_help_flags() -> bool:
return ok


def check_file(c_path: Path) -> bool:
def check_file(c_path: Path):
"""
Vérifie qu'avec ce fichier, toutes les attentes sont présentes
dans la sortie de l'analyseur.
Expand All @@ -117,48 +121,56 @@ def check_file(c_path: Path) -> bool:
expectations = extract_expectations(c_path)
if not expectations:
print(" (no expectations found, skipping)\n")
return True
return True, 0, 0

analyzer_output = run_analyzer_on_file(c_path)
norm_output = normalize(analyzer_output)

all_ok = True
total = len(expectations)
passed = 0
for idx, exp in enumerate(expectations, start=1):
norm_exp = normalize(exp)
if norm_exp in norm_output:
print(f" ✅ expectation #{idx} FOUND")
passed += 1
else:
print(f" ❌ expectation #{idx} MISSING")
print("----- Expected block -----")
print(exp)
print("----- Analyzer output (normalized) -----")
# tu peux commenter cette ligne si l'output est trop gros
# print(norm_output)
print(f"<{norm_output}>")
print("---------------------------")
all_ok = False

print()
return all_ok
return all_ok, total, passed


def main() -> int:
global_ok = check_help_flags()
total_tests = 0
passed_tests = 0

c_files = sorted(TEST_DIR.glob("**/*.c"))
c_files = sorted(list(TEST_DIR.glob("**/*.c")) + list(TEST_DIR.glob("**/*.cpp")))
if not c_files:
print(f"No .c files found under {TEST_DIR}")
print(f"No .c/.cpp files found under {TEST_DIR}")
return 0 if global_ok else 1

for f in c_files:
ok = check_file(f)
ok, total, passed = check_file(f)
passed_tests += passed
total_tests += total
if not ok:
global_ok = False

if global_ok:
print("✅ All tests passed.")
print(f"✅ Passed {passed_tests}/{total_tests} tests.")
return 0
else:
print("❌ Some tests failed.")
print(f"❌ Passed {passed_tests}/{total_tests} tests.")
return 1


Expand Down
Loading