Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
-DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
-DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" \
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined" \
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined -shared-libasan -shared-libubsan" \
-DLEARN_LLVM_ENABLE_ONE_BACKEND=OFF \
-G Ninja

Expand Down
62 changes: 62 additions & 0 deletions tests/run_koto_opt_smoke.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# run_koto_opt_smoke.cmake
# Smoke test: run opt with Kotoamatsukami plugin and verify output content.
#
# Required variables (passed via cmake -D):
# OPT_EXE - path to opt
# PLUGIN_FILE - path to Kotoamatsukami.{so,dylib}
# PASS_PIPELINE - comma-separated pass names, e.g. "flatten"
# INPUT_FILE - path to input .ll file
# CONFIG_FILE - full path to the pass-specific JSON config
# CONFIG_FILE_NAME - filename of the config (e.g. koto_flatten_smoke_config.json)
# OUTPUT_FILE - where to write the obfuscated .ll
# WORKING_DIR - scratch directory; config copied here so plugin can find it
# EXPECT_MODE - "contains" | "not_contains"
# EXPECT_TEXT - text to look for (or not) in OUTPUT_FILE

# Create scratch dir and drop the per-test config there.
# The plugin searches for Kotoamatsukami.config (by that exact name) in CWD,
# so we rename the smoke config on copy.
file(MAKE_DIRECTORY "${WORKING_DIR}")
file(COPY_FILE "${CONFIG_FILE}" "${WORKING_DIR}/Kotoamatsukami.config")

execute_process(
COMMAND "${OPT_EXE}"
-load-pass-plugin ${PLUGIN_FILE}
-passes=${PASS_PIPELINE}
-S "${INPUT_FILE}"
-o "${OUTPUT_FILE}"
WORKING_DIRECTORY "${WORKING_DIR}"
RESULT_VARIABLE result
OUTPUT_VARIABLE stdout
ERROR_VARIABLE stderr
)

if(NOT result EQUAL 0)
message(FATAL_ERROR
"plugin_koto_opt_smoke (${PASS_PIPELINE}) FAILED (exit ${result})\n"
"stderr:\n${stderr}")
endif()

file(READ "${OUTPUT_FILE}" obf_ir)

if(EXPECT_MODE STREQUAL "contains")
if(NOT obf_ir MATCHES "${EXPECT_TEXT}")
message(FATAL_ERROR
"plugin_koto_opt_smoke (${PASS_PIPELINE}): "
"expected '${EXPECT_TEXT}' in output but not found.\n"
"IR:\n${obf_ir}")
endif()
message(STATUS "plugin_koto_opt_smoke (${PASS_PIPELINE}) PASSED — found '${EXPECT_TEXT}'")

elseif(EXPECT_MODE STREQUAL "not_contains")
if(obf_ir MATCHES "${EXPECT_TEXT}")
message(FATAL_ERROR
"plugin_koto_opt_smoke (${PASS_PIPELINE}): "
"expected '${EXPECT_TEXT}' to be absent but was found.\n"
"IR:\n${obf_ir}")
endif()
message(STATUS "plugin_koto_opt_smoke (${PASS_PIPELINE}) PASSED — '${EXPECT_TEXT}' correctly absent")

else()
message(FATAL_ERROR "Unknown EXPECT_MODE: ${EXPECT_MODE}")
endif()
31 changes: 31 additions & 0 deletions tests/run_koto_plugin_smoke.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# run_koto_plugin_smoke.cmake
# Smoke test: compile example/test.c via clang with -fpass-plugin=Kotoamatsukami
#
# Required variables (passed via cmake -D):
# CLANG_EXE - path to clang
# PLUGIN_FILE - path to Kotoamatsukami.{so,dylib}
# SOURCE_FILE - path to the C source to compile
# OUTPUT_FILE - destination binary
# WORKING_DIR - project root (plugin reads Kotoamatsukami.config from here)

file(MAKE_DIRECTORY "${WORKING_DIR}")

execute_process(
COMMAND "${CLANG_EXE}"
-fpass-plugin=${PLUGIN_FILE}
-O1
"${SOURCE_FILE}"
-o "${OUTPUT_FILE}"
WORKING_DIRECTORY "${WORKING_DIR}"
RESULT_VARIABLE result
OUTPUT_VARIABLE stdout
ERROR_VARIABLE stderr
)

if(NOT result EQUAL 0)
message(FATAL_ERROR
"plugin_koto_clang_smoke FAILED (exit ${result})\n"
"stderr:\n${stderr}")
endif()

message(STATUS "plugin_koto_clang_smoke PASSED")
Loading