From d4c1b9444ffcb9b80fd82855afb016277438f754 Mon Sep 17 00:00:00 2001 From: aleksisch Date: Thu, 19 Oct 2023 13:46:31 +0300 Subject: [PATCH] add determenistic tests Change-Id: Id6f514270fde4a7f01d078749a85be1c60eaf11a Signed-off-by: aleksisch --- assembler/assembly-program.h | 13 ++-- assembler/assembly-type.h | 5 ++ assembler/tests/parser_test.cpp | 8 +-- plugins/ets/CMakeLists.txt | 50 +++++++++++--- plugins/ets/tests/CMakeLists.txt | 69 +++++++++++++------ .../common/bouncing_pandas/CMakeLists.txt | 1 + .../tests/common/bouncing_peas/CMakeLists.txt | 1 + 7 files changed, 107 insertions(+), 40 deletions(-) diff --git a/assembler/assembly-program.h b/assembler/assembly-program.h index 0f83333f1..97a0814b0 100644 --- a/assembler/assembly-program.h +++ b/assembler/assembly-program.h @@ -31,13 +31,16 @@ namespace panda::pandasm { // NOLINTBEGIN(misc-non-private-member-variables-in-classes) struct Program { + using StringT = std::set; + panda::panda_file::SourceLang lang {panda::panda_file::SourceLang::PANDA_ASSEMBLY}; - std::unordered_map record_table; - std::unordered_map function_table; - std::unordered_map> function_synonyms; + std::map record_table; + std::map function_table; + std::unordered_map> + function_synonyms; // we might keep unordered, since we don't iterate over it std::map literalarray_table; - std::unordered_set strings; - std::unordered_set array_types; + StringT strings; + std::set array_types; /* * Returns a JSON string with the program structure and scopes locations diff --git a/assembler/assembly-type.h b/assembler/assembly-type.h index c3d6fcaa8..3383b060f 100644 --- a/assembler/assembly-type.h +++ b/assembler/assembly-type.h @@ -165,6 +165,11 @@ public: return name_ == type.name_; } + bool operator<(const Type &type) const + { + return name_ < type.name_; + } + static PANDA_PUBLIC_API Type FromDescriptor(std::string_view descriptor); static PANDA_PUBLIC_API Type FromName(std::string_view name, bool ignore_primitive = false); diff --git a/assembler/tests/parser_test.cpp b/assembler/tests/parser_test.cpp index df3f9be56..ddb8c1d8d 100644 --- a/assembler/tests/parser_test.cpp +++ b/assembler/tests/parser_test.cpp @@ -1063,7 +1063,7 @@ TEST(parsertests, test39_parse_operand_string) auto item = p.Parse(v); - std::unordered_set strings = {" abc123 ", "zxcvb"}; + Program::StringT strings = {" abc123 ", "zxcvb"}; ASSERT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); ASSERT_TRUE(item.HasValue()); @@ -1109,7 +1109,7 @@ TEST(parsertests, test40_parse_operand_string_escape_seq) auto item = p.Parse(v); - std::unordered_set strings = {" \" ' \\ \a \b \f \n \r \t \v "}; + Program::StringT strings = {" \" ' \\ \a \b \f \n \r \t \v "}; ASSERT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); ASSERT_TRUE(item.HasValue()); @@ -1216,7 +1216,7 @@ TEST(parsertests, test41_parse_operand_string_hex_escape_seq) auto item = p.Parse(v); - std::unordered_set strings = {"123\xaa\x65"}; + Program::StringT strings = {"123\xaa\x65"}; ASSERT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); ASSERT_TRUE(item.HasValue()); @@ -1238,7 +1238,7 @@ TEST(parsertests, test42_parse_operand_string_octal_escape_seq) auto item = p.Parse(v); - std::unordered_set strings = {"123\1\02\00123"}; + Program::StringT strings = {"123\1\02\00123"}; ASSERT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); ASSERT_TRUE(item.HasValue()); diff --git a/plugins/ets/CMakeLists.txt b/plugins/ets/CMakeLists.txt index 8d5fa9b3d..5edb47edc 100644 --- a/plugins/ets/CMakeLists.txt +++ b/plugins/ets/CMakeLists.txt @@ -20,6 +20,46 @@ include(cmake/import.cmake) add_custom_target(ets_tests COMMENT "Running ets test suites") +function(compile_ets_code ETS_SRC OUTPUT_ABC TARGET) + set(oneValueArgs OPT_LEVEL) + cmake_parse_arguments(ARG "" "${oneValueArgs}" "" ${ARGN}) + + if (NOT DEFINED ARG_OPT_LEVEL) + set(ARG_OPT_LEVEL 2) + endif() + + set(ES2PANDA_ARGUMENTS + --opt-level=${ARG_OPT_LEVEL} + --thread=0 + --extension=ets + --output=${OUTPUT_ABC} + ) + set(COMPILE_DEPENDENCIES + ${es2panda_target} + ) + + get_filename_component(OUTPUT_DIR ${OUTPUT_ABC} DIRECTORY) + file(MAKE_DIRECTORY ${OUTPUT_DIR}) + + if ("${ETS_SRC}" STREQUAL "GEN_STD_LIB") + list(APPEND ES2PANDA_ARGUMENTS "--gen-stdlib=true") + else() + list(APPEND ES2PANDA_ARGUMENTS ${ETS_SRC}) + list(APPEND COMPILE_DEPENDENCIES etsstdlib ${ETS_SRC}) + endif() + + add_custom_command( + OUTPUT ${OUTPUT_ABC} + COMMENT "Running es2panda for ets file: ${ETS_SRC}" + COMMAND ${es2panda_bin} ${ES2PANDA_ARGUMENTS} + DEPENDS ${COMPILE_DEPENDENCIES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + + add_custom_target(${TARGET} DEPENDS ${OUTPUT_ABC}) +endfunction() + + # NB! ADDING THIS PROPERTY IS ALLOWED ONLY IN SPECIAL CASES. DO NOT COPY-PASTE IT. set_target_properties(ets_tests PROPERTIES first-level-tests-dependency TRUE) add_dependencies(tests ets_tests) @@ -52,15 +92,7 @@ add_subdirectory(arkts_header) # TODO(nsizov): change this logic when ets compiler moved into ets plugin if(TARGET es2panda) - add_custom_target(etsstdlib) - add_dependencies(etsstdlib ${es2panda_target}) - - add_custom_command(TARGET etsstdlib - COMMAND ${es2panda_bin} --gen-stdlib=true - --extension=ets - --output=${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.abc - --opt-level=2 - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + compile_ets_code(GEN_STD_LIB "${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.abc" etsstdlib) set_target_properties(etsstdlib PROPERTIES FILE "${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.abc") add_dependencies(ark etsstdlib) diff --git a/plugins/ets/tests/CMakeLists.txt b/plugins/ets/tests/CMakeLists.txt index d501b238c..49034e2a9 100644 --- a/plugins/ets/tests/CMakeLists.txt +++ b/plugins/ets/tests/CMakeLists.txt @@ -54,33 +54,45 @@ panda_add_asm_file( add_dependencies(tests ets_tests) -function(compile_ets_code ETS_SRC OUTPUT_ABC TARGET) - set(oneValueArgs OPT_LEVEL) +function(run_deterministic_tests ETS_SRC TARGET) + set(oneValueArgs ITER_NUM) + cmake_parse_arguments(ARG "" "${oneValueArgs}" "" ${ARGN}) - if (NOT DEFINED ARG_OPT_LEVEL) - set(ARG_OPT_LEVEL 2) + if (NOT DEFINED ARG_ITER_NUM) + SET(ARG_ITER_NUM 50) endif() - set(ES2PANDA_ARGUMENTS - --opt-level=${ARG_OPT_LEVEL} - --thread=0 - --extension=ets - --output=${OUTPUT_ABC} - ${ETS_SRC} - ) - - get_filename_component(OUTPUT_DIR ${OUTPUT_ABC} DIRECTORY) - file(MAKE_DIRECTORY ${OUTPUT_DIR}) - - add_custom_command( - OUTPUT ${OUTPUT_ABC} - COMMENT "Running es2panda for ets file: ${ETS_SRC}" - COMMAND ${es2panda_bin} ${ES2PANDA_ARGUMENTS} - DEPENDS es2panda etsstdlib ${ETS_SRC} - ) + + get_filename_component(SRC_FNAME ${ETS_SRC} NAME) - add_custom_target(${TARGET} DEPENDS ${OUTPUT_ABC}) + set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/${SRC_FNAME}") + file(MAKE_DIRECTORY "${TEST_DIR}") + set(DEPENDS_ON "") + + set(FIRST_ABC_APP_TARGET ${TARGET}-${SRC_FNAME}-0-ets-es2panda) + + foreach(i RANGE ${ARG_ITER_NUM}) + set(APP_FILE_OUTPUT "${TEST_DIR}/${i}.abc") + set(ABC_APP_TARGET ${TARGET}-${SRC_FNAME}-${i}-ets-es2panda) + list(APPEND all_bin_abc ${APP_FILE_OUTPUT}) + list(APPEND DEPENDS_ON "${ABC_APP_TARGET}") + compile_ets_code(${ETS_SRC} ${APP_FILE_OUTPUT} ${ABC_APP_TARGET}) + + set(target_name ${TARGET}_${SRC_FNAME}_${i}) + list(GET all_bin_abc 0 first) + add_custom_target( + ${target_name} + COMMAND bash -c "diff ${APP_FILE_OUTPUT} ${first}" + WORKING_DIRECTORY ${TEST_DIR} + COMMENT "Running ${TEST_NAME} determenistic compilation test" + DEPENDS ${ABC_APP_TARGET} ${FIRST_ABC_APP_TARGET} + ) + list(APPEND dependencies ${target_name}) + endforeach() + add_custom_target(${TARGET} + DEPENDS ${dependencies}) + add_dependencies(ets_tests ${TARGET}) endfunction() function(run_ets_code_verifier ETS_SRC WORK_DIR TARGET) @@ -288,6 +300,14 @@ function(run_aot_ets_code PAOC_MODE ETS_SRC WORK_DIR TARGET) add_dependencies(ets_tests ${TARGET}) endfunction() +function(run_deterministic_test ETS_SRC WORK_DIR TARGET) + # deterministic binary + run_deterministic_tests(${ETS_SRC} ${TARGET}-determ) + if(TARGET ${TARGET}-determ) + add_dependencies(${TARGET} ${TARGET}-determ) + endif() +endfunction() + function(run_int_jit_aot_ets_code ETS_SRC WORK_DIR TARGET) set(oneValueArgs OPT_LEVEL) set(noValues SKIP_ARM32_COMPILER) @@ -373,6 +393,11 @@ function(compile_stdlib TARGET_ARCH) endif() endfunction() +run_deterministic_tests(GEN_STD_LIB + ets-stdlib-deterministic + ITER_NUM 15) +add_dependencies(ets_tests ets-stdlib-deterministic) + add_custom_target(ets-func-tests-run) add_custom_target(ets-func-tests-run-int) add_custom_target(ets-func-tests-run-jit) diff --git a/plugins/ets/tests/common/bouncing_pandas/CMakeLists.txt b/plugins/ets/tests/common/bouncing_pandas/CMakeLists.txt index 821f4ef20..d3a8b5513 100644 --- a/plugins/ets/tests/common/bouncing_pandas/CMakeLists.txt +++ b/plugins/ets/tests/common/bouncing_pandas/CMakeLists.txt @@ -16,3 +16,4 @@ if (PANDA_TARGET_ARM32) endif() run_int_jit_aot_ets_code(${CMAKE_CURRENT_SOURCE_DIR}/bouncing_pandas.ets ${CMAKE_CURRENT_BINARY_DIR} bouncing_pandas_ets) +run_deterministic_test(${CMAKE_CURRENT_SOURCE_DIR}/bouncing_pandas.ets ${CMAKE_CURRENT_BINARY_DIR} bouncing_pandas_ets) diff --git a/plugins/ets/tests/common/bouncing_peas/CMakeLists.txt b/plugins/ets/tests/common/bouncing_peas/CMakeLists.txt index 9ba1ab0d3..dd0a6d860 100644 --- a/plugins/ets/tests/common/bouncing_peas/CMakeLists.txt +++ b/plugins/ets/tests/common/bouncing_peas/CMakeLists.txt @@ -16,6 +16,7 @@ if (PANDA_TARGET_ARM32) endif() run_int_jit_aot_ets_code(${CMAKE_CURRENT_SOURCE_DIR}/bouncing_peas.ets ${CMAKE_CURRENT_BINARY_DIR} bouncing_peas_ets) +run_deterministic_test(${CMAKE_CURRENT_SOURCE_DIR}/bouncing_peas.ets ${CMAKE_CURRENT_BINARY_DIR} bouncing_peas_ets) set(OUTPUT_ABC ${CMAKE_CURRENT_BINARY_DIR}/bouncing_peas_unit_native.abc) compile_ets_code( -- Gitee