Debian Codegraph @

check/internal-tests/mnemonic_parser_t.c

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "mnemonic_parser_t.h"
21
22 #include <fcml_mnemonic_parser.h>
23
24 #include <fcml_common.h>
25
26 fcml_bool fcml_tf_mnemonic_parser_suite_init(void) {
27 return FCML_TRUE;
28 }
29
30 fcml_bool fcml_tf_mnemonic_parser_suite_cleanup(void) {
31 return FCML_TRUE;
32 }
33
34 void fcml_tf_mnemonic_parser_test_parse_mnemonics(void) {
35
36 fcml_st_mp_mnemonic_set *mnemonics_set;
37
38 fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmps[sb,mm];cmpsw[ts,o*,aw,sf,mr];cmpsd[ts,o*,ad,sf];cmpsq[ts,o*,aq,sf]", &mnemonics_set );
39 STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );
40
41 fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
42 fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
43 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmps" );
44 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
45 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
46 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
47 STF_ASSERT_EQUAL( mnemonic->is_byte_ds, FCML_TRUE );
48 STF_ASSERT_EQUAL( mnemonic->is_full_ds, FCML_FALSE );
49 STF_ASSERT_EQUAL( mnemonic->is_mode_mem_only, FCML_TRUE );
50 STF_ASSERT_EQUAL( mnemonic->is_mode_reg_only, FCML_FALSE );
51
52 element = element->next;
53 mnemonic = (fcml_st_mp_mnemonic*)element->item;
54 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpsw" );
55 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
56 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_16 );
57 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
58 STF_ASSERT_EQUAL( mnemonic->is_byte_ds, FCML_FALSE );
59 STF_ASSERT_EQUAL( mnemonic->is_full_ds, FCML_TRUE );
60 STF_ASSERT_EQUAL( mnemonic->is_mode_mem_only, FCML_FALSE );
61 STF_ASSERT_EQUAL( mnemonic->is_mode_reg_only, FCML_TRUE );
62
63 element = element->next;
64 mnemonic = (fcml_st_mp_mnemonic*)element->item;
65 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpsd" );
66 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
67 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_32 );
68 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
69
70 element = element->next;
71 mnemonic = (fcml_st_mp_mnemonic*)element->item;
72 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpsq" );
73 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
74 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_64 );
75 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
76
77 STF_ASSERT_PTR_NULL( element->next );
78
79 fcml_fn_mp_free_mnemonics( mnemonics_set );
80 }
81
82 void fcml_tf_mnemonic_parser_test_parse_mnemonics_1(void) {
83
84 fcml_st_mp_mnemonic_set *mnemonics_set;
85
86 fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmps;", &mnemonics_set );
87 STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );
88
89 fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
90 fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
91 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmps" );
92 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
93 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
94 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
95
96 STF_ASSERT_PTR_NULL( element->next );
97
98 fcml_fn_mp_free_mnemonics( mnemonics_set );
99 }
100
101 void fcml_tf_mnemonic_parser_test_parse_mnemonics_2(void) {
102
103 fcml_st_mp_mnemonic_set *mnemonics_set;
104
105 fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmps[ts];", &mnemonics_set );
106 STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );
107
108 fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
109 fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
110 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmps" );
111 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_TRUE );
112 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
113 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
114
115 STF_ASSERT_PTR_NULL( element->next );
116
117 fcml_fn_mp_free_mnemonics( mnemonics_set );
118 }
119
120 fcml_string fcml_itb_bad_formatted_mnemonics[] = {
121 "",
122 ";",
123 ";[",
124 "[;",
125 ";;;;",
126 ";cmps",
127 "cmps[;",
128 "cmps[];",
129 "cmps];",
130 "cmps[[ts];",
131 "cmps[ts]];",
132 "cmps[ts;",
133 "cmps[ts",
134 "cmps[t",
135 "cmps[t]",
136 "cmps[bx]",
137 "cmps[om]",
138 "cm!ps",
139 " cmps",
140 "[]",
141 "cmps[oda",
142 "cmps]",
143 "cmps[odadddf]",
144 "cmps[od,,ad]",
145 "cmps[,od]",
146 "cmps[od,]",
147 "cmps[,]",
148 "cmps[,,]",
149 "cmps[,",
150 "cmps[ad;]",
151 };
152
153 void fcml_tf_mnemonic_parser_test_parse_mnemonics_3(void) {
154 int i;
155 for( i = 0; i < sizeof( fcml_itb_bad_formatted_mnemonics ) / sizeof( fcml_string ); i++ ) {
156 fcml_st_mp_mnemonic_set *mnemonics_set = NULL;
157 fcml_string mnemonic = fcml_itb_bad_formatted_mnemonics[i];
158 fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( mnemonic, &mnemonics_set );
159 /* printf("%d:%d\n", i, error);*/
160 STF_ASSERT_EQUAL( error, FCML_CEH_GEC_INVALID_INPUT );
161 STF_ASSERT_PTR_NULL( mnemonics_set );
162 }
163 }
164
165 void fcml_tf_mnemonic_parser_test_parse_mnemonics_4(void) {
166
167 fcml_st_mp_mnemonic_set *mnemonics_set;
168
169 fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmpordsd[p07]", &mnemonics_set );
170 STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );
171
172 fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
173 fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
174 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpordsd" );
175 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
176 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
177 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
178 STF_ASSERT_EQUAL( mnemonic->pseudo_op.is_not_null, FCML_TRUE );
179 STF_ASSERT_EQUAL( mnemonic->pseudo_op.value, 0x07 );
180
181 STF_ASSERT_PTR_NULL( element->next );
182
183 fcml_fn_mp_free_mnemonics( mnemonics_set );
184 }
185
186 void fcml_tf_mnemonic_parser_test_parse_mnemonics_5(void) {
187
188 fcml_st_mp_mnemonic_set *mnemonics_set;
189
190 fcml_ceh_error error = fcml_fn_mp_parse_mnemonics( "cmpordsd[S07]", &mnemonics_set );
191 STF_ASSERT_EQUAL( error, FCML_CEH_GEC_NO_ERROR );
192
193 fcml_st_coll_list_element *element = mnemonics_set->mnemonics->head;
194 fcml_st_mp_mnemonic *mnemonic = (fcml_st_mp_mnemonic*)element->item;
195 STF_ASSERT_STRING_EQUAL( mnemonic->mnemonic, "cmpordsd" );
196 STF_ASSERT_EQUAL( mnemonic->is_shortcut, FCML_FALSE );
197 STF_ASSERT_EQUAL( mnemonic->supported_asa, FCML_DS_UNDEF );
198 STF_ASSERT_EQUAL( mnemonic->supported_osa, FCML_DS_UNDEF );
199 STF_ASSERT_EQUAL( mnemonic->suffix.is_not_null, FCML_TRUE );
200 STF_ASSERT_EQUAL( mnemonic->suffix.value, 0x07 );
201
202 STF_ASSERT_PTR_NULL( element->next );
203
204 fcml_fn_mp_free_mnemonics( mnemonics_set );
205 }
206
207 fcml_stf_test_case fcml_ti_mnemonic_parser[] = {
208 { "fcml_tf_mnemonic_parser_test_parse_mnemonics", fcml_tf_mnemonic_parser_test_parse_mnemonics },
209 { "fcml_tf_mnemonic_parser_test_parse_mnemonics_1", fcml_tf_mnemonic_parser_test_parse_mnemonics_1 },
210 { "fcml_tf_mnemonic_parser_test_parse_mnemonics_2", fcml_tf_mnemonic_parser_test_parse_mnemonics_2 },
211 { "fcml_tf_mnemonic_parser_test_parse_mnemonics_3", fcml_tf_mnemonic_parser_test_parse_mnemonics_3 },
212 { "fcml_tf_mnemonic_parser_test_parse_mnemonics_4", fcml_tf_mnemonic_parser_test_parse_mnemonics_4 },
213 { "fcml_tf_mnemonic_parser_test_parse_mnemonics_5", fcml_tf_mnemonic_parser_test_parse_mnemonics_5 },
214 FCML_STF_NULL_TEST
215 };
216
217 fcml_stf_test_suite fcml_si_mnemonic_parser = {
218 "suite-fcml-mnemonic-parser", fcml_tf_mnemonic_parser_suite_init, fcml_tf_mnemonic_parser_suite_cleanup, fcml_ti_mnemonic_parser
219 };
220
221