OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 3 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 # | 6 # |
7 | 7 |
8 """ | 8 """ |
9 Responsible for generating the testing decoders based on | 9 Responsible for generating the testing decoders based on |
10 parsed table representations. | 10 parsed table representations. |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 NAMED_CLASSES_H_HEADER="""%(FILE_HEADER)s | 368 NAMED_CLASSES_H_HEADER="""%(FILE_HEADER)s |
369 %(NOT_TCB_MESSAGE)s | 369 %(NOT_TCB_MESSAGE)s |
370 | 370 |
371 #ifndef %(IFDEF_NAME)s | 371 #ifndef %(IFDEF_NAME)s |
372 #define %(IFDEF_NAME)s | 372 #define %(IFDEF_NAME)s |
373 | 373 |
374 #include "native_client/src/trusted/validator_arm/actual_classes.h" | 374 #include "native_client/src/trusted/validator_arm/actual_classes.h" |
375 #include "native_client/src/trusted/validator_arm/baseline_classes.h" | 375 #include "native_client/src/trusted/validator_arm/baseline_classes.h" |
376 #include "native_client/src/trusted/validator_arm/named_class_decoder.h" | 376 #include "native_client/src/trusted/validator_arm/named_class_decoder.h" |
377 #include "%(FILENAME_BASE)s_actuals.h" | 377 #include "%(FILENAME_BASE)s_actuals.h" |
| 378 |
378 #include "%(FILENAME_BASE)s_named_bases.h" | 379 #include "%(FILENAME_BASE)s_named_bases.h" |
379 """ | 380 """ |
380 | 381 |
381 RULE_CLASSES_HEADER=""" | 382 RULE_CLASSES_HEADER=""" |
382 /* | 383 /* |
383 * Define rule decoder classes. | 384 * Define rule decoder classes. |
384 */ | 385 */ |
385 namespace nacl_arm_dec { | 386 namespace nacl_arm_dec { |
386 | 387 |
387 """ | 388 """ |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 out.write(PARSE_TABLE_METHOD_ROW % values) | 746 out.write(PARSE_TABLE_METHOD_ROW % values) |
746 out.write(METHOD_DISPATCH_CLOSE) | 747 out.write(METHOD_DISPATCH_CLOSE) |
747 out.write(PARSE_TABLE_METHOD_FOOTER % values) | 748 out.write(PARSE_TABLE_METHOD_FOOTER % values) |
748 | 749 |
749 # Define the source for DECODER_tests.cc | 750 # Define the source for DECODER_tests.cc |
750 TEST_CC_HEADER="""%(FILE_HEADER)s | 751 TEST_CC_HEADER="""%(FILE_HEADER)s |
751 %(NOT_TCB_MESSAGE)s | 752 %(NOT_TCB_MESSAGE)s |
752 | 753 |
753 #include "gtest/gtest.h" | 754 #include "gtest/gtest.h" |
754 #include "native_client/src/trusted/validator_arm/actual_vs_baseline.h" | 755 #include "native_client/src/trusted/validator_arm/actual_vs_baseline.h" |
| 756 #include "native_client/src/trusted/validator_arm/baseline_vs_baseline.h" |
755 #include "native_client/src/trusted/validator_arm/actual_classes.h" | 757 #include "native_client/src/trusted/validator_arm/actual_classes.h" |
756 #include "native_client/src/trusted/validator_arm/baseline_classes.h" | 758 #include "native_client/src/trusted/validator_arm/baseline_classes.h" |
757 #include "native_client/src/trusted/validator_arm/inst_classes_testers.h" | 759 #include "native_client/src/trusted/validator_arm/inst_classes_testers.h" |
758 #include "native_client/src/trusted/validator_arm/arm_helpers.h" | 760 #include "native_client/src/trusted/validator_arm/arm_helpers.h" |
759 #include "native_client/src/trusted/validator_arm/gen/arm32_decode_named_bases.h
" | 761 #include "native_client/src/trusted/validator_arm/gen/arm32_decode_named_bases.h
" |
760 | 762 |
761 using nacl_arm_dec::Instruction; | 763 using nacl_arm_dec::Instruction; |
762 using nacl_arm_dec::ClassDecoder; | 764 using nacl_arm_dec::ClassDecoder; |
763 using nacl_arm_dec::Register; | 765 using nacl_arm_dec::Register; |
764 using nacl_arm_dec::RegisterList; | 766 using nacl_arm_dec::RegisterList; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 | 888 |
887 TEST_FUNCTION_BASELINE=""" | 889 TEST_FUNCTION_BASELINE=""" |
888 // %(row_comment)s | 890 // %(row_comment)s |
889 TEST_F(%(decoder_name)sTests, | 891 TEST_F(%(decoder_name)sTests, |
890 %(decoder_tester)s_Test%(test_pattern)s) { | 892 %(decoder_tester)s_Test%(test_pattern)s) { |
891 %(decoder_tester)s tester; | 893 %(decoder_tester)s tester; |
892 tester.Test("%(pattern)s"); | 894 tester.Test("%(pattern)s"); |
893 } | 895 } |
894 """ | 896 """ |
895 | 897 |
| 898 TEST_FUNCTION_BASELINE_VS_BASELINE=""" |
| 899 // %(row_comment)s |
| 900 TEST_F(%(decoder_name)sTests, |
| 901 BvB_%(decoder_tester)s_Test%(test_pattern)s) { |
| 902 %(decoder_tester)s old_baseline_tester; |
| 903 Named%(gen_decoder)s gen_baseline; |
| 904 BaselineVsBaselineTester b_vs_b_tester(gen_baseline, old_baseline_tester); |
| 905 b_vs_b_tester.Test("%(pattern)s"); |
| 906 } |
| 907 """ |
| 908 |
896 TEST_CC_FOOTER=""" | 909 TEST_CC_FOOTER=""" |
897 } // namespace nacl_arm_test | 910 } // namespace nacl_arm_test |
898 | 911 |
899 int main(int argc, char* argv[]) { | 912 int main(int argc, char* argv[]) { |
900 testing::InitGoogleTest(&argc, argv); | 913 testing::InitGoogleTest(&argc, argv); |
901 return RUN_ALL_TESTS(); | 914 return RUN_ALL_TESTS(); |
902 } | 915 } |
903 """ | 916 """ |
904 | 917 |
905 def generate_tests_cc(decoder, decoder_name, out, cl_args, tables): | 918 def generate_tests_cc(decoder, decoder_name, out, cl_args, tables): |
906 """Generates pattern tests for the rows in the given list of tables | 919 """Generates pattern tests for the rows in the given list of tables |
907 in the given decoder.""" | 920 in the given decoder.""" |
908 global _cl_args | 921 global _cl_args |
909 if not decoder.primary: raise Exception('No tables provided.') | 922 if not decoder.primary: raise Exception('No tables provided.') |
910 _cl_args = cl_args | 923 _cl_args = cl_args |
911 | 924 |
912 # Generate actuals from descriptions in tables, for each of the | 925 # Generate actuals from descriptions in tables, for each of the |
913 # tables that should automatically generate the corresponding | 926 # tables that should automatically generate the corresponding |
914 # needed actual class decoders. | 927 # needed actual class decoders. |
915 actuals = cl_args.get('auto-actual') | 928 actuals = cl_args.get('auto-actual') |
916 if actuals: | 929 if actuals: |
917 decoder = dgen_actuals.AddAutoActualsToDecoder(decoder, actuals) | 930 decoder = dgen_actuals.AddAutoActualsToDecoder(decoder, actuals) |
918 | 931 |
919 decoder = dgen_baselines.AddBaselinesToDecoder(decoder, tables) | 932 decoder = dgen_baselines.AddBaselinesToDecoder(decoder, tables) |
920 | 933 |
| 934 baselines = cl_args.get('test-base') |
| 935 if not baselines: baselines = [] |
| 936 |
921 decoder = _decoder_restricted_to_tables(decoder, tables) | 937 decoder = _decoder_restricted_to_tables(decoder, tables) |
922 | 938 |
923 values = { | 939 values = { |
924 'FILE_HEADER': dgen_output.HEADER_BOILERPLATE, | 940 'FILE_HEADER': dgen_output.HEADER_BOILERPLATE, |
925 'NOT_TCB_MESSAGE' : dgen_output.NOT_TCB_BOILERPLATE, | 941 'NOT_TCB_MESSAGE' : dgen_output.NOT_TCB_BOILERPLATE, |
926 'decoder_name': decoder_name, | 942 'decoder_name': decoder_name, |
927 } | 943 } |
928 out.write(TEST_CC_HEADER % values) | 944 out.write(TEST_CC_HEADER % values) |
929 _generate_constraint_testers(decoder, values, out) | 945 _generate_constraint_testers(decoder, values, out) |
930 _generate_rule_testers(decoder, values, out) | 946 _generate_rule_testers(decoder, values, out) |
931 out.write(TEST_HARNESS % values) | 947 out.write(TEST_HARNESS % values) |
932 _generate_test_patterns(decoder, values, out) | 948 _generate_test_patterns_with_baseline_tests(decoder, values, out, baselines) |
933 out.write(TEST_CC_FOOTER % values) | 949 out.write(TEST_CC_FOOTER % values) |
934 | 950 |
935 def _filter_test_action(action, with_patterns, with_rules): | 951 def _filter_test_action(action, with_patterns, with_rules): |
936 """Filters the actions to pull out relavant entries, based on whether we | 952 """Filters the actions to pull out relavant entries, based on whether we |
937 want to include patterns and rules. | 953 want to include patterns and rules. |
938 """ | 954 """ |
939 action_fields = ['actual', 'baseline', 'generated_baseline', | 955 action_fields = ['actual', 'baseline', 'generated_baseline', |
940 'constraints'] + dgen_decoder.METHODS | 956 'constraints'] + dgen_decoder.METHODS |
941 if with_patterns: | 957 if with_patterns: |
942 action_fields += ['pattern' ] | 958 action_fields += ['pattern' ] |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 or all tables if no names are specified. | 1100 or all tables if no names are specified. |
1085 """ | 1101 """ |
1086 if not tables: | 1102 if not tables: |
1087 return decoder | 1103 return decoder |
1088 new_decoder = dgen_core.Decoder() | 1104 new_decoder = dgen_core.Decoder() |
1089 for tbl in [tbl for tbl in decoder.tables() if tbl.name in tables]: | 1105 for tbl in [tbl for tbl in decoder.tables() if tbl.name in tables]: |
1090 new_decoder.add(tbl) | 1106 new_decoder.add(tbl) |
1091 new_decoder.set_class_defs(decoder.get_class_defs()) | 1107 new_decoder.set_class_defs(decoder.get_class_defs()) |
1092 return new_decoder | 1108 return new_decoder |
1093 | 1109 |
1094 def _generate_test_patterns(decoder, values, out): | 1110 def _generate_test_patterns_with_baseline_tests( |
| 1111 decoder, values, out, baseline_test_tables): |
| 1112 _generate_test_patterns(decoder, values, out, False) |
| 1113 _generate_test_patterns( |
| 1114 _decoder_restricted_to_tables(decoder, baseline_test_tables), |
| 1115 values, out, True) |
| 1116 |
| 1117 def _generate_test_patterns(decoder, values, out, add_baseline_tests): |
1095 """Generates a test function for each row having a pattern associated | 1118 """Generates a test function for each row having a pattern associated |
1096 with the table row. | 1119 with the table row. |
1097 """ | 1120 """ |
1098 rows = _rows_to_test(decoder, values, with_patterns=True) | 1121 rows = _rows_to_test(decoder, values, with_patterns=True) |
1099 values['test_rows'] = _index_neutral_map(rows) | 1122 values['test_rows'] = _index_neutral_map(rows) |
1100 for r in rows: | 1123 for r in rows: |
1101 _install_row_cases(r, values) | 1124 _install_row_cases(r, values) |
1102 row = _row_filter_interesting_patterns(r) | 1125 row = _row_filter_interesting_patterns(r) |
1103 action = _install_test_row(row, decoder, values, with_patterns=True) | 1126 action = _install_test_row(row, decoder, values, with_patterns=True) |
1104 if action.actual() == action.baseline(): | 1127 if add_baseline_tests: |
| 1128 if action.find('generated_baseline'): |
| 1129 values['gen_decoder'] = action.find('generated_baseline') |
| 1130 out.write(TEST_FUNCTION_BASELINE_VS_BASELINE % values) |
| 1131 elif action.actual() == action.baseline(): |
1105 out.write(TEST_FUNCTION_BASELINE % values) | 1132 out.write(TEST_FUNCTION_BASELINE % values) |
1106 else: | 1133 else: |
1107 out.write(TEST_FUNCTION_ACTUAL_VS_BASELINE % values) | 1134 out.write(TEST_FUNCTION_ACTUAL_VS_BASELINE % values) |
1108 | 1135 |
1109 def _index_neutral_map(values): | 1136 def _index_neutral_map(values): |
1110 """Returns a dictionary from each neutral_repr(value) in list | 1137 """Returns a dictionary from each neutral_repr(value) in list |
1111 values, to its corresponding index. This is done to reduce the | 1138 values, to its corresponding index. This is done to reduce the |
1112 number of compares to find the index, speeding up code | 1139 number of compares to find the index, speeding up code |
1113 generation. | 1140 generation. |
1114 """ | 1141 """ |
1115 lookup_map = {} | 1142 lookup_map = {} |
1116 index = 0 | 1143 index = 0 |
1117 for v in values: | 1144 for v in values: |
1118 lookup_map[dgen_core.neutral_repr(v)] = index | 1145 lookup_map[dgen_core.neutral_repr(v)] = index |
1119 index += 1 | 1146 index += 1 |
1120 return lookup_map | 1147 return lookup_map |
OLD | NEW |