pure.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import codecs
  2. import os
  3. import pytest
  4. import re
  5. import yql_utils
  6. import yatest.common
  7. from yql_utils import execute, get_tables, get_files, get_http_files, \
  8. KSV_ATTR, yql_binary_path, is_xfail, is_canonize_peephole, is_peephole_use_blocks, is_canonize_lineage, \
  9. is_skip_forceblocks, get_param, normalize_source_code_path, replace_vals, get_gateway_cfg_suffix, \
  10. do_custom_query_check, stable_result_file, stable_table_file, is_with_final_result_issues, \
  11. normalize_result
  12. from yqlrun import YQLRun
  13. from test_utils import get_config, get_parameters_json
  14. from test_file_common import run_file, run_file_no_cache, get_gateways_config, get_sql_query
  15. DATA_PATH = yatest.common.source_path('yql/essentials/tests/sql/suites')
  16. ASTDIFF_PATH = yql_binary_path('yql/essentials/tools/astdiff/astdiff')
  17. MINIRUN_PATH = yql_binary_path('yql/essentials/tools/minirun/minirun')
  18. def mode_expander(lst):
  19. res = []
  20. for (suite, case, cfg) in lst:
  21. res.append((suite, case, cfg, 'Results'))
  22. res.append((suite, case, cfg, 'Debug'))
  23. res.append((suite, case, cfg, 'RunOnOpt'))
  24. res.append((suite, case, cfg, 'LLVM'))
  25. if suite == 'blocks':
  26. res.append((suite, case, cfg, 'Blocks'))
  27. res.append((suite, case, cfg, 'Peephole'))
  28. return res
  29. def run_test(suite, case, cfg, tmpdir, what, yql_http_file_server):
  30. if get_gateway_cfg_suffix() != '' and what not in ('Results','LLVM','Blocks'):
  31. pytest.skip('non-trivial gateways.conf')
  32. config = get_config(suite, case, cfg, data_path = DATA_PATH)
  33. xfail = is_xfail(config)
  34. if xfail and what != 'Results':
  35. pytest.skip('xfail is not supported in this mode')
  36. program_sql = os.path.join(DATA_PATH, suite, '%s.sql' % case)
  37. with codecs.open(program_sql, encoding='utf-8') as program_file_descr:
  38. sql_query = program_file_descr.read()
  39. extra_final_args = []
  40. if is_with_final_result_issues(config):
  41. extra_final_args += ['--with-final-issues']
  42. (res, tables_res) = run_file('pure', suite, case, cfg, config, yql_http_file_server, MINIRUN_PATH,
  43. extra_args=extra_final_args, allow_llvm=False, data_path=DATA_PATH)
  44. to_canonize = []
  45. assert xfail or os.path.exists(res.results_file)
  46. assert not tables_res
  47. if what == 'Peephole':
  48. canonize_peephole = is_canonize_peephole(config)
  49. if not canonize_peephole:
  50. canonize_peephole = re.search(r"canonize peephole", sql_query)
  51. if not canonize_peephole:
  52. pytest.skip('no peephole canonization requested')
  53. force_blocks = is_peephole_use_blocks(config)
  54. (res, tables_res) = run_file_no_cache('pure', suite, case, cfg, config, yql_http_file_server,
  55. force_blocks=force_blocks, extra_args=['--peephole'],
  56. data_path=DATA_PATH, yqlrun_binary=MINIRUN_PATH)
  57. return [yatest.common.canonical_file(res.opt_file, diff_tool=ASTDIFF_PATH)]
  58. if what == 'Results':
  59. if xfail:
  60. return None
  61. if do_custom_query_check(res, sql_query):
  62. return None
  63. stable_result_file(res)
  64. to_canonize.append(yatest.common.canonical_file(res.results_file))
  65. if res.std_err:
  66. to_canonize.append(normalize_source_code_path(res.std_err))
  67. if what == 'Debug':
  68. to_canonize = [yatest.common.canonical_file(res.opt_file, diff_tool=ASTDIFF_PATH)]
  69. if what == 'RunOnOpt' or what == 'LLVM' or what == 'Blocks':
  70. is_on_opt = (what == 'RunOnOpt')
  71. is_llvm = (what == 'LLVM')
  72. is_blocks = (what == 'Blocks')
  73. files = get_files(suite, config, DATA_PATH)
  74. http_files = get_http_files(suite, config, DATA_PATH)
  75. http_files_urls = yql_http_file_server.register_files({}, http_files)
  76. parameters = get_parameters_json(suite, config, DATA_PATH)
  77. query_sql = get_sql_query('pure', suite, case, config, DATA_PATH) if not is_on_opt else None
  78. yqlrun = YQLRun(
  79. prov='pure',
  80. keep_temp=False,
  81. gateway_config=get_gateways_config(http_files, yql_http_file_server, allow_llvm=is_llvm, force_blocks=is_blocks),
  82. udfs_dir=yql_binary_path('yql/essentials/tests/common/test_framework/udfs_deps'),
  83. binary=MINIRUN_PATH
  84. )
  85. opt_res, opt_tables_res = execute(
  86. yqlrun,
  87. program=res.opt if is_on_opt else query_sql,
  88. run_sql=not is_on_opt,
  89. files=files,
  90. urls=http_files_urls,
  91. check_error=True,
  92. verbose=True,
  93. parameters=parameters)
  94. assert os.path.exists(opt_res.results_file)
  95. assert not opt_tables_res
  96. base_res_yson = normalize_result(stable_result_file(res), False)
  97. opt_res_yson = normalize_result(stable_result_file(opt_res), False)
  98. # Compare results
  99. assert opt_res_yson == base_res_yson, 'RESULTS_DIFFER\n' \
  100. 'Result:\n %(opt_res_yson)s\n\n' \
  101. 'Base result:\n %(base_res_yson)s\n' % locals()
  102. return None
  103. return to_canonize